in reply to calculating shortest path using Floyd-Warshall with perl

The code uses an old API. Graph has changed significantly since the old versions. It keeps some compatibility API, but it does not seem to help here. Maybe this is what you needed?
#!/usr/bin/perl use warnings; use strict; use Graph; use Graph::Directed; my $g = 'Graph::Directed'->new; $g->add_weighted_path(qw(a 1 b 4 c 1 d)); $g->add_weighted_path(qw(a 3 f 1 e 2 d)); $g->add_weighted_edges(qw(a c 2 a d 4 b e 2 f d 2 )); my $APSP = $g->APSP_Floyd_Warshall; print " "; foreach my $v ($APSP->vertices ) { printf "%-9s ", "$v"; } print "\n"; foreach my $u ($APSP-> vertices ) { print "$u: "; foreach my $v ( $APSP->vertices ) { my $w = $APSP->path_length($u, $v); if ($w) { my @p = $APSP->path_vertices($u, $v); printf "(%-5s)=%d ", "@p", $w; } else { printf "%-9s ", "-" } } print "\n" }
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: calculating shortest path using Floyd-Warshall with perl
by filipo (Novice) on Aug 15, 2013 at 13:54 UTC

    Thanks so much that works. I suspected the book i was using may have being a bit old and could find a recent version of it. Thanks!