Problem Solving and Search in AI Part II

68
Problem Solving Problem Solving and Search in AI and Search in AI Part II Part II

description

Problem Solving and Search in AI Part II. Search Strategies. Uninformed (blind, exhaustive) strategies use only the information available in the problem definition Breadth-first search Depth-first search Uniform-cost search - PowerPoint PPT Presentation

Transcript of Problem Solving and Search in AI Part II

Page 1: Problem Solving and Search in AI  Part II

Problem Solving and Problem Solving and Search in AI Search in AI

Part IIPart II

Page 2: Problem Solving and Search in AI  Part II

Search StrategiesSearch StrategiesUninformedUninformed (blind, exhaustive) (blind, exhaustive) strategies use strategies use only the information available in the problem only the information available in the problem definitiondefinition Breadth-first searchBreadth-first search Depth-first searchDepth-first search Uniform-cost searchUniform-cost search

HeuristicHeuristic strategies use “rules of thumb” based strategies use “rules of thumb” based on the knowledge of domain to pick between on the knowledge of domain to pick between alternatives at each stepalternatives at each step

Graph Searching Applet:http://www.cs.ubc.ca/labs/lci/CIspace/Version4/search/index.html

Page 3: Problem Solving and Search in AI  Part II

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 4: Problem Solving and Search in AI  Part II

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 5: Problem Solving and Search in AI  Part II

Breadth-First SearchBreadth-First Search

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

Page 6: Problem Solving and Search in AI  Part II

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 7: Problem Solving and Search in AI  Part II

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 8: Problem Solving and Search in AI  Part II

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 9: Problem Solving and Search in AI  Part II

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 10: Problem Solving and Search in AI  Part II

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 11: Problem Solving and Search in AI  Part II

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 12: Problem Solving and Search in AI  Part II

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 13: Problem Solving and Search in AI  Part II

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 14: Problem Solving and Search in AI  Part II

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 15: Problem Solving and Search in AI  Part II

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 16: Problem Solving and Search in AI  Part II

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 17: Problem Solving and Search in AI  Part II

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 18: Problem Solving and Search in AI  Part II

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 19: Problem Solving and Search in AI  Part II

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 20: Problem Solving and Search in AI  Part II

Depth-First SearchDepth-First Search

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

Page 21: Problem Solving and Search in AI  Part II

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 22: Problem Solving and Search in AI  Part II

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 23: Problem Solving and Search in AI  Part II

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 24: Problem Solving and Search in AI  Part II

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 25: Problem Solving and Search in AI  Part II

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 26: Problem Solving and Search in AI  Part II

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 27: Problem Solving and Search in AI  Part II

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 28: Problem Solving and Search in AI  Part II

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 29: Problem Solving and Search in AI  Part II

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 30: Problem Solving and Search in AI  Part II

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 31: Problem Solving and Search in AI  Part II

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 32: Problem Solving and Search in AI  Part II

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 33: Problem Solving and Search in AI  Part II

3333

Search ExerciseSearch Exercise

Traffic Graph:

Start Node: A

Goal Node: M

Page 34: Problem Solving and Search in AI  Part II

3434

Exercise: Breadth-FirstExercise: Breadth-FirstA

B D G

C E K L

B E F I D HO

I I J M

Order of node expansion:

A, B, D, G, C, E, K, L, B, E, F, I, O, D, H, I, I, J, M

Solution Found: A D E I M (optimal)

Page 35: Problem Solving and Search in AI  Part II

3535

Exercise: Breadth-FirstExercise: Breadth-First(with duplicate detection)(with duplicate detection)

A

B D G

C E K L

F HOI

J M

Order of node expansion:

A, B, D, G, C, E, K, L, F, I, O, H, J, M

Page 36: Problem Solving and Search in AI  Part II

3636

Exercise : Depth-FirstExercise : Depth-FirstA

B D G

C E

B E F

I

M

Order of node expansion: A, B, D, C, B, E, I, M

Solution Found: A D C E I M (not optimal)

Page 37: Problem Solving and Search in AI  Part II

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 38: Problem Solving and Search in AI  Part II

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 39: Problem Solving and Search in AI  Part II

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 40: Problem Solving and Search in AI  Part II

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 41: Problem Solving and Search in AI  Part II

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 42: Problem Solving and Search in AI  Part II

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 43: Problem Solving and Search in AI  Part II

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 44: Problem Solving and Search in AI  Part II

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 45: Problem Solving and Search in AI  Part II

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

