NAME
Graph::ChainBuilder - build directed 2-regular cyclic graphs
SYNOPSIS
This object collects data into a set of ordered chains, allowing you to organize e.g. edges AB,CD,AD,CB into the circular sequence AB,BC,CD,DA while keeping track of the directionality of the input data.
my $graph = Graph::ChainBuilder->new;
while(whatever) {
...
$graph->add($p0, $p1, $data);
}
An edge is defined by the strings $p0 and $p1. The $data is whatever you want to associate with an edge.
foreach my $loop ($graph->loops) {
foreach my $edge (@$loop) {
...
$edge->data;
}
}
Limitations
This code will identify multiple independent loops in an arbitrary set of unordered edges, but assumes that all loops are closed and that no stray edges exist. The result is undefined if your input contains duplicate or dangling edges.
new
my $graph = Graph::ChainBuilder->new;
add
Adds an edge to the graph. The nodes $p0 and $p1 will be connected (if possible) to the existing loops.
$graph->add($p0, $p1, $data);
Attempting to add an edge with a point which has already been connected will throw an error.
new
my $e = Graph::ChainBuilder::edge->new($p0, $p1, $rev, $data);
AUTHOR
Eric Wilhelm @ <ewilhelm at cpan dot org>
http://scratchcomputing.com/
BUGS
If you found this module on CPAN, please report any bugs or feature requests through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
If you pulled this development version from my /svn/, please contact me directly.
COPYRIGHT
Copyright (C) 2009 Eric L. Wilhelm, All Rights Reserved.
NO WARRANTY
Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.