CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed...

46
CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH 10/2/2013 Santiago Ontañón [email protected] https://www.cs.drexel.edu/~santi/teaching/2013/CS380/intro.html

Transcript of CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed...

Page 1: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH

10/2/2013 Santiago Ontañón [email protected] https://www.cs.drexel.edu/~santi/teaching/2013/CS380/intro.html

Page 2: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

• 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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Example Goal Robot

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Example Goal Robot

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Example Goal Robot

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Example Goal Robot

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Slides borrowed from Russell and Norvig’s website

Page 14: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Greedy search example

Arad366

Chapter 4, Sections 1–2 7

Page 18: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Greedy search example

Zerind

Arad

Sibiu Timisoara253 329 374

Chapter 4, Sections 1–2 8

Page 19: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Properties of greedy search

Complete??

Chapter 4, Sections 1–2 11

Page 22: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

A! search

Idea: avoid expanding paths that are already expensive

Evaluation function f(n) = g(n) + h(n)

g(n) = cost so far to reach nh(n) = estimated cost to goal from nf(n) = estimated total cost of path through n to goal

A! search uses an admissible heuristici.e., h(n) ! h!(n) where h!(n) is the true cost from n.(Also require h(n) " 0, so h(G) = 0 for any goal G.)

E.g., hSLD(n) never overestimates the actual road distance

Theorem: A! search is optimal

Chapter 4, Sections 1–2 16

Page 27: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

A! search example

Arad366=0+366

Chapter 4, Sections 1–2 17

Page 28: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

A! search example

Zerind

Arad

Sibiu Timisoara447=118+329 449=75+374393=140+253

Chapter 4, Sections 1–2 18

Page 29: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

A! search example

Zerind

Arad

Sibiu

Arad

Timisoara

Rimnicu VilceaFagaras Oradea

447=118+329 449=75+374

646=280+366 413=220+193415=239+176 671=291+380

Chapter 4, Sections 1–2 19

Page 30: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

A! search example

Zerind

Arad

Sibiu

Arad

Timisoara

Fagaras Oradea

447=118+329 449=75+374

646=280+366 415=239+176Rimnicu Vilcea

Craiova Pitesti Sibiu526=366+160 553=300+253417=317+100

671=291+380

Chapter 4, Sections 1–2 20

Page 31: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

A! search example

Zerind

Arad

Sibiu

Arad

Timisoara

Sibiu Bucharest

Rimnicu VilceaFagaras Oradea

Craiova Pitesti Sibiu

447=118+329 449=75+374

646=280+366

591=338+253 450=450+0 526=366+160 553=300+253417=317+100

671=291+380

Chapter 4, Sections 1–2 21

Page 32: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

A! search example

Zerind

Arad

Sibiu

Arad

Timisoara

Sibiu Bucharest

Rimnicu VilceaFagaras Oradea

Craiova Pitesti Sibiu

Bucharest Craiova Rimnicu Vilcea418=418+0

447=118+329 449=75+374

646=280+366

591=338+253 450=450+0 526=366+160 553=300+253

615=455+160 607=414+193

671=291+380

Chapter 4, Sections 1–2 22

Page 33: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Properties of A!

Complete??

Chapter 4, Sections 1–2 25

Page 34: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Properties of A!

Complete?? Yes, unless there are infinitely many nodes with f ! f(G)

Time??

Chapter 4, Sections 1–2 26

Page 35: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Properties of A!

Complete?? Yes, unless there are infinitely many nodes with f ! f(G)

Time?? Exponential in [relative error in h " length of soln.]

Space??

Chapter 4, Sections 1–2 27

Page 36: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Properties of A!

Complete?? Yes, unless there are infinitely many nodes with f ! f(G)

Time?? Exponential in [relative error in h " length of soln.]

Space?? Keeps all nodes in memory

Optimal??

Chapter 4, Sections 1–2 28

Page 37: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Properties of A!

Complete?? Yes, unless there are infinitely many nodes with f ! f(G)

Time?? Exponential in [relative error in h " length of soln.]

Space?? Keeps all nodes in memory

Optimal?? Yes—cannot expand fi+1 until fi is finished

A! expands all nodes with f(n) < C!

A! expands some nodes with f(n) = C!

A! expands no nodes with f(n) > C!

Chapter 4, Sections 1–2 29

Page 38: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 39: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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

of boat trips. • What would be a good heuristic?

Page 40: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 41: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 42: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Heuristics: 8-Puzzle • Cost: number of moves

• What would be a good heuristic?

8 1

3 2 6

7 4 5

Page 43: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 44: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

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 45: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Heuristic: Robot navigation with keys • Recall the problem we solved in class on

Friday • A robot needs to exit a maze, and has to

pick up keys to cross doors

K

K

Page 46: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH · 2013-10-07 · • Uninformed search: • When the agent has no additional information of the domain (DFS, BFS,

Heuristic: Robot navigation with keys • Recall the problem we solved in class on

Friday • 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

K