Hi everyone,
In short: I am trying to traverse an undirected graph in prolog, but don't know how to, any advise would be greatly appreciated.
Background:
Trying to model rail system, with stations as nodes and their links as edges with weight 1.
I had no problem doing it in a directed manner, but cant do it in an undirected graph.
From the net generally, i've learned that undirected graph is declared in the following way:
node(1).
node(2).
node(3).
node(4).
node(5).
node(6).
arc(1,2):-node(1),node(2),1==2.
arc(1,4):-node(1),node(4),1==4.
arc(2,3):-node(2),node(3),2==3.
arc(3,5):-node(3),node(5),3==5.
arc(4,5):-node(4),node(5),4==5.
arc(5,6):-node(5),node(6),5==6.
path(X,Z,A) :- (arc(X,Y),path(Y,Z,A1),A is A1+1;arc(X,Z), A is 1).
thus, the query path(1,2,X). should return 1, but it is not doing so...truly need help/guidance..thanks!