Problem Solving and Search in AI Part II

Post on 31-Dec-2015

25 views 1 download

Tags:

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

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

Part IIPart 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

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.

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

Breadth-First SearchBreadth-First Search

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

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

A

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

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

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

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

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

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

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

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

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

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

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

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

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

Depth-First SearchDepth-First Search

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

Breadth-First SearchBreadth-First SearchA

IB E

C D M K

N

F H

O G Q R T

P S

goal

Queue:

A

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

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

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

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

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

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

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

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

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

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

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

3333

Search ExerciseSearch Exercise

Traffic Graph:

Start Node: A

Goal Node: M

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)

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

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)

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

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

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

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

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

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

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

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

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

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

Uniform-Cost SearchUniform-Cost Search

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 <==

Uniform-Cost SearchUniform-Cost Search

Arad

Sibiu TimisoaraZerind

75 140 118

OradeaArad

75+75 71+75

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

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 <==

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 <==

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.

Uniform-Cost SearchUniform-Cost Search

Arad

Sibiu TimisoaraZerind

75 140 118

Oradea

71+75

Lugoi

111+118

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

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

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.

Uniform-Cost SearchUniform-Cost Search

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

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

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 <==

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

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

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

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

Uniform-Cost SearchUniform-Cost Search

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

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

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

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