solving problems by searching

135
Solving Problems by Searching Foundations for Uninformed Search Methods

Upload: zephr-waters

Post on 04-Jan-2016

33 views

Category:

Documents


0 download

DESCRIPTION

Solving Problems by Searching. Foundations for Uninformed Search Methods. Literature. S. Russell and P. Norvig. Artificial Intelligence: A Modern Approach , chapter 3. Prentice Hall, 2 nd edition, 2003. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Solving Problems by Searching

Solving Problems by Searching

Foundations for Uninformed Search Methods

Page 2: Solving Problems by Searching

Solving Problems by Searching 2

Literature S. Russell and P. Norvig. Artificial Intelligence: A

Modern Approach, chapter 3. Prentice Hall, 2nd edition, 2003.

S. Amarel. On Representations of Problems of Reasoning about Actions. In: D. Michie ,editor, Machine Intelligence 3, pages 131-171, Edinburgh University Press, 1968. Reprinted in: B. Webber and N. Nilsson ,editors, Readings in Artificial Intelligence, pages 2-22, Tioga, 1981.

N. Nilsson. Principles of Artificial Intelligence, chapters 1-2. Springer, 1982.

Page 3: Solving Problems by Searching

Solving Problems by Searching 3

Overview

Characterizing Search Problems Searching for Solutions Uninformed Search Strategies Avoiding Repeated States The Problem of Representation Search in AND/OR-Graphs Searching with Partial Information

Page 4: Solving Problems by Searching

Solving Problems by Searching 4

Problems of Reasoning about Actions

aim: find a course of actions that satisfies a number of specified conditions

examples:• planning an airplane trip

• planning a dinner party

Page 5: Solving Problems by Searching

Solving Problems by Searching 5

Toy Problems vs.Real-World Problems

Toy Problems• concise and exact

description

• used for illustration purposes (e.g. here)

• used for performance comparisons

Real-World Problems• no single, agreed-

upon description

• people care about the solutions

Page 6: Solving Problems by Searching

Solving Problems by Searching 6

Toy Problem: Missionaries and Cannibals

On one bank of a river are three missionaries (black triangles) and three cannibals (red circles). There is one boat available that can hold up to two people and that they would

like to use to cross the river. If the cannibals ever outnumber the missionaries on either of the river’s banks, the missionaries will get eaten. How can the boat be used to safely carry all the missionaries and cannibals across the river?

Page 7: Solving Problems by Searching

Solving Problems by Searching 7

Search Problems initial state set of possible actions/applicability conditions

• successor function: state set of <action, state>• successor function + initial state = state space• path (solution)

goal• goal test function or goal state

path cost function• assumption: path cost = sum of step costs• for optimality

Page 8: Solving Problems by Searching

Solving Problems by Searching 8

Missionaries and Cannibals: Initial State and Actions

initial state:• all missionaries, all

cannibals, and the boat are on the left bank

5 possible actions:• one missionary crossing

• one cannibal crossing

• two missionaries crossing

• two cannibals crossing

• one missionary and one cannibal crossing

Page 9: Solving Problems by Searching

Solving Problems by Searching 9

Missionaries and Cannibals: Successor Function

state set of <action, state>

(L:3m,3c,b-R:0m,0c) {<2c, (L:3m,1c-R:0m,2c,b)>,

<1m1c, (L:2m,2c-R:1m,1c,b)>,

<1c, (L:3m,2c-R:0m,1c,b)>}

(L:3m,1c-R:0m,2c,b) {<2c, (L:3m,3c,b-R:0m,0c) >,

<1c, (L:3m,2c,b-R:0m,1c)>}

(L:2m,2c-R:1m,1c,b) {<1m1c, (L:3m,3c,b-R:0m,0c) >,

<1m, (L:3m,2c,b-R:0m,1c)>}

Page 10: Solving Problems by Searching

Solving Problems by Searching 10

Missionaries and Cannibals: State Space

1c

1m1c

2c1c

2c

1c

2m

1m1c

1m1c

1c

2c

1m

2m

1c

2c

1c

1m

Page 11: Solving Problems by Searching

Solving Problems by Searching 11

Missionaries and Cannibals: Goal State and Path Cost

goal state:• all missionaries, all

cannibals, and the boat are on the right bank.

path cost• step cost: 1 for each

crossing

• path cost: number of crossings = length of path

solution path:• 4 optimal solutions

• cost: 11

Page 12: Solving Problems by Searching

Solving Problems by Searching 12

Real-World Problem:Touring in Romania

Oradea

Bucharest

Fagaras

Pitesti

Neamt

Iasi

Vaslui

Urziceni

Hirsova

Eforie

GiurgiuCraiova

Rimnicu Vilcea

Sibiu

Dobreta

Mehadia

Lugoj

Timisoara

Arad

Zerind

120

140

151

75

70

111

118

75

71

85

90

211

101

97

138

146

8099

87

92

142

98

86

Page 13: Solving Problems by Searching

Solving Problems by Searching 13

Goal Formulation

performance measure• assigns a “happiness value” to all possible world

states

goal• a condition that either is or is not satisfied in a given

world state; a set of world states

goal formulation• find a goal that must be true in all desirable world

states, i.e. all situations in which the performance measure is high

Page 14: Solving Problems by Searching

Solving Problems by Searching 14

Problem Formulation

problem formulation• process of deciding what actions and states to

consider

• granularity/abstraction level

assumptions about the environment:• static

• observable

• discrete

• deterministic

Page 15: Solving Problems by Searching

Solving Problems by Searching 15

Touring in Romania:Search Problem Definition

initial state:• In(Arad)

possible Actions:• DriveTo(Zerind), DriveTo(Sibiu), DriveTo(Timisoara),

etc.

goal state:• In(Bucharest)

step cost:• distances between cities

Page 16: Solving Problems by Searching

Solving Problems by Searching 16

Overview

Characterizing Search Problems

Searching for Solutions Uninformed Search Strategies Avoiding Repeated States The Problem of Representation Search in AND/OR-Graphs Searching with Partial Information

Page 17: Solving Problems by Searching

Solving Problems by Searching 17

Search

An agent with several immediate options of unknown value can decide what to do by first examining different possible sequences of actions that lead to states of known value, and then choosing the best sequence.

