|
| 1 | +name: social-golfer |
| 2 | +appTitle: Social Golfer Solver |
| 3 | +author: simshadows |
| 4 | +description: A solver for the Social Golfer Problem. Problem encoding credit goes to Dr. Abdallah Saffidine. Only minor modifications were made to adapt his work for the code generator tooling. Inspired by Bradley Buchanan's near-solver app (goodenoughgolfers.com). |
| 5 | + |
| 6 | +input-base: |
| 7 | + player: |
| 8 | + title: Players |
| 9 | + params: 1 |
| 10 | + initialValues: |
| 11 | + - alleson |
| 12 | + - brad |
| 13 | + - charlie |
| 14 | + - danielle |
| 15 | + - fredric |
| 16 | + - george |
| 17 | + - harriet |
| 18 | + - ivan |
| 19 | + - jenny |
| 20 | + - karen |
| 21 | + - laura |
| 22 | + - mona |
| 23 | + - nathan |
| 24 | + - olive |
| 25 | + - penelope |
| 26 | + - rachel |
| 27 | + - stan |
| 28 | + - tom |
| 29 | + |
| 30 | +input-integer: |
| 31 | + groups: |
| 32 | + title: Groups |
| 33 | + min: 1 |
| 34 | + max: 50 |
| 35 | + initial: 5 |
| 36 | + rounds: |
| 37 | + title: Rounds |
| 38 | + min: 1 |
| 39 | + max: 20 |
| 40 | + initial: 5 |
| 41 | + |
| 42 | +input-constrained: |
| 43 | + disallowed: |
| 44 | + title: Disallowed Pairs |
| 45 | + params: 2 |
| 46 | + initialValues: |
| 47 | + - brad,danielle |
| 48 | + |
| 49 | +output: |
| 50 | + assign: |
| 51 | + title: Selection |
| 52 | + fieldLabels: |
| 53 | + - Player |
| 54 | + - Round |
| 55 | + - Group |
| 56 | + |
| 57 | +constraints: | |
| 58 | + domainok(disallowed(P1,P2)) :- base(player,P1), base(player,P2), P1 != P2, instance(disallowed(P1,P2)). |
| 59 | +
|
| 60 | +encoding: | |
| 61 | + round(1..R) :- integer(rounds,R). |
| 62 | + group(1..G) :- integer(groups,G). |
| 63 | + size((N-1)/G+1) :- N = #count { P : base(player,P) }, integer(groups,G). |
| 64 | + 1 { assign(P, R, G) : group(G) } 1 :- base(player,P), round(R). |
| 65 | + N - 1 { assign(P,R,G) : base(player,P) } N :- round(R), group(G), size(N). |
| 66 | + same(P1, P2, R) :- assign(P1, R, G), assign(P2, R, G), P1 < P2. |
| 67 | + :- same(P1,P2, R), instance(disallowed(P1,P2)). |
| 68 | + :- same(P1,P2, R), instance(disallowed(P2,P1)). |
| 69 | +
|
| 70 | + :- same(P1, P2, R), same(P1, P2, S), R < S. %%% satisfaction constraint |
| 71 | + %#minimize { 1,P1,P2,R,S : same(P1, P2, R), same(P1, P2, S), R < S }. %%% optimization constraint |
| 72 | +
|
| 73 | + solution(assign(P,R,G)) :- assign(P,R,G). |
| 74 | +
|
0 commit comments