0% found this document useful (0 votes)
8 views

Admissible Search

Uploaded by

dabaci3568
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Admissible Search

Uploaded by

dabaci3568
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 49

Week # 4:

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

Timisoara Sibiu Zerind

Lugoj RV Fagaras Oradea

Mehadia C P Bucharest

BFS returns this path,


because it requires
only 3 actions.
Cost = 450 km
An example for which BFS is not optimal:
Romania
Arad

Timisoara Sibiu Zerind

Lugoj RV Fagaras Oradea

Mehadia C P Bucharest

Bucharest

It would have been


better to find this path!
Cost = 418 km
The solution: Uniform Cost Search
• Breadth-first search (BFS): Next node expanded is the one with the
fewest required actions
• Frontier is a queue
• First node into the queue is the first one expanded (FIFO)
• Uniform cost search (UCS): Next node expanded is the one with the
lowest accumulated path cost
• Frontier is a priority queue
• Lowest-cost node is the first one expanded
Example of UCS: Romania
Arad

Arad:0
Example of UCS: Romania
Arad

Timisoara Sibiu Zerind

Zerind:75, Timisoara:118, Sibiu:140


Example of UCS: Romania
Arad

Timisoara Sibiu Zerind

Oradea

Timisoara:118, Sibiu:140, Oradea:146


Example of UCS: Romania
Arad

Timisoara Sibiu Zerind

Lugoj Oradea

Sibiu:140, Oradea:146, Lugoj:239


Example of UCS: Romania
Arad

Timisoara Sibiu Zerind

Lugoj RV Fagaras Oradea

Oradea:146, Rimnicu Vilcea:220, Lugoj:239, Fagaras:239


Example of UCS: Romania
Arad

Timisoara Sibiu Zerind

Lugoj RV Fagaras Oradea

Rimnicu Vilcea:220, Lugoj:239, Fagaras:239


Example of UCS: Romania
Arad

Timisoara Sibiu Zerind

Lugoj RV Fagaras Oradea

C P

Lugoj:239, Fagaras:239, Pitesti:317, Craiova:366


Example of UCS: Romania
Arad

Timisoara Sibiu Zerind

Lugoj RV Fagaras Oradea

Mehadia C P

Fagaras:239, Mehadia:309, Pitesti:317, Craiova:366


Example of UCS: Romania
Arad

Timisoara Sibiu Zerind

Lugoj RV Fagaras Oradea

Mehadia C P Bucharest

Mehadia:309, Pitesti:317, Craiova:366, Bucharest:450


Example of UCS: Romania
Arad

Timisoara Sibiu Zerind

Lugoj RV Fagaras Oradea

Mehadia C P Bucharest

Dobreta

Pitesti:317, Craiova:366, Dobreta:384, Bucharest:450


Example of UCS: Romania
Arad

Timisoara Sibiu Zerind

Lugoj RV Fagaras Oradea

Mehadia C P

Dobreta Bucharest

Craiova:366, Dobreta:384, Bucharest:418


Example of UCS: Romania
Arad

Timisoara Sibiu Zerind

Lugoj RV Fagaras Oradea

Mehadia C P

Dobreta Bucharest

Dobreta:384, Bucharest:418
Example of UCS: Romania
Arad

Timisoara Sibiu Zerind

Lugoj RV Fagaras Oradea

Mehadia C P

Dobreta Bucharest

Bucharest:418
GOAL!!!! GOL!!!!!

Image by Rick Dikeman, GFDL 1996,


https://commons.wikimedia.org/wiki/File:Football_iu_1996.jpg
Uniform-Cost Search

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

The goal state is achieved and the


15 path S-B-G is returned. In relation
C to path cost, UCS has found the
optimal route.

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

UNIFORM COST SEARCH PATTERN


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
Heuristics main idea
Instead of choosing the node with the smallest total cost so far (UCS),

why not choose the node that’s CLOSEST TO GOAL,


and expand that one first?
Why not choose the node CLOSEST
TO GOAL?
• Answer: because we don’t know Start state
which node that is!!

• Example: which of these two is


closest to goal?

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),

why not choose the node whose


HEURISTIC ESTIMATE
indicates that it might be
CLOSEST TO GOAL?
Greedy Search Example
According to the Manhattan Start state
distance heuristic, these two
nodes are equally far from the
goal, so we have to choose one at
random.

Goal state
Greedy Search Example
Start state
If our random choice goes badly,
we might end up very far from the
goal.

= states in the explored set

= states on the frontier


Goal state
The problem with Greedy Search
Start state
Having gone down a bad path, it’s
very hard to recover, because
now, the frontier node closest to
goal (according to the Manhattan
distance heuristic) is this one:

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 ).

But it’s also farthest from the


start. Let’s say = total path cost
so far.

So the total distance from start to Goal state


goal, going through node , is
The problem with Greedy Search
Of these three nodes, this one has 15
the smallest

So if we want to find the lowest- 13


cost path, then it would be better
to try that node, instead of this
2
one, which has
12
A* notation
• cost of the total path (START, Start state
…,n,…,GOAL).
• distance of the remaining
partial path (n,…,GOAL).
• gone-already on the path so far,
(START,…,n).

• 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:

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

g(n): cost so far to reach n (path cost)


h(n): estimated cost from n to goal (heuristic)

• This is called A* search if and only if the heuristic, h(n), is


admissible. The word “admissible” just means that , and
therefore, .
𝑐 (𝑚 )
m
Admissible heuristic S G
n
𝑔 (𝑛 ) ≥ h ( 𝑛)
• Suppose we’ve found one path to ; the path goes through node . Since
we’ve calculated the whole path, we know its total path cost to be
• For every other node, , we don’t know , but we know , and we know that

• Therefore we know that

• 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)

• Sibiu: h(n) = 260km


• Timisoara: h(n) = 410km
• Zerind: h(n) = 422km
Romania using UCS
Arad

Timisoara Sibiu Zerind

Pick this one first?

Zerind:75, Timisoara:118, Sibiu:140


Romania using A*
Arad

Timisoara Sibiu Zerind

No, pick this one first!!!

Sibiu:140+260=400, Zerind:75+422=495, Timisoara:118+410=528


BFS vs. A* Search Example
The heuristic h(n)=Euclidean distance favors nodes on the
main diagonal. Those nodes all have the same g(n)+h(n), so
A* evaluates them first.

CC-BY 3.0 by Subh83, 2011, https://en.wikipedia.org/wiki/File:Astar_progress_animation.gif


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 a lower bound 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy