in reply to results from pairs combination
You are looking for connected subgraphs. Use the Graph module.
Or:use Graph; my @pairs=("a,b","c,b","d,f","e,b","f,g"); my $g = new Graph; for ( @pairs ) { my($x,$y) = split /,/; $g->add_edge($x,$y); } my @subgraphs = $g->weakly_connected_components; for my $subgraph ( @subgraphs ) { print "\nA subgraph:\n"; for my $v ( @$subgraph ) { my @s = $g->successors($v); print " $v-$_\n" for @s; } }
use Graph; use Data::Dumper; use strict; use warnings; my @pairs = qw( a,b c,b d,f e,b f,g ); my $g = new Graph edges => [ map [ split /,/ ], @pairs ]; my @av = map [ map { my $v = $_; map [$v,$_], $g->successors($v) } @$_ + ], $g->weakly_connected_components; print Dumper @av;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: results from pairs combination
by JadeNB (Chaplain) on Oct 01, 2008 at 22:34 UTC | |
by jdporter (Paladin) on Oct 01, 2008 at 22:46 UTC | |
by JadeNB (Chaplain) on Oct 01, 2008 at 22:54 UTC | |
by jdporter (Paladin) on Oct 02, 2008 at 14:33 UTC |