heuristics for sliding- tile puzzles shaun gause yu cao cse department university of south carolina
TRANSCRIPT
Heuristics for Heuristics for slidisliding-tile ng-tile
puzzlespuzzlesShaun GauseShaun Gause
Yu CaoYu CaoCSE DepartmentCSE Department
University of South CarolinaUniversity of South Carolina
ContentsContents
IntroductionIntroduction Heuristic SearchHeuristic Search Relaxed Heuristic FunctionsRelaxed Heuristic Functions Pattern Database HeuristicPattern Database Heuristic Linear Conflict HeuristicLinear Conflict Heuristic Gaschnig’s HeuristicGaschnig’s Heuristic ConclusionConclusion
Sliding-Tile PuzzleSliding-Tile Puzzle
Invented by Sam Loyd in the 1870’sInvented by Sam Loyd in the 1870’s The oldest type of sliding block puzzleThe oldest type of sliding block puzzle
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Solving Sliding Puzzle Solving Sliding Puzzle ProblemProblem
Brute-Force Search (Exhaustive Exhaustive SearchSearch).
Heuristic Search (A*, IDA*,etc).
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Brute Force Brute Force (Exhaustive Search)(Exhaustive Search)
8 Puzzle: 108 Puzzle: 105 5 .01 seconds.01 seconds 15 Puzzle: 1015 Puzzle: 1013 13 6 days6 days 24 Puzzle: 1024 Puzzle: 1025 25 12 billion years12 billion years 48 Puzzle: 1048 Puzzle: 104848 why dinosaurs why dinosaurs
really went really went extinctextinct
Brute-Force Search Time (10 million nodes/second)
Problem Nodes
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
A*A* Hart, Nilsson, and Raphael, 1968Hart, Nilsson, and Raphael, 1968 Best-first search with cost functionBest-first search with cost function
f’(s)=g(s)+h’(s) f’(s)=g(s)+h’(s) g(s) – length of the shortest path from initig(s) – length of the shortest path from initi
al state to sal state to s h’(s) – length of the shortest path from s h’(s) – length of the shortest path from s
to any goal stateto any goal state A* stores all the nodes it generates, exA* stores all the nodes it generates, ex
hausting available memory in minutes.hausting available memory in minutes.
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Iterative-Deepening-A* Iterative-Deepening-A* (IDA*)(IDA*)
IDA* (Korf, 1985) is a linear-space versiIDA* (Korf, 1985) is a linear-space version of A*, using the same cost function.on of A*, using the same cost function.
Each iteration searches depth-first for Each iteration searches depth-first for solutions of a given length.solutions of a given length.
IDA* is simpler, and often faster than IDA* is simpler, and often faster than A*, due to less overhead per node.A*, due to less overhead per node.
First to find optimal solution to randoFirst to find optimal solution to random instances of 15-Puzzle (using Manham instances of 15-Puzzle (using Manhattan distance)ttan distance)
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Heuristics (Wikipedia)Heuristics (Wikipedia) A method to help solve a problem, A method to help solve a problem,
commonly informal. commonly informal. It is particularly used for a method It is particularly used for a method
that often rapidly leads to a solution that often rapidly leads to a solution that is usually reasonably close to that is usually reasonably close to the best possible answer. the best possible answer.
Heuristics are "rules of thumb", Heuristics are "rules of thumb", educated guesses, intuitive educated guesses, intuitive judgments or simply common sense.judgments or simply common sense.
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Admissible HeuristicsAdmissible Heuristics Never over estimatedNever over estimated Guaranteed to find optimal solutions (AGuaranteed to find optimal solutions (A
* or IDA*)* or IDA*) Based on evaluation function: f’(s) = gBased on evaluation function: f’(s) = g
(s) + h’(s)(s) + h’(s)
h’(s)h’(s): estimate of length of shortest path fr: estimate of length of shortest path from s to goal stateom s to goal state
h(s)h(s): actual length: actual length
)]()('[ shshs
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Monotone HeuristicMonotone Heuristic Closed SetClosed Set Implies AdmissibleImplies Admissible
Not all Admissible are MonotoneNot all Admissible are Monotone Based on evaluation function: f’(s) = g(s) + Based on evaluation function: f’(s) = g(s) +
h’(s)h’(s)
s’: successor of ss’: successor of s f’(s): evaluation functionf’(s): evaluation function f’(s’): evaluation function of the successor statf’(s’): evaluation function of the successor stat
ee
)]'(')('[', sfsfss
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Relaxed HeuristicRelaxed Heuristic
Relaxed problemRelaxed problem
A problem with fewer restrictions on A problem with fewer restrictions on the actions is called a relaxed the actions is called a relaxed problem.problem.
The cost of an optimal solution to a The cost of an optimal solution to a relaxed problem is an admissible relaxed problem is an admissible heuristic for the original problem.heuristic for the original problem.
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Systematic RelaxationSystematic Relaxation
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Precondition ListPrecondition List A conjunction of predicates that must hold true before the A conjunction of predicates that must hold true before the
action can be appliedaction can be applied Add ListAdd List
A list of predicates that are to be added to the description A list of predicates that are to be added to the description of the world-state as a result of applying the actionof the world-state as a result of applying the action
Delete ListDelete List A list of predicates that are no longer true once the action A list of predicates that are no longer true once the action
is applied and should, therefore, be deleted from the state is applied and should, therefore, be deleted from the state descriptiondescription
Primitive PredicatesPrimitive Predicates ON(x, y)ON(x, y) :: tile x is on cell ytile x is on cell y CLEAR(y)CLEAR(y) :: cell y is clear of tilescell y is clear of tiles ADJ(y, z)ADJ(y, z) :: cell y is adjacent to cell zcell y is adjacent to cell z
Two simple relaxed models of Two simple relaxed models of Sliding Puzzle problemsSliding Puzzle problems
We can generate two simple relaxed models by rWe can generate two simple relaxed models by removing certain conditions:emoving certain conditions:
Move(x, y, z):Move(x, y, z):precondition listprecondition list :: ON(x, y), CLEAR(z), AON(x, y), CLEAR(z), ADJ(y, z)DJ(y, z)add listadd list :: ON(x, z), CLEAR(y)ON(x, z), CLEAR(y)delete listdelete list :: ON(x, y), CLEAR(z)ON(x, y), CLEAR(z)
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
(1) By removing CLEAR(z) and ADJ(y, z), we can (1) By removing CLEAR(z) and ADJ(y, z), we can derive “Misplaced distance”.derive “Misplaced distance”.
Misplaced distance is 1+1=2 movesMisplaced distance is 1+1=2 moves
1 2 34 5 6 78 9 10 11
12 13 14 15
15 1 2 34 5 6 78 9 10 11
13 14 12
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
(2) By removing CLEAR(z), we can derive “Man(2) By removing CLEAR(z), we can derive “Manhattan distance”.hattan distance”.
Manhattan distance is 6+3=9 movesManhattan distance is 6+3=9 moves
1 2 34 5 6 78 9 10 11
12 13 14 15
15 1 2 34 5 6 78 9 10 11
13 14 12
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Three more relaxed heuristic Three more relaxed heuristic functionsfunctions
Pattern Database HeuristicsPattern Database Heuristics
Linear Conflict HeuristicsLinear Conflict Heuristics
Gaschnig’s HeuristicsGaschnig’s Heuristics
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Pattern Database HeuristicsPattern Database Heuristics
The idea behind pattern database The idea behind pattern database heuristics is to store these exact heuristics is to store these exact solution costs for every possible sub-solution costs for every possible sub-problem instance.problem instance.
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Fringe PatternFringe Pattern
37
1112 13 14 15
14 73
15 1211 13
37
1112 13 14 15
7 1312
15 311 14
37
1112 13 14 15
12 117 14
13 315
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Disjoint Pattern Database Disjoint Pattern Database HeuristicsHeuristics
Two or more patterns that have no tiles in Two or more patterns that have no tiles in common.common.
Add together the heuristic values from the Add together the heuristic values from the different databases.different databases.
The sum of different heuristics results still The sum of different heuristics results still be an admissible functions which is closed be an admissible functions which is closed to the actual optimal cost.to the actual optimal cost.
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Examples for Disjoint Pattern Database Examples for Disjoint Pattern Database HeuristicsHeuristics
1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
5 10 14 7
8 3 6 1
15 12 9
2 11 4 13
20 moves needed to solve red tiles25 moves needed to solve blue tiles
Overall heuristic is sum, or 20+25=45 moves
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
1 2 34 5 6 78 9 10 11
12 13 14 15
5 10 14 78 3 6 1
15 12 92 11 4 13
Overall heuristic is sum of the Manhattan Distance of each tile which is 39 moves.
A trivial example of disjoint pattern A trivial example of disjoint pattern database heuristics is Manhattan database heuristics is Manhattan Distance in the case that I view every Distance in the case that I view every slide as a single pattern databaseslide as a single pattern database
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Def. Linear Conflict HeuristicDef. Linear Conflict Heuristic--Two tiles t--Two tiles tj j and tand tkk are in a linear conflict if are in a linear conflict if
ttjj and t and tkk are the same line, the goal positio are the same line, the goal positions of tns of tjj and t and tkk are both in that line, t are both in that line, t jj is to t is to the right of the right of tkk, and goal position of t, and goal position of t jj is to t is to the left of the goal position of the left of the goal position of tkk..
Linear Conflict Heuristic Linear Conflict Heuristic FunctionFunction
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Linear Conflict ExampleLinear Conflict Example
1 33 1
Manhattan distance is 2+2=4 moves
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
1 33 1
Manhattan distance is 2+2=4 moves
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Linear Conflict ExampleLinear Conflict Example
1 331
Manhattan distance is 2+2=4 moves
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Linear Conflict ExampleLinear Conflict Example
1 331
Manhattan distance is 2+2=4 moves
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Linear Conflict ExampleLinear Conflict Example
1 331
Manhattan distance is 2+2=4 moves
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Linear Conflict ExampleLinear Conflict Example
1 331
Manhattan distance is 2+2=4 moves
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Linear Conflict ExampleLinear Conflict Example
1 331
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Manhattan distance is 2+2=4 moves
Linear Conflict ExampleLinear Conflict Example
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Consistency of Linear Consistency of Linear ConflictConflict
The linear conflict heuristic cost will at The linear conflict heuristic cost will at least 2 more than Manhattan distance. least 2 more than Manhattan distance.
Linear conflict heuristic is more Linear conflict heuristic is more accurate or more informative than just accurate or more informative than just using Manhattan Distance since it is using Manhattan Distance since it is closer to the actual optimal cost.closer to the actual optimal cost.
Linear Conflict Heuristic Linear Conflict Heuristic FunctionFunction
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Gaschnig introduced the 9MAXSWAP proGaschnig introduced the 9MAXSWAP problem.blem.
The relaxed problem assume that a tile caThe relaxed problem assume that a tile can move from square A to B if B is blank, bn move from square A to B if B is blank, but A and B do not need to be adjacent.ut A and B do not need to be adjacent.
It underestimates the distance function of It underestimates the distance function of 8-puzzle, it is a closer approximation of th8-puzzle, it is a closer approximation of the 8-puzzle’s distance.e 8-puzzle’s distance.
Gaschnig’s Heuristic FunctioGaschnig’s Heuristic Functionn
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Maxsort AlgorithmMaxsort Algorithm One algorithm to solve 9MAXSWAP is MaOne algorithm to solve 9MAXSWAP is Ma
xsort.xsort.
P: the current permutationP: the current permutation B: the location of element i in the permutB: the location of element i in the permut
ation Array.ation Array. Basic Idea: swaps iteratively P[B[n]] with Basic Idea: swaps iteratively P[B[n]] with
P[B[b[n]]] for n-puzzle.P[B[b[n]]] for n-puzzle.
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
To apply MAXSORT as a heuristic for To apply MAXSORT as a heuristic for the 8-puzzle, we take the number of the 8-puzzle, we take the number of switches as the heuristic cost at any switches as the heuristic cost at any search node.search node.
Apply MAXSORT as A Apply MAXSORT as A HeuristicHeuristic
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Current Node : Goal Current Node : Goal Node:Node:
29613478 29613478 12345678912345678922 99 66
11 33 44
77 55 88
Gaschnig Heuristic ExampleGaschnig Heuristic Example
11 22 33
44 55 66
77 88 99
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Gaschnig Heuristic FunctionGaschnig Heuristic Functioniterationiteration permutationpermutation b arrayb array
11 296134758296134758 415683792415683792
22 926134758926134758 425683791425683791
33 126934758126934758 125683794125683794
44 126439758126439758 125483796125483796
55 129436758129436758 125486793125486793
66 123496758123496758 123486795123486795
77 123456798123456798 123456798123456798
88 123456789123456789 123456789123456789
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
Gaschnig Heuristic FunctionGaschnig Heuristic Function
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
In the previous exaIn the previous example, the Gaschnig mple, the Gaschnig Heuristic cost for thHeuristic cost for the node on the right se node on the right side is 7 which is just ide is 7 which is just the number of switcthe number of switches to make the seqhes to make the sequence 296134758 to uence 296134758 to be 123456789. (9 mebe 123456789. (9 means blank)ans blank)
22 99 66
11 33 44
77 55 88
Comparison of Heuristic Comparison of Heuristic EstimatesEstimates
PuzzlePuzzle AveraAvera
gege σ²σ²
Misplaced Misplaced TilesTiles 44 44 88 77 5.755.75 4.24.2
55Relaxed AdjaceRelaxed Adjace
ncyncy(Gaschnig’s)(Gaschnig’s)
66 66 1010 1010 885.35.3
33
ManhattanManhattanDistanceDistance
(Subset of (Subset of Pattern)Pattern)
66 66 2222 1414 121258.58.
6677
Linear Linear ConflictConflict 88 1212 2222 2424 16.516.5
59.59.6677
Actual Actual DistanceDistance 2222 2020 2626 2626 23.523.5 99
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion
SourcesSources www.tilepuzzles.comwww.tilepuzzles.com www.wikipedia.comwww.wikipedia.com Sakawa, Masatoshi and Yano, Hitoshi. “Criticizing Solutions to Relaxed Models Sakawa, Masatoshi and Yano, Hitoshi. “Criticizing Solutions to Relaxed Models
Yields Powerful Admissible Heuristics.” Information Sciences 63, 1992. 207-227Yields Powerful Admissible Heuristics.” Information Sciences 63, 1992. 207-227 Korf, Richard E. “Recent Progress in the Design and Analysis of Admissible HeuKorf, Richard E. “Recent Progress in the Design and Analysis of Admissible Heu
ristic Functions.” American Association for Artificial Intelligence, 2000.ristic Functions.” American Association for Artificial Intelligence, 2000. Gaschnig, John. “A Problem Similarity Approach to Devising Heuristics: First RGaschnig, John. “A Problem Similarity Approach to Devising Heuristics: First R
esults.” International Joint Conferences on Artificial Intelligence, 1979. 301-307.esults.” International Joint Conferences on Artificial Intelligence, 1979. 301-307. Pearl, Judea. “Heuristics: Intelligent Search Strategies for Computer Problem SPearl, Judea. “Heuristics: Intelligent Search Strategies for Computer Problem S
olving.” Addison-Wesley, 1984. 118-125.olving.” Addison-Wesley, 1984. 118-125. Hansson, Othar and Mayer, Andrew and Yung, Mordechai. “Criticizing SolutionHansson, Othar and Mayer, Andrew and Yung, Mordechai. “Criticizing Solution
s to Relaxed Models Yields Powerful Admissible Heuristics.” Information Sciens to Relaxed Models Yields Powerful Admissible Heuristics.” Information Sciences: an International Journal. Volume 63, Issue 3. 207-227.ces: an International Journal. Volume 63, Issue 3. 207-227.
Valtorta, Marco. “A Result on the Computational Complexity of Heuristic EstimValtorta, Marco. “A Result on the Computational Complexity of Heuristic Estimates for the A* Algorithm.” Information Science 34, 47-59(1984).ates for the A* Algorithm.” Information Science 34, 47-59(1984).
Hansson, Othar and Mayer, Andrew and Valtorta, Marco. “A New Result on The Hansson, Othar and Mayer, Andrew and Valtorta, Marco. “A New Result on The Complexity of Heuristic Estimates for The A* Algorithm.” Artificial Intelligence Complexity of Heuristic Estimates for The A* Algorithm.” Artificial Intelligence 55 (1992) 129-143.55 (1992) 129-143.
Korf’s Slides for “Recent Progress in the Design and Analysis of Admissible HeKorf’s Slides for “Recent Progress in the Design and Analysis of Admissible Heuristic Functions”. http://sara2000.unl.edu/Korf-slides.ppt#295,49,Time Compluristic Functions”. http://sara2000.unl.edu/Korf-slides.ppt#295,49,Time Complexity of Admissible Heuristic Search Algorithms exity of Admissible Heuristic Search Algorithms
Introduction Heuristic Search Relaxed Heuristic Functions Pattern Database Linear Conflict Gaschnig Conclusion