본문 바로가기
Computer Science/Programming language

prolog - 가족관계 추론

by HaningYa 2020. 5. 1.
728x90

가족관계 추론

prolog pylog 사용하여 가족관계를 추론할 있는 프로그램을 작성.


예시 가계도

male(rahim).
male(karim).
male(kabir).
male(roy).
female(tisa).
female(jesi).
parent(rahim,karim).
parent(rahim,kabir).
parent(karim,tisa).
parent(karim, jesi).
parent(babir, roy).

son(X,Y):- male(X), parent(Y,X).
daughter(X,Y):- female(X), parent(Y,X).
father(X,Y) :- male(X), parent(X,Y).
mother(X,Y) :- female(X), parent(X,Y).
spouse(X,Y) :- child(P,X), child(P,Y).
brother(X,Y) :- male(X), sibling(X,Y).
sister(X,Y) :- female(X), sibling(X,Y).
cousin(X,Y) :- parent(P,X), sibling(P,Q), parent(Q,Y).
child(X,Y) :- parent(Y,X).
sibling(X,Y) :- parent(P,X), parent(P,Y), X\=Y.

실행결과

 


[사용한 프로그램]

 

SWISH -- SWI-Prolog for SHaring

ebeveyn(ayla,ulas). ebeveyn(pinar,ayla). ebeveyn(cansu,dilek). ebeveyn(cagri,yaprak). ebeveyn(arif,dilek). ebeveyn(pinar,arif). ebeveyn(pinar,fatma). ebeveyn(fatma,burak). ebeveyn(serkan,cansu). ebeveyn(serkan,muge). ebeveyn(talat,cagri). ebeveyn(talat,osm

swish.swi-prolog.org

[참고자료]

[참고코드]

 

FediSalhi/Prolog-Family-Tree

Programming of a family tree using SWI. Contribute to FediSalhi/Prolog-Family-Tree development by creating an account on GitHub.

github.com

 

728x90

댓글