in reply to Finding connected components in a graph.
Update: If you also want to generate the subgraphs corresponding to the components, you can use the following code:print "Number: ", scalar @subgraphs, "\n"; print "First: ", @{ $subgraphs[0] }, "\n";
my @subg; for my $component (0 .. @subgraphs - 1) { $subg[$component] = Graph::Undirected->new; for my $i (0 .. $#a) { $subg[$component]->add_edge($a[$i], $b[$i]) if grep $_ eq $a[$i], @{ $subgraphs[$component] }; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding connected components in a graph.
by zing (Beadle) on Oct 03, 2012 at 15:50 UTC | |
by choroba (Cardinal) on Oct 03, 2012 at 15:56 UTC | |
by zing (Beadle) on Oct 03, 2012 at 16:04 UTC |