Skip Menu |

This queue is for tickets about the Graph CPAN distribution.

Report information
The Basics
Id: 1784
Status: resolved
Priority: 0/
Queue: Graph

People
Owner: Nobody in particular
Requestors: ehs [...] pobox.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.20101
Fixed in: (no value)



Subject: storing objects in Graph
It would be nice to be able to add objects to the Graphs. I was using Graph::Directed and Graph::DFS to build a graph whose vertices were my own objects. This spelled trouble when I tried to do a DFS through my graph, and then used the retrieved objects, since they weren't all retrieved as objects. I tracked the source of my trouble in Graph::Traversal::reset() which creates a pool keyed to the vertices, which are stringified in the process. I've attached my test file that I was using to help locate where things were going wrong. I'm going to get around this by Data::Dumper::Dump'ing my object to a string, and then eval'ing after I get it back. I don't if it would be easy to have Graph::* support storing objects, but it would be nice. Please et me know if I'm somehow laboring under some kind of misunderstanding. //Ed
use Test::More ( no_plan ); use strict; use Graph::Directed; use Graph::DFS; use Data::Dumper; # create a graph my $v1 = foo->new( name => 'v1' ); my $v2 = foo->new( name => 'v2' ); my $v3 = foo->new( name => 'v3' ); my $G = Graph::Directed->new(); $G->add_path( $v1, $v2, $v3 ); # verify that our objects are in the graph foreach my $v ( $G->vertices() ) { isa_ok( $v, 'foo', "vertices() knows $v " ); } # now try to iterate through them with Graph::Traversal my $dfs = Graph::DFS->new( $G ); while ( my $v = $dfs->next_postorder() ) { isa_ok( $v, 'foo', "next_postorder() knows $v " ); } # foo class package foo; sub new { my ( $class, %opts ) = @_; return( bless { %opts } ); } sub name { my $self = shift; return( $self->{name} ); }
Date: Thu, 14 Nov 2002 02:56:22 +0200
From: Jarkko Hietaniemi <jhi [...] iki.fi>
To: Guest via RT <bug-Graph [...] rt.cpan.org>
Cc: "AdminCc of cpan Ticket #1784": ;
Subject: Re: [cpan #1784] storing objects in Graph
RT-Send-Cc:
Well, Ed, I didn't see your email address so I can't answer directly, but here's something from the new fully rewritten release of Graph I'm working on: $ perl -Ilib -MGraph -MMath::Complex -MDevel::Peek -wle '$x=cplx(1,2);$y=cplx(3,4);$g=Graph->new;$g->add_edge($x,$y);my @e = $g->edges; print "@{$e[0]}";$x->Im(5);print "@{$e[0]};$e[0]->[1]->Im(6);print $y' 1+2i 3+4i 1+5i 3+4i 3+6i So you can create an edge between two complex numbers (which, of course, are objects), and changes in the object will be visible in the graph (and vice versa). Estimated release date for this new rewrite? Sorry, I'm not going to give false hope by saying anything, I've been working on this on and off for years now. When it's ready. -- Jarkko Hietaniemi <jhi@iki.fi> http://www.iki.fi/jhi/ "There is this special biologist word we use for 'stable'. It is 'dead'." -- Jack Cohen
From: Dave Maltz <dmaltz [...] myprivacy.ca>
[guest - Wed Nov 13 16:19:16 2002]: Show quoted text
> It would be nice to be able to add objects to the Graphs. I was using > Graph::Directed and Graph::DFS to build a graph whose vertices were > my own objects. This spelled trouble when I tried to do a DFS > through my graph, and then used the retrieved objects, since they > weren't all retrieved as objects. > > I tracked the source of my trouble in Graph::Traversal::reset() which > creates a pool keyed to the vertices, which are stringified in the > process. I've attached my test file that I was using to help locate > where things were going wrong. > > I'm going to get around this by Data::Dumper::Dump'ing my object to a > string, and then eval'ing after I get it back. I don't if it would > be easy to have Graph::* support storing objects, but it would be > nice.
Thanks for tracking down the source of the bug and posting a nice example to exercise the bug. I think I've got an easier fix than Data::Dumper. I won't swear it's completely correct, but has held up in testing so far. Cheers, -dam Index: Traversal.pm =================================================================== RCS file: /afs/cs/project/enternet/cvs/perl-modules/Graph-0.20105/lib/Graph/Traversal.pm,v retrieving revision 1.3 diff -c -r1.3 Traversal.pm *** Traversal.pm 20 Sep 2004 14:49:33 -0000 1.3 --- Traversal.pm 21 Sep 2004 01:17:02 -0000 *************** *** 123,129 **** return $get_next_root; } } else { ! return $G->largest_out_degree( keys %{ $S->{ pool } } ); } } --- 123,133 ---- return $get_next_root; } } else { ! # the keys in the pool are the stringified versions of the vertices. ! # indirect through the Graph->{V} to get the actual vertex ! # see http://rt.cpan.org/NoAuth/Bug.html?id=1784 for more info. ! # This is a WAG based on some poking-around. -dam 9/20/04 ! return $G->{V}->{ $G->largest_out_degree( keys %{ $S->{ pool } } ) }; } }
This functionality now exists in Graph 0.50.