Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
edge(a,b). edge(a,c). edge(b,c). edge(c,d). visit(A,B) :- traverse(A,B,P), display_path(P). traverse(A,B,P) :- % we can get from A to B iff... traverse(A,B,[A],P). % - we invoke the helper, seeding the list of visited nodes with A, the origin node % --------------------------------------- % traverse(Origin, Destination, Visited ) % --------------------------------------- traverse( A , B , V, P ) :- % we can get from A to B iff... edge(A,B), % - A and B are directly connected, reverse([B|V],P). traverse( A , B , V, P ) :- % Otherwise, we can get from A to B iff... edge(A,X), % - An edge exists from A to X, and not_visited(X,V), % - We have not yet visited X, and traverse(X,B,[X|V],P). % - We can get from X to B not_visited(N,V) :- % we haven't visited node N... \+ member(N,V). % - if N is not contained in the list of visited nodes (V). display_path([]). display_path([_]). display_path([A,B|Ns]) :- display_leg(A,B), display_path([B|Ns]). display_leg(From,To) :- write(From), write(' --> '), write(To), nl.