Top Banner
Search Search Introduction to Introduction to Artificial Intelligence Artificial Intelligence COS302 COS302 Michael L. Littman Michael L. Littman Fall 2001 Fall 2001
29
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Search

SearchSearch

Introduction toIntroduction toArtificial IntelligenceArtificial Intelligence

COS302COS302

Michael L. LittmanMichael L. Littman

Fall 2001Fall 2001

Page 2: Search

AdministrationAdministration

Short written homeworks each weekShort written homeworks each weekFirst one todayFirst one todayWeb page is up with first lectureWeb page is up with first lectureSend me (Send me (mlittman@csmlittman@cs) your email ) your email

address so I can make a mailing listaddress so I can make a mailing listOffice hours…Office hours…

Page 3: Search

What’s AI? (to me)What’s AI? (to me)

Computers making decisions in real-Computers making decisions in real-world problemsworld problems

apply

formulate solve

Page 4: Search

Search ProblemsSearch Problems

Let Let SS be the set of states (strings) be the set of states (strings)

Input:Input:

• Initial state: sInitial state: s00

• Neighbor generator, N: Neighbor generator, N: S S 2 2SS

• Goal function, G: Goal function, G: S S {0,1} {0,1}

Page 5: Search

Search AnswerSearch Answer

ss11,…,s,…,snn such that: such that:

• ss11,…,s,…,sn n SS

• for all 1for all 1iin, sn, siiN(sN(si-1i-1))

• G(sG(snn) ) 11

Page 6: Search

ExamplesExamples

We’re very impressed. Meaning?We’re very impressed. Meaning?• Rush HourRush Hour• 8-puzzle8-puzzle• LogisticsLogistics• 8-queens problem8-queens problem• Logic puzzlesLogic puzzles• Job-shop schedulingJob-shop scheduling

Page 7: Search

Rush HourRush Hour

Move cars forward and backward to Move cars forward and backward to “escape”“escape”

Page 8: Search

Search VersionSearch Version

States: configurations of carsStates: configurations of cars

N(s): reachableN(s): reachable

statesstates

G(s): 1 if redG(s): 1 if red

car at gatecar at gate

Page 9: Search

8-puzzle8-puzzle

Slide tiles into orderSlide tiles into order

States:States:

N(s):N(s):

G(s):G(s):

6

4

2 7

8 1

3 5

6

4

2 7

8 1

3 5

6

4

2 7

8 1

3 5

6 2 7

8 1

3 5

6

4

2 7

8 1

3

1 2 3

5 6

87

Page 10: Search

LogisticsLogistics

Very sophisticated. What goes Very sophisticated. What goes where when?where when?

Desert Storm logistics “paid for AI Desert Storm logistics “paid for AI research”research”

Page 11: Search

8 Queens Puzzle8 Queens Puzzle

No capturesNo captures

States:States:

N(s):N(s):

G(s):G(s):

Page 12: Search

Logic PuzzlesLogic Puzzles

1.1. Jody, who is an ape, wasn’t the ape Jody, who is an ape, wasn’t the ape who returned immediately after Tom who returned immediately after Tom and immediately before the animal and immediately before the animal who appeared in the movie with no who appeared in the movie with no rating.rating.

2.2. The only lions that were used in the The only lions that were used in the movies were the one who was the third movies were the one who was the third to return, the one who appeared in the to return, the one who appeared in the R movie, and the one who appeared in R movie, and the one who appeared in “Luck”. …“Luck”. …

Page 13: Search

Job-Shop SchedulingJob-Shop Scheduling

Industrial problem:Industrial problem:• Allocate machines and machinists Allocate machines and machinists

to time slotsto time slots• Constraints on orders in which Constraints on orders in which

parts are servicedparts are serviced

Page 14: Search

Search TemplateSearch Template

