Given a corner x
of an undirected Graph G
I would like to ask for the connected component of x
, but my first try does not work as desired. Here it is:
edge( a,b ).
edge( b,a ).
edge( b,c ).
edge( c,b ).
edge( c,d ).
edge( d,c ).
connected( X,X ).
connected( X,Y ) :- edge(X,Y).
connected( X,Y ) :- \+ edge(X,Y), edge( X,Z ), connected( Z,Y ).
And here are my queries and the results:
| ?- connected(b,What).
What = b ? ;
What = a ? ;
What = c ? ;
no
| ?- connected(b,b).
true ? ;
true ? ;
true ? ;
no
Why is corner b
not connected to corner d
? Why is corner b
connected to itself three times? I am afraid of other problems I will get with more complex graphs. Are there any?