人工智能导论prolog编程题目
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了人工智能导论prolog编程题目相关的知识,希望对你有一定的参考价值。
试编写一个描述亲属关系的PROLOG程序,然后再给出一些事实数据,简历一个小型演绎数据库。提示:可以以父亲和母亲为基本关系(作为基本谓词),再由此来描述祖父祖母兄弟姐妹以及其他亲属关系
参考技术A随便从网上找的一个family tree
--------------------------------------------------
----------------------------------------------------
male(tom).
male(john).
male(adam).
male(nike).
male(bob).
female(alisa).
female(abby).
female(anne).
female(alice).
female(betty).
female(carry).
female(chris).
%
mother(alisa, alice).
mother(alisa, anne).
mother(alice, carry).
mother(abby, adam).
mother(abby, betty).
mother(betty, chris).
mother(betty, bob).
%
father(tom, anne).
father(tom, alice).
father(john, adam).
father(john, betty).
father(nike, chris).
father(nike, bob).
father(adam, carry).
%%%%%%%%%%%%%%%%%%%%%%
% Parent: a father or mother
parent(A, B):-
(
father(A, B);
mother(A, B)
).
% Child: a human offspring (son or daughter) of any age
child(A, B):-
parent(B, A).
% Daughter: a female human offspring
daughter(A, B):-
female(A),
child(A, B).
% Son: a male human offspring
son(A, B):-
male(A),
child(A, B).
% Sibling: a person's brother or sister
sibling(A, B):-
parent(C, A),
parent(C, B),
A \\= B.
% Sister: a female person who has the same parents
% as another person
sister(A, B):-
sibling(A, B),
female(A).
% Brother: a male with the same parents as someone else
brother(A, B):-
sibling(A, B),
male(A).
%%%%%%%%%%%%%%%%%%%%%%%%
% Aunt: the sister of your father or mother
aunt(A, B):-
parent(C, B),
sister(A, C).
% Uncle: the brother of your father or mother
uncle(A, B):-
parent(C, B),
brother(A, C).
% Cousin: the child of your aunt or uncle
cousin(A, B):-
parent(C, B),
sibling(D, C),
child(A, D).
%%%%%%%%%%%%%%%%%%%%%%%%
% Grandparent: a parent of your father or mother
grandparent(A, B):-
parent(A, C),
parent(C, B).
% Grandfather: the father of your father or mother
grandfather(A, B):-
male(A),
grandparent(A, B).
% Grandmother: the mother of your father or mother
grandmother(A, B):-
female(A),
grandparent(A, B).
% Grandchild: a child of your son or daughter
grandchild(A, B):-
grandparent(B, A).
% Grandson: a male grandchild
grandson(A, B):-
male(A),
grandchild(A, B).
% Granddaughter: a female grandchild
grandson(A, B):-
female(A),
grandchild(A, B).
------------------------------------------------------
以上是关于人工智能导论prolog编程题目的主要内容,如果未能解决你的问题,请参考以下文章