Problem Solving by Search & Uninformed Search Algorithms
Problem Solving by Search & Uninformed Search Algorithms
Uninformed search
CE417: Introduction to Artificial Intelligence
Sharif University of Technology
Spring 2016
Soleymani
2
Problem-Solving Agents
Problem Formulation: process of deciding what actions
and states to consider
States of the world
Actions as transitions between states
Agent must find out how to act now and in the future to
reach a goal state
Search: process of looking for solution (a sequence of actions
that reaches the goal starting from initial state)
3
Problem-Solving Agents
A goal-based agent adopts a goal and aim at satisfying it
(as a simple version of intelligent agent maximizing a performance measure)
4
Example: Romania
On holiday in Romania; currently in Arad.
Flight leaves tomorrow from Bucharest
Map of Romania
Initial state
currently in Arad
Formulate goal
be in Bucharest
Formulate problem
states: various cities
actions: drive between cities
Solution
sequence of cities, e.g.,Arad, Sibiu, Fagaras, Bucharest
5
Example: Romania (Cont.)
Assumptions about environment
Known
Observable
The initial state can be specified exactly.
Deterministic
Each applied action to a state results in a specified state.
Discrete
6
Problem-solving agents
7
Problem types
Deterministic and fully observable (single-state problem)
Agent knows exactly its state even after a sequence of actions
Solution is a sequence
A sample
belief state
World states
9
Example: vacuum world
Single-state, start in {5}
Solution?
[Right, Suck]
Contingency
Nondeterministic: Suck may dirty a clean carpet
Partially observable: location, dirt only at the current location
Percept: [L, Clean], i.e., start in {5} or {7}
Solution?
[Right, if dirt then Suck] [Right, while dirt do Suck]
10
Single-state problem
In this lecture, we focus on single-state problem
Search for this type of problems is simpler
And also provide strategies that can be base for search in
more complex problems
11
Single-state problem formulation
A problem is defined by five items:
12
Single-state problem formulation
A problem is defined by five items:
Transition model: 𝑅𝐸𝑆𝑈𝐿𝑇𝑆(𝑠, 𝑎) shows the state that results from doing
action 𝑎 in state 𝑠
e.g., 𝑅𝐸𝑆𝑈𝐿𝑇𝑆(𝐼𝑛(𝐴𝑟𝑎𝑑), 𝐺𝑜(𝑍𝑒𝑟𝑖𝑛𝑑)) = 𝐼𝑛(𝑍𝑒𝑟𝑖𝑛𝑑)
13
Single-state problem formulation
A problem is defined by five items:
Transition model: 𝑅𝐸𝑆𝑈𝐿𝑇𝑆(𝑠, 𝑎) shows the state that results from doing
action 𝑎 in state 𝑠
14
Single-state problem formulation
A problem is defined by five items:
Transition model: 𝑅𝐸𝑆𝑈𝐿𝑇𝑆(𝑠, 𝑎) shows the state that results from doing
action 𝑎 in state 𝑠
Path cost (additive): assigns a numeric cost to each path that reflects agent’s
performance measure
e.g., sum of distances, number of actions executed, etc.
𝑐(𝑥, 𝑎, 𝑦) ≥ 0 is the step cost
15
Single-state problem formulation
A problem is defined by five items:
Transition model: 𝑅𝐸𝑆𝑈𝐿𝑇𝑆(𝑠, 𝑎) shows the state that results from doing
action 𝑎 in state 𝑠
Path cost (additive): assigns a numeric cost to each path that reflects agent’s
performance measure
Solution: a sequence of actions leading from the initial state to a goal state
Optimal Solution has the lowest path cost among all solutions.
16
State Space
State space: set of all reachable states from initial state
Initial state, actions, and transition model together define it
17
Vacuum world state space graph
2 × 22 = 8
States
9!/2 = 181,440
States
64 × 63 × ⋯ × 57
≃ 1.8 × 1014 States
20
Example: 8-queens problem
(other formulation)
2,057 States
Example: 4! ! = 5
23
Tree search algorithm
Basic idea
offline, simulated exploration of state space by generating successors of
already-explored states
Different data structures (e.g, FIFO, LIFO) for frontier can cause different
orders of node expansion and thus produce different search algorithms.
24
Tree search example
25
Tree search example
26
Tree search example
27
Graph Search
Redundant paths in tree search: more than one way to get from
one state to another
may be due to a bad problem definition or the essence of the problem
can cause a tractable problem to become intractable
28
Graph Search
Example: rectangular grid
explored
frontier
29
Search for 8-puzzle Problem
Start Goal
31
Search strategies
Search strategy: order of node expansion
Strategies performance evaluation:
Completeness: Does it always find a solution when there is one?
Time complexity: How many nodes are generated to find solution?
Space complexity: Maximum number of nodes in memory during search
Optimality: Does it always find a solution with minimum path cost?
32
Uninformed Search Algorithms
33
Uninformed (blind) search strategies
No additional information beyond the problem definition
Breadth-First Search (BFS)
Uniform-Cost Search (UCS)
Depth-First Search (DFS)
Depth-Limited Search (DLS)
Iterative Deepening Search (IDS)
34
Breadth-first search
Expand the shallowest unexpanded node
Implementation: FIFO queue for the frontier
35
Breadth-first search
36
Breadth-first search
37
Breadth-first search
38
Properties of breadth-first search
Complete?
Yes (for finite 𝑏 and 𝑑)
Time
𝑏 + 𝑏2 + 𝑏3 + ⋯ + 𝑏𝑑 = 𝑂(𝑏𝑑 ) total number of generated nodes
goal test has been applied to each node when it is generated
Optimal?
Yes, if path cost is a non-decreasing function of d
e.g. all actions having the same cost
39
Properties of breadth-first search
Space complexity is a bigger problem than time complexity
Time is also prohibitive
Exponential-complexity search problems cannot be solved by
uninformed methods (only the smallest instances)
d Time Memory
10 3 hours 10 terabytes
12 13 days 1 pentabyte
14 3.5 years 99 pentabytes
16 350 years 10 exabytes
40
Uniform-Cost Search (UCS)
Expand node 𝑛 (in the frontier) with the lowest path cost 𝑔(𝑛)
Extension of BFS that is proper for any step cost function
41
Properties of uniform-cost search
Complete?
Yes, if step cost ≥ 𝜀 > 0 (to avoid infinite sequence of zero-cost
actions)
Time
1+ 𝐶 ∗ 𝜀
Number of nodes with 𝑔 ≤ cost of optimal solution, 𝑂(𝑏 )
where 𝐶 ∗ is the optimal solution cost
𝑂(𝑏 𝑑+1 ) when all step costs are equal
Space
∗
Number of nodes with 𝑔 ≤ cost of optimal solution, 𝑂(𝑏1+ 𝐶 𝜀
)
Optimal?
Yes – nodes expanded in increasing order of 𝑔(𝑛)
43
Depth First Search (DFS)
Expand the deepest node in frontier
44
DFS
Expand the deepest unexpanded node in frontier
45
DFS
Expand the deepest unexpanded node in frontier
46
DFS
Expand the deepest unexpanded node in frontier
47
DFS
Expand the deepest unexpanded node in frontier
48
DFS
Expand the deepest unexpanded node in frontier
49
DFS
Expand the deepest unexpanded node in frontier
50
DFS
Expand the deepest unexpanded node in frontier
51
DFS
Expand the deepest unexpanded node in frontier
52
DFS
Expand the deepest unexpanded node in frontier
53
DFS
Expand the deepest unexpanded node in frontier
54
DFS
Expand the deepest unexpanded node in frontier
55
Properties of DFS
Complete?
Tree-search version: not complete (repeated states & redundant paths)
Graph-search version: fails in infinite state spaces (with infinite non-goal path)
but complete in finite ones
Time
𝑂(𝑏𝑚): terrible if 𝑚 is much larger than 𝑑
In tree-version, 𝑚 can be much larger than the size of the state space
Space
𝑂(𝑏𝑚), i.e., linear space complexity for tree search
So depth first tree search as the base of many AI areas
Recursive version called backtracking search can be implemented in 𝑂(𝑚)
space
Optimal?
No DFS: tree-search version
56
Depth Limited Search
Depth-first search with depth limit 𝑙 (nodes at depth 𝑙 have no successors)
Solves the infinite-path problem
In some problems (e.g., route finding), using knowledge of problem to specify 𝑙
Complete?
If 𝑙 > 𝑑, it is complete
Time
𝑂(𝑏𝑙 )
Space
𝑂(𝑏𝑙)
Optimal?
No
57
Iterative Deepening Search (IDS)
Not such wasteful (most of the nodes are in the bottom level)
58
IDS: Example l =0
59
IDS: Example l =1
60
IDS: Example l =2
61
IDS: Example l =3
62
Properties of iterative deepening search
Complete?
Yes (for finite 𝑏 and 𝑑)
Time
𝑑 × 𝑏1 + (𝑑 − 1) × 𝑏2 + ⋯ + 2 × 𝑏 𝑑−1 + 1 × 𝑏𝑑 = 𝑂(𝑏𝑑 )
Space
𝑂(𝑏𝑑)
Optimal?
Yes, if path cost is a non-decreasing function of the node depth
63
Iterative deepening search
Number of nodes generated to depth d:
𝑁𝐼𝐷𝑆 = 𝑑 × 𝑏1 + (𝑑 − 1) × 𝑏2 + … + 2 × 𝑏 𝑑−1 + 1 × 𝑏𝑑
= 𝑂(𝑏𝑑 )
64
Bidirectional search
Simultaneous forward and backward search (hoping that they
meet in the middle)
Idea: 𝑏 𝑑/2 + 𝑏 𝑑/2 is much less than 𝑏 𝑑
“Do the frontiers of two searches intersect?” instead of goal test
First solution may not be optimal
Implementation
Hash table for frontiers in one of these two searches
Space requirement: most significant weakness
Computing predecessors?
May be difficult
List of goals? a new dummy goal
Abstract goal (checkmate)?!
65
Summary of algorithms (tree search)
a Complete if b is finite
b Complete if step cost ≥ ε>0
c Optimal if step costs are equal
d If both directions use BFS
Iterative deepening search uses only linear space and not much
more time than other uninformed algorithms
66