search (through the state space) for• a goal state

• a sequence of actions that leads to a goal state

• a sequence of actions with minimal path cost that leads to a goal state

Page 18: Solving Problems by Searching

Solving Problems by Searching 18

Search Trees

search tree: tree structure defined by initial state and successor function

Touring Romania (partial search tree):

In(Arad)

In(Zerind) In(Sibiu) In(Timisoara)

In(Arad) In(Oradea) In(Fagaras) In(Rimnicu Vilcea)

In(Sibiu) In(Bucharest)

Page 19: Solving Problems by Searching

Solving Problems by Searching 19

Search Nodes

search nodes: the nodes in the search tree data structure:

• state: a state in the state space

• parent node: the immediate predecessor in the search tree

• action: the action that, performed in the parent node’s state, leads to this node’s state

• path cost: the total cost of the path leading to this node

• depth: the depth of this node in the search tree

Page 20: Solving Problems by Searching

Solving Problems by Searching 20

Expanding a Search Node

function expand(node, problem)

successors { }for each <action, result> in problem.successorFn(node.state) do

s new searchNode(result)s.parentNode nodes.action actions.pathCost node.pathCost +

problem.stepCost(action, node.state)s.depth node.depth + 1successors successors + s

return successors

Page 21: Solving Problems by Searching

Solving Problems by Searching 21

Expanded Search Nodesin Touring Romania Example

In(Arad)

In(Zerind) In(Sibiu) In(Timisoara)

In(Arad) In(Oradea) In(Fagaras) In(Rimnicu Vilcea)

In(Sibiu) In(Bucharest)

Page 22: Solving Problems by Searching

Solving Problems by Searching 22

Fringe Nodesin Touring Romania Example

fringe nodes: nodes that have not been expanded

In(Arad)

In(Zerind) In(Sibiu) In(Timisoara)

In(Arad) In(Oradea) In(Fagaras) In(Rimnicu Vilcea)

In(Sibiu) In(Bucharest)

Page 23: Solving Problems by Searching

Solving Problems by Searching 23

Search (Control) Strategy

search or control strategy: an effective method for scheduling the application of the successor function to generate new states• selects the next node to be expanded from the fringe

• determines the order in which nodes are expanded

• aim: produce a goal state as quickly as possible

examples: • LIFO-queue for fringe nodes

• alphabetical ordering

Page 24: Solving Problems by Searching

Solving Problems by Searching 24

General Tree Search Algorithm

function treeSearch(problem, strategy)fringe { new

searchNode(problem.initialState) }loop

if empty(fringe) then return failurenode selectFrom(fringe, strategy)if problem.goalTest(node.state) then

return pathTo(node)fringe fringe + expand(problem, node)

Page 25: Solving Problems by Searching

Solving Problems by Searching 25

Key Features of the General Search Algorithm

systematic• guaranteed to not generate the same state

infinitely often

• guaranteed to come across every state eventually

incremental• attempts to reach a goal state step by step

(rather than guessing it all at once)

Page 26: Solving Problems by Searching

Solving Problems by Searching 26

Possible Outcomes

algorithm terminates with:• failure: no solution could be found

• success: solution path was found

algorithm does not terminate

Page 27: Solving Problems by Searching

Solving Problems by Searching 27

In(Arad) In(Oradea) In(Rimnicu Vilcea)

In(Zerind) In(Timisoara)

In(Sibiu) In(Bucharest)

In(Fagaras)

In(Sibiu)

General Search Algorithm:Touring Romania Example

In(Arad)

fringe

selected

Page 28: Solving Problems by Searching

Solving Problems by Searching 28

Measuring Problem-Solving Performance

completeness• Is the algorithm guaranteed to find a solution when

there is one?

optimality• Does the strategy find the optimal solution?

time complexity• How long does it take to find a solution?

space complexity• How much memory is need to perform the search?

Page 29: Solving Problems by Searching

Solving Problems by Searching 29

Search Problem Complexity Measures

in theoretical Computer Science:• size of the state space graph

in Artificial Intelligence:• branching factor: maximum number of

successors per node

• depth of the shallowest goal node

• maximum length of any path in the state space

Page 30: Solving Problems by Searching

Solving Problems by Searching 30

Problem-Solving Performance: Examples

Touring Romania Missionaries and Cannibals

size of state space

20 16

branching factor 4 3

shallowest goal depth

3 11

maximum path length

16 13

Page 31: Solving Problems by Searching

Solving Problems by Searching 31

Search Cost vs. Total Cost

search cost:• time (and memory) used to find a solution

total cost:• search cost + path cost of solution

optimal trade-off point:• further computation to find a shorter path

becomes counterproductive

Page 32: Solving Problems by Searching

Solving Problems by Searching 32

Overview

Characterizing Search Problems Searching for Solutions

Uninformed Search Strategies Avoiding Repeated States The Problem of Representation Search in AND/OR-Graphs Searching with Partial Information

Page 33: Solving Problems by Searching

Solving Problems by Searching 33

Uninformed vs. Informed Search

uninformed search (blind search)• no additional information about states beyond

problem definition

• only goal states and non-goal states can be distinguished

informed search (heuristic search)• additional information about how “promising”

a state is available

Page 34: Solving Problems by Searching

Solving Problems by Searching 34

Breadth-First Search

strategy:• expand root node

• expand successors of root node

• expand successors of successors of root node

• etc. implementation:

• use FIFO queue to store fringe nodes in general tree search algorithm

Page 35: Solving Problems by Searching

Solving Problems by Searching 35

de

pth

= 3

Breadth-First Search: Missionaries and Cannibals

de

pth

= 0

de

pth

= 1

de

pth

= 2

Page 36: Solving Problems by Searching

Solving Problems by Searching 36

Time and Space Complexity for Breadth-First Search

assumptions:• every search node has exactly b successors (b finite)

• shallowest goal node is at finite depth d

analysis:• worst case: goal node last node at depth d

• bn successors at depth n

• time complexity: O(bd+1)

• space complexity: O(bd+1)

1132 ddd bObbbbbb

Page 37: Solving Problems by Searching

Solving Problems by Searching 37

