I need to make a predicate isConnected/1
that takes a graph as an argument and determines if there is an undirected path between the pairs.
Suppose I have a list of edges (where G
is a graph):
isEdge(G,1,2).
isEdge(G,2,3).
isEdge(G,4,5).
So because there is no edge between 3 and 4 this should fail.
How would I approach this problem? Would I have to traverse though each edge and record the edges in a list? or is there a better approach to do this?
Assuming that this is a followup to this question:
First, you need to define what it means to be connected:
Then you need to determine the set of nodes. Commonly the set of nodes is given, but it seems you want them being defined implicitly through all the edges:
Now being connected means that each node is connected to all other nodes.
(All this assumes that the nodes are actually ground terms.)
Here are all the missing meta predicate declarations: