18
Comp 307 Problem Solving and Search • Formalize a problem as State Space Search • Blind search strategies • Heuristic search

Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Embed Size (px)

Citation preview

Page 1: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307Problem Solving and Search

• Formalize a problem as State Space Search

• Blind search strategies• Heuristic search

Page 2: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

Motivation

Intelligence as problem solving • Examples of problems:

– The Monkey and Bananas Problem– The Missionaries and Cannibals

Problem– The 8-puzzle– The Tower of Hanoi– Route finding – Water jug– Wolf, Goat and Cabbage

– Chess– Bridge– Go

Page 3: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

Problem definitionProblem solving as State Space Search

State: a state of the world. • State space: Collection of all possible states • Initial state: where the search starts• Goal state: where the search stops

Operators: Links between pairs of states, that is, what actions can be taken in any state to get to a new state.

A path in the state space is a sequence of operators leading from one state to another

Solve problem by searching for path from initial state to goal state through legal states.

Each operator has an associated cost.Path cost: the sum of the costs of operators

along the path.

Page 4: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

8 puzzle

• States: location of the 8 tiles• Operators: blank moves left, right,

up, or down• Path cost: length of path

5

8 3

17

4

6

2

1 3

5

87

2

6

4

Initial State Goal State

Page 5: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

Route finding

• State: current location on map– Initial state: city A – Goal state: city B

• Operators: move along a road to another location

• Path cost: sum on lengths of road

A simplified road map of Romania

Page 6: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

Search Strategies

• Uninformed (blind) search– Breadth first– Uniform cost– Depth first – Depth limited– Iterative deepening– Bidirectional

• Heuristic search– A *– Greedy Best first– Hill climbing– Beam search– …

Page 7: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

Search Tree

58 3

17

4

62

58

3 17

4

62

58

43176

2

5 3817

4

62

58 3

17

4

62

58

31

7

4

62

left down

upleft down

Page 8: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

General search algorithm

• We collect the nodes in a queue

loopIf the queue is empty

then return failure

Take the first node from the front of the queue

If the node represents the goal state

then return success

Else expand the node and put the children notes on the queue (reorder the queue)

end loop

Page 9: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

Criteria for search strategies

• Completeness: is the strategy guaranteed to find a solution when one exists?

• Optimality: does the strategy find the highest-quality solution (lowest cost) when there are several solutions?

• Time complexity: how long does it take to find a solution?

• Space complexity: how much memory does it need to perform the search?

Page 10: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

Breadth first search

• Start at the initial state;• Find all states reachable from the

initial state;• Find all states reachable from the

states available at the previous step;• Repeat the previous step until the

final state is reached;

• Implement with General-Search and Enqueue-at-End

• One must be careful not to repeatedly visit states that have been seen before.

Page 11: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

Issues for Breadth-first Search

• Breadth-first search is guaranteed to find the shortest path

– Complete– Optimal if all operators have same

cost (so shallowest solution is cheapest solution)

• In practice, breadth-first search is very expensive

– Time complexity O(bd)– Space complexity O(bd)

• b: the branching factor of nodes (ie, average number of children a node has)

• d: the depth of the desired solution

Page 12: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

Uniform cost search

• Expand lowest cost nodes first• Implement with General-Search

and Enqueue-By-Cost

S G

A

B

C

1

10

5 5

15 5

Page 13: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307 Issues for Uniform Cost Search

• Same as breadth-first search if all operators have the same cost

• Complete• Optimal if all operators have

positive cost

• Time Complexity O(bd)• Space Complexity O(bd)

Page 14: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

Depth-first search

Make the initial state the current state;

If current state is a final state then succeed– else make the current state a state

reachable from the current state; Repeat previous step until success,

backtracking if necessary;

Implement with General-Search and Enqueue-at-Start

Page 15: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

Issues for Depth-first Search

• Depth-first search is prone to being lost– Complete only if search tree is finite– Not optimal

• In practice, depth-first search is efficient

– Time Complexity O(bm)– Space Complexity O(bm) (m=max

depth of search tree)

• Good when many solutions in deep (but finite) trees

Page 16: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307 Depth limited search:

• Like depth-first, but with depth cut off

• Complete only if solution is at – depth <= c where c is the depth

limit

• Not optimal

• Time complexity O(bc)

• Space complexity O(bc)

Page 17: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

Iterative deepening search

• Iterative depth limited search• Limit= 0, • Limit=1, • Limit=2, • Limit=3, • …

a

bc

d e f g

h i j k l nm o

Page 18: Comp 307 Problem Solving and Search Formalize a problem as State Space Search Blind search strategies Heuristic search

Comp 307

Iterative deepening search

• Optimal and Complete (if operators all have same cost)

• Time complexity O(bd)• Space complexity O(bd)

• Expands some nodes multiple times– But “wasted” effort is actually

quite small and goes down as the branching factor goes up

• In general, iterative deepening is the preferred search method when there is a large search space and the depth of the solution is not known.