Re: Graph Theory problem
From: Jeff Zucker <jeff_at_vpservices.com>
Date: Sun, 28 Oct 2001 15:31:21 -0800
Message-ID: <3BDC9549.A0E24EA6_at_vpservices.com>
> adding the
> base tables and pairs to the graph, then only taking the pairs as result,
> seems to give the results you desire
Date: Sun, 28 Oct 2001 15:31:21 -0800
Message-ID: <3BDC9549.A0E24EA6_at_vpservices.com>
Tom Renfro wrote:
>
> I think what you are wanting is a topological sort.
> my $G = new Graph::Undirected;
>...
> adding the
> base tables and pairs to the graph, then only taking the pairs as result,
> seems to give the results you desire
sub order_joins {
my $joins = shift;
My way seems like it is closer to what is actually being modeled, but
should it produce the same result? (in my test cases, it seems to)
my $G = new Graph::Directed;
foreach $pair (_at_$joins) {
my ($first,$second) = _at_$pair;
$G->add_path( $first, $second );
$G->add_path( $second, $first );
}
my(undef,$unconnected) = $G->strongly_connected_components();
return undef if $unconnected;
my %isa;
return [ grep !$isa{$_}++, $G->toposort ];
}
Thanks much Tom!
-- JeffReceived on Mon Oct 29 2001 - 00:31:21 CET