Graph::RandomPath - Find a random path between two graph vertices
use Graph::RandomPath; my $generator = Graph::RandomPath->create_generator($g, $from, $to); say "Vertices on random path 1: ", join ' ', $generator->(); say "Vertices on random path 2: ", join ' ', $generator->();
Generates random paths between two vertices in a Graph.
Returns a reference to a sub routine that returns a list of vertices that describe a path from (inclusive) $start_vertex to $final_vertex (inclusive) in the Graph-compatible object $graph. The function stores a snapshot of the graph, modifications to the orignal graph are ignored. An exception is raised if no paths can be generated, e.g. when there is no path from $start_vertex to $final_vertex at all. The number of vertices in the path determines the length, edge weights are currently ignored.
$start_vertex
$final_vertex
$graph
The options hash %opt can set the following values:
%opt
The maximum length for generated paths. The default is 64.
64
None.
The create_generator function internally calls SPT_Dijkstra on a reduced graph containing only reachable vertices. Depending on how the supplied Graph object implements this method it might not work on large graphs due to the algorithmic complexity of the function.
create_generator
SPT_Dijkstra
Copyright (c) 2014 Bjoern Hoehrmann <bjoern@hoehrmann.de>. This module is licensed under the same terms as Perl itself.
To install Graph::RandomPath, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Graph::RandomPath
CPAN shell
perl -MCPAN -e shell install Graph::RandomPath
For more information on module installation, please visit the detailed CPAN module installation guide.