Post on 09-Mar-2018
transcript
© HSLU - JK
Artificial Intelligence 2.2 Heuristic (Informed) Search
Prof. Dr. Jana Koehler Fall 2016
© HSLU - JK
Agenda
Using Knowledge during Search – evaluation of search states – admissible and monotone (consistent) Heuristics – finding good heuristics
(1) Greedy Best-First Search (2) A* and IDA* (3) Recursive Best-First Search
Artificial Intelligence 2016 - Heuristic Search 2
© HSLU - JK
How to Determine the next Node for Expansion?
Uninformed Search – rigid procedure, no knowledge of the cost from a node to
the goal – e.g. FIFO, LIFO queues
Informed Search
– "value" of expanding a node as knowledge that steers the search algorithm through the search space
– evaluation function f(n) assigns a real number to each node
Artificial Intelligence 2016 - Heuristic Search 3
© HSLU - JK
The Evaluation Function f(n) = g(n) + h(n)
Artificial Intelligence 2016 - Heuristic Search 4
g(n) = the costs from the initial state to the current state (a precise value)
+ h(n) = the costs from the current state to the goal state (an estimated value)
© HSLU - JK
Heuristic Function h(n)
h(n) is a heuristic – describes the estimated costs from node n to a goal state
Heuristics are problem-specific and steer the search
Important properties of h(n)
– h(n) = 0 if n is a goal state – h is admissible – h is consistent
Artificial Intelligence 2016 - Heuristic Search 5
© HSLU - JK
Admissible h(n)
h*(n) = the real costs of the optimal path from node n to the goal
h is admissible if it guarantees for all n
h is an optimistic estimate of the costs that actually occur – it underestimates the real costs
Artificial Intelligence 2016 - Heuristic Search 6
© HSLU - JK
Consistent (Monotone) h(n)
Artificial Intelligence 2016 - Heuristic Search 7
goal state
a node n
n' is a successor of n
c(n,a,n') step cost of getting from n to n' with action a
h(n)
h(n')
a
Die Dreiecksungleichung muss erfüllt sein. triangle inequality: each side of a triangle cannot be longer than the sum of the other two sides
© HSLU - JK
(1) Greedy (Best-First) Search
Uses f(n) = h(n) Epands the node first that is estimated as being closest to
the goal Does not consider the current path costs
– "counterpart" to uniform-cost search, which uses f(n) = g(n)
Artificial Intelligence 2016 - Heuristic Search 8
© HSLU - JK
Greedy Search on the Romania Travel Example
Artificial Intelligence 2016 - Heuristic Search 9
h: Aerial Distances to Bucharest
© HSLU - JK
Artificial Intelligence 2016 - Heuristic Search 10
© HSLU - JK
Example of Incompleteness
Artificial Intelligence 2016 - Heuristic Search 11
Problem: From Iasi to Fagaras • Iasi to Neamt estimated shorter than Vaslui to Fagaras • Neamt is expanded, but it is a dead-end the algorithm gets stuck without finding a solution
if it expands Neamt, it puts Iasi back into the frontier (infinite loop)
Cannot use this table, why?
© HSLU - JK
Properties of Greedy Search
minimal search costs (expands a single path) not optimal incomplete (graph search is complete on finite spaces) time and space complexity is O(bm) m - maximum depth
Artificial Intelligence 2016 - Heuristic Search 12
© HSLU - JK
Greedy search only uses h(n)
Uniform-Cost search uses g(n) – finds an optimal solution if path costs grow monotonically
A* uses f(n) = g(n) + h(n)
A* combines both using preferably admissible and consistent heuristics
(2) A* (Hart, Nilsson, Raphael 1968)
Artificial Intelligence 2016 - Heuristic Search 13
© HSLU - JK
Properties of A*
Complete – if a solution exists, A* will find it provided that
1) every node has a finite number of successor nodes, and 2) each action has positive and finite costs
Optimal – first solution found has minimum path cost if h is
admissible (on trees) or if h is consistent (on graphs) • under an admissable heuristics on graphs, A* needs to expand
all nodes with f(n) <= C* (cost of optimal solution)
Complexity – space and time exponential in the path length of the
solution
Artificial Intelligence 2016 - Heuristic Search 14
© HSLU - JK
f-based Contours in a Search Space
A* fans out from the start node, adding nodes in concentric bands of increasing f-costs – with good heuristics the bands stretch towards the goal state and are
more narrowly focused around the optimal path
Artificial Intelligence 2016 - Heuristic Search 15
© HSLU - JK
Branch and Bound under admissible Heuristics
Artificial Intelligence 2016 - Heuristic Search 16
a first solution with cost C has been found
…
f(n) > C
all nodes with f > C can be pruned from the search space
A* on graphs finds a first solution s with cost C, - if f is consistent, s is the optimal solution - if f is only admissible, A* needs to expand all nodes with lower or equal
costs than C, until only nodes with f(n) > C are left to be sure that s is the optimal solution
© HSLU - JK
IDA* (Korf 1985)
A* requires exponential memory in the worst case – combine with Depth-Limited Search
Idea: use successive iterations with increasing f costs – use f bounds instead of bounding the length of the path
At each iteration, perform a depth-first search, cutting off a
branch when its total cost (g + h) exceeds a given threshold – threshold starts at the estimate of the cost of the initial
state, and increases for each iteration of the algorithm – at each iteration, the threshold used for the next iteration
is the minimum cost of all values that exceeded the current threshold
Artificial Intelligence 2016 - Heuristic Search 17
© HSLU - JK
Example of IDA*
initial f-cost limit = 366 (f-costs of the initial state) – first expansion: T=118 +329, S=140+253, Z=75+374
next f-cost limit = 393 (S)
Artificial Intelligence 2016 - Heuristic Search 18
© HSLU - JK
Heuristics
Informed search depends on good heuristics
Heuristic = method to help solve a problem, commonly informal – "rules of thumb", educated guesses, intuitive judgments
or simply common sense
Artificial Intelligence 2016 - Heuristic Search 22
© HSLU - JK
Designing Heuristic Functions
The informedness of the heuristic is critical for the success of the search algorithm – steer the algorithm towards the most promising parts of
the search space – recognize dead ends early – find a near-optimal solution under practical conditions
Requires an understanding of the application domain
– keep heuristic and search approach separate – try out different variants in empirical tests – an art …(… and a hot topic in AI research)
Artificial Intelligence 2016 - Heuristic Search 23
© HSLU - JK
Heuristic Functions Example
Artificial Intelligence 2016 - Heuristic Search 24
(Misplaced Tiles)
© HSLU - JK
Misplaced Tiles vs. Manhattan Distance
Distance between two points measured along axes at right angles
Disadvantage: considers all tiles independently
Artificial Intelligence 2016 - Heuristic Search 25
h1 = 8 (all tiles are misplaced)
h2 = 3 + 1 + 2 + … = 18
goal position
current position
initial state goal state
© HSLU - JK
Empirical Comparison of Both Example Heuristics
Artificial Intelligence 2016 - Heuristic Search 26
© HSLU - JK
Linear Conflict Heuristic vs. Manhattan Distance
Two tiles tj and tk are in a linear conflict if tj and tk are in the same line, the goal positions of tj and tk are both in that line, tj is to the right of tk and the goal position of tj is to the left of the goal position of tk – LC will add a cost of 2 moves for each pair of conflicting
tiles to the Manhattan Distance – motivation: tiles need to surround one another
Artificial Intelligence 2016 - Heuristic Search 27
MH = 2 + 0 = 2 LC = 2 + 2 = 4
© HSLU - JK
Gaschnigs Heuristic
Relaxed Move: Any tile can be moved to the blank position (count the number of swaps) If 9 is not at the 1st position & the permutation is not a solution then swap 9 with the element whose target position 9 is taking else swap 9 with the rightmost element that is not in its proper place
Artificial Intelligence 2016 - Heuristic Search 28
9 stands for the blank transform 724596831 into 912345678
724596831 – 729546831 – 792546831 – 712546839 – 712546938 – 712549638 – 712945638 – 712345698 – 912345678 = 8 swaps
© HSLU - JK
Applying Gaschnigs Heuristic During Search
4 successor nodes Compute the number of swaps for each node Expand the node with the fewest number of swaps first Problem relaxation is a powerful idea and very successfully
used to derive good heuristics Artificial Intelligence 2016 - Heuristic Search 29
724596831
794526831 724956831 724569831 724536891
© HSLU - JK
General Technique: Problem Relaxation
Primitive Predicates in the N-Puzzle – ON(x, y) : tile x is on cell y – CLEAR(y) : cell y is clear of tiles – ADJ(y, z) : cell y is adjacent to cell z
Move(x, y, z) preconditions : ON(x, y) & CLEAR(z) & ADJ(y, z) effects : ON(x, z) & CLEAR(y) & NOT ON(x, y) & NOT CLEAR(z)
Remove CLEAR(z) & ADJ(y, z) – Misplaced Tile Distance Remove CLEAR(z) – Manhattan Distance Remove ADJ(y, z) – Gaschnigs Distance
Artificial Intelligence 2016 - Heuristic Search 30
© HSLU - JK
Pattern Database
Apply the Divide and Conquer principle – decompose the problem into subproblems (subgoals) – store solutions to the subproblems with associated costs
(patterns) – reuse these solutions
Famous example: end game libraries in chess Artificial Intelligence 2016 - Heuristic Search 31
Divide the 15 puzzle into Fringe + 8 puzzle • map the current location of the fringe tiles
into an index of the database • the data base tells us the minimal number
of moves to achieve the fringe • achieve the fringe + solve the remaining 8
puzzle
© HSLU - JK
Learning Heuristic Functions
Relaxed problem heuristic
– problem with fewer restrictions on the actions is called a relaxed problem
– cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem
Modern search algorithms analyze the domain and the given problem instance – learn a problem-instance specific heuristic before they
start searching
Artificial Intelligence 2016 - Heuristic Search 32
© HSLU - JK
Summary Questions
1. Explain the underlying ideas of greedy best-first search, A* and IDA*.
2. What are the properties of A*? 3. Why can IDA* be more efficient in practice? 4. What is the principal idea behind branch and bound? 5. What are heuristics, which role do they play in informed
search, and how can we develop good heuristics? 6. What is an admissible heuristics? 7. What can happen with A* if f is non-admissible?
Artificial Intelligence 2016 - Heuristic Search 33
© HSLU - JK
Exercise 2.2.1 A* Search of the Example
Take the path costs from the Romania map for g(n) and the aerial distance estimates for h(h) a) Perform an A* search from Arad to Bucharest! b) Do you obtain the optimal route as the solution? Why?
Artificial Intelligence 2016 - Heuristic Search 34
© HSLU - JK
a) Formalize the vacuum world with a variable number of rooms, one cleaning agent, the actions left, right, up, down, suck (each with costs 1) that are always executable in any state. A room can be clean or dirty, with some random dirt distribution that is known to the agent. The goal is to have all rooms clean.
b) Define a simple to compute heuristic and expand an A* search tree to depth 3 using your heuristic starting from the initial state shown below. Show the values for f(h), g(n), h(n)
c) Give an argument why your heuristic is or is not admissible + monotone. Hint: the goal of this exercise is to investigate how A* explores the search and how this is influenced by the heuristic. Your heuristic does not need to be admissible and monotone.
Exercise 2.2.2 A* for the Vacuum World
Artificial Intelligence 2016 - Heuristic Search 35
TESTAT bis zum 9.10. 24:00