03 - uninformed search - povinelli.eece.mu.edupovinelli.eece.mu.edu/teaching/eece6820/slides/03 -...
TRANSCRIPT
Copyright Richard J. Povinelli Page 1rev 1.1, 9/3/2003
Uninformed Search
Dr. Richard J. Povinelli
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 2
Objectives
You shouldbe able to formulate a search problem. be able to evaluate a search algorithm on the basis of completeness, optimality, time complexity, and space complexity. be able to compare, contrast, classify, and implement various search algorithms including breadth-first, uniform-cost, depth-first, depth-limited, iterative deepening, bidirectional.
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 3
Problem-solving agentsRestricted form of general agentNote: this is offline problem solving. Online problem solving involves acting without complete knowledge of the problem and solution.function Simple-Problem-Solving-Agent( percept) returns an action static: seq, an action sequence, initially empty
state, some description of the current world state goal, a goal, initially null problem, a problem formulation
state ← Update-State(state,percept) if seq is empty thengoal ← Formulate-Goal(state) problem ← Formulate-Problem(state, goal) seq ← Search( problem) action ← Recommendation(seq, state) seq ← Remainder(seq, state) return action
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 4
Example: Romania
On holiday in Romaniacurrently in AradFlight leaves tomorrow from Bucharest
Formulate goal: be in Bucharest
Formulate problem:states: various citiesoperators: drive between cities
Find solution: sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 5
Example: Romania
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 6
Problem typesDeterministic, fully observable => single-state problem
Agent knows exactly which state it will be in; solution is a sequence
Non-observable => conformant (sensorless) problemAgent may have no idea where it is; solution (if any) is a sequence
Nondeterministic and/or partially observable=> contingency problem
Percepts provide new information about current statesolution is a tree or policyoften interleave search, execution
Unknown state space => exploration problem (“online”)
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 7
Example: vacuum worldSingle-state, start in #5
Solution??Conformant, start in {1, 2, 3, 4, 5, 6, 7, 8}
e.g., Right goes to {2, 4, 6, 8}.Solution??
Contingency, start in #5Murphy's Law: Suck can dirty a clean carpetLocal sensing: dirt, location only.Solution??
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 8
Single-state problem formulationA problem is defined by four items:
initial state “at Arad”
successor function S(x) = set of action-state pairsS(Arad) = {
<Arad → Zerind, Zerind>, <Arad → Sibiu, Zerind>,<Arad → Timisoara, Timisoara >}
goal testexplicit, e.g., x = “at Bucharest”implicit, e.g., NoDirt(x)
path cost (additive)sum of distances, number of operators executed, or others
A solution is a sequence of actions leading from the initial state to a goal state
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 9
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
“Arad → Zerind” represents a complex set of possible routes, detours, rest stops, and other states.
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 worldEach abstract action should be “easier” than the original problem!
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 10
CAT – 8 PuzzleDescribe the following for the 8 puzzle
statesoperatorsgoal testpath cost
Work with a partner for 5 minutes
Start State Goal State
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 11
Example: The 8-puzzle
states??: integer locations of tiles (ignore intermediate positions)operators??: move blank left, right, up, down (ignore unjamming)goal test??: = goal state (given)path cost??: 1 per move[Note: optimal solution of n-Puzzle family is NP-hard]
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Start State Goal State
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 12
Example: vacuum world
AIMA Slides © Stuart Russell and Peter Norvig, 1998
states??operators??goal test??path cost??
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 13
Example: vacuum world
AIMA Slides © Stuart Russell and Peter Norvig, 1998
states??: integer dirt and robot locations (ignore dirt amounts)operators??: Left, Right, Suck, NoOp goal test??: no dirtpath cost??: 1 per operator (0 for NoOp)
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 14
Example: robotic assembly
AIMA Slides © Stuart Russell and Peter Norvig, 1998
states??: real-valued coordinates of robot joint angles, parts of the object to be assembledoperators??: continuous motions of robot jointsgoal test??: complete assembly with no robot included!path cost??: time to execute
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 15
Tree Search algorithms
Basic idea: offline, simulated exploration of state space by generating successors of already-explored states (a.k.a. expanding states)
AIMA Slides © Stuart Russell and Peter Norvig, 1998
function Tree-Search( problem, strategy) returns a solution, or failure initialize the search tree using the initial state of problemloop do
if there are no candidates for expansion then return failure choose a leaf node for expansion according to strategyif the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree
end
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 16
Implementation: states vs. nodesA state is a (representation of) a physical configurationA 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!
AIMA Slides © Stuart Russell and Peter Norvig, 1998
The Expand function creates new nodes, filling in the various fields and using the Operators (or SuccessorFn) of the problem to create the corresponding states.
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 17
Implementation of general tree search
function Tree-Search( problem, fringe) returns a solution or failurefringe ← Insert(Make-Node(Initial-State[problem]), fringe) loop do
if fringe is empty then return failure node ← Remove-Front(fringe ) if Goal-Test[problem] applied to State(node) succeeds
then return node fringe ← InsertAll (Expand(node, problem), fringe)
function Expand(node, problem) returns a set of nodessuccessors ← the empty setfor each action, result in Successor-Fn [problem](State[node]) do
s ← a new NodeParent-Node [s] ← node; Action[s] ← action; State[s] ← resultPath-Cost[s] ← Path-Cost[node] + Step-Cost(node, action, s)Depth[s] ← Depth[node] + 1add s to successors
return successorsAIMA Slides © Stuart Russell and Peter Norvig, 2003
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 18
Tree search example
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 19
Search strategiesA strategy is defined by picking the order of node expansionStrategies are evaluated along the following dimensions
completeness – does it always find a solution if one exists?time complexity – number of nodes generated/expandedspace complexity – maximum number of nodes in memoryoptimality – does it always find a least-cost solution?
Time and space complexity are measured in terms ofb – maximum branching factor of the search treed – depth of the least-cost solutionm – maximum depth of the state space (may be ∞)
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 20
Uninformed search strategiesUninformed strategies use only the information available in the problem definitionBreadth-first searchUniform-cost searchDepth-first searchDepth-limited searchIterative deepening search
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 21
CAT – Manual search I
Find the shortest cost route from Bucharest to Zerind in 15 s.
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 22
CAT – Manual search II
Find the shortest cost route from Pitesti to Timisoaro in 1 minute
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 23
CAT – Manual search III
Bucharest to Zerind: 101 + 97 + 80 + 140 + 75 = 493Pitesti to Timisoaro: 97 + 80 + 140 + 118 = 435
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 24
Breadth-first searchExpand shallowest unexpanded node Implementation:
fringe is a FIFO queue, I.e. new successors go at end
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 25
Properties of breadth-first searchComplete??Time??Space??Optimal??
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 26
Properties of breadth-first searchComplete?? Yes (if b is finite)Time?? 1 + b + b2 + b3 + … + bd = O(bd ), i.e., exponential in dSpace?? 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 10MB/sec so 24hrs = 860GB.
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 27
Romania with step costs in km
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 28
Uniform-cost searchExpand least-cost unexpanded nodeImplementation: fringe = queue ordered by path cost
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 29
Properties of uniform-cost searchExpand least-cost unexpanded nodeImplementation:
fringe = queue ordered by path costEquivalent to breadth-first if step costs all equalComplete?? Yes, if step cost ≥ εTime?? # of nodes with g ≤ cost of optimal solution, O(b^(ceil(C*/ε)), where C* is the cost of the optimal solutionSpace?? # of nodes with g ≤ cost of optimal solution, O(b^(ceil(C*/ε)) Optimal?? Yes, nodes expanded in increasing order of g(n)
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 30
DFS on a depth-3 binary tree
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Expand deepest unexpanded nodeImplementation
fringe = LIFO queue, i.e., put successors at front
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 31
Properties of depth-first searchComplete??Time??Space??Optimal??
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 32
Properties of depth-first searchComplete??
No: fails in infinite-depth spaces, spaces with loopsModify to avoid repeated states along path ⇒ complete in finite spaces
Time?? O(bm ): terrible if m (maximum depth of the state space) is much larger than d, (depth of the least-cost solution)but if solutions are dense, may be much faster than breadth-first
Space?? O(bm), i.e., linear space!Optimal?? No
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 33
Depth-limited searchDepth-first search with depth limitImplementation: Nodes at depth l have no successors
function Depth-Limited-Search (problem, limit) returns soln/fail/cutoffRecursive-DLS(Make-Node(Initial-State[problem]), problem, limit)
function Recursive-DLS (node, problem, limit) returns soln/fail/cutoffcutoff-occurred? ← falseif Goal-Test[problem](State[node]) then return nodeelse if Depth[node] = limit then return cutoffelse for each successor in Expand(node, problem) do
result ← Recursive-DLS(successor, problem, limit)if result = cutoff then cutoff-occurred? ← trueelse if result ≠ failure then return result
if cutoff-occurred? then return cutoff else return failure
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 34
Iterative deepening search
function Iterative-Deepening-Search( problem) returns a solutioninputs: problem, a problem for depth ← 0 to ∞ do
result ← Depth-Limited-Search( problem, depth) if result ≠ cutoff then return result
end
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 35
Iterative deepening search l = 0
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Arad
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 36
Iterative deepening search l = 1
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Arad
Sibiu TimisoaraZerind
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 37
Iterative deepening search l = 2
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Arad
Sibiu TimisoaraZerind
OradeaArad OradeaArad Fagaras Rimnicu Vilcea Arad Lugoj
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 38
Properties of iterative deepening search
Complete??Time??Space??Optimal??
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 39
Properties of iterative deepening search
Complete?? YesTime?? (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 treeNumerical comparison for b=10 and d=5, solution at far right:
N(IDS) = 50 + 400 + 3,000 + 20,000 + 100,000 = 123,450N(BFS) = 10 + 100 + 1,000 + 10,000 + 100,000 + 999,990 = 1,111,100
AIMA Slides © Stuart Russell and Peter Norvig, 1998
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 40
CAT – Search StrategiesWork out the tree for the four queens search problems. Each team will use a different search strategy
Breadth-firstUniform-costDepth-firstIterative deepening
Work with a partner for 5 minutes, write on board
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 41
Summary of algorithms
a – complete if b is finiteb – complete if step costs ≥ ε e for positive ec – optimal if step costs are all identicald – if both directions use breadth-first search
Criterion Breadth- Uniform- Depth- Depth- IterativeFirst Cost First Limited Deepening
Complete? Yesa Yesa,b No No Yesa
Time O (b d +1) O (b 1+floor(C* /ε )) O (b m ) O (b l ) O (b d )Space O (b d +1) O (b 1+floor(C* /ε )) O (bm ) O (bl ) O (bd ) Optimal? Yesc Yes No No Yesc
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 42
Repeated states
Failure to detect repeated states can turn a linear problem into an exponential one!
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 43
Graph searchfunction Graph-Search(problem, fringe) returns a solution, or
failureclosed ← an empty setfringe ← Insert(Make-Node(Initial-State[problem]), fringe)loop do
if fringe is empty then return failurenode ← Remove-Front(fringe)if Goal-Test[problem](State[node]) then return nodeif State[node] is not in closed then
add State[node] to closedfringe ← InsertAll(Expand(node, problem), fringe)
end
Copyright Richard J. Povinelli rev 1.1, 9/3/2003 Page 44
SummaryProblem formulation usually requires abstracting away real-world details to define a state space that can feasibly be exploredVariety of uninformed search strategiesIterative deepening search uses only linear space and not much more time than other uninformed algorithms
AIMA Slides © Stuart Russell and Peter Norvig, 1998