Skip Menu |

This queue is for tickets about the Graph-Easy CPAN distribution.

Report information
The Basics
Id: 39075
Status: open
Worked: 10 min
Priority: 0/
Queue: Graph-Easy

People
Owner: TELS [...] cpan.org
Requestors: dhorne [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.76
Fixed in: (no value)



Subject: Can get multiple edges per Graph when nodes defined more than once
Hi, If I add nodes that I have already added, and edges using the add_edge_once method, it is possible to have more than one edge between two nodes. Test case: use Graph::Easy; $graph = Graph::Easy->new; my $START1 = $graph->add_node('START1'); $FORK = $graph->add_node('FORK'); $graph->add_edge_once( $START1, $FORK ); $DMT_TOU_SERVICE_POINTS_FLW = $graph->add_node('DMT_TOU_SERVICE_POINTS_FLW'); $graph->add_edge_once( $FORK, $DMT_TOU_SERVICE_POINTS_FLW ); $AND_ACTIVITY = $graph->add_node('AND_ACTIVITY'); $graph->add_edge_once( $DMT_TOU_SERVICE_POINTS_FLW, $AND_ACTIVITY ); $DMT_ACCOUNT_GROUPS_FLW = $graph->add_node('DMT_ACCOUNT_GROUPS_FLW'); $graph->add_edge_once( $AND_ACTIVITY, $DMT_ACCOUNT_GROUPS_FLW ); $DMT_PROSPECT_AND_LOSSES_FLW = $graph->add_node('DMT_PROSPECT_AND_LOSSES_FLW'); $graph->add_edge_once( $DMT_ACCOUNT_GROUPS_FLW, $DMT_PROSPECT_AND_LOSSES_FLW ); $END_SUCCESS = $graph->add_node('END_SUCCESS'); $graph->add_edge_once( $DMT_PROSPECT_AND_LOSSES_FLW, $END_SUCCESS ); $DMT_TOU_CUST_ACCOUNTS_FLW = $graph->add_node('DMT_TOU_CUST_ACCOUNTS_FLW'); $graph->add_edge_once( $FORK, $DMT_TOU_CUST_ACCOUNTS_FLW ); $AND_ACTIVITY = $graph->add_node('AND_ACTIVITY'); $graph->add_edge_once( $DMT_TOU_CUST_ACCOUNTS_FLW, $AND_ACTIVITY ); $DMT_ACCOUNT_GROUPS_FLW = $graph->add_node('DMT_ACCOUNT_GROUPS_FLW'); $graph->add_edge_once( $AND_ACTIVITY, $DMT_ACCOUNT_GROUPS_FLW ); $DMT_PROSPECT_AND_LOSSES_FLW = $graph->add_node('DMT_PROSPECT_AND_LOSSES_FLW'); $graph->add_edge_once( $DMT_ACCOUNT_GROUPS_FLW, $DMT_PROSPECT_AND_LOSSES_FLW ); $END_SUCCESS = $graph->add_node('END_SUCCESS'); $graph->add_edge_once( $DMT_PROSPECT_AND_LOSSES_FLW, $END_SUCCESS ); $DMT_CUST_ACCOUNTS_FLW = $graph->add_node('DMT_CUST_ACCOUNTS_FLW'); $graph->add_edge_once( $FORK, $DMT_CUST_ACCOUNTS_FLW ); $AND_ACTIVITY = $graph->add_node('AND_ACTIVITY'); $graph->add_edge_once( $DMT_CUST_ACCOUNTS_FLW, $AND_ACTIVITY ); $DMT_ACCOUNT_GROUPS_FLW = $graph->add_node('DMT_ACCOUNT_GROUPS_FLW'); $graph->add_edge_once( $AND_ACTIVITY, $DMT_ACCOUNT_GROUPS_FLW ); $DMT_PROSPECT_AND_LOSSES_FLW = $graph->add_node('DMT_PROSPECT_AND_LOSSES_FLW'); $graph->add_edge_once( $DMT_ACCOUNT_GROUPS_FLW, $DMT_PROSPECT_AND_LOSSES_FLW ); $END_SUCCESS = $graph->add_node('END_SUCCESS'); $graph->add_edge_once( $DMT_PROSPECT_AND_LOSSES_FLW, $END_SUCCESS ); $DMT_CAMPAIGNS_FLW = $graph->add_node('DMT_CAMPAIGNS_FLW'); $graph->add_edge_once( $FORK, $DMT_CAMPAIGNS_FLW ); $AND_ACTIVITY = $graph->add_node('AND_ACTIVITY'); $graph->add_edge_once( $DMT_CAMPAIGNS_FLW, $AND_ACTIVITY ); $DMT_ACCOUNT_GROUPS_FLW = $graph->add_node('DMT_ACCOUNT_GROUPS_FLW'); $graph->add_edge_once( $AND_ACTIVITY, $DMT_ACCOUNT_GROUPS_FLW ); $DMT_PROSPECT_AND_LOSSES_FLW = $graph->add_node('DMT_PROSPECT_AND_LOSSES_FLW'); $graph->add_edge_once( $DMT_ACCOUNT_GROUPS_FLW, $DMT_PROSPECT_AND_LOSSES_FLW ); $END_SUCCESS = $graph->add_node('END_SUCCESS'); $graph->add_edge_once( $DMT_PROSPECT_AND_LOSSES_FLW, $END_SUCCESS ); $graph->set_attribute( 'flow', 'south' ); print $graph->as_ascii; If I add the edge between the node names rather than the node objects, I don't get multiple edges, i.e.: $graph->add_edge_once( 'DMT_PROSPECT_AND_LOSSES_FLW', 'END_SUCCESS' ); vs $graph->add_edge_once( $DMT_PROSPECT_AND_LOSSES_FLW, $END_SUCCESS ); Now it probably isn't a good idea to add a node more than once, but according to the documentation it should have no effect. Note this problem does not occur in 0.60 (I cannot test in any versions other then 0.60 and 0.63) Regards Dan
Duh. My test case could be much simpler: use Graph::Easy; my $graph = Graph::Easy->new; for (1..10) { $source = $graph->add_node("source"); $target = $graph->add_node("target"); $edge = $graph->add_edge_once($source, $target); } print $graph->as_ascii; I've attached a patch which I believe fixes the problem
--- Easy.pm Sat May 17 19:19:56 2008 +++ Easy.pm.new Mon Sep 08 14:11:04 2008 @@ -513,20 +513,8 @@ my ($self, $x, $y, $edge) = @_; # got an edge object? Don't add it twice! - return undef if ref($edge); - - # turn plaintext scalars into objects - my $x1 = $self->{nodes}->{$x} unless ref $x; - my $y1 = $self->{nodes}->{$y} unless ref $y; - - # nodes do exist => maybe the edge also exists - if (ref($x1) && ref($y1)) - { - my @ids = $x1->edges_to($y1); - - return undef if @ids; # found already one edge? - } - + return undef if ref($edge); + return undef if $self->edge($x, $y); $self->add_edge($x,$y,$edge); }
On Sun Sep 07 22:28:51 2008, DHORNE wrote: Show quoted text
> Duh. My test case could be much simpler: > > use Graph::Easy; > > my $graph = Graph::Easy->new; > > for (1..10) { > $source = $graph->add_node("source"); > $target = $graph->add_node("target"); > $edge = $graph->add_edge_once($source, $target); > } > > > print $graph->as_ascii;
It is even simpler, you don't need to add the nodes even. Just calling add_edge_once() with objects instead of "names" is enough. Oops. I forgot to include that fix in 0.64, will be in v0.65. Sorry for the delay :)