Sei sulla pagina 1di 29

# Modelling and Solving

## English Peg Solitaire

Chris Jefferson, Angela Miguel,
Ian Miguel, Armagan Tarim.
AI Group
Department of Computer Science
University of York
English Peg Solitaire
The French variant has a slightly larger
board, and is considerably more difficult.
0 1 2 3 4 5 6
0
1
2
3
4
5
6
0
1
2
3
4
5
6
0 1 2 3 4 5 6
Before After
Horizontal or
vertical moves:
Initial: Goal:
Solitaire: Interesting Features
A challenging search problem.
Highly symmetric.
Symmetries of the board, symmetries of moves.
Planning-style problem.
Not usually tackled directly with constraint
satisfaction/integer programming.
Model A: IP
31 moves required to solve a single-peg reversal.
Exploit this in the modelling.
bState[i,j,t] e {0, 1}.
describes the state of the board at time-step t = 0, , 31.
M[i,j,t,d] e {0, 1}.
denotes whether a move was made from location i, j at
time-step t. d in {N, S, E, W}.
Model A: IP
] bState[ ] , , , [ i,j,t E t j i M s
] 1 bState[ ] , , , [ ,j,t i E t j i M + s
] 2 bState[ 1 ] , , , [ ,j,t i E t j i M + s

e
= +
} , , , {
] , , , [ ] , , bState[ ] 1 , , [ bState
W E S N d
d t j i M - t j i t j i
] , , , 2 [ ] , , , 1 [ ] , , , 2 [ ] , , , 1 [ W t j i M W t j i M E t j i M E t j i M + + + +
] , , 2 , [ ] , , 1 , [ ] , , 2 , [ ] , , 1 , [ N t j i M N t j i M S t j i M S t j i M + + + +
Move Conditions:
Connecting board states. Consider all moves affecting a position
Model A: IP
One move at a time:

e
= + + +
B j i
W t j i M E t j i M S t j i M N t j i M
) , (
1 ]) , , , [ ] , , , [ ] , , , [ ] , , , [ (

=
e
hole centre ) , (
) , (
] 31 , , [
j i
B j i
j i bState
Objective function.
Minimise:
Model B: CSP
Rather than record the board state, model B
records the sequence of moves required: moves[t]
Each transition is assigned a unique number:
No. Trans. No. Trans. No. Trans.
0 2,04,0 3 4,02,0 6 2,12,3
1 2,02,2 4 4,04,2 7 3,13,3
2 3,03,2 5 2,14,1 8 4,12,1
Model B: CSP
Problem constraints can be stated on moves[] alone.
Consider transition 0: 2, 0 4, 0 at time-step t. The
following must hold at time-step t-1.
There must be pegs at 2, 0 and 3, 0.
There must be a hole at 4, 0.
Ensure by imposing constraints on moves[1..t-1]:
Drawback: many such constraints needed. Some of very large size.
) , conflict( ) , support( ) pre( } 31 ,..., 1 { p p p T t t t t t t t e e e e e
+
+
= . < < - . = - = t t t ] [ moves : ] [ moves : ] [ moves h i h g h g g t
0
1
0 1 2 3 4 5 6
Model C = A + B: CSP
Combines models A and B to remove some of
the problems of both.
Maintains: bState[i,j,t], moves[t].
Discards (A): M[], board state connection constraints.
Discards (B): Large arity constraints on moves[].
Channelling constraints are added to maintain
consistency between the two representations.
These connect bState[i,j,t], moves[t], bState[i,j,t+1].
t
bState[t]
moves[]
bState[t+1]
constrains constrains
Model C Channelling Constraints
These constraints closely resemble pre- and post-
conditions of an AI Planning-style operator.
)}) , ( changes | ] [ moves { ( ]) 1 , , [ bState ] , , [ bState ( j i t t j i t j i e = . + = t t
)}) , ( pegIn | ] [ moves { ( ) 1 ] 1 , , [ bState 0 ] , , [ bState ( j i t t j i t j i e = v = + . = t t
)}) , ( pegOut | ] [ moves { ( ) 0 ] 1 , , [ bState 1 ] , , [ bState ( j i t t j i t j i e = v = + . = t t
Changes(i,j): set of transitions that change the state of i, j
pegIn(i,j): set of transitions that place a peg at i, j
pegOut(i,j): set of transitions that remove a peg from i, j
Results: Central Solitaire
Model A (IP): No solution in 12 hours.
Several alternative formulations also failed.
Reason: artificial objective function, hence no
tight bounds to exploit.
Model B (CP): Exhausts memory.
Model C (A+B, CP solver): 16 seconds.
So:
Develop model C further.
Apply to other variations of Solitaire.
Pagoda Functions
Value assigned to each board position such that:
Given positions a, b, c in a horizontal/vertical line:
a+b > c.
Pagoda value of a board state:
Sum of values at positions where there is a peg.

Pagoda condition:
If pagoda value for an intermediate position is less
than that of final position, backtrack.
a b c a b c
Pagoda Functions: Examples
For a single-peg Solitaire reversal at position i, j,
want pagoda functions with non-zero entries at i, j.
Otherwise no pruning.
A rotation of one of these three gives a useful
pagoda function for every board position:
1 1
1 1 1 1
1 1 1 1
1 1
1
1 1 1
1
1
1
1
1
1
1
1
1
Board Symmetries
Rotation.
Reflection.
Break rotational symmetry by selecting 1
st
move:
Reflection symmetry persists. Remove 5,2 3,2:
Board Symmetries
Further into the search are both broken and re-
established, depending on the moves made.
Breaking this symmetry is a possible application for SBDS or SBDD.
Symmetries of Independent Moves
Many pairs of moves can be performed in any order
without affecting the rest of the solutions.
Two transitions are independent iff:
The set of pegs upon which they operate do not intersect.
Break this symmetry by ordering adjacent entries in
moves[]:
independent(moves[i], moves[i+1])
moves[i] s moves[i+1]
This problem extends to larger sets of transitions.
If 2 is independent of {3, 1}, can have 2, 3, 1 and 3, 1, 2.
Results: Solitaire Reversals
Compared Model C against state of the art AI
planning systems:
Blackbox 4.2, FastForward 2.3, HSP 2.0, and Stan 4.
Experiments on the full set of single-peg reversals.
Although many board positions symmetrical, these
positions are distinguished by the transition ordering.
Transitions chosen in ascending order.
No. Trans. No. Trans. No. Trans.
0 2,04,0 3 4,02,0 6 2,12,3
1 2,02,2 4 4,04,2 7 3,13,3
2 3,03,2 5 2,14,1 8 4,12,1
Solitaire Reversals via AI Planning
13
49
-
-
-
-
148
-
14
622
-
-
25
121
-
>1hr
47
1
-
-
28
0.1
125
-
42
0.15
-
-
16
553
-
>1hr
18
>1hr
298
-
543
-
-
-
48
3544
86
-
-
-
57
-
44
0.05
313
-
17
1
-
>1hr
38
0.6
27
-
30
48
-
-
49
0.05
60
-
27
1521
-
>1hr
21
9.8
154
-
25
0.7
-
1126
862
>1hr
-
>1hr
14
0.05
97
>1hr
19
0.2
30
-
19
276
-
-
21
0.6
32
-
19
-
125
-
14
273
48
>1hr
620
>1hr
574
>1hr
16
1564
-
>1hr
BBox4.2
FF2.3
HSP2.0
Stan4
Bbox, FF most
successful, achieve a
high percentage of
coverage.
Note how
symmetric
positions
differ.
- memory exhausted.
-
>1hr
-
-
-
-
-
-
-
-
-
>1hr
-
-
-
-
Solitaire Reversals via Model C
17
3.5
18
4.9
116
19.1
102
22,3
>1hr
337.8
>1hr
349.6
7
2.7
8
2.7
1700
197
1712
199.9
>1hr
1891.2
>1hr
1036
439
61.1
443
64.9
Basic
Pair Sym Breaking
Pagoda Functions
Pagoda+Sym
ordering?
Sym breaking, pagoda
help.
Blank: all >1hr
2903
221.5
2730
54.6
16
4.1
7.9
5
Model C + Corner Bias Value Ordering
17
3.5
18
4.9
116
19.1
102
22,3
>1hr
337.8
>1hr
349.6
7
2.7
8
2.7
1700
197
1712
199.9
>1hr
1891.2
>1hr
1036
439
61.1
443
64.9
Basic
Pair Sym Breaking
Pagoda Functions
Pagoda+Sym
1.3 1.2
0.7
Taking symmetry back
into account, can now
cover all but one reversal
Blank: all >1hr
2903
221.5
2730
54.6
16
4.1
7.9
5
1.2
0.7
4.6
Symmetric Paths
There are often multiple ways of arriving at the
same board state.
Some are due to independent moves. Others are not:
Symmetric Paths
Find all solutions to a given depth.
Group the transition sequences that lead to identical
positions.
Insert constraints that allow one representative per group.
Depth Solutions
Found
Solutions
Pruned
Constraints
Time (s)
4 328 32 32 <1
5 1572 234 205 1.5
6 7152 1504 1256 10
7 29953 8111 6167 116
Total 50600 28818 7660
Fools Solitaire
An optimisation variant.
Reach a position where no further moves are
possible in the shortest sequence of moves.
Not easily stated as an AI planning problem.
Shows the flexibility of the CP and IP approaches.
Fools Solitaire: IP Model
Moves, connection of board states same as model A.
1 ] , 2 , [ bState ] , 1 , [ bState ] , , [ bState ] , , [ + + + > t j i t j i t j i t j i C
1 ] , 2 , [ bState ] , 1 , [ bState ] , , [ bState ] , , [ + > t j i t j i t j i t j i C
1 ] , , 2 [ bState ] , , 1 [ bState ] , , [ bState ] , , [ + + + > t j i t j i t j i t j i C
1 ] , , 2 [ bState ] , , 1 [ bState ] , , [ bState ] , , [ + > t j i t j i t j i t j i C
New objective function.
Minimise:

e =

B j i t
t
t j i C
) , (
31
1
1
] , , [ 33
C[i,j,t]=1 iff there is a peg at position i,j with a legal move.
Fools Solitaire: CP Model
Modified version of model C.
domain of the moves[] variables.
Assigned when no other move is possible.
deadEnd transition is only allowed when no
other transitions are possible.
Preconditions based on bState[].
If deadEnd at moves[t], then also at all following
time-steps:
deadEnd ] 1 [ moves deadEnd ] [ moves : } 30 ,..., 1 { = + = e t t t
Fools Solitaire: Results
CP, reverse instantiation order: 20s
IP, iterative approach: 27s
Conclusions
Basic, and ineffective CP and IP models
combined into a superior CP model.
Another instance of the utility of channelling
between two complementary models.
Each allows easy statement of different aspects of
the problem:
Model A: preconditions on state changes without
considering entire move history.
Model B: one move at once, combines 3 state changes
into a single token.
Conclusions
Encouraging results versus dedicated AI
planning systems.
Lessons learned should generalise to other
sequential planning-style problems.
Channelling constraints specify action pre- and
post-conditions.
Breaking symmetry of independent
actions/paths.
Future Work
Further configurations of English Solitaire.
Other optimisation variants:
Minimise number of draughts-like multiple
moves using a single peg.
Proving unsolvability.
Large search space to explore.
Will need improved symmetry breaking.
French Solitaire.