1010101
1010101

Reputation: 51

Answer Set Programming: Group into two sets so that those who like each other are in same set, and dislike = different set

I'm basically a beginner to Answer Set Programming (CLINGO), so I've been attempting this problem for hours now.

person(a;b;c;d;e;f).

likes(b,e; d,f).

dislikes(a,b; c,e).

People who like each other must be in the same set, and cannot be in the same set as someone they dislike. So the output should be: b,e | a, c, d,f

I know the logic behind it; partition it so that if an element is in both likes & dislikes, then it should be in its own set, and everything else in the other. But this is declarative programming, so I'm not sure how to tackle this. Any help would be appreciated.

Upvotes: 0

Views: 492

Answers (1)

Vijaya Pandey
Vijaya Pandey

Reputation: 4282

Try this one, it should work for you:

person(a;b;c;d;e;f). 
like(b,e; d,f).
dislike(a,b; c,e).

group(1..2). 

% every person belongs to one group only. 
1{in(S,G): group(G)}1 :- person(S).

% no two persons who do dislike each other are in the same group 
:- in(X, G), in(Y, G), dislike(X,Y). 

#show in/2.

The result you'll get is:
a & b are in different group.
and c & e are in different group.

The result you can get is like: answer set programming: group into two sets using clingo

Upvotes: 1

Related Questions