I am searching for paths using some generic definitions. For example, when I search for A
to B
, I actually want to find paths like A
to B
, A_1
to B_2
, A
to B_1
, or A_5
to B
.
The middle nodes traversed may or may not be have a suffix like _N based on the connections in the tree. My prolog statement is like below.
path(A,B,Path) :-
travel(A,B,[A],Q),
reverse(Q,Path).
travel(A,B,P,[B|P]) :-
arc(A,B).
travel(A,B,Visited,Path) :-
arc(A,C),
C \== B,
\+member(C,Visited),
travel(C,B,[C|Visited],Path).
Using this prolog code, I can find some paths but can not find others. For example, for the generic search criteria A -->15
Paths like (A, 1, 4, 7, 15) are ok,
Paths like (A, 1_1, 4_3, 7, 15) are also ok
Paths like
- (A_1, X, X, X, 15)
- (A, X, X, X, 15_2),
- (A_3, X, X, X, 15_1)
are not ok
Note: X is a placeholder for any node either with the underscore or not.
Can you please help me to find out the problem.
Many thanks, Ferda