Assume I have a graph and want to find 2 different cliques withhin the graph. A clique is a subset of the graphs vertices where all of them are connected. Example Graph with 2 cliques (a,b,c) and (b,c,d) of cliquesize 3 :
edge(a,b). edge(a,c). edge(b,c). edge(d,c). edge(d,b).
vertex(X;Y) :- edge(X,Y).
Getting 2 cliques is rather easy:
#const cs=3. % cliquesize
cs{clique1(X) : vertex(X)}cs.
:- clique1(X), clique1(Y), X!=Y, not edge(X,Y), not edge(Y,X).
cs{clique2(X) : vertex(X)}cs.
:- clique2(X), clique2(Y), X!=Y, not edge(X,Y), not edge(Y,X).
#show clique1/1.
#show clique2/1.
gives:
Answer: 1
clique2(d) clique1(a) clique2(b) clique2(c) clique1(b) clique1(c)
Answer: 2
clique2(d) clique1(d) clique2(b) clique2(c) clique1(b) clique1(c)
Answer: 3
clique2(a) clique1(a) clique2(b) clique2(c) clique1(b) clique1(c)
Answer: 4
clique2(a) clique1(d) clique2(b) clique2(c) clique1(b) clique1(c)
SATISFIABLE
which can be interpretet as:
Answer 1: (a,b,c), (b,c,d)
Answer 2: (b,c,d), (b,c,d)
Answer 3: (a,b,c), (a,b,c)
Answer 4: (b,c,d), (a,b,c)
But how to test if both cliques are different? I tried
differ() :- clique1(X), clique2(Y), X!=Y.
:- not differ().
But this has no effect on the output. How do I test if two cliques differ?
Now I found this Solution:
differ() :- clique1(X), vertex(X), not clique2(X).
:- not differ().
It works but I don't like that it needs 2 lines. How do I put it in one constraint?