Solving problems by searching Course Teacher Moona Kanwal
Solving problems by searching Course Teacher: Moona Kanwal 12/13/2021 1
Outline n n n Well-defined Problems Solutions (as a sequence of actions). Examples Search Trees Uninformed Search Algorithms 12/13/2021 2
Problem-Solving w Goal formulation (final state): limits objectives w Problem formulation (set of states): actions+states w Search (solution): sequence of actions w Execution (follows states in solution) 12/13/2021 3
Problem types n n Deterministic, fully observable single-state problem: initial state known, results of action known Non-observable sensor less problem (conformant problem): initial state not known, results of action known Nondeterministic and/or partially observable contingency problem: unknown states on some results of action Unknown state space exploration problem: unknown states, unknown actions 12/13/2021 4
Well Defined Problems A problem is defined by four items: 2. initial state actions or successor function S(x) = set of 3. goal test or predicate γ : S → {0, 1} is 1 iff goal 1. action–state pairs state n n n Explicit: concrete goal implicit : abstract description of goal path cost (additive): g, assigns a numeric cost to a given path. 12/13/2021 5
Well Defined Problems n State-Space n n n An Initial State, s 0 ∈ S. A Set of Operators (or Actions), {Ai|i = 1, 2, . . } Formally, the state space is the set of states that can be reached by any sequence of actions applied to the initial state, e. g. , S = {s 0, . . . , Ai 1 Ai 2 s 0, . . . , Ai 1 Ai 2 ・・・Aiks 0, . . . } A path is a particular sequence of actions applied to the initial state. 12/13/2021 6
Solutions A solution is a sequence of actions leading from the initial state to a goal state n A solution is a path that satisfies the goal test. n An optimal solution is a solution with minimal cost. n 12/13/2021 7
12/13/2021 8
Example: Romania n n n On holiday in Romania; currently in Arad. Flight leaves tomorrow from Bucharest Formulate goal: n n Formulate problem: n n n be in Bucharest states: various cities actions: drive between cities Find solution: n sequence of cities, e. g. , Arad, Sibiu, Fagaras, Bucharest 12/13/2021 9
Example: Romania 12/13/2021 10
12/13/2021 11
Example: The 8 -puzzle n n states? actions? goal test? path cost? 12/13/2021 12
Example: The 8 -puzzle n n states? locations of tiles actions? move blank left, right, up, down goal test? = goal state (given) path cost? 1 per move 12/13/2021 13
12/13/2021 14
Example: vacuum world n Single-state, n start in #5. Solution? n 12/13/2021 15
Example: vacuum world n Single-state, n start in #5. Solution? [Right, Suck] n Sensorless, start in n {1, 2, 3, 4, 5, 6, 7, 8} e. g. , Right goes to {2, 4, 6, 8} Solution? 12/13/2021 16
Example: vacuum world n Sensorless, start in {1, 2, 3, 4, 5, 6, 7, 8} e. g. , Right goes to {2, 4, 6, 8} Solution? [Right, Suck, Left, Suck] n Contingency n n n Nondeterministic: Suck may dirty a clean carpet Partially observable: location, dirt at current location. Percept: [L, Clean], i. e. , start in #5 or #7 Solution? 12/13/2021 17
Example: vacuum world n Sensorless, start in {1, 2, 3, 4, 5, 6, 7, 8} e. g. , Right goes to {2, 4, 6, 8} Solution? [Right, Suck, Left, Suck] n Contingency n n n Nondeterministic: Suck may dirty a clean carpet Partially observable: location, dirt at current location. Percept: [L, Clean], i. e. , start in #5 or #7 Solution? [Right, if dirt then Suck] 12/13/2021 18
Vacuum world state space graph n n states? actions? goal test? path cost? 12/13/2021 19
Vacuum world state space graph n n states? integer dirt and robot location actions? Left, Right, Suck goal test? no dirt at all locations path cost? 1 per action 12/13/2021 20
Example: robotic assembly n n 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 path cost? : time to execute 12/13/2021 21
12/13/2021 22
12/13/2021 23
12/13/2021 24
Tree search algorithms n Basic idea: n offline, simulated exploration of state space by generating successors of alreadyexplored states (a. k. a. expanding states) 12/13/2021 25
Tree search example 12/13/2021 26
Tree search example 12/13/2021 27
Tree search example 12/13/2021 28
Implementation: general tree search 12/13/2021 29
Implementation: states vs. nodes n n n A state is a (representation of) a physical configuration A node is a data structure constituting part of a search tree includes state, parent node, action, path cost g(x), depth The Expand function creates new nodes, filling in the various fields and using the Success or Fn of the problem to create the corresponding states. 12/13/2021 30
12/13/2021 31
Search strategies Time and space complexity are measured in terms of n b: maximum branching factor of the search tree n d: depth of the least-cost solution n m: maximum depth of the state space (may be ∞) 12/13/2021 32
12/13/2021 33
Uninformed search strategies use only the information available in the problem definition n Breadth-first search n Uniform-cost search n Depth-first search n Depth-limited search n Iterative deepening search 12/13/2021 34
Breadth-first search n Expand shallowest unexpanded node n Implementation: n fringe is a FIFO queue, i. e. , new successors go at end 12/13/2021 35
Breadth-first search n Expand shallowest unexpanded node n Implementation: n fringe is a FIFO queue, i. e. , new successors go at end 12/13/2021 36
Breadth-first search n n Expand shallowest unexpanded node Implementation: n fringe is a FIFO queue, i. e. , new successors go at end 12/13/2021 37
Breadth-first search n n Expand shallowest unexpanded node Implementation: n fringe is a FIFO queue, i. e. , new successors go at end 12/13/2021 38
12/13/2021 39
12/13/2021 40
12/13/2021 41
12/13/2021 42
12/13/2021 43
12/13/2021 44
12/13/2021 45
12/13/2021 46
12/13/2021 47
12/13/2021 48
12/13/2021 49
12/13/2021 50
12/13/2021 51
12/13/2021 52
Properties of breadth-first search n Complete? Yes (if b is finite) Time? 1+b+b 2+b 3+… +bd + b(bd-1) = O(bd+1) Space? O(bd+1) (keeps every node in memory) Optimal? Yes (if cost = 1 per step) n Space is the bigger problem (more than time) n n n 12/13/2021 53
Uniform-cost search n n Expand least-cost unexpanded node Implementation: n fringe = queue ordered by path cost n 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, n Optimal? Yes – nodes expanded in increasing order of g(n) n n n O(bceiling(C*/ ε)) 12/13/2021 54
12/13/2021 55
12/13/2021 56
12/13/2021 57
12/13/2021 58
12/13/2021 59
12/13/2021 60
12/13/2021 61
12/13/2021 62
12/13/2021 63
12/13/2021 64
12/13/2021 65
12/13/2021 66
12/13/2021 67
12/13/2021 68
12/13/2021 69
12/13/2021 70
12/13/2021 71
12/13/2021 72
12/13/2021 73
12/13/2021 74
12/13/2021 75
12/13/2021 76
12/13/2021 77
12/13/2021 78
Depth-first search n n Expand deepest unexpanded node Implementation: n fringe = LIFO queue, i. e. , put successors at front 12/13/2021 79
Depth-first search n n Expand deepest unexpanded node Implementation: n fringe = LIFO queue, i. e. , put successors at front 12/13/2021 80
Depth-first search n n Expand deepest unexpanded node Implementation: n fringe = LIFO queue, i. e. , put successors at front 12/13/2021 81
Depth-first search n n Expand deepest unexpanded node Implementation: n fringe = LIFO queue, i. e. , put successors at front 12/13/2021 82
Depth-first search n n Expand deepest unexpanded node Implementation: n fringe = LIFO queue, i. e. , put successors at front 12/13/2021 83
Depth-first search n n Expand deepest unexpanded node Implementation: n fringe = LIFO queue, i. e. , put successors at front 12/13/2021 84
Depth-first search n n Expand deepest unexpanded node Implementation: n fringe = LIFO queue, i. e. , put successors at front 12/13/2021 85
Depth-first search n n Expand deepest unexpanded node Implementation: n fringe = LIFO queue, i. e. , put successors at front 12/13/2021 86
Depth-first search n n Expand deepest unexpanded node Implementation: n fringe = LIFO queue, i. e. , put successors at front 12/13/2021 87
Depth-first search n n Expand deepest unexpanded node Implementation: n fringe = LIFO queue, i. e. , put successors at front 12/13/2021 88
Depth-first search n n Expand deepest unexpanded node Implementation: n fringe = LIFO queue, i. e. , put successors at front 12/13/2021 89
Depth-first search n n Expand deepest unexpanded node Implementation: n fringe = LIFO queue, i. e. , put successors at front 12/13/2021 90
12/13/2021 91
12/13/2021 92
12/13/2021 93
12/13/2021 94
12/13/2021 95
12/13/2021 96
12/13/2021 97
12/13/2021 98
12/13/2021 99
12/13/2021 100
12/13/2021 101
12/13/2021 102
Properties of depth-first search n Complete? No: fails in infinite-depth spaces, spaces with loops n Modify to avoid repeated states along path complete in finite spaces n Time? O(bm): terrible if m is much larger than d n n n but if solutions are dense, may be much faster than breadth-first Space? O(bm), i. e. , linear space! Optimal? No 12/13/2021 103
Depth-limited search = depth-first search with depth limit l, i. e. , nodes at depth l have no successors n Recursive implementation: 12/13/2021 104
Iterative deepening search 12/13/2021 105
Iterative deepening search 12/13/2021 106
Iterative deepening search 12/13/2021 107
Iterative deepening search 12/13/2021 108
Iterative deepening search 12/13/2021 109
Iterative deepening search n n Number of nodes generated in a depth-limited search to depth d with branching factor b: NDLS = b 0 + b 1 + b 2 + … + bd-2 + bd-1 + bd Number of nodes generated in an iterative deepening search to depth d with branching factor b: NIDS = (d+1)b 0 + d b^1 + (d-1)b^2 + … + 3 bd-2 +2 bd-1 + 1 bd For b = 10, d = 5, n NDLS = 1 + 100 + 1, 000 + 100, 000 = 111, 111 n NIDS = 6 + 50 + 400 + 3, 000 + 20, 000 + 100, 000 = 123, 456 Overhead = (123, 456 - 111, 111)/111, 111 = 11% 12/13/2021 110
Properties of iterative deepening search n Complete? Yes n Time? O(bd) (d+1)b 0 + d b 1 + (d-1)b 2 + … + bd = O(bd) n Space? n Optimal? Yes, if step cost = 1 12/13/2021 111
Summary of algorithms 12/13/2021 112
Repeated states n Failure to detect repeated states can turn a linear problem into an exponential one! 12/13/2021 113
Graph search 12/13/2021 114
Summary n n n 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 12/13/2021 115
- Slides: 115