1/21/20141 solving problems by searching course teacher: moona kanwal

115
06/26/22 1 Solving problems by searching Course Teacher: Moona Kanwal

Upload: sara-pope

Post on 26-Mar-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 1

Solving problems by searching

Course Teacher: Moona Kanwal

Page 2: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/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

Page 3: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 3

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)

Page 4: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 4

Problem types

Deterministic, fully observableDeterministic, fully observable single-state problem: initial state known, results of action known

Non-observableNon-observable sensor less problem (conformant problem): initial state not known, results of action known

Nondeterministic and/or partially observableNondeterministic and/or partially observable contingency problem: unknown states on some results of action

Unknown state spaceUnknown state space exploration problem: unknown states, unknown actions

Page 5: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 5

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.

Page 6: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 6

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.

Page 7: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 7

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.

Page 8: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 8

Page 9: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 9

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

Page 10: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 10

Example: Romania

Page 11: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 11

Page 12: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 12

Example: The 8-puzzle

states? actions? goal test? path cost?

Page 13: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 13

Example: The 8-puzzle

states? locations of tileslocations of tiles actions? move blank left, right, up, downmove blank left, right, up, down goal test? = goal state (given)goal state (given) path cost?1 per move1 per move

Page 14: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 14

Page 15: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 15

Example: vacuum world

Single-state, Single-state, start in #5start in #5.

Solution?

Page 16: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 16

Example: vacuum world

Single-state, Single-state, start in #5start in #5.

Solution? [Right, Suck][Right, Suck]

SensorlessSensorless, start in {1,2,3,4,5,6,7,8} e.g., Right goes to {2,4,6,8} Solution?

Page 17: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 17

Example: vacuum world

SensorlessSensorless, start in {1,2,3,4,5,6,7,8} e.g., Right goes to {2,4,6,8} Solution? [Right,Suck,Left,Suck]

ContingencyContingency 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?

Page 18: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 18

Example: vacuum world

SensorlessSensorless, start in {1,2,3,4,5,6,7,8} e.g., Right goes to {2,4,6,8} Solution? [Right,Suck,Left,Suck]

ContingencyContingency 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]

Page 19: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 19

Vacuum world state space graph

states? actions? goal test? path cost?

Page 20: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 20

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

Page 21: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 21

Example: robotic assembly

states?: real-valued coordinates of robot joint real-valued coordinates of robot joint angles parts of the object to be assembledangles parts of the object to be assembled

actions?: continuous motions of robot jointscontinuous motions of robot joints goal test?: complete assemblycomplete assembly path cost?: time to executetime to execute

Page 22: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 22

Page 23: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 23

Page 24: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 24

Page 25: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 25

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)

Page 26: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 26

Tree search example

Page 27: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 27

Tree search example

Page 28: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 28

Tree search example

Page 29: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 29

Implementation: general tree search

Page 30: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 30

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.

Page 31: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 31

Page 32: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 32

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 ∞∞))

Page 33: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 33

Page 34: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 34

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

Page 35: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 35

Breadth-first search

Expand shallowest unexpanded nodeExpand shallowest unexpanded node Implementation:

fringe is a FIFO queue, i.e., new successors go at end

Page 36: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 36

Breadth-first search

Expand shallowest unexpanded nodeExpand shallowest unexpanded node Implementation:

fringe is a FIFO queue, i.e., new successors go at end

Page 37: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 37

Breadth-first search

Expand shallowest unexpanded node Implementation:

fringe is a FIFO queue, i.e., new successors go at end

Page 38: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 38

Breadth-first search

Expand shallowest unexpanded node Implementation:

fringe is a FIFO queue, i.e., new successors go at end

Page 39: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 39

Page 40: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 40

Page 41: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 41

Page 42: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 42

Page 43: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 43

Page 44: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 44

Page 45: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 45

Page 46: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 46

Page 47: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 47

Page 48: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 48

Page 49: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 49

Page 50: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 50

Page 51: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 51

Page 52: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 52

Page 53: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 53

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)

Page 54: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 54

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)

Page 55: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 55

Page 56: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 56

Page 57: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 57

Page 58: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 58

Page 59: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 59

Page 60: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 60

Page 61: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 61

Page 62: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 62

Page 63: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 63

Page 64: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 64

Page 65: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 65

Page 66: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 66

Page 67: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 67

Page 68: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 68

Page 69: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 69

Page 70: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 70

Page 71: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 71

Page 72: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 72

Page 73: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 73

Page 74: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 74

Page 75: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 75

Page 76: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 76

Page 77: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 77

Page 78: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 78

Page 79: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 79

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 80: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 80

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 81: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 81

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 82: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 82

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 83: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 83

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 84: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 84

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 85: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 85

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 86: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 86

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 87: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 87

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 88: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 88

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 89: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 89

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 90: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 90

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 91: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 91

Page 92: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 92

Page 93: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 93

Page 94: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 94

Page 95: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 95

Page 96: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 96

Page 97: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 97

Page 98: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 98

Page 99: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 99

Page 100: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 100

Page 101: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 101

Page 102: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 102

Page 103: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 103

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

Page 104: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 104

Depth-limited search

= depth-first search with depth limit l,i.e., nodes at depth l have no successors

Recursive implementation:

Page 105: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 105

Iterative deepening search

Page 106: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 106

Iterative deepening search

Page 107: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 107

Iterative deepening search

Page 108: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 108

Iterative deepening search

Page 109: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 109

Iterative deepening search

Page 110: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 110

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%

Page 111: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 111

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

Page 112: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 112

Summary of algorithms

Page 113: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 113

Repeated states

Failure to detect repeated states can turn a linear problem into an exponential one!

Page 114: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 114

Graph search

Page 115: 1/21/20141 Solving problems by searching Course Teacher: Moona Kanwal

04/10/23 115

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