I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2012-08-21 18:52:15.719539-07 by zakihaider
How to use Paths-Graph to calculate shortest path
I am trying to write a code that can find shortest path between nodes. I tried Paths-Graph example it works well but as soon as i replaced node's names into their ip address it started showing error. my code is as below which seems not working.
data.txt contents: (10.0.0.128 =>{10.0.0.129=>3,10.0.0.129=>4,10.0.0.130=>3,10.0.0.131=>2,10.0.0.132=>1,10.0.0.133=>1, +10.0.0.134=>2,10.0.0.135=>4,10.0.0.136=>1,10.0.0.137=>4,10.0.0.138=>3}, 10.0.0.129 =>{10.0.0.128=>3,10.0.0.130=>1,10.0.0.131=>2,10.0.0.132=>1,10.0.0.133=>2,10.0.0.134=>1,1 +0.0.0.135=>2,10.0.0.136=3,10.0.0.137=>3,10.0.0.138=>4}, ); Code: open FILE, '<', "data.txt" or die $!; my %graph = <FILE> use Paths::Graph; my $g = Paths::Graph->new(-origin=>"10.0.0.128"=>"10.0.0.138",-graph=>\%graph); my @paths = $g->shortest_path(); for my $path (@paths) { print "Shortest Path:" . join ("->" , @$path) . " Cost:". $g->get_path_cost(@$path) ."\n"; }
Direct Responses: Write a response