Page 46: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost Search Each move has some cost The cost of the path to each node N is g(N) = sum of the move costs The goal is to generate a solution path of minimal cost The queue is sorted in increasing cost order

So, lower cost nodes go to the front

S 0

1A 5B

15CS G

A

B

C

5

1

15

10

5

5

G11

G10

Page 47: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost Search

Page 48: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost SearchAlways expand the least-cost unexpanded nodeAlways expand the least-cost unexpanded node Queue = insert in order of increasing path costQueue = insert in order of increasing path cost

Arad

Sibiu TimisoaraZerind

75 140 118

<== Zerind, Timisoara, Sibiu <==<== Zerind, Timisoara, Sibiu <==

Page 49: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost Search

Arad

Sibiu TimisoaraZerind

75 140 118

OradeaArad

75+75 71+75

<== Timisoara, Sibiu, Oradea, Arad <==<== Timisoara, Sibiu, Oradea, Arad <==

Page 50: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost Search

Arad

Sibiu TimisoaraZerind

75 140 118

OradeaArad

75+75 71+75

LugoiArad

118+118 111+118

<== Sibiu, Oradea, Arad, Lugoi, Arad <==<== Sibiu, Oradea, Arad, Lugoi, Arad <==

Page 51: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost Search

Arad

Sibiu TimisoaraZerind

75 140 118

OradeaArad

75+75 71+75

LugoiArad

118+118 111+118

<== Sibiu, Oradea, Arad, Lugoi, Arad <==<== Sibiu, Oradea, Arad, Lugoi, Arad <==

Page 52: Problem Solving and Search in AI  Part II

Uniform Cost SearchUniform Cost Search

For the rest of the example, let us assume For the rest of the example, let us assume repeated state checkingrepeated state checkingHowever for uniform cost search we always However for uniform cost search we always keep the state that has the least path cost from keep the state that has the least path cost from the start node.the start node.

Page 53: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost Search

Arad

Sibiu TimisoaraZerind

75 140 118

Oradea

71+75

Lugoi

111+118

<== Sibiu, Oradea, Lugoi <==<== Sibiu, Oradea, Lugoi <==

Page 54: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost Search

Arad

Sibiu TimisoaraZerind

75 140 118

Oradea

146

Lugoi

229

<== Oradea, Rimnicu, Lugoi, Fagaras <==<== Oradea, Rimnicu, Lugoi, Fagaras <==

Fagaras Rimnicu

239 220

Page 55: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost Search

Arad

Sibiu TimisoaraZerind

75 140 118

Oradea

146

Lugoi

229

<== Rimnicu, Lugoi, Fagaras <==<== Rimnicu, Lugoi, Fagaras <==

Fagaras Rimnicu

239 220

Note: Oradea only leads to repeated states.

Page 56: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost Search

Page 57: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost SearchArad

Sibiu TimisoaraZerind

75 140 118

Oradea

146

Lugoi

229

<== Lugoi, Fagaras, Pitesti, Craiova <==<== Lugoi, Fagaras, Pitesti, Craiova <==

Fagaras Rimnicu

239 220

Craiova Pitesti

367 317

Page 58: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost SearchArad

Sibiu TimisoaraZerind

75 140 118

Oradea

146

Lugoi

229

<== Fagaras, Mehadia, Pitesti, Craiova <==<== Fagaras, Mehadia, Pitesti, Craiova <==

Fagaras Rimnicu

239 220

Craiova Pitesti

367 317

Mehadia

299

Page 59: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost SearchArad

Sibiu TimisoaraZerind

75 140 118

Oradea

146

Lugoi

229

Fagaras Rimnicu

239 220

Craiova Pitesti

367 317

Mehadia

299

Bucharest

450

<== Mehadia, Pitesti, Craiova, Bucharest <==<== Mehadia, Pitesti, Craiova, Bucharest <==

Page 60: Problem Solving and Search in AI  Part II

LugoiOradea

Sibiu

Arad

TimisoaraZerind

Uniform-Cost SearchUniform-Cost Search

75 140 118

146 229

Fagaras Rimnicu

