Upload
karen-patterson
View
214
Download
0
Embed Size (px)
DESCRIPTION
initial state goal state A trivial example
Citation preview
8puzzle in CP
1
4
6
2
7
3
5
8
1
4
2
7
6
3
5
8
initialstate
goal state
A trivial example
146
2
7
358
146
27
358
14
276
358
1
4
276
358
146
2
7
358
1
4
276
358
147
258
369
Representation
1 4 72 5 83 6 9
146
2
7
358
1
4
276
358
Representation
1 4 62 73 5 81 4 62 73 5 81 42 7 63 5 81 42 7 63 5 8
146
2
7
358
1
4
276
358
Representationof states
To get from initial state to a goal state we make a number of movesand moves take us to new states
If we have a plan that takes us from I to G in n stepswe will have n-1 states between I and G
• Represent a state as 9 constrained integer variables• S[i] has a value [0..8], the tile in position i• the value 0 corresponds to the blank tile
Therefore for a plan, let’s say of 3 steps from I to G we will havestates S[1..4][1..9]
S[1][5] is the tile in the 5th position of the 1st state (and is 0 in our example)
146
2
7
358
1
4
276
358
Representationof moves
There are 24 possible moves from a state
position of blank (zero) possible moves (swaps) move numbers 1 (1,2),(1,4) 1,2 2 (2,1),(2,3),(2,5) 3,4,5 3 (3,2),(3,6) 6,7 4 (4,1),(4,5),(4,7) 8,9,10 5 (5,2),(5,4),(5,6),(5,8) 11,12,13,14, 6 (6,3),(6,5),(6,9) 15,16,17 7 (7,4),(7,8) 18,19 8 (8,5),(8,7),(8,9) 20,21,22 9 (9,6),(9,8) 23,24
147
258
369
We have n-1 move variables, where move[i] has a domain [1..24]
146
2
7
358
1
4
276
358
Representationof moves & states
1 4 62 73 5 8
1 4 62 73 5 8
1 42 7 63 5 8
1 42 7 63 5 8
move[1] = 14
move[2] = 21
move[1] = 18
position of blank (zero) possible moves (swaps) move numbers 1 (1,2),(1,4) 1,2 2 (2,1),(2,3),(2,5) 3,4,5 3 (3,2),(3,6) 6,7 4 (4,1),(4,5),(4,7) 8,9,10 5 (5,2),(5,4),(5,6),(5,8) 11,12,13,14, 6 (6,3),(6,5),(6,9) 15,16,17 7 (7,4),(7,8) 18,19 8 (8,5),(8,7),(8,9) 20,21,22 9 (9,6),(9,8) 23,24
146
2
7
358
1
4
276
358
Constraints on a move
]2][1[]1][2[0]2][2[1]1[0]1][1[ SSSmoveS
If we are in state 1 and the blank tile is in position 1 and we make move 1 (swap(1,2))then in state 2 the blank is in position 2 and what is in position 2 of in state 1 is now in position 1 in state 2
]4][1[]1][2[0]4][2[2]1[0]1][1[ SSSmoveS
]2][1[]1][2[0]2][2[3]1[0]2][1[ SSSmoveS
]3][1[]2][2[0]3][2[4]1[0]2][1[ SSSmoveS
]8][1[]9][2[0]8][2[24]1[0]9][1[ SSSmoveS
...
146
2
7
358
1
4
276
358
Constraints on a move
]2][1[]1][[0]2][[1]1[0]1][1[ nSnSnSnmovenS
]4][1[]1][[0]4][[2]1[0]1][1[ nSnSnSnmovenS
]2][1[]1][[0]2][[3]1[0]2][1[ nSnSnSnmovenS
]3][1[]2][[0]3][[4]1[0]2][1[ nSnSnSnmovenS
]8][1[]9][[0]8][[24]1[0]9][1[ nSnSnSnmovenS
...
146
2
7
358
1
4
276
358
Constraints on a move
But … when we make a move, only the things that we move change!
This is the frame problem (GOF AI)
]8][2[]8][1[]7][2[]7][1[]6][2[]6][1[]5][2[]5][1[]4][2[]4][1[]3][2[]3][1[
]2][1[]1][2[0]2][2[1]1[0]1][1[
SSSSSSSSSSSSSSSmoveS
… and so on
146
2
7
358
1
4
276
358
Constraints on a move
We also need to say that if the blank tile (zero) is notin a specific position we cannot make a specified move
2]1[1]1[0]1][1[ movemoveS
… and so on
This is one of our propagation steps!
146
2
7
358
1
4
276
358
Solving
The move variables are our decision variablesFind values for the move variables that satisfy the constraintsThis will find a plan of n-1 steps if one exists
146
2
7
358
1
4
276
358
Bi-directional search
Search from I to G and from G to I simultaneously
• Replace the variables move[i]• introduce fmove[i]
• the forwards move from state i to state i+1• introduce bmove[i]
• the backward move from state i + 1 to I• post all the constraints we had before in both directions!• add the following constriants
I call this a bridge between backward & forward moves
We can now search in the following orderfmove[1],bmove[n-1],fmove[2],bmove[n-2] ...
][][][ xinverseibmovexifmove
146
2
7
358
1
4
276
358
Propagation through plans
There is little if any propagation through plans
146
2
7
358
1
4
276
358
Propagation through plans
There is little if any propagation through plans
If in state i I cannot move the blank tile into position xthen in state i+1 I cannot make a move out of position x!
Example: If at time I cannot put the bunch of flowers on the table then at time +1 I cannot move the bunch of flowers from the table
146
2
7
358
1
4
276
358
Propagation through plans
If in state i I cannot move the blank tile into position xthen in state i+1 I cannot make a move out of position x!
2]2[1]2[8]1[3]1[ fmovefmovefmovefmove
position of blank (zero) possible moves (swaps) move numbers 1 (1,2),(1,4) 1,2 2 (2,1),(2,3),(2,5) 3,4,5 3 (3,2),(3,6) 6,7 4 (4,1),(4,5),(4,7) 8,9,10 5 (5,2),(5,4),(5,6),(5,8) 11,12,13,14, 6 (6,3),(6,5),(6,9) 15,16,17 7 (7,4),(7,8) 18,19 8 (8,5),(8,7),(8,9) 20,21,22 9 (9,6),(9,8) 23,24
I call this a rippling constraint
146
2
7
358
1
4
276
358
My problems with planning
• what happens if we cannot find a plan in n-1 steps?• Build a bigger model … or• add another layer to the model
• like iterative dfs• could we have a null move, i.e. a move[i] = 0
• yes, but we have to condition the rippling constraint• our rippling constraint can generate a contradiction otherwise!
• the model is BIG• I’m working on something neater
That’s all for now folks