我有以下简单的图表:
x <---> y <---> z
edge(x,y).
edge(y,z).
path(Start,End,Path) :- % path/3: there is a `Path` from `Start` to `End`
path(Start,End,[Start],Path).
path(End,End,RPath,Path) :- % internal helper predicate `path/4`
reverse(RPath,Path).
path(Start,End,Visited,Path) :-
edge(Start,Next),
\+ memberchk(Next,Visited),
path(Next,End,[Next|Visited],Path).
示例查询:
?- path(x,z,P).
P = [x, y, z] ; % works as expected
false.
?- path(z,x,P).
false. % unexpectedly fails!
我该怎么做才能使上述查询成功?