Subject: | set_edge_attribute_by_id() borken in 0.66 |
Graph 0.66 breaks Graph::Easy rather badly. My Graph::Easy package has a method that is called connetions() and returns the number of egdes coming in plus going out. For "A-B,C-B" it should return "2" for "B" as it does with Graph 0.65. With 0.66, it will return "3". Breakage ensues.
It seems either get_multiedge_ids() or set_edge_attribute_by_id() has changed somehow. Attached is a script to reproduce the symptom.
I am adding three vertices to the (multi-edged) graph, with two edges:
A => B
C => B
I also attach an attribute to the edges (as Graph::Easy does, one attribute per vertex and edge containing the pointer to the objects from the Graph::Easy name space).
When not commenting out the line to add the attribute, get_multiedge_ids() suddenlty returns "1 0" for "C => B", instead of the expected "0" (there is only one edge with the ID "0" from "C" to "B").
I do think the change from 0.65 to 0.66 is a bug.
The problem is probably somewhere in set_edge_attribute_by_id() but after tracking this down for a few hours I am too tired to look further. (It maybe thinks the edge does not yet exist and adds it again).
Best wishes,
Tels
use Graph;
use strict;
print "creating graph\n";
my $gr = Graph->new( multiedged => 1 );
my $A = { name => 'A' };
my $B = { name => 'B' };
my $C = { name => 'C' };
print "adding A => B\n";
add_edge ($gr,$A,$B);
dumper2($gr);
print "adding C => B\n";
add_edge( $gr, $C, $B );
dumper2($gr);
sub add_edge
{
my ($g,$x,$y) = @_;
my $edge_id = $g->add_edge_get_id($x->{name}, $y->{name});
# work around bug in Graph v0.65 returning something else instead of '0'
# on first call
$edge_id = '0' if ref($edge_id);
# comment this line out, and the dump changes
$g->set_edge_attribute_by_id( $x->{name}, $y->{name}, $edge_id, "OBJ", {});
}
sub dumper2
{
my @nodes = $gr->vertices();
for my $n (sort @nodes)
{
print "$n:\n";
print " successors : ", scalar $gr->successors($n),"\n";
print " predecessors : ", scalar $gr->predecessors($n),"\n";
my @suc = $gr->successors($n);
for my $s (@suc)
{
print " multiedge_ids $n => $s: ", join (", ", $gr->get_multiedge_ids($n, $s)),"\n";
}
my @pre = $gr->predecessors($n);
for my $p (@pre)
{
print " multiedge_ids $p => $n: ", join (", ", $gr->get_multiedge_ids($p, $n)),"\n";
}
}
}