Colin Wetherbee > Algorithm-Functional-BFS-0.01 > Algorithm::Functional::BFS

Download:
Algorithm-Functional-BFS-0.01.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  

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 ^

Version 0.01

SYNOPSIS ^

    use Algorithm::Functional::BFS;

    # Create your object.
    my $bfs = Algorithm::Functional::BFS->new
    (
        adjacent_nodes_func => $some_func,
        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.

LICENSE AND COPYRIGHT ^

Copyright 2012 Colin Wetherbee.

This program is distributed under the MIT (X11) License: http://www.opensource.org/licenses/mit-license.php

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

syntax highlighting: