search.cpan.org is shutting down
Colin Wetherbee > Algorithm-Functional-BFS-0.01 > Algorithm::Functional::BFS
Module Version: 0.01

# NAME

Algorithm::Functional::BFS - A functional approach to the breadth-first search algorithm.

This implementation supports both cyclic and acyclic graphs but does not support edge or vertex weighting.

Version 0.01

# SYNOPSIS

```    use Algorithm::Functional::BFS;

my \$bfs = Algorithm::Functional::BFS->new
(
victory_func        => \$some_other_func,
);
# Get a list (ref) of all the routes from your start node to the node(s)
# that satisfy the victory condition.
my \$routes_ref = \$bfs->search(\$start_node);```

# METHODS

## new(%params)

Create a new Algorithm::Functional::BFS object with the specified parameters.

Required parameters:

```    adjacent_nodes_func:
A function (reference to a sub) that, given a node, returns an array ref
of adjacent nodes.  If the node has no adjacent nodes, this function must
return an empty array ref.

victory_func:
A function (referenec to a sub) that, given a node, returns a value that
evaluates to true if and only if the node satisfies the victory condition
of this search.```

Optional parameters:

```    include_start_node:
If this is a true value, then the start node is a candidate for the
victory condition.  That is, if the start node matches the victory
condition, then a single route will be returned by the search algorithm,
and that route will contain only the start node.

one_result:
If this is a true value, then the search stops after a single route is
found, instead of searching for all the routes that satisfy the victory
condition at the depth of the first route.```

## search(\$start_node)

```    Perform a breadth-first-search from the specified node until the depth at
which at least one node satisfies the victory condition.

Returns an array ref of routes.  Each route is an array ref of the nodes
that are along the route from the start node to the node at which the
victory condition was satisfied.  Because this implementation works on
cyclic graphs, multiple routes may be returned (and, indeed, multiple
nodes at the same depth level may satisfy the victory condition).  If the
"one_result" option was passed to the constructor, then only one route
will be returned, but it will still be encapsulated in another array ref.```

# AUTHOR

Colin Wetherbee, `<cww at cpan.org>`

# BUGS

Please file issues at this project's GitHub repository site.