solving problems by searching - cs.uwaterloo.caklarson%a0/teaching/w16... · search problems • a...
TRANSCRIPT
![Page 1: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/1.jpg)
Solving Problems by Searching
CS 486/686: Introduction to Artificial IntelligenceWinter 2016
1
![Page 2: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/2.jpg)
Introduction
• Search was one of the first topics studied in AI
- Newell and Simon (1961) General Problem Solver
• Central component to many AI systems
- Automated reasoning, theorem proving, robot navigation, scheduling, game playing,...
2
![Page 3: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/3.jpg)
Search Problems• A search problem consists of
• a state space
• a successor function (actions, cost)
• a start state and a goal test
• A solution is a sequence of actions (plan) from the start state to a goal state
(N, 1.0)
(E, 1.0)
3
![Page 4: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/4.jpg)
Example: Traveling in Romania
Start
End
• States:
• Initial State:
• Successor Function:
• Goal test:
• Solution:
4
![Page 5: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/5.jpg)
Examples of Search Problems
• States:
• Initial State:
• Successor Function:
• Goal test:
• Solution:
• States:
• Initial State:
• Successor Function:
• Goal test:
• Solution:5
![Page 6: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/6.jpg)
Examples of Search Problems
6
![Page 7: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/7.jpg)
Our Definition Excludes...
Chance
Continuous states
All of the above
Chance
Partial Observability
Adversaries
7
![Page 8: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/8.jpg)
What is is a state space?
The world state includes every last detail of the environment
A search state keeps only the details needed for planning (abstraction)
▪ Problem: Pathing▪ States: (x,y) location▪ Actions: NSEW▪ Successor: update location
only▪ Goal test: is (x,y)=END
▪ Problem: Eat-All-Dots▪ States: {(x,y), dot booleans}▪ Actions: NSEW▪ Successor: update location
and possibly a dot boolean▪ Goal test: dots all false
Adapted from UC Berkeley’s CS188 Course 8
![Page 9: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/9.jpg)
Representing Search
• State space graph
- Vertices correspond to states (one vertex for each state)
- Edges correspond to successors
- Goal test is a set of goal nodes
• We search for a solution by building a search tree and traversing it to find a goal state
S
G
d
b
p q
c
e
h
a
f
r
9
![Page 10: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/10.jpg)
Search Tree• A search tree:
• Start state is the root of the tree
• Children are successors
• A plan is a path in the tree. A solution is a path from the root to a goal node.
• For most problems we do not actually generate the entire tree
SB
A
G
SA B
GB G
G10
![Page 11: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/11.jpg)
Quiz
• Given this state graph, how large is the search tree?
SB
A
G
11
![Page 12: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/12.jpg)
Expanding Nodes
• Expanding a node
- Applying all legal operators to the state contained in the node
- Generating nodes for all corresponding successor states
12
![Page 13: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/13.jpg)
Example: Traveling in Romania
Start
End
13
![Page 14: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/14.jpg)
Expanding Nodes
14
![Page 15: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/15.jpg)
Generic Search Algorithm
• Initialize with initial state of the problem
• Repeat
- If no candidate nodes can be expanded return failure
- Choose leaf node for expansion, according to search strategy
- If node contains goal state, return solution
- Otherwise, expand the node. Add resulting nodes to the tree
15
![Page 16: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/16.jpg)
Implementation Details
• Need to keep track of nodes to be expanded (fringe)
• Implement using a queue:
- Insert node for initial state
- Repeat- If queue is empty, return failure
- Dequeue a node
- If node contains goal state, return solution
- Expand node
• Search algorithms differ in their queuing function!
16
![Page 17: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/17.jpg)
Search Strategies
S
G
d
b
pq
c
e
h
a
f
r
Adapted from UC Berkeley’s CS188 Course 17
![Page 18: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/18.jpg)
Search StrategiesS
a
b
d p
a
c
e
p
h
f
r
q
q c G
a
qe
p
h
f
r
q
q c G
a
18
![Page 19: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/19.jpg)
Depth-First Search
S
G
d
b
p q
c
e
h
a
f
r
S
a
b
d p
a
c
e
p
h
f
r
q
q c G
a
qe
p
h
f
r
q
q c G
a
Strategy: Expand deepest node firstImplementation: LIFO stack
19
![Page 20: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/20.jpg)
Key Properties• Completeness: Is the alg. guaranteed to find a
solution if the solution exists?
• Optimality: Does the alg. find the optimal solution?
• Time complexity
• Space complexity (size of the fringe) …b
1 node
b nodes
b2 nodes
bm nodes
m tiers
b: branching factorm: maximum depth d: depth of shallowest goal node
Number of nodes in tree? 1+b+b2+…+bm=O(bm)20
![Page 21: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/21.jpg)
DFS Properties• Complete?
• No! m could be infinite (why?)
• Optimal?
• No! It finds “leftmost” solution first, regardless of cost or depth
• Time complexity
• It could process the entire tree! Therefore O(bm)
• Space complexity
• Only has siblings on path to root! Therefore O(bm)!
…b
1 nodeb nodes
b2 nodes
bm nodes
m tiers
21
![Page 22: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/22.jpg)
Breadth-First Search
S
G
d
b
p q
c
e
h
a
f
r
S
a
b
d p
a
c
e
p
h
f
r
q
q c G
a
qe
p
h
f
r
q
q c G
a
Strategy: Expand shallowest node firstImplementation: FIFO queue
22
![Page 23: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/23.jpg)
BFS Properties• Complete?
• Yes! d must be finite is a solution exists
• Optimal?
• Maybe! If costs are all 1
• Time complexity
• It could process the tree until it finds the shallowest goal! Therefore O(bd)
• Space complexity
• O(bd)
…b
1 nodeb nodes
b2 nodes
bm nodes
m tiers
23
![Page 24: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/24.jpg)
Quiz: DFS vs BFS
…b
…b
24
![Page 25: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/25.jpg)
Iterative Deepening Search• Can we combine search methods to take advantage
of DFS space complexity and BFS completeness/shallow solution advantage?
25
![Page 26: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/26.jpg)
IDS Properties• Complete?
• Yes! d must be finite is a solution exists (like BFS)
• Optimal?
• Maybe! If costs are all 1
• Time complexity
• It could process the tree until it finds the shallowest goal! Therefore O(bd)
• Space complexity
• O(bd)
…b
1 nodeb nodes
b2 nodes
bm nodes
m tiers
Wasteful? Most nodes found in lowest level of search so not too bad
26
![Page 27: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/27.jpg)
Cost-Sensitive Search
START
GOAL
d
b
pq
c
e
h
a
f
r
2
9 2
81
8
2
3
2
4
4
15
1
32
2
Recall that BFS was only optimal under some conditions (i.e. we only cared about number of actions taken). What can we do if actions have different costs? 27
![Page 28: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/28.jpg)
Uniform Cost SearchStrategy: Expand cheapest node firstImplementation: Priority queue
START
GOAL
d
b
pq
c
e
h
a
f
r
2
9 2
81
8
2
3
2
4
4
15
1
32
2
28
![Page 29: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/29.jpg)
UCS Properties• Complete?
• Yes! (assuming min cost is positive and best solution has finite cost)
• Optimal?
• Yes!
• Time complexity
•Processes all nodes with cost less than cheapest solution
• If cheapest solution cost C* and edges cost at least 𝜀 then “depth” is approximately C*/𝜀. Thus time O(bC*/𝜀)
• Space complexity
• O(bC*/𝜀)
…b
C*/𝜀 tiers
29
![Page 30: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/30.jpg)
Summary• These algorithms are basically the
same except for the order in which they expand nodes
• Basically all priority queues with different ways to determining priorities
• How successful the search is depends heavily on your model!
30
![Page 31: Solving Problems by Searching - cs.uwaterloo.caklarson%A0/teaching/W16... · Search Problems • A search problem consists of • a state space • a successor function (actions,](https://reader036.vdocuments.us/reader036/viewer/2022071216/60472a470a9b2a601a060deb/html5/thumbnails/31.jpg)
Questions?
• Next class: Informed search
31