【问题标题】:Answer Set Programming: how to assign students to a group such that no two students who dislike each other are in a same group答案集编程:如何将学生分配到一个小组中,这样不会有两个不喜欢彼此的学生在同一个小组中
【发布时间】:2015-12-08 06:29:18
【问题描述】:

我是答案集编程的初学者。我想将所有学生分组到不同的组中,这样: 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.

我已经添加了每个组可以包含多少学生的约束,但不知道如何满足其他两个条件。

您的帮助将不胜感激。谢谢。

【问题讨论】:

    标签: answer-set-programming clingo gringo


    【解决方案1】:

    试试这个:

    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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2017-10-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多