20
Best-First Search: The A* Algorithm Keith L. Downing August 22, 2017 Keith L. Downing Best-First Search: The A* Algorithm

Best-First Search: The A* Algorithm - NTNU · Incremental -vs- Local Search Incremental Local The problem-solver works with partial -vs- complete solutions. Keith L. Downing Best-First

  • Upload
    vonhan

  • View
    219

  • Download
    3

Embed Size (px)

Citation preview

Best-First Search: The A* Algorithm

Keith L. Downing

August 22, 2017

Keith L. Downing Best-First Search: The A* Algorithm

Search is..

A (preferably methodical) process for finding something.

Searching for:

pre-existing entities (information, objects, etc.)strategies for creating/designing entities.

Examples:

Web search (for just about anything)AI search - creates something, doesn’t just find it.Web search for AI search algorithms.

Uninformed -vs - Informed: Do points in the search space giveinformation that helps the searcher to determine the next step?

Partial -vs- Complete solutions (i.e., attempts): Could the current stateof search always be considered a complete solution, though notnecessarily good or optimal? Or is it often a partial state that must beincrementally enhanced to become a solution?

E.g. 2 approaches to origami.Closed-loop -vs- Open-loop control

Keith L. Downing Best-First Search: The A* Algorithm

Incremental -vs- Local Search

Incremental Local

The problem-solver works with partial -vs- complete solutions.

Keith L. Downing Best-First Search: The A* Algorithm

8 Puzzle: An AI Classic

1

2

34

56

78

1

234

56

78

Move Up

1

2

34

56 78

MoveDown

1

2

34

5678

Move Left

1

7

38

2456

Goal State

Current State

For this puzzle, a complete solution is a sequence of moves that achieves thegoal configuration. Typically, this is solved using incremental methods thatadd one move at a time to a partial sequence.

Keith L. Downing Best-First Search: The A* Algorithm

The Horizon of a Search Graph

Root Node Contains Starting Search State Open, Unexpanded

Closed, ExpandedExpansion = Generating Child Nodes

Expansion

Keith L. Downing Best-First Search: The A* Algorithm

3 Common Incremental Search Algorithms

Depth-First Breadth-First

Best-First

General General

Problem-Specific

"Intelligent"

Keith L. Downing Best-First Search: The A* Algorithm

Stacks, Queues and Agendas

The key decision that differentiates depth-first, breadth-first andbest-first search is: What node on the OPEN list should beexpanded next?

Depth-First: OPEN = a stack (LIFO - Last in, first out)Breadth-First: OPEN = a queue (FIFO - First in, first out)Best-First: OPEN = a sorted list known as the agenda,where sorting is based on the node’s evaluation, whichreflects the algorithm’s knowledge about that search stateand its potential to be extended into an optimal solution.

Keith L. Downing Best-First Search: The A* Algorithm

Shakey the Robot: Stanford Research Institute, 1960’s

Needed a good route-planning algorithm.Hart, Nilsson, Raphael (1968), A formal basis for the heuristicdetermination of minimum cost paths, in IEEE Transactions SystemScience and CyberneticsStill used by the vehicle-navigation industry.https://www.youtube.com/watch?v=mQ7M-zhiu7U

Keith L. Downing Best-First Search: The A* Algorithm

The Evaluation Function in Best-First Search

x

GoalState

f(x) = g(x) + h(x)

h(x)

g(x)

Concrete Estimate

Keith L. Downing Best-First Search: The A* Algorithm

The Heuristic Function: h(X)

1

2

34

56

78

1

7

38

2456

Goal StateCurrent State

Distance ??

1 35

8

Euclidiean Distance

1 35

8

Manhattan Distance

The heuristic function estimates the distance (typically in terms of the numberof moves) from the current state to the goal.

Keith L. Downing Best-First Search: The A* Algorithm

The A* Algorithm

DEFINE best-first-search()1 CLOSED← /0; OPEN← /02 Generate the initial node, n0, for the start state.3 g(n0)← 0; Calculate h(n0)4 f(n0)← g(n0) + h(n0);5 Push n0 onto OPEN.6 Do Agenda Loop

Keith L. Downing Best-First Search: The A* Algorithm

The Agenda Loop (Open List = Agenda)

If OPEN = /0 return FAIL

X← pop(OPEN)

push(X,CLOSED)

If X is a solution, return (X, SUCCEED)

SUCC← generate-all-successors(X)

For each S ∈ SUCC do:

If node S* has previously been created, and if state(S*) =state(S), then S← S*.push(S,kids(X))If not(S ∈ OPEN) and not(S ∈ CLOSED) do:

attach-and-eval(S,X)insert(S,OPEN) ;; OPEN is sorted by ascending f value.

else if g(X) + arc-cost(X,S) < g(S) then (found cheaper pathto S):

attach-and-eval(S,X)If S ∈ CLOSED then propagate-path-improvements(S)

Keith L. Downing Best-First Search: The A* Algorithm

Node Expansion in A*

A(10)

B(9) C(9)

D(8) E(10)

Agenda(Open Nodes)

C

D

E

Closed Nodes

A

B

2

1

1

1

F(7) G(7) H(8)

A(10)

B(9) C(9)

D(8) E(10)

2

1

1

1

2 1 1

Expand D

Agenda(Open Nodes)

Closed Nodes

A

B

D

C

E

H

G

F

Keith L. Downing Best-First Search: The A* Algorithm

Updating g values in A*

P1g = 4 h = 20

C1g = 5 h = 19

P2g = 2 h = 22

C2g = 6 h = 18

C1g = 3 h = 19

C2g = 4 h = 18

Before After

Keith L. Downing Best-First Search: The A* Algorithm

Admissable Heuristics for A*An admissable heuristic NEVER overestimates distance to the goal.

W

X

Y

Z

Agenda

W

X

Time

1

11

1

2

2

1

V

f(w) = 5 + 0

f(v) <= 3 + 2

h(x) <= 2

h(v) <= 2

V

X W

Z

W

Y

f(x) <= 2 + 2f(y) <= 3 + 1f(z) = 4

SolutionFound

Keith L. Downing Best-First Search: The A* Algorithm

Losing AdmissabilityIf h over-estimates for state x, node X dies on the agenda despite being onoptimal path.

W

X

Y

Z

f(x) = 2 + 4

Agenda

W

X

Time

1

11

1

2

2

1

V

f(w) = 5 + 0

f(v) = 3 + 2

h(x) = 4

h(v) = 2

V

X

W

X

W

X

SolutionFound

Keith L. Downing Best-First Search: The A* Algorithm

Rush Hour

4

0

3

21

5

0, 2, 2, 20, 0, 4, 30, 3, 4, 20, 4, 1, 21, 2, 0, 21, 4, 2, 2

ScenarioSpecification

Exit

What is g?Find an admissible h.

Keith L. Downing Best-First Search: The A* Algorithm

Missionaries and Cannibals: A Classic AI Puzzle

M

M

MC C

C

3 x (M,C) => Boat holds 2(4 or 5) x (M,C) => Boat holds 3(6 or more) x (M,C) => Boat holds 4

What is g?Find an admissible h.

Keith L. Downing Best-First Search: The A* Algorithm

The Switchboard Puzzle

Start

End

Visit every peg from start to end. Neighbor distance is D, buteach turn requires an extra amount, W, for wrapping.

What is g?Find an admissible h.

Keith L. Downing Best-First Search: The A* Algorithm

Example Demos

Missionaries and CannibalsRush HourNavigation

Keith L. Downing Best-First Search: The A* Algorithm