239 220

Craiova Pitesti

367 317

Mehadia299

Bucharest

450

<== Pitesti, Craiova, Dobreta, Bucharest <==<== Pitesti, Craiova, Dobreta, Bucharest <==

Dobreta374

Page 61: Problem Solving and Search in AI  Part II

LugoiOradea

Sibiu

Arad

TimisoaraZerind

Uniform-Cost SearchUniform-Cost Search

75 140 118

146 229

Fagaras Rimnicu

239 220

Craiova Pitesti

367 317

Mehadia299

Bucharest

450

<== Craiova, Dobreta, Bucharest <==<== Craiova, Dobreta, Bucharest <==

Dobreta374Bucharest Craiova

418 455

Page 62: Problem Solving and Search in AI  Part II

LugoiOradea

Sibiu

Arad

TimisoaraZerind

Uniform-Cost SearchUniform-Cost Search

75 140 118

146 229

Fagaras Rimnicu

239 220

Craiova Pitesti

367 317

Mehadia299

Bucharest

450

<== Craiova, Dobreta, Bucharest <==<== Craiova, Dobreta, Bucharest <==

Dobreta374Bucharest Craiova

418 455

Page 63: Problem Solving and Search in AI  Part II

LugoiOradea

Sibiu

Arad

TimisoaraZerind

Uniform-Cost SearchUniform-Cost Search

75 140 118

146 229

Fagaras Rimnicu

239 220

Craiova Pitesti

367 317

Mehadia299

<== Craiova, Dobreta, Bucharest <==<== Craiova, Dobreta, Bucharest <==

Dobreta374

Bucharest

418

Goes to repeated states withhigher path costs than previousvisits to those states

Page 64: Problem Solving and Search in AI  Part II

Uniform-Cost SearchUniform-Cost Search

Page 65: Problem Solving and Search in AI  Part II

LugoiOradea

Sibiu

Arad

TimisoaraZerind

Uniform-Cost SearchUniform-Cost Search

75 140 118

146 229

Fagaras Rimnicu

239 220

Craiova Pitesti

367 317

Mehadia299

<== Bucharest <==<== Bucharest <==

Dobreta374

Bucharest

418

Page 66: Problem Solving and Search in AI  Part II

LugoiOradea

Sibiu

Arad

TimisoaraZerind

Uniform-Cost SearchUniform-Cost Search

75 140 118

146 229

Fagaras Rimnicu

239 220

Craiova Pitesti

367 317

Mehadia299

<== Urziceni, Giurgiu <==<== Urziceni, Giurgiu <==

Dobreta374

Bucharest

418

Pitesti

519

Fagaras629

Giurgiu

508

Urziceni

503

Page 67: Problem Solving and Search in AI  Part II

LugoiOradea

Sibiu

Arad

TimisoaraZerind

Uniform-Cost SearchUniform-Cost Search

75 140 118

146 229

Fagaras Rimnicu

239 220

Craiova Pitesti

367 317

Mehadia299

Dobreta374

Bucharest

418

Solution Path: Arad Sibiu Rimnicu Pitesti Bucharest

Total cost: 418

Compare this to: Arad Sibiu Fagaras Bucharest with total cost of 450

Page 68: Problem Solving and Search in AI  Part II

Heuristic SearchHeuristic Search

Problem with uniform cost searchProblem with uniform cost search We are only considering the cost so far, not the expected cost of We are only considering the cost so far, not the expected cost of

getting to the goal nodegetting to the goal node But, we don’t know before hand the cost of getting to the goal But, we don’t know before hand the cost of getting to the goal

from a previous statefrom a previous state

Solution:Solution: Need to estimate for each state the cost of getting from there to Need to estimate for each state the cost of getting from there to

a goal statea goal state Use “Use “heuristicheuristic” information to guess which nodes to expand next” information to guess which nodes to expand next the heuristic is in the form of an evaluation function based on the heuristic is in the form of an evaluation function based on

domain-specific information related to the problem.domain-specific information related to the problem. the the evaluation functionevaluation function gives us a way to evaluate a node gives us a way to evaluate a node

“locally” based on an estimate of the cost to get from the node to “locally” based on an estimate of the cost to get from the node to a goal node (the idea is to find the least cost path to a goal a goal node (the idea is to find the least cost path to a goal node).node).