Skip Menu |

This queue is for tickets about the Graph CPAN distribution.

Report information
The Basics
Id: 6741
Status: resolved
Priority: 0/
Queue: Graph

People
Owner: Nobody in particular
Requestors: dmaltz [...] myprivacy.ca
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Documentation for params to Graph::Traversal and control of Traversal starting node
This is feature enhancement. I've written some documentation describing the params to Graph::Traversal. I've also added a few functions and their documentation to the Traversal object. graph() - an accessor that just returns the stored graph, but is handy to have in callback functions like those that might be registered with successor $S->travese_starting_at($v) - specifies a node to start the traversal from $S->travese_single_component_starting_at($v); - specifies a node to start the traversal from and specifies that if the graph is partitioned, constrain the traversal to the component containing $v.
Only in Graph-0.20105-cmu/: Makefile Only in Graph-0.20105-cmu/: blib diff -r -c Graph-0.20105/lib/Graph/Traversal.pm Graph-0.20105-cmu/lib/Graph/Traversal.pm *** Graph-0.20105/lib/Graph/Traversal.pm Sun Apr 4 16:19:45 2004 --- Graph-0.20105-cmu/lib/Graph/Traversal.pm Wed Jun 9 12:21:53 2004 *************** *** 3,8 **** --- 3,10 ---- use strict; local $^W = 1; + use Carp; + use Graph::Base; use vars qw(@ISA); *************** *** 38,44 **** $dfs = Graph::DFS->new($G, %param) $bfs = Graph::BFS->new($G, %param) ! I<%param documentation to be written> =cut --- 40,46 ---- $dfs = Graph::DFS->new($G, %param) $bfs = Graph::BFS->new($G, %param) ! See below for %param documentation. =cut *************** *** 436,442 **** --- 438,564 ---- =pod + =item graph + + my $G = $S->graph(); + + Returns the graph object that the search is operating over. + + =cut + + sub graph { + my $S = shift; + my $G = $S->{ G }; + + return $G; + } + + =pod + + =item traverse_single_component_starting_at + + $S->travese_single_component_starting_at($v); + + Tell search object to begin traversal at vertex $v, and stop when all + vertices in the component containing $v have been traversed. + + =cut + + sub traverse_single_component_starting_at { + my $S = shift; + my $start_vertex = shift; + + my $G = $S->{ G }; + + + croak "'$start_vertex' not in graph" if (!$G->has_vertex($start_vertex)); + + $S->{param}->{get_next_root} = + sub { + return (exists $_[0]->{vertex_found}->{$start_vertex} ? + undef : $start_vertex) + } + } + + + =pod + + =item traverse_starting_at + + $S->travese_starting_at($v); + + Tell search object to begin traversal at vertex $v. If there are + multiple components in the graph, the rest of the components will be + traversed starting at the node with highest degree. + + =cut + + sub traverse_starting_at { + my $S = shift; + my $start_vertex = shift; + + my $G = $S->{ G }; + + + croak "'$start_vertex' not in graph" if (!$G->has_vertex($start_vertex)); + + $S->{param}->{get_next_root} = $start_vertex; + } + + + =pod + =back + + =head1 USING PARAMS TO CONTROL THE SEARCH + + The following named parameters can be passed to new() when a search + object is created, or to some of the methods on the object. + Parameters passed to a method override the ones passed to new(). + + =head2 Controlling where the traversal starts + + =over + + =item get_next_root + + Used the determine the root vertex for the traversal. If it is a code + reference, the result of running it with parameters ($S, %param) will + be the next root. Otherwise it is assumed to be the next root vertex + as it is. + + See also C<traverse_starting_at()> and C<traverse_single_component_starting_at()> + + =back + + =head2 Invoking a callback as each edge is traversed + + Each of the following parameters is assumed to be bound to a closure + that will be called at the respective time with the arguments + (From_vertex, To_vertex, Ref_to_Search_Object). + + =over + + =item successor + + Called as each potential successor is expanded. Will be called once + for all reachable edges in graph. + + =item unseen_successor + + Called the first time vertex $v is found. + + =item seen_successor + + Called each subsequent time vertex $v is found. + + =back + + If there are multiple edges between $u and $v, either C<seen_sucessor> + or C<unseen_successo>r will be called for the first edge, depending on + whether $v has been visited before. C<seen_successor> will be called + once for each of the rest of the multiple edges. + =head1 COPYRIGHT Only in Graph-0.20105-cmu/lib/Graph: Traversal.pm~ Only in Graph-0.20105-cmu/: pm_to_blib
From: Dave Maltz <dmaltz [...] myprivacy.ca>
[guest - Wed Jun 23 17:13:51 2004]: Show quoted text
> This is feature enhancement. > > I've written some documentation describing the params to > Graph::Traversal. > I've also added a few functions and their documentation to the > Traversal object.
I've got some more extensions and bug fixes. Email me if you want them. I may post another patch once they're ready and stable. Cheers, -dam
Graph 0.50 has a new better documented traversal interface.