You're calling an object method without constructing the object.
From your description, it sounds like you want a complete graph for the vertices listed in each element of list1.
That adds all the elements of list2 as vertices in the constructor, then adds edges for all pairs in each element of list1. Is that close to what you want?use Graph::Undirected; my @colors = qw( black white red green blue cyan magenta yellow); my @combos = ( [qw(black cyan yellow)], [qw(red white blue)], [qw(white blue)], [qw(green red)], [qw(cyan magenta)], [qw(yellow magenta)], [qw(magenta cyan)], [qw(magenta black yellow)], ); my $g = Graph::Undirected->new(@colors); for my $combo (@combos) { # Special case of all @$combo <= 3, the following # can be replaced by: # $g->add_cycle( @$combo); for my $pick (0..$#$combo-1) { $g->add_edge( $combo->[$pick], $combo->[$_]) for $pick+1..$#$ +combo; } } my @components = $g->strongly_connected_components; print "@$_", $/ for @components;
Update: Repaired a couple of typos and a harmless fencepost error in the inner loop which added self-edges to most vertices. Added comment with simpler code for the case that the @combos elements don't have more than three colors. In response to glwtta's reply, modified data to exhibit disconnected components and added component extraction code with the &Graph::Base::strongly_connected_components method. The Graph module has lots of methods like this, documented in Graph::Base
After Compline,
Zaxo
In reply to Re: using Graph::Undirected
by Zaxo
in thread using Graph::Undirected
by glwtta
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |