nosbod has asked for the wisdom of the Perl Monks concerning the following question:
I've tried to do this by calculating shortest paths between each pair of nodes but have the problem that implementations of shortest path algorithms will only return one path where there are multiple shortest paths of the same length. I need all shortest paths. For example, there a 2 paths of length 3 between nodes 1 and 4 in the following example. This bit of code will only return one of them
Anybody have any ideas?#!/usr/bin/perl use Boost::Graph; my $graph = new Boost::Graph(directed=>0, net_name=>'Graph Name', net_ +id=>1000); # add edges $graph->add_edge(node1=>'1', node2=>'2', weight=>1); $graph->add_edge(node1=>'1', node2=>'3', weight=>1); $graph->add_edge(node1=>'2', node2=>'4', weight=>1); $graph->add_edge(node1=>'3', node2=>'4', weight=>1); my $path=$graph->dijkstra_shortest_path('1','4'); print @{$path->{'path'}};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Graph modules
by tachyon-II (Chaplain) on May 19, 2008 at 13:22 UTC | |
by lima1 (Curate) on May 19, 2008 at 14:01 UTC | |
by nosbod (Scribe) on May 19, 2008 at 15:34 UTC | |
by nosbod (Scribe) on May 19, 2008 at 15:44 UTC | |
|
Re: Graph modules
by psini (Deacon) on May 19, 2008 at 11:08 UTC | |
|
Re: Graph modules
by dragonchild (Archbishop) on May 19, 2008 at 13:38 UTC | |
by nosbod (Scribe) on May 19, 2008 at 15:31 UTC | |
by dragonchild (Archbishop) on May 19, 2008 at 16:06 UTC |