• fringe = {(sfringe = {(s00, 0)}; /* initial cost */, 0)}; /* initial cost */• markvisited(smarkvisited(s00););• While (1) {While (1) {

If empty(fringe), return failure;If empty(fringe), return failure;(s, c) = removemincost(fringe);(s, c) = removemincost(fringe);If G(s) return s;If G(s) return s;Foreach s’ in N(s)Foreach s’ in N(s)

if unvisited(s’)if unvisited(s’)fringe = fringe U {(s’, cost(s’)};fringe = fringe U {(s’, cost(s’)};

markvisited(smarkvisited(s00););

}}

Page 15: Search

Data StructuresData Structures

How implement this efficiently?How implement this efficiently?• removemincost-U-empty?removemincost-U-empty?

• markvisited-unvisited?markvisited-unvisited?

Page 16: Search

Vary CostVary Cost

How does search behavior change How does search behavior change with cost?with cost?

• cost(s’) = c + 1cost(s’) = c + 1

• cost(s’) = c - 1cost(s’) = c - 1

Page 17: Search

Grid Example: BFSGrid Example: BFS

ss00

GG

ss00

GG

ss00

GG

ss00

GG

ss00

GG

ss00

GG

Page 18: Search

Grid Example: DFSGrid Example: DFS

ss00

GG

ss00

GG

ss00

GG

ss00

GG

ss00

GG

ss00

GG

ss00

GG

ss00

GG

ss00

GG

ss00

GG

ss00

GG

Page 19: Search

How Evaluate?How Evaluate?

What makes one search scheme What makes one search scheme better than another?better than another?– Completeness: Find solution?Completeness: Find solution?– Time complexity: How long?Time complexity: How long?– Space complexity: Memory?Space complexity: Memory?– Optimality: Find shortest path?Optimality: Find shortest path?

Page 20: Search

Depth vs. Breadth-firstDepth vs. Breadth-first

Let |T(s)| Let |T(s)| b (branching factor), goal b (branching factor), goal at depth dat depth d

• How implement priority queue?How implement priority queue?• Completeness?Completeness?• Time complexity?Time complexity?• Space complexity?Space complexity?• Optimality?Optimality?

Page 21: Search

BFSBFS

• Completeness?Completeness?– YesYes

• Time complexity?Time complexity?– O(bO(bdd))

• Space complexity?Space complexity?– O(bO(bdd) )

• Optimality?Optimality?– yesyes

Page 22: Search

DFSDFS

• Completeness?Completeness?– Yes, assuming state space finiteYes, assuming state space finite

• Time complexity?Time complexity?– O(|O(|SS |), can do well if lots of goals |), can do well if lots of goals

• Space complexity?Space complexity?– O(n), n deepest point of searchO(n), n deepest point of search

• Optimality?Optimality?– No No

Page 23: Search

Depth-limited SearchDepth-limited Search

DFS, only expand nodes depth DFS, only expand nodes depth l. l. • Completeness?Completeness?

– No, if l No, if l d. d. • Time complexity?Time complexity?

– O(bO(bll))

• Space complexity?Space complexity?– O(l)O(l)

• Optimality?Optimality?– No No

Page 24: Search

Iterative DeepeningIterative Deepening

Depth limited, increasing l. Depth limited, increasing l. • Completeness?Completeness?

– Yes. Yes. • Time complexity?Time complexity?

– O(bO(bdd), even with repeated work! ), even with repeated work! • Space complexity?Space complexity?

– O(d) O(d) • Optimality?Optimality?

– Yes Yes

Page 25: Search

Bidirectional SearchBidirectional Search

BFS in both directionsBFS in both directions

Need NNeed N-1-1

How could this help?How could this help?– bbll vs 2b vs 2bl/2l/2

What makes this hard to implement?What makes this hard to implement?

Page 26: Search

Which do you choose?Which do you choose?

• 8-queens, neighbors of s add one 8-queens, neighbors of s add one queen to boardqueen to board

Page 27: Search

Which do you choose?Which do you choose?

• Big grid, goal nearbyBig grid, goal nearby

Page 28: Search

What to LearnWhat to Learn

How to express problems in the How to express problems in the search frameworksearch framework

The basic algorithms for searchThe basic algorithms for search

Strengths and weaknesses of the Strengths and weaknesses of the basic algorithmsbasic algorithms

Page 29: Search

Homework 1 (due 9/26)Homework 1 (due 9/26)

1. Send your email address (right away) to 1. Send your email address (right away) to littman@[email protected]. Let BFS’ and DFS’ be versions of BFS and DFS that don’t 2. Let BFS’ and DFS’ be versions of BFS and DFS that don’t

check whether a state has been previously visited. check whether a state has been previously visited. Evaluate BFS’ and DFS’ on the four comparison criteria Evaluate BFS’ and DFS’ on the four comparison criteria we discussed.we discussed.

3. Consider the Rush Hour board from these notes. 3. Consider the Rush Hour board from these notes. Assume a single move consists of sliding a car forward Assume a single move consists of sliding a car forward or backward some number of spaces. (a) Give an upper or backward some number of spaces. (a) Give an upper bound on the branching factor. (b) Assuming the bound on the branching factor. (b) Assuming the solution is at depth 20, how many nodes will be solution is at depth 20, how many nodes will be searched? (c) Ignoring the search, how many states are searched? (c) Ignoring the search, how many states are in the search space? Give as tight an upper bound as in the search space? Give as tight an upper bound as you can.you can.