cs 380: artificial intelligence problem …artificial intelligence problem solving: informed search...

34
CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón [email protected]

Upload: others

Post on 05-Jun-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

CS 380: ARTIFICIAL INTELLIGENCE

PROBLEM SOLVING:INFORMED SEARCH

Santiago Ontañó[email protected]

Page 2: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

• Problem Solving:• Problem Formulation• Finding a solution:

• Uninformed search: • When the agent has no additional information of the domain (DFS, BFS, ID)

• Informed search

Page 3: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Recall• Search methods:

• They manage a list of OPEN nodes• Different strategies (BFS, DFS, etc.) constructed by expanding

nodes in that list in different orders. • For example, BFS:

A

B C

D E F

G

Iteration 1: [A](expand A): Remove A, Insert B,C

Iteration 2: [B,C](expand B): Remove B, Insert D,E

Iteration 3: [C,D,E](expand C): Remove C, Insert F

Iteration 4: [D,E,F](expand D): Remove D

Iteration 5: [E,F](expand E): Remove E, Insert G

Iteration 6: [F,G](expand F): Remove F

Iteration 7: [G]

Page 4: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Recall• Search methods:

• They manage a list of OPEN nodes• Different strategies (BFS, DFS, etc.) constructed by expanding

nodes in that list in different orders. • For example, BFS:

A

B C

D E F

G

BFS: we remove the first element in the list, and add its children at

the end.

DFS: we remove the first element in the list and add its children at

the beginning.

Iteration 1: [A](expand A): Remove A, Insert B,C

Iteration 2: [B,C](expand B): Remove B, Insert D,E

Iteration 3: [C,D,E](expand C): Remove C, Insert F

Iteration 4: [D,E,F](expand D): Remove D

Iteration 5: [E,F](expand E): Remove E, Insert G

Iteration 6: [F,G](expand F): Remove F

Iteration 7: [G]

Page 5: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Recall• Search methods:

• They manage a list of OPEN nodes• Different strategies (BFS, DFS, etc.) constructed by expanding

nodes in that list in different orders. • For example, BFS:

A

B C

D E F

G

BFS: we remove the first element in the list, and add its children at

the end.

DFS: we remove the first element in the list and add its children at

the beginning.

Iteration 1: [A](expand A): Remove A, Insert B,C

Iteration 2: [B,C](expand B): Remove B, Insert D,E

Iteration 3: [C,D,E](expand C): Remove C, Insert F

Iteration 4: [D,E,F](expand D): Remove D

Iteration 5: [E,F](expand E): Remove E, Insert G

Iteration 6: [F,G](expand F): Remove F

Iteration 7: [G]

In other words:

BFS: we expand the node with the smallest depth

DFS: we expand the node with the largest depth.

Page 6: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Recall• All the problem solving strategies we have seen so far

use the following knowledge:• Goal check: knowing if the problem is solved• States• Actions: an agent knows which actions can be executed in the

current state.

• Notice that is very little information

Page 7: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Example

There are 4 possible actions to execute. Now, if you were the robot, which one would you try first?

(3,2,6,2)

(2,2,6,2) (3,1,6,2) (3,3,6,2) (4,2,6,2)

Page 8: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

ExampleGoalRobot

There are 4 possible actions to execute. If you were the robot, which one would you try first?

What if now you know what the coordinates mean?

Page 9: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

ExampleGoalRobot

There are 4 possible actions to execute. If you were the robot, which one would you try first?

What if now you know what the coordinates mean?

General Idea: if we have information about the

problem we are trying to solve, we can exploit it during problem solving.

Page 10: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Evaluation Function• Idea: represent the information we have about the domain

as an “evaluation function” h

• Evaluation function (heuristic):• Given a state s• h(s) it estimates how close or how far it is from the goal

• Example:• In a maze solving problem: Euclidean distance to the goal

Page 11: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

ExampleGoalRobot

h(s2) = 4 h(s3) = 3.16 h(s3) = 3.16 h(s4) = 2

h(s1) = 3

h: Euclidean distance to the goal

Page 12: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

ExampleGoalRobot

h(s2) = 4 h(s3) = 3.16 h(s3) = 3.16 h(s4) = 2

h(s1) = 3

h: Euclidean distance to the goal

The evaluation function (heuristic) can help the agent determine which actions are

more promising.

Page 13: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Slides borrowed from Russell and Norvig’s website

Page 14: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Best-first search

Idea: use an evaluation function for each node– estimate of “desirability”

⇒ Expand most desirable unexpanded node

Implementation:fringe is a queue sorted in decreasing order of desirability

Special cases:greedy searchA∗ search

Chapter 4, Sections 1–2 4

Page 15: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Romania with step costs in km

Bucharest

Giurgiu

Urziceni

Hirsova

Eforie

NeamtOradea

Zerind

Arad

Timisoara

LugojMehadia

DobretaCraiova

Sibiu

Fagaras

PitestiRimnicu Vilcea

Vaslui

Iasi

