minizinc坐在朋友的桌子上远离furius的人

时间:2017-11-30 17:53:17

标签: constraints minizinc

我们有自行车桌 2.男人必须坐在男人旁边的女人和女人旁边 3.客人必须分享爱好(他们的爱好之间至少有一个共同点) 有几对愤怒的客人。他们不能坐在一起,彼此相邻 5.没有人列出愤怒的客人必须坐在开始(座位1)或结束(座位N) -pR是愤怒夫妇的数量

我的模特:

int :N;
set of int: GUESTS  = 1..N;
set of int: POSITIONS = 1..N;
array[GUESTS] of 1..2 : gender;
array[GUESTS] of set of int: hobbies;
enum PAIR = {first,second};
int : pR;
set of int: LIST = 1..pR;
array[LIST,PAIR] of GUESTS : furious;
array[POSITIONS] of var GUESTS : guest_at;
array[POSITIONS] of var 1..2: table_gender;
constraint forall(i in 1..length(table_gender)-1)(
   table_gender[i]!=table_gender[i+1]
   /\
   table_gender[1]!=table_gender[length(table_gender)]
)
   ;
include "alldifferent.mzn";
constraint alldifferent(guest_at);
constraint forall(i in 2..N-1)(card(hobbies[guest_at[i+1]] intersect hobbies[guest_at[i]]) >0);
constraint card(hobbies[guest_at[N]] intersect hobbies[guest_at[1]]) >0;
constraint forall(i in 2..N-1,l in LIST, p in PAIR)(if guest_at[i]=furious[i,first] then guest_at[i+1]!=furious[i,second] /\ guest_at[i-1]!=furious[i,second] else true endif);
constraint forall(l in LIST, p in PAIR)(guest_at[1]!=furious[l,p] /\ guest_at[N]!=furious[l,p]);
solve satisfy;
output 
       ["guest_at = \(guest_at);"]
       ++ ["\ntable_gender = \(table_gender); \n" ] 
       ++ ["Furious Placement\n"]
       ++ [show_int(4,furious[i,j]) | i in LIST, j in PAIR] ++["\n"] 
       ++ [if fix(guest_at[p]) = furious[i,j] then show_int(4,p) else "" endif | i in LIST, j in PAIR, p in POSITIONS]
       ;

我模特的错误:

C:/Users/�������/Documents/������/����������/Gala/gala.mzn:36:
  in call 'forall'
  in array comprehension expression
    with i = 4
    with l = 3
    with p = 1
  in if-then-else expression
  in binary '=' operator expression
  in array access

  WARNING: Further warnings have been suppressed.

1 个答案:

答案 0 :(得分:1)

这个带有错误的约束包含一些奇怪的东西:

constraint 
     forall(i in 2..N-1,l in LIST, p in PAIR) (
         if guest_at[i]=furious[i,first] then 
            guest_at[i+1]!=furious[i,second] /\  
            guest_at[i-1]!=furious[i,second] 
         else 
             true 
         endif
     );

1)永远不会使用第二个和第三个循环参数l in Listp in PAIR,因此它们毫无意义。

2)警告的主要原因是furious矩阵只有两行,但循环变量i从2变为16.错误(array access out of bounds)表示当i大于2时,它超出furious矩阵的范围。