inf2d05: informedsearchandexploration foragents · outline best-firstsearch...

29
Inf2D 05: Informed Search and Exploration for Agents Stefano Albrecht School of Informatics, University of Edinburgh 25/01/18 Slide Credits: Jacques Fleuriot, Michael Rovatsos, Michael Herrmann

Upload: ngokhue

Post on 22-Apr-2018

222 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Inf2D 05: Informed Search and Explorationfor Agents

Stefano Albrecht

School of Informatics, University of Edinburgh

25/01/18

Slide Credits: Jacques Fleuriot, Michael Rovatsos, Michael Herrmann

Page 2: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Outline

Best-first searchGreedy best-first searchA∗ searchHeuristicsAdmissibility

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 3: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Review: Tree search

A search strategy is defined by picking the order of nodeexpansion from the frontier

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 4: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Best-first search

An instance of general TREE-SEARCH orGRAPH-SEARCHIdea: use an evaluation function f (n) for each node n

estimate of “desirability”Ü Expand most desirable unexpanded node, usually thenode with the lowest evaluation

Implementation:Order the nodes in frontier in decreasing order ofdesirabilitySpecial cases:

Greedy best-first searchA∗search

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 5: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Romania with step costs in km

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 6: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Greedy best-first search

Evaluation function f (n) = h(n) (heuristic)h(n): estimated cost of cheapest path from state at noden to a goal state

e.g., hSLD(n): straight-line distance from n to goal(Bucharest)Greedy best-first search expands the node that appearsto be closest to goal

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 7: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Added slide: HeuristicWhat is a heuristic?

From the greek word “heuriskein” meaning “to discover”or “to find”A heuristic is any method that is believed or practicallyproven to be useful for the solution of a given problem,although there is no guarantee that it will always work orlead to an optimal solution.Here we will use heuristics to guide tree search. This maynot change the worst case complexity of the algorithm,but can help in the average case.We will introduce conditions (admissibility, consistency,see below) in order to identify good heuristics, i.e. thosewhich actually lead to an improvement over uninformedsearch.See also: https://en.wikipedia.org/wiki/Heuristic

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 8: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Greedy best-first search example

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 9: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Greedy best-first search example

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 10: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Greedy best-first search example

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 11: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Greedy best-first search example

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 12: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Properties of greedy best-first search

Complete? No – can get stuck in loops

Graph search version is complete in finite space, but notin infinite ones

Time? O(bm) for tree version, but a good heuristic cangive dramatic improvementSpace? O(bm) – keeps all nodes in memoryOptimal? No

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 13: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

A∗ search

Idea: avoid expanding paths that are already expensiveEvaluation function f (n) = g(n) + h(n)

g(n): cost so far to reach nh(n): estimated cost from n to goalf (n): estimated total cost of path through n to goal

A∗ is both complete and optimal if h(n) satisfies certainconditions

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 14: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

A∗ search example

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 15: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

A∗ search example

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 16: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

A∗ search example

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 17: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

A∗ search example

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 18: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

A∗ search example

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 19: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

A∗ search example

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 20: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Admissible heuristics

A heuristic h(n) is admissible if for every node n,h(n) ≤ h∗(n), where h∗(n) is the true cost to reach thegoal state from n.An admissible heuristic never overestimates the cost toreach the goal, i.e., it is optimistic

Thus, f (n) = g(n) + h(n) never overestimates the truecost of a solution

Example: hSLD(n) (never overestimates the actual roaddistance)Theorem: If h(n) is admissible, A∗ using TREE-SEARCHis optimal.

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 21: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Optimality of A∗ (proof)

Suppose some suboptimal goal G2 has been generatedand is in the frontier. Let n be an unexpanded node inthe frontier such that n is on a shortest path to anoptimal goal G .

f (G2) = g(G2) since h(G2) = 0f (G ) = g(G ) since h(G ) = 0g(G2) > g(G ) since G2 is suboptimalf (G2) > f (G ) from above

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 22: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Optimality of A∗ (proof cntd.)

Suppose some suboptimal goal G2 has been generatedand is in the frontier. Let n be an unexpanded node inthe frontier such that n is on a shortest path to anoptimal goal G .

f (G ) < f (G2) from above (G2 is suboptimal)h(n) ≤ h∗(n) since h is admissibleg(n) + h (n) ≤ g (n) + h∗ (n) = f (G )f (n) ≤ f (G )

Hence f (n) < f (G2) ⇒ A∗ will never select G2 for expansion.

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 23: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Consistent heuristics

A heuristic is consistent if for every node n, everysuccessor n′ of n generated by any action a,

h(n) ≤ c(n, a, n′) + h(n′)

If h is consistent, we have

f (n′) = g(n′) + h(n′)

= g(n) + c(n, a, n′) + h(n′)

≥ g(n) + h(n)

≥ f (n)

i.e., f (n) is non-decreasingalong any path.

Theorem:If h(n) is consistent, A∗ using GRAPH-SEARCH is optimal.

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 24: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Optimality of A∗

A∗ expands nodes in order of increasing f valueGradually adds “f -contours” of nodesContour i has all nodes with f = fi , where fi < fi+1

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 25: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Properties of A∗

Complete? Yes (unless there are infinitely many nodeswith f ≤ f (G ))Time? ExponentialSpace? Keeps all nodes in memoryOptimal? Yes

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 26: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Admissible heuristics

Example:

for the 8-puzzle:

h1(n): number of misplaced tilesh2(n): total Manhattan distance

(i.e., no. of squares from desired location of each tile)

Exercise: Calculatethese two values:

h1 (S) = ?

h2 (S) = ?

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 27: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Dominance

If h2(n) ≥ h1(n) for all n (both admissible) then

h2 dominates h1h2 is better for search

Typical search costs (average number of nodes expanded):

d = 12 IDS = 3,644,035 nodesA∗(h1) = 227 nodesA∗(h2) = 73 nodes

d = 24 IDS = too many nodesA∗(h1) = 39,135 nodesA∗(h2) = 1,641 nodes

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 28: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Relaxed problems

A problem with fewer restrictions on the actions is calleda relaxed problemThe cost of an optimal solution to a relaxed problem is anadmissible heuristic for the original problemIf the rules of the 8-puzzle are relaxed so that a tile canmove anywhere,

then h1(n) gives the shortest solution

If the rules are relaxed so that a tile can move to anyadjacent square,

then h2(n) gives the shortest solution

Can use relaxation to automatically generate admissibleheuristics

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents

Page 29: Inf2D05: InformedSearchandExploration forAgents · Outline Best-firstsearch Greedybest-firstsearch A search Heuristics Admissibility Stefano Albrecht Inf2D 05: Informed Search and

Summary

Smart search based on heuristic scores.

Best-first searchGreedy best-first searchA∗ searchAdmissible heuristics and optimality.

Stefano Albrecht Inf2D 05: Informed Search and Exploration for Agents