Date post: | 11-Jan-2016 |
Category: |
Documents |
Upload: | ali-siddiqui |
View: | 227 times |
Download: | 1 times |
04/21/23 1
Solving problems by searching
Course Teacher: Moona Kanwal
04/21/23 2
Outline
Well-defined ProblemsWell-defined Problems Solutions (as a sequence of actions).Solutions (as a sequence of actions). ExamplesExamples Search TreesSearch Trees Uninformed Search AlgorithmsUninformed Search Algorithms
04/21/23 3
Recall:Problem-Solving
Goal formulationGoal formulation (final state): limits objectives
Problem formulationProblem formulation (set of states): actions+states
Search Search (solution): sequence of actions
ExecutionExecution (follows states in solution)
04/21/23 4
Recall:Well Defined Problems
A problem is defined by four itemsA problem is defined by four items:
1.1. initial stateinitial state2.2. actions or successor functionactions or successor function S(x) = set of
action–state pairs
3.3. goal test or predicate goal test or predicate γ : S → {0, 1} is 1 iff goal state
Explicit: concrete goal implicit : abstract description of goal
path costpath cost (additive):g, assigns a numeric cost to a given path.
04/21/23 5
Well Defined Problems
State-Space State-Space An Initial State, s0 ∈ S. A Set of Operators (or Actions), {Ai|i = 1, 2, . . }
Formally, the state space is the set of states Formally, the state space is the set of states that can be reached by any sequence of that can be reached by any sequence of actions applied to the initial state, e.g.,actions applied to the initial state, e.g.,
S = {sS = {s00, . . . ,A, . . . ,Ai1i1ss00, . . . ,A, . . . ,Ai1i1AiAi22ss00, . . . ,A, . . . ,Ai1i1AAi2i2 ・・・・・・ AAikikss00, . . . }, . . . }
A path is a particular sequence of actions A path is a particular sequence of actions applied to the initial state.applied to the initial state.
04/21/23 6
Solutions
A solution is a sequence of actions A solution is a sequence of actions leading from the initial state to a leading from the initial state to a goal stategoal state
A solution is a path that satisfies A solution is a path that satisfies the goal test.the goal test.
An optimal solution is a solution An optimal solution is a solution with minimal cost.with minimal cost.
04/21/23 7
04/21/23 8
Example: Romania
On holiday in Romania; currently in Arad. Flight leaves tomorrow from Bucharest Formulate goal:
be in Bucharest Formulate problem:
states: various cities actions: drive between cities
Find solution: sequence of cities, e.g., Arad, Sibiu, Fagaras,
Bucharest
04/21/23 9
Example: Romania
04/21/23 10
04/21/23 11
04/21/23 12
Vacuum world state space graph
states? integer dirt and robot locationinteger dirt and robot location actions? Left, Right, SuckLeft, Right, Suck goal test? no dirt at all locationsno dirt at all locations path cost? 11 per actionper action
04/21/23 13
04/21/23 14
04/21/23 15
04/21/23 16
Tree search algorithms
Basic ideaBasic idea: offline, simulated exploration of state offline, simulated exploration of state
space by generating successors of already-space by generating successors of already-explored states (a.k.a.expanding states)explored states (a.k.a.expanding states)
04/21/23 17
Tree search example
04/21/23 18
Tree search example
04/21/23 19
Tree search example
04/21/23 20
Implementation: general tree search
04/21/23 21
Implementation: states vs. nodes
A state is a (representation of) a physical configurationA state is a (representation of) a physical configuration A node is a data structure constituting part of a search tree A node is a data structure constituting part of a search tree
includes state, parent node, action, path cost g(x), depthincludes state, parent node, action, path cost g(x), depth
The Expand function creates new nodes, filling in the various The Expand function creates new nodes, filling in the various fields and using the Success or Fn of the problem to create the fields and using the Success or Fn of the problem to create the corresponding states.corresponding states.
04/21/23 22
04/21/23 23
Search strategies
Time and space complexity are measured Time and space complexity are measured in terms of in terms of b: maximum branching factor of the b: maximum branching factor of the
search treesearch tree d: depth of the least-cost solutiond: depth of the least-cost solution m: maximum depth of the state space m: maximum depth of the state space
(may be (may be ∞∞))
04/21/23 24
04/21/23 25
Uninformed search strategies
Uninformed search strategies use only the Uninformed search strategies use only the information available in the problem information available in the problem definitiondefinition
Breadth-first searchBreadth-first search Uniform-cost searchUniform-cost search Depth-first searchDepth-first search Depth-limited searchDepth-limited search Iterative deepening searchIterative deepening search
04/21/23 26
Breadth-first search
Expand shallowest unexpanded nodeExpand shallowest unexpanded node Implementation:
fringe is a FIFO queue, i.e., new successors go at end
04/21/23 27
Breadth-first search
Expand shallowest unexpanded nodeExpand shallowest unexpanded node Implementation:
fringe is a FIFO queue, i.e., new successors go at end
04/21/23 28
Breadth-first search
Expand shallowest unexpanded node Implementation:
fringe is a FIFO queue, i.e., new successors go at end
04/21/23 29
Breadth-first search
Expand shallowest unexpanded node Implementation:
fringe is a FIFO queue, i.e., new successors go at end
04/21/23 30
04/21/23 31
04/21/23 32
04/21/23 33
04/21/23 34
04/21/23 35
04/21/23 36
04/21/23 37
04/21/23 38
04/21/23 39
04/21/23 40
04/21/23 41
04/21/23 42
04/21/23 43
04/21/23 44
Properties of breadth-first search
Complete? Yes (if b is finite) Time? 1+b+b2+b3+… +bd + b(bd-1) =
O(bd+1) Space? O(bd+1) (keeps every node in
memory) Optimal? Yes (if cost = 1 per step)
Space is the bigger problem (more than time)
04/21/23 45
Uniform-cost search
Expand least-cost unexpanded node Implementation:
fringe = queue ordered by path cost Equivalent to breadth-first if step costs all equal Complete? Yes, if step cost ≥ ε Time? # of nodes with g ≤ cost of optimal solution,
O(bceiling(C*/ ε)) where C* is the cost of the optimal solution
Space? # of nodes with g ≤ cost of optimal solution, O(bceiling(C*/ ε))
Optimal? Yes – nodes expanded in increasing order of g(n)
04/21/23 46
04/21/23 47
04/21/23 48
04/21/23 49
04/21/23 50
04/21/23 51
04/21/23 52
04/21/23 53
04/21/23 54
04/21/23 55
04/21/23 56
04/21/23 57
04/21/23 58
04/21/23 59
04/21/23 60
04/21/23 61
04/21/23 62
04/21/23 63
04/21/23 64
04/21/23 65
04/21/23 66
04/21/23 67
04/21/23 68
04/21/23 69
04/21/23 70
Depth-first search
Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front
04/21/23 71
Depth-first search
Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front
04/21/23 72
Depth-first search
Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front
04/21/23 73
Depth-first search
Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front
04/21/23 74
Depth-first search
Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front
04/21/23 75
Depth-first search
Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front
04/21/23 76
Depth-first search
Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front
04/21/23 77
Depth-first search
Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front
04/21/23 78
Depth-first search
Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front
04/21/23 79
Depth-first search
Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front
04/21/23 80
Depth-first search
Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front
04/21/23 81
Depth-first search
Expand deepest unexpanded node Implementation:
fringe = LIFO queue, i.e., put successors at front
04/21/23 82
04/21/23 83
04/21/23 84
04/21/23 85
04/21/23 86
04/21/23 87
04/21/23 88
04/21/23 89
04/21/23 90
04/21/23 91
04/21/23 92
04/21/23 93
04/21/23 94
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
04/21/23 95
Depth-limited search
= depth-first search with depth limit l,i.e., nodes at depth l have no successors
Recursive implementation:
04/21/23 96
Iterative deepening search
04/21/23 97
Iterative deepening search
04/21/23 98
Iterative deepening search
04/21/23 99
Iterative deepening search
04/21/23 100
Iterative deepening search
04/21/23 101
Iterative deepening search
Number of nodes generated in a depth-limited search to depth d with branching factor b:
NDLS = b0 + b1 + b2 + … + bd-2 + bd-1 + bd
Number of nodes generated in an iterative deepening search to depth d with branching factor b:
NIDS = (d+1)b0 + d b^1 + (d-1)b^2 + … + 3bd-2 +2bd-1 + 1bd
For b = 10, d = 5, NDLS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 =
111,111 NIDS = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 =
123,456
Overhead = (123,456 - 111,111)/111,111 = 11%
04/21/23 102
Properties of iterative deepening search
Complete? Yes Time? (d+1)b0 + d b1 + (d-1)b2 + … +
bd = O(bd) Space? O(bd) Optimal? Yes, if step cost = 1
04/21/23 103
Summary of algorithms
04/21/23 104
Repeated states
Failure to detect repeated states can turn a linear problem into an exponential one!
04/21/23 105
Graph search
04/21/23 106
Summary
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