Problem Solving and Search
Chapter 3, Sections 1–4
Copyright By PowCoder代写 加微信 powcoder
AIMA Slides © and ; Chapter 3, Sections 1–4 1
♢ Problem-solving agents
♢ Problem types
♢ Problem formulation
♢ Example problems
♢ Basic search algorithms
AIMA Slides © and ; Chapter 3, Sections 1–4 2
Problem-solving agents
Restricted form of general agent:
function Simple-Problem-Solving-Agent( p) returns an action
inputs: p, a percept
static: s, an action sequence, initially empty
state, some description of the current world state
g, a goal, initially null
problem, a problem formulation
state←Update-State(state, p)
if s is empty then
g←Formulate-Goal(state)
problem←Formulate-Problem(state, g)
s←Search( problem)
action←Recommendation(s, state)
s←Remainder(s, state)
return action
Note: this is offline problem solving.
Online problem solving involves acting without complete knowledge of the
problem and solution.
AIMA Slides © and ; Chapter 3, Sections 1–4 3
Example: Romania
On holiday in Romania; currently in Arad.
Flight leaves tomorrow from Bucharest
Formulate goal:
be in Bucharest
Formulate problem:
states: various cities
operators: drive between cities
Find solution:
sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
AIMA Slides © and ; Chapter 3, Sections 1–4 4
Example: Romania
AIMA Slides © and ; Chapter 3, Sections 1–4 5
Single-state problem formulation
A problem is defined by four items:
initial state e.g., “at Arad”
actions (or successor function S(x))
e.g., Arad → → Sibiu etc.
goal test, can be
explicit, e.g., x = “at Bucharest”
implicit, e.g., Checkmate in chess
path cost (additive)
e.g., sum of distances, number of actions executed, etc.
A solution is a sequence of actions
leading from the initial state to a goal state
Note: we sometimes refer to actions as “operators”
AIMA Slides © and ; Chapter 3, Sections 1–4 6
Selecting a state space
Real world is absurdly complex
⇒ state space must be abstracted for problem solving
(Abstract) state = set of real states
(Abstract) action = complex combination of real actions
e.g., “Arad → Zerind” represents a complex set
of possible routes, detours, rest stops, etc.
For guaranteed realizability, any real state “in Arad”
must get to some real state “in Zerind”
(Abstract) solution =
set of real paths that are solutions in the real world
Each abstract action should be “easier” than the original problem!
AIMA Slides © and ; Chapter 3, Sections 1–4 7
Example: The 8-puzzle
Start State Goal State
goal test??
path cost??
[Note: optimal solution of n-Puzzle family is NP-hard]
AIMA Slides © and ; Chapter 3, Sections 1–4 8
Example: The 8-puzzle
Start State Goal State
states??: integer locations of tiles (ignore intermediate positions)
actions??: move blank left, right, up, down (ignore unjamming etc.)
goal test??: = goal state (given)
path cost??: 1 per move
[Note: optimal solution of n-Puzzle family is NP-hard]
AIMA Slides © and ; Chapter 3, Sections 1–4 9
Example: robotic assembly
states??: real-valued coordinates of
robot joint angles
parts of the object to be assembled
actions??: continuous motions of robot joints
goal test??: complete assembly with no robot included!
path cost??: time to execute
AIMA Slides © and ; Chapter 3, Sections 1–4 10
Search algorithms
Basic idea:
offline, simulated exploration of state space
by generating successors of already-explored states
(a.k.a. expanding states)
function General-Search( problem, strategy) returns a solution, or failure
initialize the search tree using the initial state of problem
if there are no candidates for expansion then return failure
choose a leaf node for expansion according to strategy
if the node contains a goal state then return the corresponding solution
else expand the node and add the resulting nodes to the search tree
AIMA Slides © and ; Chapter 3, Sections 1–4 11
General search example
AIMA Slides © and ; Chapter 3, Sections 1–4 12
General search example
AIMA Slides © and ; Chapter 3, Sections 1–4 13
General search example
AIMA Slides © and ; Chapter 3, Sections 1–4 14
General search example
AIMA Slides © and ; Chapter 3, Sections 1–4 15
Implementation of search algorithms
function General-Search( problem,Queuing-Fn) returns a solution, or failure
nodes←Make-Queue(Make-Node(Initial-State[problem]))
if nodes is empty then return failure
node←Remove-Front(nodes)
if Goal-Test[problem] applied to State(node) succeeds then return node
nodes←Queuing-Fn(nodes,Expand(node,Operators[problem]))
AIMA Slides © and ; Chapter 3, Sections 1–4 16
Implementation contd: states vs. nodes
A state is a (representation of) a physical configuration
A node is a data structure constituting part of a search tree
includes parent, children, depth, path cost g(x)
States do not have parents, children, depth, or path cost!
The Expand function creates new nodes, filling in various fields and using
Operators (or Actions) of problem to create the corresponding states.
AIMA Slides © and ; Chapter 3, Sections 1–4 17
Search strategies
A strategy is defined by picking the order of node expansion
Strategies are evaluated along the following dimensions:
completeness—does it always find a solution if one exists?
time complexity—number of nodes generated/expanded
space complexity—maximum number of nodes in memory
optimality—does it always find a least-cost solution?
Time and space complexity are measured in terms of
b—maximum branching factor of the search tree
d—depth of the least-cost solution
m—maximum depth of the state space (may be ∞)
AIMA Slides © and ; Chapter 3, Sections 1–4 18
Uninformed search strategies
Uninformed strategies use only the information available
in the problem definition
Breadth-first search
Uniform-cost search
Depth-first search
Depth-limited search
Iterative deepening search
AIMA Slides © and ; Chapter 3, Sections 1–4 19
Breadth-first search
Expand shallowest unexpanded node
Implementation:
QueueingFn = put successors at end of queue
AIMA Slides © and ; Chapter 3, Sections 1–4 20
Breadth-first search
Expand shallowest unexpanded node
Implementation:
QueueingFn = put successors at end of queue
AIMA Slides © and ; Chapter 3, Sections 1–4 21
Breadth-first search
Expand shallowest unexpanded node
Implementation:
QueueingFn = put successors at end of queue
AIMA Slides © and ; Chapter 3, Sections 1–4 22
Breadth-first search
Expand shallowest unexpanded node
Implementation:
QueueingFn = put successors at end of queue
AIMA Slides © and ; Chapter 3, Sections 1–4 23
Properties of breadth-first search
Complete??
AIMA Slides © and ; Chapter 3, Sections 1–4 24
Properties of breadth-first search
Complete?? Yes (if b is finite)
Time?? 1 + b + b2 + b3 + . . . + bd = O(bd), i.e., exponential in d
Space?? O(bd) (keeps every node in memory)
Optimal?? Yes (if cost = 1 per step); not optimal in general
Space is the big problem; can easily generate nodes at 1MB/sec
so 24hrs = 86GB.
AIMA Slides © and ; Chapter 3, Sections 1–4 25
Romania with step costs in km
AIMA Slides © and ; Chapter 3, Sections 1–4 26
Uniform-cost search
Expand least-cost unexpanded node
Implementation:
QueueingFn = insert in order of increasing path cost
AIMA Slides © and ; Chapter 3, Sections 1–4 27
Uniform-cost search
Expand least-cost unexpanded node
Implementation:
QueueingFn = insert in order of increasing path cost
AIMA Slides © and ; Chapter 3, Sections 1–4 28
Uniform-cost search
Expand least-cost unexpanded node
Implementation:
QueueingFn = insert in order of increasing path cost
AIMA Slides © and ; Chapter 3, Sections 1–4 29
Uniform-cost search
Expand least-cost unexpanded node
Implementation:
QueueingFn = insert in order of increasing path cost
AIMA Slides © and ; Chapter 3, Sections 1–4 30
Properties of uniform-cost search
Complete?? Yes, if step cost ≥ ϵ
Time?? # of nodes with g ≤ cost of optimal solution
Space?? # of nodes with g ≤ cost of optimal solution
Optimal?? Yes
AIMA Slides © and ; Chapter 3, Sections 1–4 31
Depth-first search
Expand deepest unexpanded node
Implementation:
QueueingFn = insert successors at front of queue
AIMA Slides © and ; Chapter 3, Sections 1–4 32
Depth-first search
Expand deepest unexpanded node
Implementation:
QueueingFn = insert successors at front of queue
AIMA Slides © and ; Chapter 3, Sections 1–4 33
Depth-first search
Expand deepest unexpanded node
Implementation:
QueueingFn = insert successors at front of queue
AIMA Slides © and ; Chapter 3, Sections 1–4 34
Depth-first search
Expand deepest unexpanded node
Implementation:
QueueingFn = insert successors at front of queue
I.e., depth-first search can perform infinite cyclic excursions
Need a finite, non-cyclic search space (or repeated-state checking)
AIMA Slides © and ; Chapter 3, Sections 1–4 35
Properties of depth-first search
Complete??
AIMA Slides © and ; Chapter 3, Sections 1–4 36
Properties of depth-first search
Complete?? No: fails in infinite-depth spaces, spaces with loops
Modify to avoid repeated states along path
⇒ complete in finite spaces
Time?? O(bm): terrible if m is much larger than d
but if solutions are dense, may be much faster than breadth-first
Space?? O(bm), i.e., linear space!
Optimal?? No
AIMA Slides © and ; Chapter 3, Sections 1–4 37
Depth-limited search
= depth-first search with depth limit l
Implementation:
Nodes at depth l have no successors
AIMA Slides © and ; Chapter 3, Sections 1–4 38
Iterative deepening search
function Iterative-Deepening-Search( problem) returns a solution sequence
inputs: problem, a problem
for depth← 0 to ∞ do
result←Depth-Limited-Search( problem, depth)
if result ̸= cutoff then return result
AIMA Slides © and ; Chapter 3, Sections 1–4 39
Properties of iterative deepening search
Complete?? Yes
Time?? (d + 1)b0 + db1 + (d− 1)b2 + . . . + bd = O(bd)
Space?? O(bd)
Optimal?? Yes, if step cost = 1
Can be modified to explore uniform-cost tree
AIMA Slides © and ; Chapter 3, Sections 1–4 40
Bidirectional Search
Search simultaneously forwards from the start point, and backwards from
the goal, and stop when the two searches meet in the middle.
Problems: generate predecessors; many goal states; efficient check for node
already visited by other half of the search; and, what kind of search.
AIMA Slides © and ; Chapter 3, Sections 1–4 41
Properties of Bidirectional Search
Complete?? Yes
Time?? O(b
Space?? O(b
Optimal?? Yes (if done with correct strategy – e.g. breadth first).
AIMA Slides © and ; Chapter 3, Sections 1–4 42
Problem formulation usually requires abstracting away real-world details to
define a state space that can feasibly be explored
Variety of uninformed search strategies
Iterative deepening search uses only linear space
and not much more time than other uninformed algorithms
Examples of skills expected:
♢ Formulate single-state search problem
♢ Apply a search strategy to solve problem
♢ Analyse complexity of a search strategy
AIMA Slides © and ; Chapter 3, Sections 1–4 43
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com