Search
-
Upload
vinay-saodkar -
Category
Technology
-
view
208 -
download
0
Transcript of Search
SearchSearch
Introduction toIntroduction toArtificial IntelligenceArtificial Intelligence
COS302COS302
Michael L. LittmanMichael L. Littman
Fall 2001Fall 2001
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…
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
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}
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
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
Rush HourRush Hour
Move cars forward and backward to Move cars forward and backward to “escape”“escape”
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
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
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”
8 Queens Puzzle8 Queens Puzzle
No capturesNo captures
States:States:
N(s):N(s):
G(s):G(s):
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”. …
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
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););
}}
Data StructuresData Structures
How implement this efficiently?How implement this efficiently?• removemincost-U-empty?removemincost-U-empty?
• markvisited-unvisited?markvisited-unvisited?
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
Grid Example: BFSGrid Example: BFS
ss00
GG
ss00
GG
ss00
GG
ss00
GG
ss00
GG
ss00
GG
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
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?
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?
BFSBFS
• Completeness?Completeness?– YesYes
• Time complexity?Time complexity?– O(bO(bdd))
• Space complexity?Space complexity?– O(bO(bdd) )
• Optimality?Optimality?– yesyes
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
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
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
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?
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
Which do you choose?Which do you choose?
• Big grid, goal nearbyBig grid, goal nearby
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
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.