Hi can you help please? I am new to perl and i'm trying to run the code below to calculate the shortest path using Floyd-Warshall algorithm. The code is directly copied from "Mastering algorithm with perl" from O'Reilliy media. The problem is when i run the code i don't get any results and i get the following message "get_attribute: not a compat02 graph ". Am i missing a module? Can anyone help please? thanks in advance. filipo.

#!/usr/bin/perl -w use strict; use Graph; use Graph::Directed; #how to use the Floyd-Warshall code 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->get_attribute("weight", $u, $v); if (defined $w) { my $p = $APSP->get_attribute("path", $u, $v); printf "(%-5s)=%d ", "@$p", $w } else { printf "%-9s ", "-" } } print "\n" }

In reply to calculating shortest path using Floyd-Warshall with perl by filipo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.