Breadth-First Search: Evaluation

completeness yes

optimality shallowest

time complexity O(bd+1)

space complexity O(bd+1)

Page 38: Solving Problems by Searching

Solving Problems by Searching 38

Exponential Complexity

Depth Nodes Time Memory

2 1100 0.11 seconds 1 megabyte

4 111100 11 seconds 106 megabytes

6 107 19 minutes 10 gigabytes

8 109 31 hours 1 terabyte

10 1011 129 days 101 terabytes

12 1013 35 years 10 petabytes

14 1015 3523 years 1 exabyte

Page 39: Solving Problems by Searching

Solving Problems by Searching 39

Exponential Complexity: Important Lessons

memory requirements are a bigger problem for breadth-first search than is the execution time

time requirements are still a major factor

exponential-complexity search problems cannot be solved by uninformed methods for any but the smallest instances

Page 40: Solving Problems by Searching

Solving Problems by Searching 40

Uniform-Cost Search

breadth-first search is optimal when all step costs are equal

uniform-cost search:• always expand the fringe node with lowest

path cost first

Page 41: Solving Problems by Searching

Solving Problems by Searching 41

d =

3

Uniform-Cost Search:Touring Romania

Sibiu(290)

Zerind(225)

Timisoara(268) Zerind

(217)Sibiu(297)

Sibiu(300)

Pitesti(317)

Craiova(346) Mehadia

(299)Timisoara

(340)

Arad(280)

Rimnicu Vilcea(220)

Fagaras(239)

Oradea(291)

Arad(300)

Oradea(296)

Arad(292)

Oradea(288)

Arad(150)

Oradea(146)

Arad(236)

Lugoj(229)

Zerind(75)

Sibiu(140)

Timisoara(118)

Arad(0) d =

0d

= 2

d =

1d

= 4

fringe

selected

Page 42: Solving Problems by Searching

Solving Problems by Searching 42

Time and Space Complexity for Uniform-Cost Search

assumptions:• every search node has exactly b successors (b finite)

• every step has cost ≥ ε for some positive constant ε

• let C* be the cost of an optimal solution

analysis:• time complexity: O(b1+⌊C*/ε⌋)

• space complexity: O(b1+⌊C*/ε⌋)

Page 43: Solving Problems by Searching

Solving Problems by Searching 43

Uniform-Cost Search: Evaluation

completeness yes

optimality yes

time complexity O(b1+⌊C*/ε⌋)

space complexity O(b1+⌊C*/ε⌋)

Page 44: Solving Problems by Searching

Solving Problems by Searching 44

Depth-First Search

strategy:• always expand the deepest node in the current fringe

first

• when a sub-tree has been completely explored, delete it from memory and “back up”

implementation:• use LIFO queue (stack) to store fringe nodes in

general tree search algorithm

• alternative: recursive function that calls itself on each of its children in turn

Page 45: Solving Problems by Searching

Solving Problems by Searching 45

de

pth

= 3

Depth-First Search:Missionaries and Cannibals

de

pth

= 0

de

pth

= 1

de

pth

= 2

Page 46: Solving Problems by Searching

Solving Problems by Searching 46

Recursive Implementation of Depth-First Search

