0% found this document useful (0 votes)
13 views37 pages

[24F-COSE361] 1. Search (2)(1)

The document covers various search methods in artificial intelligence, focusing on uninformed search techniques such as Depth-First Search, Breadth-First Search, Iterative Deepening Search, and Uniform-Cost Search. It also introduces informed search methods that utilize heuristics to estimate the proximity of a state to the goal, including Greedy Search. Key properties, advantages, and limitations of each search method are discussed, along with examples and comparisons.

Uploaded by

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

[24F-COSE361] 1. Search (2)(1)

The document covers various search methods in artificial intelligence, focusing on uninformed search techniques such as Depth-First Search, Breadth-First Search, Iterative Deepening Search, and Uniform-Cost Search. It also introduces informed search methods that utilize heuristics to estimate the proximity of a state to the goal, including Greedy Search. Key properties, advantages, and limitations of each search method are discussed, along with examples and comparisons.

Uploaded by

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

COSE361 Artificial Intelligence

Search (2)

[Adapted from the original slides from CS188 Intro to AI at UC Berkeley]


Review
▪ Agents that Plan Ahead
▪ Reflex Agents
▪ Planning Agents
▪ Search Problems
▪ State Space Graphs
▪ Search Trees
▪ Uninformed Search Methods
▪ Depth-first Search
▪ Breadth-first Search
Outline
▪ Uninformed Search Methods
▪ Depth-First Search
▪ Breadth-First Search
▪ Iterative Deepening Search
▪ Uniform-Cost Search
▪ Informed (Heuristic) Search
Iterative Deepening Search
▪ Combining the best of DFS and BFS

Search takes time O(bm) space O(bm) Search takes time O(bs) space O(bs)

May get stuck on infinite paths Guaranteed to find a solution if one exists
Finds the “leftmost” solution Finds the “shallowest” solution
Iterative Deepening Search
▪ Idea: DFS’s space advantage + BFS’s time/shallow-solution advantages
▪ For every depth limit, perform DFS until the depth limit is reached
▪ Run a DFS with depth limit 1. If no solution…
▪ Run a DFS with depth limit 2. If no solution…
▪ Run a DFS with depth limit 3. …..

b

Example: Iterative Deepening Search
▪ Build search trees for depth = 0, 1, 2 on the search graph below
▪ Starting from S (a root node, depth = 0)
▪ Quiz: what is the total number of nodes visited?

a G
b c

e
d f
S h
p r
q
Iterative Deepening Search
▪ Idea: DFS’s space advantage + BFS’s time/shallow-solution advantages
▪ For every depth limit, perform DFS until the depth limit is reached

▪ Isn’t that wastefully redundant?


b = 10
▪ No, generally most work happens in the lowest level searched …
▪ # of nodes grows exponentially
s=5
▪ Example: branching factor 10, solution at depth 5:
▪ Number of nodes visited?
▪ BFS: 10 + 100 + 1,000 + 10,000 + 100,000 = 111,110
▪ IDS: 50 + 400 + 3,000 + 20,000 + 100,000 = 123,450
Iterative Deepening Search
▪ Time Complexity
▪ O(bs), exponential in s, same as BFS

▪ Space Complexity b

▪ O(bs), linear in s, similar to DFS
s tiers

▪ Completeness
▪ Yes, same as BFS

