basic search procedure 1. start with the start node (root of the search tree) and place in on the...

39
Basic Search Procedure Basic Search Procedure 1. Start with the start node (root of the 1. Start with the start node (root of the search tree) and place in on the search tree) and place in on the queue queue 2. Remove the front node in the queue and 2. Remove the front node in the queue and If the node is a If the node is a goal node goal node , then we are done; , then we are done; stop. stop. Otherwise Otherwise expand expand the node the node generate its generate its children using the successor function (other children using the successor function (other states that can be reached with one move) states that can be reached with one move) 3. Place the children on the queue 3. Place the children on the queue according to the according to the search strategy search strategy 4. Go back to step 2. 4. Go back to step 2.

Upload: jemimah-cook

Post on 21-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Basic Search ProcedureBasic Search Procedure

1. Start with the start node (root of the search 1. Start with the start node (root of the search tree) and place in on the tree) and place in on the queuequeue

2. Remove the front node in the queue and 2. Remove the front node in the queue and If the node is a If the node is a goal nodegoal node, then we are done; stop., then we are done; stop. Otherwise Otherwise expandexpand the node the node generate its children generate its children

using the successor function (other states that can be using the successor function (other states that can be reached with one move)reached with one move)

3. Place the children on the queue according to 3. Place the children on the queue according to the the search strategysearch strategy

4. Go back to step 2.4. Go back to step 2.

Page 2: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Search StrategiesSearch Strategies

Search strategies differ based on the order Search strategies differ based on the order in which new successor nodes are added in which new successor nodes are added to the queueto the queueBreadth-first Breadth-first add nodes to the end of add nodes to the end of the queuethe queueDepth-first Depth-first add nodes to the front add nodes to the frontUniform cost Uniform cost sort the nodes on the sort the nodes on the queue based on the cost of reaching the queue based on the cost of reaching the node from start nodenode from start node

Page 3: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First Search

add nodes to the end of the queueadd nodes to the end of the queue

Page 4: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

A

Page 5: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

B I E

Page 6: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

I E C D

Page 7: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

E C D M K

Page 8: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

C D M K F H

Page 9: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

D M K F H N

Page 10: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

M K F H N

Page 11: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

K F H N O G

Page 12: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

F H N O G

Page 13: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

H N O G Q

Page 14: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

N O G Q R T

Page 15: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

O G Q R T P S

Page 16: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

G Q R T P S

Page 17: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

Q R T P S

DONE!!!

Solution: A I M G

Page 18: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Depth-First SearchDepth-First Search

add nodes to the front of the queueadd nodes to the front of the queue

Page 19: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

A

Page 20: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

B I E

Page 21: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

C D I E

Page 22: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

N D I E

Page 23: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

P S D I E

Page 24: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

S D I E

Page 25: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

D I E

Page 26: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

I E

Page 27: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

M K E

Page 28: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

O G K E

Page 29: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

G K E

Page 30: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

K E

DONE!!!

Solution: A I M G

Page 31: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

Example: The 8-PuzzleExample: The 8-Puzzle

States?States? integer location of tilesinteger location of tiles

Operators? Operators? move blank left, right, up, downmove blank left, right, up, down

Goal Test?Goal Test? = goal state (given)= goal state (given)

Path Cost?Path Cost? One per moveOne per move

Page 32: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

We will assume that we can do repeated state checking(i.e., we will not generate nodes that have been previously expanded)

5 4

6 1 8

7 3 2

Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search

Page 33: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

5 4

6 1 8

7 3 2

5 4

6 1 8

7 3 2

5 4 8

6 1

7 3 2

Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search

Page 34: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

5 4

6 1 8

7 3 2

5 4

6 1 8

7 3 2

5 4 8

6 1

7 3 2

5 4

6 1 8

7 3 2

5 1 4

6 8

7 3 2

Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search

Page 35: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

5 4

6 1 8

7 3 2

5 4

6 1 8

7 3 2

5 4 8

6 1

7 3 2

5 4

6 1 8

7 3 2

5 1 4

6 8

7 3 2

6 5 4

1 8

7 3 2

Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search

Page 36: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

5 4

6 1 8

7 3 2

5 4

6 1 8

7 3 2

5 4 8

6 1

7 3 2

5 4

6 1 8

7 3 2

5 1 4

6 8

7 3 2

6 5 4

1 8

7 3 2

6 5 4

1 8

7 3 2

6 5 4

7 1 8

3 2

Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search

Page 37: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

5 4

6 1 8

7 3 2

5 4

6 1 8

7 3 2

5 4 8

6 1

7 3 2

5 4

6 1 8

7 3 2

5 1 4

6 8

7 3 2

6 5 4

1 8

7 3 2

5 1 4

6 8

7 3 2

5 1 4

6 8

7 3 2

5 1 4

6 3 8

7 2

6 5 4

1 8

7 3 2

6 5 4

7 1 8

3 2

Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search

Page 38: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

5 4

6 1 8

7 3 2

5 4

6 1 8

7 3 2

5 4 8

6 1

7 3 2

5 4

6 1 8

7 3 2

5 1 4

6 8

7 3 2

6 5 4

1 8

7 3 2

5 1 4

6 8

7 3 2

5 1 4

6 8

7 3 2

5 1 4

6 3 8

7 2

6 5 4

1 8

7 3 2

6 5 4

7 1 8

3 2

1 4

5 6 8

7 3 2

5 1 4

7 6 8

3 2

Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search

Page 39: Basic Search Procedure 1. Start with the start node (root of the search tree) and place in on the queue 2. Remove the front node in the queue and If the

5 4

6 1 8

7 3 2

5 4

6 1 8

7 3 2

5 4 8

6 1

7 3 2

5 4

6 1 8

7 3 2

5 1 4

6 8

7 3 2

5 4 8

6 1

7 3 2

5 4 8

6 1 2

7 3

6 5 4

1 8

7 3 2

5 1 4

6 8

7 3 2

5 1 4

6 8

7 3 2

5 1 4

6 3 8

7 2

5 8

6 4 1

7 3 2

5 4 8

6 3 1

7 2

5 4 8

6 1

7 3 2

5 4 8

6 1 2

7 3

6 5 4

1 8

7 3 2

6 5 4

7 1 8

3 2

1 4

5 6 8

7 3 2

5 1 4

7 6 8

3 2 . . .

Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search