1

这是一个 Prolog 程序,我想检查 Linux 包之间的依赖关系以及是否存在任何冲突。

dep(gnome1,gcc7).
confl(gcc7,gcc8).

% recursive chain dependency
depend(X,Y):- dep(X,Y).
depend(X,Y):- dep(X,Z), depend(Z,Y).

% conflict(X,Y) holds if X and Y depend
on two packages which conflict, conflict between two
packages should be a symmetric relation.

% my poor attempt
conflict(X,Y):- depend(X,A), depend(Y,B), (confl(A,B) | confl(B,A)).
4

1 回答 1

1

我认为您的方法几乎是正确的:

dep(gnome1,libc7).
dep(gnome1,gcc7).

dep(gnome2,gnome1).
dep(gnome2,gcc8).

confl(gcc7,gcc8).

% recursive chain dependency
depend(X,Y):- dep(X,Y).
depend(X,Y):- dep(X,Z), depend(Z,Y).

% conflict(X,Y) holds if X and Y depend
% on two packages which conflict, conflict between two
% packages should be a symmetric relation.

conflict(X,Y) :-
    depend(X,A), depend(Y,B),
    X @< Y,  % break symmetry
    (confl(A,B) ; confl(B,A)).

我添加了一些(错误)配置来测试:

11 ?- conflict(X,Y).
X = gnome1,
Y = gnome2 ;
false.
于 2013-03-10T21:22:20.973 回答