.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Graph::Traversal 3pm" .TH Graph::Traversal 3pm "2023-10-31" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Graph::Traversal \- traverse graphs .SH "SYNOPSIS" .IX Header "SYNOPSIS" Don't use Graph::Traversal directly, use Graph::Traversal::DFS or Graph::Traversal::BFS instead. .PP .Vb 6 \& use Graph; \& my $g = Graph\->new; \& $g\->add_edge(...); \& use Graph::Traversal::...; \& my $t = Graph::Traversal::...\->new($g, %opt); \& $t\->... .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" You can control how the graph is traversed by the various callback parameters in the \f(CW%opt\fR. In the parameters descriptions below the \&\f(CW$u\fR and \f(CW$v\fR are vertices, and the \f(CW$self\fR is the traversal object itself. .SS "Callback parameters" .IX Subsection "Callback parameters" The following callback parameters are available: .IP "tree_edge" 4 .IX Item "tree_edge" Called when traversing an edge that belongs to the traversal tree. Called with arguments ($u, \f(CW$v\fR, \f(CW$self\fR). .IP "non_tree_edge" 4 .IX Item "non_tree_edge" Called when an edge is met which either leads back to the traversal tree (either a \f(CW\*(C`back_edge\*(C'\fR, a \f(CW\*(C`down_edge\*(C'\fR, or a \f(CW\*(C`cross_edge\*(C'\fR). Called with arguments ($u, \f(CW$v\fR, \f(CW$self\fR). .IP "pre_edge" 4 .IX Item "pre_edge" Called for edges in preorder. Called with arguments ($u, \f(CW$v\fR, \f(CW$self\fR). .IP "post_edge" 4 .IX Item "post_edge" Called for edges in postorder. Called with arguments ($u, \f(CW$v\fR, \f(CW$self\fR). .IP "back_edge" 4 .IX Item "back_edge" Called for back edges. Called with arguments ($u, \f(CW$v\fR, \f(CW$self\fR). .IP "down_edge" 4 .IX Item "down_edge" Called for down edges. Called with arguments ($u, \f(CW$v\fR, \f(CW$self\fR). .IP "cross_edge" 4 .IX Item "cross_edge" Called for cross edges. Called with arguments ($u, \f(CW$v\fR, \f(CW$self\fR). .IP "pre" 4 .IX Item "pre" .PD 0 .IP "pre_vertex" 4 .IX Item "pre_vertex" .PD Called for vertices in preorder. Called with arguments ($v, \f(CW$self\fR). .IP "post" 4 .IX Item "post" .PD 0 .IP "post_vertex" 4 .IX Item "post_vertex" .PD Called for vertices in postorder. Called with arguments ($v, \f(CW$self\fR). .IP "first_root" 4 .IX Item "first_root" Called when choosing the first root (start) vertex for traversal. Called with arguments ($self, \f(CW$unseen\fR) where \f(CW$unseen\fR is a hash reference with the unseen vertices as keys. .IP "next_root" 4 .IX Item "next_root" Called when choosing the next root (after the first one) vertex for traversal (useful when the graph is not connected). Called with arguments ($self, \f(CW$unseen\fR) where \f(CW$unseen\fR is a hash reference with the unseen vertices as keys. If you want only the first reachable subgraph to be processed, set the next_root to \f(CW\*(C`undef\*(C'\fR. .IP "start" 4 .IX Item "start" Identical to defining \f(CW\*(C`first_root\*(C'\fR and undefining \f(CW\*(C`next_root\*(C'\fR. .IP "next_alphabetic" 4 .IX Item "next_alphabetic" Set this to true if you want the vertices to be processed in alphabetic order (and leave first_root/next_root undefined). .IP "next_numeric" 4 .IX Item "next_numeric" Set this to true if you want the vertices to be processed in numeric order (and leave first_root/next_root undefined). .IP "next_successor" 4 .IX Item "next_successor" Called when choosing the next vertex to visit. Called with arguments ($self, \f(CW$next\fR) where \f(CW$next\fR is a hash reference with the possible next vertices as keys. Use this to provide a custom ordering for choosing vertices, as opposed to \f(CW\*(C`next_numeric\*(C'\fR or \f(CW\*(C`next_alphabetic\*(C'\fR. .PP The parameters \f(CW\*(C`first_root\*(C'\fR and \f(CW\*(C`next_successor\*(C'\fR have a 'hierarchy' of how they are determined: if they have been explicitly defined, use that value. If not, use the value of \f(CW\*(C`next_alphabetic\*(C'\fR, if that has been defined. If not, use the value of \f(CW\*(C`next_numeric\*(C'\fR, if that has been defined. If not, the next vertex to be visited is chosen randomly. .SS "Methods" .IX Subsection "Methods" The following methods are available: .IP "unseen" 4 .IX Item "unseen" Return the unseen vertices in random order. .IP "seen" 4 .IX Item "seen" Return the seen vertices in random order. .IP "seeing" 4 .IX Item "seeing" Return the active fringe vertices in random order. .IP "preorder" 4 .IX Item "preorder" Return the vertices in preorder traversal order. .IP "postorder" 4 .IX Item "postorder" Return the vertices in postorder traversal order. .IP "vertex_by_preorder" 4 .IX Item "vertex_by_preorder" .Vb 1 \& $v = $t\->vertex_by_preorder($i) .Ve .Sp Return the ith (0..$V\-1) vertex by preorder. .IP "preorder_by_vertex" 4 .IX Item "preorder_by_vertex" .Vb 1 \& $i = $t\->preorder_by_vertex($v) .Ve .Sp Return the preorder index (0..$V\-1) by vertex. .IP "vertex_by_postorder" 4 .IX Item "vertex_by_postorder" .Vb 1 \& $v = $t\->vertex_by_postorder($i) .Ve .Sp Return the ith (0..$V\-1) vertex by postorder. .IP "postorder_by_vertex" 4 .IX Item "postorder_by_vertex" .Vb 1 \& $i = $t\->postorder_by_vertex($v) .Ve .Sp Return the postorder index (0..$V\-1) by vertex. .IP "preorder_vertices" 4 .IX Item "preorder_vertices" Return a hash with the vertices as the keys and their preorder indices as the values. .IP "postorder_vertices" 4 .IX Item "postorder_vertices" Return a hash with the vertices as the keys and their postorder indices as the values. .IP "tree" 4 .IX Item "tree" Return the traversal tree as a graph. .IP "has_state" 4 .IX Item "has_state" .Vb 1 \& $t\->has_state(\*(Aqs\*(Aq) .Ve .Sp Test whether the traversal has state 's' attached to it. .IP "get_state" 4 .IX Item "get_state" .Vb 1 \& $t\->get_state(\*(Aqs\*(Aq) .Ve .Sp Get the state 's' attached to the traversal (\f(CW\*(C`undef\*(C'\fR if none). .IP "set_state" 4 .IX Item "set_state" .Vb 1 \& $t\->set_state(\*(Aqs\*(Aq, $s) .Ve .Sp Set the state 's' attached to the traversal. .IP "delete_state" 4 .IX Item "delete_state" .Vb 1 \& $t\->delete_state(\*(Aqs\*(Aq) .Ve .Sp Delete the state 's' from the traversal. .SS "Special callbacks" .IX Subsection "Special callbacks" If in a callback you call the special \f(CW\*(C`terminate\*(C'\fR method, the traversal is terminated, no more vertices are traversed. .SH "SEE ALSO" .IX Header "SEE ALSO" Graph::Traversal::DFS, Graph::Traversal::BFS .SH "AUTHOR AND COPYRIGHT" .IX Header "AUTHOR AND COPYRIGHT" Jarkko Hietaniemi \fIjhi@iki.fi\fR .SH "LICENSE" .IX Header "LICENSE" This module is licensed under the same terms as Perl itself.