Kotsos
Kotsos

Reputation: 19

minizinc sitting-friends-at-a-table-far-from-furius ones

1.we have cycling table 2.a man must be sit next to a woman and a woman next to a man 3. guests must share hobbies (at least one common between their hobbies) 4. there are couples of furious guests. they must not sit near to next to each other 5. nobody of list o furious guests must sit at start(seat 1) or end (seat N) -pR is the number of furious couples

my model:

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]
       ;

my model's bugs:

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.

Upvotes: 0

Views: 63

Answers (1)

hakank
hakank

Reputation: 6854

This constraint, where there errors are referring to, contains a couple of strange things:

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) The second and third loop parameters l in List and p in PAIR is never used, so they are meaningless.

2) The main reason for the warning is that the furious matrix is just two rows, but in the loop variable i goes from 2 to 16. The error (array access out of bounds) indicates that when i is larger than 2 it's out of bound of the furious matrix.

Upvotes: 1

Related Questions