▪ Optimality
▪ No, only the shallowest solution, same as BFS
▪ (but Yes if costs are all 1)
Quiz
▪ Find the shortest path (in terms of # of nodes in the path) from
Start node to Goal node

a G

b c

e
d
f
S h

p r
q
Cost-Sensitive Search

a GOAL
2 2
b c
3
2
1 8
2 e
Cost: 3 d
f
9 8 2
START h
1 4 2

p 4 r
15
q

▪ BFS finds the shortest path in terms of number of actions, but not the least-cost path
▪ We will now cover a similar algorithm which does find the least-cost path
Uniform Cost Search
Uniform Cost Search (a.k.a. Dijkstra’s algorithm)
2 a G
Strategy: expand a cheapest node first b c
1 8 2
2 e
Fringe is a priority queue 3 d f
9 2
S h 8
(i.e., ordered by cumulative cost) 1
1 p q r
15

S 0

d 3 e 9 p 1

b 4 c e 5 h 17 r 11 q 16
11
Cost a 6 a h 13 r 7 p q f
contours
p q f 8 q c G

q 11 c G 10 a

a
Uniform Cost Search (UCS) Properties
▪ What nodes does UCS expand?
▪ Processes all nodes with cost less than cheapest solution!
b c1
▪ If that solution costs C* and arcs cost at least  , then the …
“effective depth” is roughly C*/ C*/ “tiers”
c2

▪ Takes time O(b ) (exponential in effective depth)
C*/
c3

▪ How much space does the fringe take?


▪ Has roughly the last tier, so O(bC*/)

▪ Is it complete?
▪ Yes, assuming best solution has a finite cost and minimum arc
cost is positive

▪ Is it optimal?
▪ Yes
Uniform Cost Search Issues
▪ UCS explores increasing cost contours c1

c2
c3
▪ The good:
▪ UCS is complete and optimal!

▪ The bad:
▪ Explores options in every “direction”
▪ No information about goal location Start Goal
▪ How can we fix that?
Video of Demo Empty UCS
Video of Demo Contours UCS Pacman Small Maze
Video of Demo Maze with Deep/Shallow Water --- DFS, BFS, or UCS?
Comparing Uninformed Search Algorithms

▪ All these search algorithms are the same except for fringe strategies
▪ Conceptually, all fringes are priority queues (i.e., collections of nodes with priorities)
▪ Practically, for DFS and BFS, you can use LIFO stacks and FIFO queues
Summary

▪ Search problem:
▪ States (configurations of the world)
▪ Successor function (world dynamics)
▪ Actions and costs
▪ Start state and goal test

▪ Search tree:
▪ Nodes: represent plans for reaching states
▪ Plans have costs (sum of action costs)

▪ Search algorithm:
▪ Systematically builds a search tree
▪ Chooses an ordering of the fringe (unexplored nodes)
▪ Finds least-cost plans
Example: Pancake Problem

Cost? Action? State space size?


Example: Pancake Problem
Partial state space graph with costs (# of pancakes flipped)

4
2 3
2
3

4
3
4 2

3 2
2
4

3
General Tree Search

Action: flip top two Action: fliptoallreach


Path four goal:
Cost: 2 Cost:
Flip 4 flip three
four,
Total cost: 7
Outline
▪ Uninformed Search Methods
▪ Depth-First Search
▪ Breadth-First Search
▪ Iterative Deepening Search
▪ Uniform-Cost Search
▪ Informed (Heuristic) Search
▪ Heuristics
▪ Greedy Search
Informed Search
▪ Uninformed search
▪ Consider every state to be the same
▪ Does not know which state is closer to the goal state
▪ May not find the optimal solution

▪ Informed (with heuristic) search


▪ Estimate how close the state is to the goal
▪ c.f., heuristic (in computing): finding a solution by trying different actions (with soft
rules) to see if they produce the result that is wanted, rather than using strict rules
▪ Try to find the optimal solution with the estimation by intuitive clues
Search Heuristics
▪ A search heuristic is:
▪ A function h(x) that estimates how close a state x is to a goal G
▪ Designed for a particular search problem
▪ Examples: Manhattan/Euclidean distance for pathing

10

5
11.2
Example: Heuristic Function for Traveling
h(x)
Quiz: Heuristic Function for Pancake
Slido.com
What could be the heuristic function for the pancake problem? → Code: 2650956

Goal state
Quiz: Heuristic Function for Pancake
Example heuristic: the number (ID) of the largest pancake that is still out of place

3
h(x): 4

3
4
3 0
4
4 3
4
4 2
3
Greedy Search
Greedy Search (with Heuristics)
▪ Expand the node that seems closest to the goal

Heuristics h(x)

Cost
178

▪ What can go wrong?


Greedy Search
b
▪ Strategy: …
▪ Expand a node that you think is closest to a goal state
▪ Heuristic: estimate of distance to nearest goal for each state

▪ A common case:
▪ Greedy best-first may take you straight to the (wrong) goal
b
▪ Worst-case: …

▪ Becomes like a badly-guided DFS

▪ Properties:
▪ Exponential both for time and space
▪ Not complete, not optimal
Video of Demo Contours Greedy (Empty)
Video of Demo Contours Greedy (Pacman Small Maze)
Example: Uniform-Cost Search
State space graph with cost Search Tree

8
e
Cost 1
S 1 a 3 d 2 G
1
c 1 b

Example: Teg Grenager


Example: Greedy Search
State space graph with heuristics Search Tree

8
e h=1
Cost 1
S 1 a 3 d 2 G
h=6 1 h=5 h=2 h=0
c 1 b
h=7 h=6

Example: Teg Grenager


Today
▪ Uninformed Search Methods
▪ Depth-First Search
▪ Breadth-First Search
▪ Iterative Deepening Search
▪ Uniform-Cost Search
▪ Informed (Heuristic) Search
▪ Heuristics
▪ Greedy Search
Next
▪ Informed (Heuristic) Search
▪ Heuristics
▪ Greedy Search
▪ A* Search
▪ Admissibility and optimality
▪ Designing admissible heuristics
▪ Graph search

You might also like