Skip to content

Commit 2d551a3

Browse files
committed
Created a social golfer spec using Abdallah's encoding
It generates a web app straight out of the box!
1 parent 081cbf7 commit 2d551a3

7 files changed

Lines changed: 124 additions & 8 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
% The contents below is Abdallah's work.
2+
3+
integer(groups,5).
4+
integer(rounds,5).
5+
base(player,alleson).
6+
base(player,brad).
7+
base(player,charlie).
8+
base(player,danielle).
9+
base(player,fredric).
10+
base(player,george).
11+
base(player,harriet).
12+
base(player,ivan).
13+
base(player,jenny).
14+
base(player,karen).
15+
base(player,laura).
16+
base(player,mona).
17+
base(player,nathan).
18+
base(player,olive).
19+
base(player,penelope).
20+
base(player,rachel).
21+
base(player,stan).
22+
base(player,tom).
23+
instance(disallowed(brad,danielle)).
24+
25+
26+
% domain constraints
27+
domainok(disallowed(P1,P2)) :- base(player,P1), base(player,P2), P1 != P2, instance(disallowed(P1,P2)).
28+
29+
% solution constaints
30+
% output: assign/3
31+
round(1..R) :- integer(rounds,R).
32+
group(1..G) :- integer(groups,G).
33+
size((N-1)/G+1) :- N = #count { P : base(player,P) }, integer(groups,G).
34+
1 { assign(P, R, G) : group(G) } 1 :- base(player,P), round(R).
35+
N - 1 { assign(P,R,G) : base(player,P) } N :- round(R), group(G), size(N).
36+
same(P1, P2, R) :- assign(P1, R, G), assign(P2, R, G), P1 < P2.
37+
:- same(P1,P2, R), instance(disallowed(P1,P2)).
38+
:- same(P1,P2, R), instance(disallowed(P2,P1)).
39+
40+
:- same(P1, P2, R), same(P1, P2, S), R < S. %%% satisfaction constraint
41+
%#minimize { 1,P1,P2,R,S : same(P1, P2, R), same(P1, P2, S), R < S }. %%% optimization constraint

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
"keywords": [],
88
"packageManager": "[email protected]",
99
"scripts": {
10-
"devdebug": "yarn solves -s ./test/sample-spec.yml",
11-
"devdebug2": "yarn solves -s ./test/cnf-sat.yml",
12-
"devdebug2alt": "yarn solves -s ./test/cnf-sat-alt.yml",
13-
"devdebug3": "yarn solves -s ./test/vertex-cover.yml",
10+
"devdebug": "yarn solves -s ./test/social-golfer.yml",
11+
"devdebug2": "yarn solves -s ./test/sample-spec.yml",
12+
"devdebug3": "yarn solves -s ./test/cnf-sat.yml",
13+
"devdebug3alt": "yarn solves -s ./test/cnf-sat-alt.yml",
14+
"devdebug4": "yarn solves -s ./test/vertex-cover.yml",
1415
"test": "yarn workspace solves test",
1516
"build": "yarn workspace solves build",
1617
"compile": "yarn workspace solves compile",

solves/test/cnf-sat-alt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: cnf-sat
22
appTitle: CNF-SAT Solver (with dummy output for debugging)
33
author: simshadows
4-
description: your description here
4+
description: Problem encoding credit goes to Dr. Abdallah Saffidine. Only minor modifications were made to adapt his work for the code generator tooling.
55

66
input-base:
77
variable:

solves/test/cnf-sat.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: cnf-sat
22
appTitle: CNF-SAT Solver
33
author: simshadows
4-
description: your description here
4+
description: Problem encoding credit goes to Dr. Abdallah Saffidine. Only minor modifications were made to adapt his work for the code generator tooling.
55

66
input-base:
77
variable:

solves/test/sample-spec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: graph-colouring
22
appTitle: Vertex Colouring Solver
33
author: simshadows
4-
description: your description here
4+
description: Problem encoding credit goes to Dr. Abdallah Saffidine. Only minor modifications were made to adapt his work for the code generator tooling.
55

66
input-base:
77
colour:

solves/test/social-golfer.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+

solves/test/vertex-cover.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: vertex-cover
22
appTitle: Vertex Cover Solver
33
author: simshadows
4-
description: your description here
4+
description: Problem encoding credit goes to Dr. Abdallah Saffidine. Only minor modifications were made to adapt his work for the code generator tooling.
55

66
input-base:
77
vertex:

0 commit comments

Comments
 (0)