function depthFirstSearch(problem)return recursiveDFS(

new searchNode(problem.initialState, problem)

function recursiveDFS(node, problem)if problem.goalTest(node.state) then return pathTo(node)for each successor in expand(node, problem) do

result recursiveDFS(successor, problem)if result ≠ failure then return result

return failure

Page 47: Solving Problems by Searching

Solving Problems by Searching 47

Time and Space Complexity for Depth-First Search

assumptions:• every search node has exactly b successors

(b finite)

• depth of the deepest node in the tree is m

analysis:• time complexity: O(bm)

• space complexity: O(bm)

Page 48: Solving Problems by Searching

Solving Problems by Searching 48

Depth-First Search: Evaluation

completeness no

optimality no

time complexity O(bm)

space complexity O(bm)

Page 49: Solving Problems by Searching

Solving Problems by Searching 49

Depth-First Search: Finding the Optimal Path

first solution discovered may not be optimal must keep searching

continued search:• assumption: non-decreasing path costs

• remember path cost of cheapest path found so far

• do not expand nodes for which path cost exceeds cheapest found so far

Page 50: Solving Problems by Searching

Solving Problems by Searching 50

Backtracking Search

a variant of depth-first search• generate only one successor at a time

• each node remembers which successor to generate next

• space complexity: O(m)

• generate successors by modifying current state representation• must be able to undo modifications

• may use even less memory (and time)

Page 51: Solving Problems by Searching

Solving Problems by Searching 51

Depth-Limited Search

strategy:• always expand the deepest node in the

current fringe first (like depth-first search)

• treat nodes at a given depth l as if they have no successors

implementation:• like depth-first search, but test for depth limit

before expanding a node

Page 52: Solving Problems by Searching

Solving Problems by Searching 52

Recursive Implementation of Depth-Limited Search

function depthLimitedSearch(problem, limit)return recursiveDLS(

new searchNode(problem.initialState), problem, limit)

function recursiveDLS(node, problem, limit)cutoffOccured falseif problem.goalTest(node) then return pathTo(node)if node.depth = limit then return cutofffor each successor in expand(node, problem) do

result recursiveDLS(successor, problem, limit)if result = cutoff then cutoffOccured trueelse if result ≠ failure then return result

if cutoffOccured then return cutoff else return failure

Page 53: Solving Problems by Searching

Solving Problems by Searching 53

Time and Space Complexity for Depth-Limited Search

assumptions:• every search node has exactly b successors

(b finite)

• the given depth limit is l

analysis:• time complexity: O(bl)

• space complexity: O(bl)

Page 54: Solving Problems by Searching

Solving Problems by Searching 54

Depth-Limited Search: Evaluation

completeness no

optimality no

time complexity O(bl)

space complexity O(bl)

Page 55: Solving Problems by Searching

Solving Problems by Searching 55

How to Choose the Depth Limit?

example: Touring Romania• there are 20 cities on the map. Thus, choose l=19.

• the longest distance between two cities on the map is 9 steps; thus, choose l=9.

in general:• the diameter of a search space is the longest distance

between two nodes in the search space

• choose the diameter as the depth limit to guarantee completeness

Page 56: Solving Problems by Searching

Solving Problems by Searching 56

Iterative Deepening Search

strategy:• based on depth-limited (depth-first) search

• repeat search with gradually increasing depth limit until a goal state is found

implementation:for depth 0 to ∞ do

result depthLimitedSearch(problem, depth)

if result ≠ cutoff then return result

Page 57: Solving Problems by Searching

Solving Problems by Searching 57

de

pth

= 3

Iterative Deepening Search:Missionaries and Cannibals

de

pth

= 0

de

pth

= 1

de

pth

= 2

Page 58: Solving Problems by Searching

Solving Problems by Searching 58

Time and Space Complexity for Iterative Deepening Search

assumptions:• every search node has exactly b successors (b

finite)

• the shallowest goal node is at depth d

analysis:• time complexity:

(d)b + (d-1)b2 + … + (2)b(d-1) + (1)bd ∈ O(bd)

• space complexity: O(bd)

Page 59: Solving Problems by Searching

Solving Problems by Searching 59

Iterative Deepening Search: Evaluation

completeness yes

optimality shallowest

time complexity O(bd)

space complexity O(bd)

Page 60: Solving Problems by Searching

Solving Problems by Searching 60

Iterative Lengthening Search

iterative analogue of uniform-cost search strategy:

• based on cost-limited (depth-first) search

• repeat search with gradually increasing path cost limit until a goal state is found

problem: How to increase the path cost limit?• use minimum: substantial overhead

• use fixed step size: no optimality

Page 61: Solving Problems by Searching

Solving Problems by Searching 61

Bidirectional Search

idea: run two simultaneous searches: • one forward from the initial state,

• one backward from the goal state, until the two fringes meet.The solution path must cross the meeting point.

Start Goal

Page 62: Solving Problems by Searching

Solving Problems by Searching 62

Bidirectional Search: Caveats

What search strategy for forward/backward search?• breadth-first search

How to check whether a node is in the other fringe?• hash table

must know goal state for backward search must be able to compute predecessors and

successors for a given state

Page 63: Solving Problems by Searching

Solving Problems by Searching 63

Bidirectional Search: Evaluation

completeness yes

optimality shallowest

time complexity O(bd/2)

space complexity O(bd/2)

Page 64: Solving Problems by Searching

Solving Problems by Searching 64

Comparing Uninformed Search Strategies

Breadth-First

Uniform-Cost

Depth-First

Depth-Limited

Iterative Deepening

Bidirectional Breadth-F.

complete? Yes Yes No No Yes Yes

optimal? Yes Yes No No Yes Yes

time complexity

O(bd+1) O(b1+⌊C*/ε⌋) O(bm) O(bl) O(bd) O(bd/2)

space complexity

O(bd+1) O(b1+⌊C*/ε⌋) O(bm) O(bl) O(bd) O(bd/2)

Page 65: Solving Problems by Searching

Solving Problems by Searching 65

Overview

Characterizing Search Problems Searching for Solutions Uninformed Search Strategies

Avoiding Repeated States The Problem of Representation Search in AND/OR-Graphs Searching with Partial Information

Page 66: Solving Problems by Searching

Solving Problems by Searching 66

Repeated States

problem: repeated states waste time and memory by expanding states that have already been encountered, i.e. repeating work

solution:formulate the problem in such a way that repeated states are not generated

Page 67: Solving Problems by Searching

Solving Problems by Searching 67

Discovering Repeated States: Potential Savings

sometimes repeated states are unavoidable, resulting in infinite search trees

checking for repeated states:• infinite search tree ⇒ finite search tree

•finite search tree ⇒ exponential reduction

stat

e sp

ace

grap

h

sear

ch t

ree

stat

e sp

ace

grap

h

Page 68: Solving Problems by Searching

Solving Problems by Searching 68

Discovering Repeated States

compare node about to be expanded to all previously expanded nodes

if there was a match, one node can be discarded

issues:• storing the nodes: hash table

• matching: usually equality testing

Page 69: Solving Problems by Searching

Solving Problems by Searching 69

General Graph Search Algorithm

function graphSearch(problem, strategy)closed { }fringe { new searchNode(problem.initialState) }loop

if empty(fringe) then return failurenode selectFrom(fringe, strategy)if problem.goalTest(node.state) then

return pathTo(node)if node.state ∉ closed

closed closed + nodefringe fringe + expand(problem, node)

Page 70: Solving Problems by Searching

Solving Problems by Searching 70

Repeated States and Depth-First Search

problem:depth-first search keeps only nodes on the current path and their siblings in memory

two approaches:• test only against the above nodes:

avoids only loops, not all repeated states

• remember all closed nodes: may increase space complexity of depth-first search to O(bd)

Page 71: Solving Problems by Searching

Solving Problems by Searching 71

Optimality and Graph Search

function graphSearch always discards newly discovered path to the same state which may be shorter• retains optimality for (bidirectional) breadth-first search

or uniform-cost search with constant step costs

• depth-first and depth-limited search are not optimal anyway

• iterative deepening search may become non-optimal:

• loop testing only: remains optimal

• testing all states: not optimal; requires extension

Page 72: Solving Problems by Searching

Solving Problems by Searching 72

Representing Sets of States: Splitting

idea: instead of individual states, represent (implicit) sets of states

actions: splitting into subsets• disjoint subsets avoid repeated states

• will reach goal state (set with one state eventually)

example: N-queens problem

Page 73: Solving Problems by Searching

Solving Problems by Searching 73

Toy Problem: N-Queens Problem

Place n queens on an n by n chess board such that none of the queens attacks any of the others.

Page 74: Solving Problems by Searching

Solving Problems by Searching 74

Problem Formulation: N-Queens Problem complete-state formulation:

• states: any arrangement of 8 queens on the chess board• initial state: any arrangement of 8 queens on the board • actions: move a queen on the board• goal test: no queen attacks another

constructive formulation:• states: any arrangement of 0 to 8 queens on the board• initial state: no queens on the board• actions: place a queen on the board (next free row!)• goal test: 8 queens on board, none attacks another

constructive problem formulations lend themselves to systematic search

Page 75: Solving Problems by Searching

Solving Problems by Searching 75

Overview

Characterizing Search Problems Searching for Solutions Uninformed Search Strategies Avoiding Repeated States

The Problem of Representation Search in AND/OR-Graphs Searching with Partial Information

Page 76: Solving Problems by Searching

Solving Problems by Searching 76

Representation and Efficiency

there usually is a choice of representation during problem formulation

there is a relationship between the chosen representation and the efficiency with which a problem-solving system can be expected to solve the problem

understanding this relationship is a prerequisite for designing good representations

Page 77: Solving Problems by Searching

Solving Problems by Searching 77

Generalized Missionaries and Cannibals (GM&C) Problem

On one bank of a river are N missionaries and N cannibals. There is one boat available that can hold up to K people and that they would like to use to cross the river. If the cannibals ever outnumber the missionaries on either of the river’s banks or in the boat, the missionaries will get eaten. How can the boat be used to safely carry all the missionaries and cannibals across the river?

Page 78: Solving Problems by Searching

Solving Problems by Searching 78

Toy Problem: Sliding-Block Puzzle

876

543

21

138

65

427

the 8-Puzzle

Page 79: Solving Problems by Searching

Solving Problems by Searching 79

Other Real-World Problems

Route-Finding Problem Touring Problem (TSP) VLSI Layout Robot Navigation Automatic Assembly Sequencing Internet Searching

Page 80: Solving Problems by Searching

Solving Problems by Searching 80

Systems of Production

a system of production provides a framework for formally representing search problems• more restrictive approach than what we have

seen so far

• generic problem solver can solve any problem specified in the framework

• opens the door for reasoning about the representation

Page 81: Solving Problems by Searching

Solving Problems by Searching 81

Systems of Production: N-State Languages states of nature (N-states) consist of

• entities that exist in this state• properties of these entities• relations between the entities

an N-state language L0 is a tuple (U0, P0) where:• U0 is a non-empty set of entities called the basic

universe and• P0 is a non-empty set of basic predicates defined

for elements of U0

Page 82: Solving Problems by Searching

Solving Problems by Searching 82

Example: N-State Language for the GM&C Problem

the basic universe U0 contains:• N individuals m1, …, mN representing missionaries

• N individuals c1, …, cN representing cannibals

• the boat b (with capacity K)

• two places pL and pR representing the left and right river bank

the set of predicates P0 contains:• at(x, y): asserts that the entity x (a person or the boat)

is at place y (pL or pR)

• on(x, b): asserts that the person x is aboard b

Page 83: Solving Problems by Searching

Solving Problems by Searching 83

Systems of Production: Derived Description Languages N-states also require:

• additional entities for defining legal states and actions

• additional properties and relations for defining legal states and actions

a derived description language L1 is a tuple (U1, P1) where:

• U1 ⊇ U0 is a non-empty set of entities called the extended universe and

• P1 is a non-empty set of basic predicates defined for elements of U1

Page 84: Solving Problems by Searching

Solving Problems by Searching 84

Example: Derived Description Language for the GM&C Problem

the extended universe U1 additionally contains:• {m}L, {m}R, {m}b, {c}L, {c}R, {c}b: the subsets of

missionaries/cannibals on the right/left river bank or on the boat

• ML, MR, Mb, CL, CR, Cb: the respective set sizes

• 1, …, N: numbers for representing these sizes

the set of predicates P1 additionally contains:

• =, <, > (relations for comparing numbers)

Page 85: Solving Problems by Searching

Solving Problems by Searching 85

Production Systems: Configurations a configuration is a finite set (possibly empty) of

expressions in an N-state language.• The empty configuration will be written Λ (upper case

lambda).• The set union of two configurations α and β is again a

configuration and it is written “α, β”

configurations list the basic features of a situation at one point in time

logical interpretation: conjunction of the true assertions made by the component expressions, true proposition

Page 86: Solving Problems by Searching

Solving Problems by Searching 86

Example: Configurations in the GM&C Problem

configurations in the N-state language L0:

for the initial state of the GM&C problem{ at(m1, pL),…, at(mN, pL), at(c1, pL), …, at(cN, pL), at(b, pL) }

for the goal state of the GM&C problem{ at(m1, pR),…, at(mN, pR), at(c1, pR), …, at(cN, pR), at(b, pR) }

Page 87: Solving Problems by Searching

Solving Problems by Searching 87

Production Systems: Descriptions of N-States a basic description, s, of an N-state is a

configuration from which all true statements about the N-state (that can be expressed in terms of the N-state language) can be directly obtained or derived

a derived description, d(s), associated with an N-state is a configuration from which all true statements about the N-state (that can be expressed in terms of the derived description language) can be directly obtained or derived

in a mixed description s’ = s;d(s), s is a basic description and d(s) its associated derived description

Page 88: Solving Problems by Searching

Solving Problems by Searching 88

Example: Descriptions in the GM&C Problem

mixed description for the goal state of the GM&C problem: { at(m1, pR),…, at(mN, pR), at(c1, pR), …, at(cN, pR), at(b, pR) } }; { {m}L={}, {m}R ={m1…mN}, {m}b ={}, {c}L ={}, {c}R ={c1…cN}, {c}b ={}, ML=0, MR=N, Mb=0, CL=0, CR=N, Cb=0 }

Page 89: Solving Problems by Searching

Solving Problems by Searching 89

Production Systems:Rules of Action

Let A be an action and let (A) denote the corresponding rule of action which must have the form:

(A): sa;d(sa) sb;d(sb)

The application of A in sa is permissible if both, d(sa) and d(sb) are satisfied.

Page 90: Solving Problems by Searching

Solving Problems by Searching 90

Example: Rules of Action in the GM&C Problem

let α denote an arbitrary configuration and x an individual (missionary or cannibal)

action (LBL): load boat at left, one individual at a time:α, at(b, pL), at(x, pL); (Mb+Cb ≤ K-1)

α, at(b, pL), on(x, b); Λ action (MBLR): move boat across river from left to right:

α, at(b, pL); (Mb+Cb > 0) α, at(b, pR); Λ action (UBR): load boat at left, one individual at a time:

α, at(b, pR), on(x, b); Λ α, at(b, pR), at(x, pR); Λ

actions: (LBR), (MBRL), (UBL) by swapping pL and pR

Page 91: Solving Problems by Searching

Solving Problems by Searching 91

Production Systems: Trajectories An N-state sb is directly attainable from an N-state sa

(written sa↦sb) if there exists an applicable rule of action (A) that transforms sa into sb.

A trajectory from an N-state sa to an N-state sb is a sequence of N-states (s1,…, sm) where• sa= s1 and • sb= sm and• for each i, 1<i≤m, si is directly attainable from si-1

An N-state sb is attainable from an N-state sa (written sa⇒sb) if there exists a trajectory from sa to sb.

Page 92: Solving Problems by Searching

Solving Problems by Searching 92

Task of a Production System

given:• an N-state language

• an extended description language

• a set of rules of actions

• an initial N-state and a terminal N-state

find the shortest trajectory from the initial N-state to the terminal N-state

Page 93: Solving Problems by Searching

Solving Problems by Searching 93

From Verbal to Formal Representations

given: verbal formulation formalization – choice points:

• extended universe U1

• extended set of predicates P1

• set of actions

these choices determine the efficiency with which problems can be solved.

Page 94: Solving Problems by Searching

Solving Problems by Searching 94

Macro Actions

macro actions: sequences of primitive actions level of abstraction: such that all constraints in

the problem specification can still be verified GM&C example: load boat; cross and unload

transfer r individuals from left to right (1≤r≤K):

(MBLR)(LBL), (LBL), …, (LBL)

r times

(UBR), (UBR), …, (UBR)

r times

Page 95: Solving Problems by Searching

Solving Problems by Searching 95

Example: Specifying Macro Actions for the GM&C Problem

Let α denote an arbitrary configuration and x1, …, xr a set of individuals (missionaries and/or cannibals)

macro action (LrBL): load empty boat at left with r individuals, 1≤r≤K :α, at(b, pL), at(x1, pL), …, at(xr, pL); (Mb+Cb=0)

α, at(b, pL), on(x1, b), …, on(xr, b); ((ML=0) ∨ (ML≥CL)), ((Mb=0) ∨ (Mb≥Cb))

macro action (MBLR+ UrBR): move boat (loaded with r individuals) across river from left to right and unload all passengers at right: α, at(b, pL), on(x1, b), …, on(xr, b); (Mb+Cb=r)

α, at(b, pR), at(x1, pR), …, at(xr, pR); ((MR=0) ∨ (MR≥CR)) macro actions: (LrBR), (MBRL+UrBL) by swapping pL and pR

Page 96: Solving Problems by Searching

Solving Problems by Searching 96

Dropping the Non-Cannibalism Condition for the Boat Theorem: If at both, the beginning and the end of a

transfer, the non-cannibalism conditions (ML=0) ∨ (ML≥CL) and (MR=0) ∨ (MR≥CR) are satisfied for the two river banks, then the non-cannibalism condition for the boat, i.e. (Mb=0) ∨ (Mb≥Cb), is also satisfied.

Proof:

• (ML=0) ∨ (ML=N) ∨ (ML=CL) must hold before and after each transfer

• For each transfer from a configuration satisfying one of the three disjuncts to a configuration satisfying one (possibly the same) of the three disjuncts, the non-cannibalism condition on the boat must be satisfied.

Page 97: Solving Problems by Searching

Solving Problems by Searching 97

Distinguishing Individuals

individuals:• verbal formulation: N cannibals, N missionaries

• representation: distinguish only those individuals that are distinguishable

states:• vector (ML=i1, CL=i2, BL=i3) where

• ML/CL missionaries/cannibals on left river bank

• MR/CR determined by ML+MR=CL+CR=N

• BL=1 if at(b,pL), BL=0 if at(b,pR)

• examples: initial state: (N, N, 1), goal state: (0, 0, 0)

Page 98: Solving Problems by Searching

Solving Problems by Searching 98

Parameterized Actions add parameters to actions to simplify representation

macro action (TLR Mb Cb): transfer safely a mix (Mb Cb) from left to right:(ML, CL, 1); Λ (ML-Mb, CL-Cb, 0);

((ML-Mb=0) ∨ (ML-Mb≥CL-Cb)), ((N-(ML-Mb)=0) ∨ (N-(ML-Mb)≥N-(CL-Cb)))

macro action (TRL Mb Cb): transfer safely a mix (Mb Cb) from right to left:(ML, CL, 0); Λ (ML+Mb, CL+Cb, 1);

((ML+Mb=0) ∨ (ML+Mb≥CL-Cb)), ((N-(ML+Mb)=0) ∨ (N-(ML+Mb)≥N-(CL+Cb)))

Page 99: Solving Problems by Searching

Solving Problems by Searching 99

An Alternative View: Reduction Systems

search the space of P-states: S=(sa⇒sb)(read sb is attainable from sa)

•Example: GM&C initial state: S0=((N, N, 1) ⇒(0, 0, 0))

successors: Let (sa⇒sb) be a P-state and (A) an action that is applicable in sa. Let sc be the result of applying (A) in sa. Then (sc⇒sb) is a successor of (sa⇒sb).

goal state: (sb⇒sb)

Page 100: Solving Problems by Searching

Solving Problems by Searching 100

Problem Reduction: GM&C with N=3 and b=2

(331)⇒(000)

(310)⇒(000)

(320)⇒(000)

(220)⇒(000)

(321)⇒(000)

(300)⇒(000)

(311)⇒(000)

(110)⇒(000) (221)⇒(000)

(000)⇒(000)

(021)⇒(000) (111)⇒(000)

(010)⇒(000)

(031)⇒(000)

(020)⇒(000)

Page 101: Solving Problems by Searching

Solving Problems by Searching 101

Problem Reduction: GM&C with N=5 and b=3

(551)⇒(000)

(440)⇒(000)

(540)⇒(000)

(520)⇒(000)

(541)⇒(000)

(510)⇒(000)

(521)⇒(000)

(220)⇒(000) (331)⇒(000)

(000)⇒(000)

(021)⇒(000) (031)⇒(000)

(010)⇒(000)

(041)⇒(000)

(030)⇒(000)

(530)⇒(000)

(531)⇒(000)

(330)⇒(000) (500)⇒(000)

(511)⇒(000)(441)⇒(000)

(051)⇒(000)

(020)⇒(000)

(111)⇒(000)

Page 102: Solving Problems by Searching

Solving Problems by Searching 102

Symmetry in the Search Space consider states (311) in normal direction and (020) in

reverse direction:• Reached by (TLR 0 1) and (TRL 0 1) respectively

• Applicable actions: (TLR 2 0) and (TRL 2 0) respectively Definition: sa↤sb if and only if sb↦sa Definition: Let σ be the N-state space partially ordered

under the relation , and let↦ σ’ be the dual space (i.e. the same elements partially ordered under the relation ). ↤Then we define the function Θ: σ σ’ for the GM&C problem as:

Θ: (ML, CL, BL) (N-ML, N-CL, 1-BL) Note: Θ(Θ(s))=s

Page 103: Solving Problems by Searching

Solving Problems by Searching 103

Attainability and Symmetry

Theorem: For any pair of N-states sa,

sb the following equivalence holds: sa↦sb ≡ Θ(sa)↤Θ(sb)

or equivalently: sa↦sb ≡ Θ(sb)↦Θ(sa)

Corollary: For any pair of N-states sa,

sb the following equivalence holds: sa⇒sb ≡ Θ(sb)⇒Θ(sa)

sb

Θ(sb)

sa

Θ(sa)

Θ Θ

↦↤

Page 104: Solving Problems by Searching

Solving Problems by Searching 104

Exploiting Symmetry in the Search Space

Let s0 be the initial state and st=Θ(s0) the terminal state. Let sf be the set of fringe nodes during a search process. If there exist two nodes s,s’∈sf such that s=Θ(s’) or s↦s’ then s0⇒st.

s0

sf

st

Θ(sf)

=

or

Page 105: Solving Problems by Searching

Solving Problems by Searching 105

Exploiting Symmetry in the Search Space: Example

(331)⇒(000)

(310)⇒(000)

(320)⇒(000)

(220)⇒(000)

(321)⇒(000)

(300)⇒(000)

(311)⇒(000)

(110)⇒(000) (221)⇒(000)

(000)⇒(000)

(021)⇒(000) (111)⇒(000)

(010)⇒(000)

(031)⇒(000)

(020)⇒(000)

(011)⇒(000){(331)} {(000)}⇒

{(310) (220) (320)} {(011) (021) (111)}⇒

Problem:

{(321)} {(010)}⇒

{(300)} {(031)}⇒

{(311)} {(020)}⇒

{(110)} {(221)}⇒

{(110)} ↦ {(221)}

Page 106: Solving Problems by Searching

Solving Problems by Searching 106

Global View of the N-State Space of the M&C Problem

state space: 2(N+1)2 states in two planes

permissible states (white): non-cannibalism condition not violated

potential actions: subject to boat conditions (examples shown)

ML

CL

BL=0BL=1

Page 107: Solving Problems by Searching

Solving Problems by Searching 107

Solution to the M&C Problem in the Collapsed N-State Space

ML

CL

0

1

2

3

0 1 2 3

collapsed N-state space :

LTR transfers

RTL transfers

Page 108: Solving Problems by Searching

Solving Problems by Searching 108

General Shape of the Collapsed N-State Space

permissible territory: Z-shaped: (ML=0) ∨ (ML=N) ∨ (ML=CL)

initial state: top right goal state: bottom left possible actions: depend

on boat capacity

permissible territory:

Page 109: Solving Problems by Searching

Solving Problems by Searching 109

Solution Patterns for the GM&C Problem

boat capacity k ≥ 4 sliding along the

diagonal directly• repeat

•(TLR 2 2)

•(TRL 1 1)

boat capacity k ≤ 3 4 main steps

• slide along top leg

• jump to diagonal

• jump to bottom leg

• slide along bottom leg

Page 110: Solving Problems by Searching

Solving Problems by Searching 110

Global Movements for the GM&C Problem (H1): sliding along the ML=N line:

(N, CL, 1); 0<CL<N, k≥2 (N, N, 1) (H1,J1): slide and jump to diagonal:

(N, CL, 1); 0<CL<N, k≥2 (N-k+1, N-k+1, 1) (D): sliding along diagonal:

(ML, CL, 1); 0<CL=ML<N, k≥4 (0, 0, 0) (J2): jump to the ML=0 line:

(ML, CL, 1); 0<CL=ML≤k (0, CL, 0) (D,J2): slide and jump to the ML=0 line:

(ML, CL, 1); CL=ML>k≥4 (0, k, 0) (H2): sliding along the ML=0 line:

(0, CL, 0); 0≤CL<N, k≥2 (0, C’L, 0); 0≤C’L<N, CL≠C’L

Page 111: Solving Problems by Searching

Solving Problems by Searching 111

Global Movements: Example

problem:• N=9, k=4

• Initial state:(9, 1, 1)

• Goal state:(0, 8, 0)

(911)⇒(080)

(991)⇒(080) (661)⇒(080)

(000)⇒(080) (040)⇒(080)

(080)⇒(080)

(H1,J1)-[6](H1)-[6]

(D)-[15]

(D,J2)-[11] (D)-[9]

(D,J2)-[5]

(H2)-[6] (H2)-[4]

Page 112: Solving Problems by Searching

Solving Problems by Searching 112

High-Level and Low-Level Search Space high-level space is a subset of the low-level space regions of the search space:

• search spaces can divided into regions• example: M&C search space: top line, diagonal line, and

bottom line of the Z-shape

• movements within a region are relatively easy

• transitions between regions are difficult high-level search space provides an abstraction that

focuses on the transition points problems: defining the regions and transition points

Page 113: Solving Problems by Searching

Solving Problems by Searching 113

Overview

Characterizing Search Problems Searching for Solutions Uninformed Search Strategies Avoiding Repeated States The Problem of Representation

Search in AND/OR-Graphs Searching with Partial Information

Page 114: Solving Problems by Searching

Solving Problems by Searching 114

The Counterfeit Coin Problem

