A simple (?) graph algorithm

From: pimko (profesorpimko_at_wp.pl)
Date: 04/19/04


Date: 19 Apr 2004 00:41:08 -0700

Hi
I have a directed graph described as a set of edges:
edge(v1,v2).
edge(v2,v3).
edge(v2,v4).
edge(v4,v5).
(for example)
I've created a predicate connected(X,Y) which is true when there is a
path from X to Y:
connected(X,Y):-edge(X,Y).
connected(X,Y):-edge(X,Z),connected(Z,Y).

What I need is a predicate like allconnected(X,List) that would give
me a list of all vertices that are connected to X:
allconnected(v3,List). would give List=[v1,v2];
allconnected(v5,List). would give List=[v1,v2,v4].

How can I use the "connected" predicate to make "allconnected"
predicate? Or maybe there is a simpler way of doing this?
Please help

Best regards
Pimko