% See social_golfers1.mzn
int: weeks = 5;
int: groups = 7;
int: groupSize = 3;
int: golfers = groups * groupSize;
set of int: Golfer = 1..golfers;
set of int: Week = 1..weeks;
set of int: Group = 1..groups;
% Search space: The set of all possible group assignments to all players in each of the weeks
% weeks.
array[Golfer, Week] of var Group: assign;
% solve satisfy;
solve :: int_search([assign[i,j] | i in Golfer, j in Week ], first_fail, indomain_min, complete) satisfy;
constraint
% C1: Each group has exactly groupSize players
forall (gr in Group, w in Week) (
sum (g in Golfer) ( bool2int(assign[g,w] = gr)) = groupSize
)
/\
% C2: Each pair of players only meets at most once
forall (g1, g2 in Golfer, w1, w2 in Week where g1 != g2 /\ w1 != w2) (
(bool2int(assign[g1,w1] = assign[g2,w1]) + bool2int(assign[g1,w2] = assign[g2,w2])) <= 1
)
;
output [
if j = 1 then "\n" else " " endif ++
show(assign[i,j])
| i in Golfer, j in Week
]