30 lines
1.1 KiB
MiniZinc
30 lines
1.1 KiB
MiniZinc
enum Guests = { bride, groom, bestman, bridesmaid, bob, carol,
|
|
ted, alice, ron, rona, ed, clara};
|
|
set of int: Seats = 1..12;
|
|
set of int: Hatreds = 1..5;
|
|
array[Hatreds] of Guests: h1 = [groom, carol, ed, bride, ted];
|
|
array[Hatreds] of Guests: h2 = [clara, bestman, ted, alice, ron];
|
|
set of Guests: Males = {groom, bestman, bob, ted, ron,ed};
|
|
set of Guests: Females = {bride,bridesmaid,carol,alice,rona,clara};
|
|
|
|
array[Guests] of var Seats: pos; % seat of guest
|
|
|
|
include "alldifferent.mzn";
|
|
constraint alldifferent(pos);
|
|
|
|
constraint forall(g in Males)( pos[g] mod 2 == 1 );
|
|
constraint forall(g in Females)( pos[g] mod 2 == 0 );
|
|
|
|
constraint not (pos[ed] in {1,6,7,12});
|
|
constraint abs(pos[bride] - pos[groom]) <= 1 /\
|
|
(pos[bride] <= 6 <-> pos[groom] <= 6);
|
|
|
|
solve maximize sum(h in Hatreds)(
|
|
let { var Seats: p1 = pos[h1[h]];
|
|
var Seats: p2 = pos[h2[h]];
|
|
var 0..1: same = bool2int(p1 <= 6 <-> p2 <= 6); } in
|
|
same * abs(p1 - p2) + (1-same) * (abs(13 - p1 - p2) + 1));
|
|
|
|
output [ show(g)++" " | s in Seats,g in Guests where fix(pos[g]) == s]
|
|
++ ["\n"];
|