Straight−line distanceto Bucharest

0160242161

77151

241

366

193

178

25332980199

244

380

226

234

374

98

Giurgiu

UrziceniHirsova

Eforie

Neamt

Oradea

Zerind

Arad

Timisoara

Lugoj

Mehadia

DobretaCraiova

Sibiu Fagaras

Pitesti

Vaslui

Iasi

Rimnicu Vilcea

Bucharest

71

75

118

111

70

75120

151

140

99

80

97

101

211

138

146 85

90

98

142

92

87

86

Chapter 4, Sections 1–2 5

Page 16: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Greedy search

Evaluation function h(n) (heuristic)= estimate of cost from n to the closest goal

E.g., hSLD(n) = straight-line distance from n to Bucharest

Greedy search expands the node that appears to be closest to goal

Chapter 4, Sections 1–2 6

Page 17: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Greedy search example

Arad366

Chapter 4, Sections 1–2 7

Page 18: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Greedy search example

Zerind

Arad

Sibiu Timisoara253 329 374

Chapter 4, Sections 1–2 8

Page 19: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Greedy search example

Rimnicu Vilcea

Zerind

Arad

Sibiu

Arad Fagaras Oradea

Timisoara329 374

366 176 380 193

Chapter 4, Sections 1–2 9

Page 20: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Greedy search example

Rimnicu Vilcea

Zerind

Arad

Sibiu

Arad Fagaras Oradea

Timisoara

Sibiu Bucharest

329 374

366 380 193

253 0

Chapter 4, Sections 1–2 10

Page 21: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Properties of greedy search

Complete??

Chapter 4, Sections 1–2 11

Page 22: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Properties of greedy search

Complete?? No–can get stuck in loops, e.g., with Oradea as goal,Iasi → Neamt → Iasi → Neamt →

Complete in finite space with repeated-state checking

Time??

Chapter 4, Sections 1–2 12

Page 23: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Properties of greedy search

Complete?? No–can get stuck in loops, e.g.,Iasi → Neamt → Iasi → Neamt →

Complete in finite space with repeated-state checking

Time?? O(bm), but a good heuristic can give dramatic improvement

Space??

Chapter 4, Sections 1–2 13

Page 24: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Properties of greedy search

Complete?? No–can get stuck in loops, e.g.,Iasi → Neamt → Iasi → Neamt →

Complete in finite space with repeated-state checking

Time?? O(bm), but a good heuristic can give dramatic improvement

Space?? O(bm)—keeps all nodes in memory

Optimal??

Chapter 4, Sections 1–2 14

Page 25: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Properties of greedy search

Complete?? No–can get stuck in loops, e.g.,Iasi → Neamt → Iasi → Neamt →

Complete in finite space with repeated-state checking

Time?? O(bm), but a good heuristic can give dramatic improvement

Space?? O(bm)—keeps all nodes in memory

Optimal?? No

Chapter 4, Sections 1–2 15

Page 26: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Heuristics• Idea: estimate the distance to the solution.

• Must be computationally efficient (otherwise, one could just run the complete search algorithm to determine the actual cost!).

• Finding good heuristics makes a huge difference in computation time.

Page 27: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Heuristics: Fox-Goat-Cabbage • Assuming that “cost” is the number

of boat trips.

• What would be a good heuristic?

Page 28: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Heuristics: Fox-Goat-Cabbage • Assuming that “cost” is the number

of boat trips.

• What would be a good heuristic?

• Example:• Number of “items” on the left bay.• Since, we know that at least we have to

make that number of trips

Page 29: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Heuristics: Fox-Goat-Cabbage • Assuming that “cost” is the number

of boat trips.

• What would be a good heuristic?

• Example:• Number of “items” on the left bay.• Since, we know that at least we have to

make that number of trips

• We can improve: • (“number of items in left bay” – 1) * 2. • Add 1 if boat on right bay and “number of

items in left bay” > 0

Page 30: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Heuristics: 8-Puzzle• Cost: number of moves

• What would be a good heuristic?

8 1

3 2 6

7 4 5

Page 31: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Heuristics: 8-Puzzle• Cost: number of moves

• What would be a good heuristic?

• Heuristic 1:• Number of blocks out of place

8 1

3 2 6

7 4 5

Page 32: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Heuristics: 8-Puzzle• Cost: number of moves

• What would be a good heuristic?

• Heuristic 1:• Number of blocks out of place

• Heuristic 2:• Distance of each block to its target position

8 1

3 2 6

7 4 5

Page 33: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Heuristic: Robot navigation with keys• A robot (blue) needs to exit a maze (light

green), and has to pick up keys to cross doors (red)

K

R D E

K

Page 34: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM …ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH Santiago Ontañón so367@drexel.edu • Problem Solving: • Problem Formulation

Heuristic: Robot navigation with keys• A robot needs to exit a maze, and has to

pick up keys to cross doors

• Heuristic 1:• Simply Euclidean distance to goal (ignoring keys

and doors)

• Can you improve it?

K

R D E

K