Answer Set Programming:如何将学生分配到一个组中,使得没有两个互不喜欢的学生在同一组中
Answer Set Programming: how to assign students to a group such that no two students who dislike each other are in a same group
我是答案集编程的初学者。我想将所有学生分组到不同的组中,以便:
1. 每组3-4名学生
2. 没有两个互不喜欢的同学在同一组。
3. 不能将同一个学生分配到不同的组。
我这样写的:
%suppose there are total 6 students
student(1..6).
%suppose there are 2 groups
group(1..2).
%1 and 4 like each other, 4 and 5 dislike each other
dislike(1,4). dislike(5,4).
% each group has 3 to 4 students
:- group(G), #count {S : in(S,G)} < 3.
:- group(G), #count {S : in(S,G)} > 4.
我已经添加了每个组可以包含多少学生的限制,但不知道如何满足其他两个条件。
非常感谢您的帮助。谢谢
试试这个:
student(1..6).
group(1..2).
dislike(1,4). dislike(5,4).
% each group has 3 to 4 students
:- group(G), #count {S : in(S,G)} < 3.
:- group(G), #count {S : in(S,G)} > 4.
%no two students who dislike each other are in the same group
:-in(X, G1), in(Y,G2), dislike(X,Y), group(G1), group(G2), G1==G2.
%each student should be assigned to only one group
1{in(S,G): group(G)}1 :- student(S).
#show in/2.
我是答案集编程的初学者。我想将所有学生分组到不同的组中,以便: 1. 每组3-4名学生 2. 没有两个互不喜欢的同学在同一组。 3. 不能将同一个学生分配到不同的组。
我这样写的:
%suppose there are total 6 students
student(1..6).
%suppose there are 2 groups
group(1..2).
%1 and 4 like each other, 4 and 5 dislike each other
dislike(1,4). dislike(5,4).
% each group has 3 to 4 students
:- group(G), #count {S : in(S,G)} < 3.
:- group(G), #count {S : in(S,G)} > 4.
我已经添加了每个组可以包含多少学生的限制,但不知道如何满足其他两个条件。
非常感谢您的帮助。谢谢
试试这个:
student(1..6).
group(1..2).
dislike(1,4). dislike(5,4).
% each group has 3 to 4 students
:- group(G), #count {S : in(S,G)} < 3.
:- group(G), #count {S : in(S,G)} > 4.
%no two students who dislike each other are in the same group
:-in(X, G1), in(Y,G2), dislike(X,Y), group(G1), group(G2), G1==G2.
%each student should be assigned to only one group
1{in(S,G): group(G)}1 :- student(S).
#show in/2.