Admissible Search
Admissible Search
Uniform Cost
Search and A*
Search
,
Review: DFS and BFS
• Breadth-first search
• Frontier is a queue: expand the shallowest node
• Complete: always finds a solution, if one exists
• Optimal (finds the best solution) if all actions have the same cost.
• Time complexity:
• Space complexity: .
• Depth-first search – utility depends on relationship between m and d
• Frontier is a stack: expand the deepest node
• Not complete (might never find a solution, if m is infinite)
• Not optimal (returned solution is rarely the best one)
• Time complexity:
• Space complexity: .
Outline of today’s lecture
1. Uniform Cost Search (UCS): like BFS, but for actions that have different costs
• Complete: always finds a solution, if one exists
• Optimal: finds the best solution
• Time complexity = # nodes that have cost < goal
• Space complexity = # nodes that have cost < goal
2. Heuristics, e.g., Manhattan distance
3. Greedy Best-first search
4. A*: Like UCS but adds an estimate of the remaining path length
• Complete: always finds a solution, if one exists
• Optimal: finds the best solution
• Time complexity = # nodes that have cost+heuristic < goal
• Space complexity = # nodes that have cost+heuristic < goal
An example for which BFS is not optimal:
Romania
Arad
Mehadia C P Bucharest
Mehadia C P Bucharest
Bucharest
Arad:0
Example of UCS: Romania
Arad
Oradea
Lugoj Oradea
C P
Mehadia C P
Mehadia C P Bucharest
Mehadia C P Bucharest
Dobreta
Mehadia C P
Dobreta Bucharest
Mehadia C P
Dobreta Bucharest
Dobreta:384, Bucharest:418
Example of UCS: Romania
Arad
Mehadia C P
Dobreta Bucharest
Bucharest:418
GOAL!!!! GOL!!!!!
November 7, 2024 21
Consider the following
problem…
A
1 10
5 5
S B G
15 5
C
We wish to find the shortest route from node S to node G; that is, node S is the
initial state and node G is the goal state. In terms of path cost, we can clearly
see that the route SBG is the cheapest route. However, if we let breadth-first
search loose on the problem it will find the non-optimal path SAG, assuming
that A is the first node to be expanded at level 1.
Once
Node
WeNode
Wenow
Anode
start
is
Sexpand
removed
isB
with
removed
hasour
the
been
from
initial
node
from
expanded
the
state
at
the
queue
the
queue
and
front
itand
is
expand
and
removed
ofthe
the
the
revealed
queue,
revealed
fromnode
node
thenodes
queue
A.
(node
Press
areand
G)added
space
the
is added
revealed
to
tothe
to
the
node
continue.
queue.
it…
queue.
(node The
The
G)queue
isqueue
added.
isisthen
again
Thesorted
queue
sorted onisonpath
again
path
cost.
sorted
cost.Nodes
Note,
on path
with
wecost.
cheaper
haveNote,nowpath
found
nodecost
Ga have
goal
nowpriority.In
appears
state butthis
indothe
case
notqueue
recognise
the queue
twice,itwill
once
as be it is
as
Node
not
G10 atAand
the
(1),once
front
nodeof
as
Bthe
(5),
G11queue.
.followed
As G10 Node
isbyatnode
Bthe
is C
the(15).
frontcheaper
of Press
the queue,
node.
space. Press
we now space.
proceed to goal state. Press space.
A 10
1
5 5
S B G
Size of Queue: 0
1
3 Queue: A,
S 10B,
B,
G
Empty
G
, 11
GC,11C, C15
Nodes expanded: 3
0
1
2 CurrentFINISHED
action: Expanding
Waiting….
Backtracking
SEARCH Current level: 2
n/a
0
1
Goal state
We don’t know which state is closest
to goal
• Finding the shortest path is the Start state
whole point of the search
• If we already knew which state
was closest to goal, there would
be no reason to do the search
• Figuring out which one is closest,
in general, is a complexity
problem.
Goal state
Search heuristics: estimates of
distance-to-goal
• Often, even if we don’t know the
distance to the goal, we can Start state
estimate it.
• This estimate is called a
heuristic.
• A heuristic is useful if:
1. Accurate: , where is the
heuristic estimate, and is the
true distance to the goal
2. Cheap: It can be computed in
complexity less than Goal state
Example heuristic: Manhattan
distance If there were no walls, this would
• A common heuristic function be the path to goal: straight down,
Start state
used in grid-based pathfinding is then straight right.
the Manhattan distance, which
is the sum of the absolute 𝑦𝑛
differences in the x and y
coordinates between two points.
• If there were no walls in the
maze, then the number of steps
from position to the goal
position would be 𝑦𝐺 Goal state
𝑥𝑛 𝑥𝐺 𝑥
Outline of today’s lecture
1. Uniform Cost Search (UCS): like BFS, but for actions that have different costs
• Complete: always finds a solution, if one exists
• Optimal: finds the best solution
• Time complexity = # nodes that have cost < goal
• Space complexity = # nodes that have cost < goal
2. Heuristics, e.g., Manhattan distance
3. Greedy Best-first search
4. A*: Like UCS but adds an estimate of the remaining path length
• Complete: always finds a solution, if one exists
• Optimal: finds the best solution
• Time complexity = # nodes that have cost+heuristic < goal
• Space complexity = # nodes that have cost+heuristic < goal
Greedy Best-First Search
Instead of choosing the node with the smallest total cost so far (UCS),
Goal state
Greedy Search Example
Start state
If our random choice goes badly,
we might end up very far from the
goal.
Goal state
The problem with Greedy Search
Start state
That’s not a useful path…
Goal state
The problem with Greedy Search
Start state
Neither is that one…
Goal state
What went wrong?
Outline of today’s lecture
1. Uniform Cost Search (UCS): like BFS, but for actions that have different costs
• Complete: always finds a solution, if one exists
• Optimal: finds the best solution
• Time complexity = # nodes that have cost < goal
• Space complexity = # nodes that have cost < goal
2. Heuristics, e.g., Manhattan distance
3. Greedy Best-first search
4. A*: Like UCS but adds an estimate of the remaining path length
• Complete: always finds a solution, if one exists
• Optimal: finds the best solution
• Time complexity = # nodes that have cost+heuristic < goal
• Space complexity = # nodes that have cost+heuristic < goal
The problem with Greedy Search
Among nodes on the frontier, this Start state
one seems closest to goal
(smallest , where ).
• heuristic, .
Goal state
A* Search
• Idea: avoid expanding paths that are already expensive
• The evaluation function f(n) is the estimated total cost of the
path through node n to the goal:
• So if for every node n that’s still in the frontier, then we know that m is
the best path.
𝑐 (𝑚 )
m
A* Search S G
n
𝑔 (𝑛 ) ≥ h ( 𝑛)
Definition: A* SEARCH
• If is admissible , and
• if the frontier is a priority queue sorted according to , then
• the FIRST path to goal uncovered by the tree search, path , is
guaranteed to be the SHORTEST path to goal
( for every node that is not on path )
Example of A*: Romania
Suppose we don’t know the distance
from Sibiu to Bucharest on highways,
but we DO know the distance “as the
crow flies.”
Euclidean distance (as the crow flies)