代码之家  ›  专栏  ›  技术社区  ›  Kotsos

迷你锌坐在桌旁的朋友远离furius One

  •  0
  • Kotsos  · 技术社区  · 7 年前

    1.我们有自行车台 男人必须坐在女人旁边,女人必须坐在男人旁边 3、客人必须分享爱好(至少有一个共同爱好) 有几对愤怒的客人。他们不能挨着坐 5.o名单上愤怒的客人不得坐在开始(座位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 回复  |  直到 7 年前
        1
  •  1
  •   hakank    7 年前

    此约束(其中引用了错误)包含两个奇怪的内容:

    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 List p in PAIR 从不使用,所以它们没有意义。

    2) 发出警告的主要原因是 furious 矩阵只有两行,但在循环变量中 i 从2到16。错误 (array access out of bounds) 表示当 大于2,超出 狂怒的 矩阵