Given 12 gold coins of which one is known to be counterfeit, use a two-pan scale to identify the counterfeit coin and determine whether it is heavy or light in no more than three tests.

solution: a weighing strategy – a tree of tests (depth ≤ 3, branching factor = 3)

coin

coin

coin

coin

coin

coin

coin

coin

coin

coin

coin

coin

Page 115: Solving Problems by Searching

Solving Problems by Searching 115

AND/OR-Graphs: Example

1 1 2 2 3 3 4 4 5 5 6 6

1 111

11

alternativetests

alternativeoutcomes

reoccurringsub-problem

1 1

alternativetests

OR

AND

Page 116: Solving Problems by Searching

Solving Problems by Searching 116

AND/OR-Graphs

an AND/OR-graph is a hypergraph G=(N, C) where:• N is a set of nodes

•C ⊆ N x ℙ(N) is a set of connectors •1-connector: (n, s) ∈ C and |s|=1

for OR-connections

•k-connector: (n, s) ∈ C and |s|=kfor AND-connections

nodes with outgoing 1-connectors: OR-nodes

nodes with outgoing k-connectors: AND-nodes

Page 117: Solving Problems by Searching

Solving Problems by Searching 117

Solution Graphs for AND/OR-Graphs

a solution graph G’=(N’, C’) for an AND/OR-graph G=(N, C) is a sub-graph for which:• the start node is contained in N’

• every node n’∈N’ that has no outgoing connectors must be a terminal node

• if n’∈N’ and there exists a c’=(n, s) ∈ C’ with n’∈s then s ⊆ N’ must hold.

Page 118: Solving Problems by Searching

Solving Problems by Searching 118

Hypergraphs and Solution Graphs: Examples

start nodeterminal node

hypergraph: solution graph 1: solution graph 2:

Page 119: Solving Problems by Searching

Solving Problems by Searching 119

Labelling Nodes in an AND/OR-Graph as Solved

a node in an AND/OR graph can be considered solved if one of the following conditions holds:• it is a terminal node

• it is a non-terminal node with • at least one outgoing k-connector for which

• all descendants (the nodes the k-connector points to) are solved

Page 120: Solving Problems by Searching

Solving Problems by Searching 120

Search Algorithms for AND/OR Graphs

adaptation of breadth-first or depth-first search main difference: termination condition

• previously: goal is property of single node

• AND/OR graph: set of solved nodes collectively constitutes a solution

approach: • whenever a terminal node is reached

• label the node accordingly

• propagate the label the all ancestors (as far as possible)

• until the root node can be labelled solved/unsolvable

Page 121: Solving Problems by Searching

Solving Problems by Searching 121

Searching AND/OR-Graphs: Example

S UU U S U S U

U S

U

S S

S

S

Page 122: Solving Problems by Searching

Solving Problems by Searching 122

Appropriateness of AND/OR-Graphs

good for problems• in which the solution takes the form of a graph or tree

• example: counterfeit coin problem

• that are decomposable

• example: symbolic integration

• in which the solution is a set of partially ordered actions

not good for problems• in which sub-goals interact strongly

• example: sliding-tile puzzles

Page 123: Solving Problems by Searching

Solving Problems by Searching 123

Sub-Goal Interaction: Towers of Hanoi

aim: transfer disks from peg A to peg B best representation: decompose into

sub-goals (despite sub-goal interference)

A B C

Page 124: Solving Problems by Searching

Solving Problems by Searching 124

Overview

Characterizing Search Problems Searching for Solutions Uninformed Search Strategies Avoiding Repeated States The Problem of Representation Search in AND/OR-Graphs

Searching with Partial Information

Page 125: Solving Problems by Searching

Solving Problems by Searching 125

Assumptions

environment• fully observable

• deterministic

actions• all effects are known

Not very realistic!

Page 126: Solving Problems by Searching

Solving Problems by Searching 126

Three Types of Problems with Partial Information

Sensorless Problems:unknown initial state due to lack of perception

Contingency Problems:• environment only partially observable or

• actions with uncertain outcomes Exploration Problems:

• neither states nor actions are known

Page 127: Solving Problems by Searching

Solving Problems by Searching 127

Toy Problem:Vacuum World

R

L

S S

SS

SS

SS

L

L

L

L

L

L

L

R

R

R

R

R

R

R

Page 128: Solving Problems by Searching

Solving Problems by Searching 128

Sensorless Problem

reason about sets of states rather than single states

belief state: a set of states representing an agent’s current belief about the possible physical states it might be in.

coercion:perform actions that result in a belief state that contains only one physical state

Page 129: Solving Problems by Searching

Solving Problems by Searching 129

Belief State Space: Vacuum WorldL R

S

L R

S S

L R

R

L

SS

LLR R

SSL

R

Page 130: Solving Problems by Searching

Solving Problems by Searching 130

Non-Deterministic Actions

non-deterministic actions:• actions may have several possible outcomes

• without sensors, agent cannot tell which outcome occurred

approach:• unchanged, reason about belief states

• add all possible outcomes of an action to the belief state representing the outcome of the action

Page 131: Solving Problems by Searching

Solving Problems by Searching 131

Example: Murphy’s Law World

like Vacuum World except:action S (suck dirt) sometimes deposits dirt on the carpet, but only if there is no dirt there already• two possible outcomes for some actions

• renders Vacuum World unsolvable

Page 132: Solving Problems by Searching

Solving Problems by Searching 132

Belief State Space: Murphy’s Law World

L R

L R

S S S

Page 133: Solving Problems by Searching

Solving Problems by Searching 133

Contingency Problems

the agent can obtain new information from its sensors after acting

solution more complex: often tree structure• branching point is decision point

• decision depends on perception at the time example: Murphy’s Law World with

perception

Page 134: Solving Problems by Searching

Solving Problems by Searching 134

Algorithms forContingency Problems

contingency problems cannot be solved with the search techniques described here

interleaving problem-solving (search) and execution of action• more realistic approach for many real world

problems and some toy problems

Page 135: Solving Problems by Searching

Solving Problems by Searching 135

Overview

Characterizing Search Problems Searching for Solutions Uninformed Search Strategies Avoiding Repeated States The Problem of Representation Search in AND/OR-Graphs Searching with Partial Information