290 likes | 317 Views
Modelling and Solving English Peg Solitaire. Chris Jefferson, Angela Miguel, Ian Miguel, Armagan Tarim. AI Group Department of Computer Science University of York. 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.
E N D
Modelling and SolvingEnglish Peg Solitaire Chris Jefferson, Angela Miguel,Ian Miguel, Armagan Tarim. AI Group Department of Computer Science University of York
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 English Peg Solitaire • The French variant has a slightly larger board, and is considerably more difficult. Initial: Goal: • Horizontal or vertical moves:
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] {0, 1}. • describes the state of the board at time-step t = 0, …, 31. • M[i,j,t,d] {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 Move Conditions: `1’ means move made. Connecting board states. Consider all moves affecting a position
Model A: IP One move at a time: 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:
0 1 2 3 4 5 6 0 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.
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]. bState[t] bState[t+1] moves[] constrains constrains t
Model C Channelling Constraints Changes(i,j): set of transitions that change the state of i, j • These constraints closely resemble pre- and post-conditions of an AI Planning-style operator. 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 • Used to spot dead-ends early. • 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. • Monotonically decreasing as moves made: • Pagoda condition: • If pagoda value for an intermediate position is less than that of final position, backtrack. a b c a b c
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 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:
Board Symmetries • Rotation. • Reflection. • Break rotational symmetry by selecting 1st 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] 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.
1349-- - - 148 - 14 622 - - Solitaire Reversals via AI Planning BBox4.2 FF2.3 HSP2.0 Stan4 25 121 - >1hr 543 - - - 17 1 - >1hr • memory exhausted. 19 0.2 30 - 25 0.7 - 1126 47 1 - - 48 3544 86 - 38 0.6 27 - 14 273 48 >1hr 21 0.6 32 - - - - - 862 >1hr - >1hr 28 0.1 125 - - - 57 - 30 48 - - 620 >1hr 574 >1hr - >1hr - - 19 276 - - 14 0.05 97 >1hr 42 0.15 - - 44 0.05 313 - 49 0.05 60 - 16 1564 - >1hr 19 - 125 - 16 553 - >1hr - - - >1hr 27 1521 - >1hr Note howsymmetricpositionsdiffer. Bbox, FF most successful, achieve a high percentage of coverage. 18 >1hr 298 - - - - - 21 9.8 154 -
Solitaire Reversals via Model C Basic Pair Sym Breaking Pagoda Functions Pagoda+Sym 2903 221.5 2730 54.6 Blank: all >1hr 439 61.1 443 64.9 7 2.7 8 2.7 17 3.5 18 4.9 16 4.1 7.9 5 1700 197 1712 199.9 >1hr 1891.2 >1hr 1036 116 19.1 102 22,3 >1hr 337.8 >1hr 349.6 Less robust. Bad valueordering?Sym breaking, pagodahelp.
Model C + Corner Bias Value Ordering Basic Pair Sym Breaking Pagoda Functions Pagoda+Sym 2903 221.5 2730 54.6 Blank: all >1hr 439 61.1 443 64.9 7 2.7 8 2.7 0.7 17 3.5 18 4.9 16 4.1 7.9 5 1700 197 1712 199.9 1.2 1.3 >1hr 1891.2 >1hr 1036 116 19.1 102 22,3 >1hr 337.8 >1hr 349.6 0.7 Taking symmetry backinto account, can nowcover all but one reversal 1.2 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.
Fool’s 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.
Fool’s Solitaire: IP Model C[i,j,t]=1 iff there is a peg at position i,j with a legal move. • Moves, connection of board states same as model A. New objective function. Minimise:
Fool’s Solitaire: CP Model • Modified version of model C. • An extra transition, deadEnd, is added to the 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:
Fool’s 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.