如何去除序言中的重复项?

时间:2018-09-14 03:39:38

标签: prolog

我是prolog的新手,我有一个列出员工及其主管的分层数据库:

employee(employee1, employee4).
employee(employee2, employee4).
employee(employee3, employee4).
employee(employee4, employee8).
employee(employee5, employee7).
employee(employee6, employee7).
employee(employee7, employee8).
employee(employee8, employee9).
employee(employee9, employee10).

我想建立一个名为coworker(A,B)的谓词,该谓词列出某个雇员拥有的所有同事,包括其上司。

coworker(Who, employee1).
Who = employee2 ?;
Who = employee3 ?;
Who = employee4 ?;
Who = employee5 ?;
Who = employee6 ?;
Who = employee7 ?;
Who = employee8 ?;
Who = employee9 ?;
Who = employee10 ?;

到目前为止,我的代码是:

supervisor(A,B):-employee(B,A).

boss(A,B):-supervisor(A,B).
boss(A,B):-supervisor(A,C),boss(C,B).

coworker(A,B):-boss(C,A),boss(C,B).
coworker(A,B):-employee(A,B).
coworker(A,B):-supervisor(A,B).
coworker(A,B):-boss(X,Y).

但是,我很难完全摆脱同事的所有可能重复。我该怎么做才能解决此问题?

0 个答案:

没有答案