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

Post on 05-Jun-2020

1 views 0 download

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

CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH

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

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

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

•  Informed search

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]

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]

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.

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

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)

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?

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.

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

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

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.

Slides borrowed from Russell and Norvig’s website

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

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

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

Greedy search example

Arad366

Chapter 4, Sections 1–2 7

Greedy search example

Zerind

Arad

Sibiu Timisoara253 329 374

Chapter 4, Sections 1–2 8

Greedy search example

Rimnicu Vilcea

Zerind

Arad

Sibiu

Arad Fagaras Oradea

Timisoara329 374

366 176 380 193

Chapter 4, Sections 1–2 9

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

Properties of greedy search

Complete??

Chapter 4, Sections 1–2 11

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

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

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

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

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

A! search example

Arad366=0+366

Chapter 4, Sections 1–2 17

A! search example

Zerind

Arad

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

Chapter 4, Sections 1–2 18

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

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

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

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

Properties of A!

Complete??

Chapter 4, Sections 1–2 25

Properties of A!

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

Time??

Chapter 4, Sections 1–2 26

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

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

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

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.

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

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

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

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

Heuristics: 8-Puzzle • Cost: number of moves

• What would be a good heuristic?

8 1

3 2 6

7 4 5

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

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

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

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