Last active
August 29, 2015 14:02
-
-
Save zkessin/43545458cd5c29088803 to your computer and use it in GitHub Desktop.
Code for partially ordered sets in prolog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
connected(A,B) :- | |
edge(A,B). | |
sib(A,B) :- | |
path(C,A,_), | |
path(C,B,_), | |
\+path(A,B,_), | |
\+path(B,A,_). | |
ancestor(A,B) :- | |
path(A,B,_). | |
descendent(A,B) :- | |
path(B,A,_). | |
path(A,B,Path) :- | |
travel(A,B,[A],Q), | |
reverse(Q,Path). | |
travel(A,B,P,[B|P]) :- | |
connected(A,B). | |
travel(A,B,Visited,Path) :- | |
connected(A,C), | |
C \== B, | |
\+member(C,Visited), | |
travel(C,B,[C|Visited],Path). | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment