Subject: | Problem with APSP and default weight 1 |
as shown in the attached script:
- I define a graph with vertices a,b,c and two edges (a,b) (length 0)
and (b,c) (length 1)
- I compute the all-pairs-shortest-paths with Floyd-Warshall
- I ask for the length of the shortest path between a and c
I get 2 instead of 1.
I guess this has to do with the fact that "If no weight is defined for
an edge, 1 (one) is assumed".
However, I have explicitly defined the weight of (a,b) to be 0, so I
would expect that the default does not apply.
My problem is that I need to define some 0-length and compute the APSP.
thank you
Subject: | weight.pl |
use Graph;
use feature say;
my $g = new Graph();
$g->add_vertex('a');
$g->add_vertex('b');
$g->add_vertex('c');
$g->add_weighted_edge('a','b',0);
$g->add_weighted_edge('b','c',1);
my $apsp = $g->APSP_Floyd_Warshall;
my $w = $apsp->path_length('a','c');
say $w;