SlideShare a Scribd company logo
1 of 63
Chapter 3
Solving problems by searching
Search
We will consider the problem of designing goal-based
agents in observable, deterministic, discrete, known
environments
The solution is a fixed sequence of actions
Search is the process of looking for the sequence of
actions that reaches the goal
Once the agent begins executing the search solution, it can
ignore its percepts (open-loop system)
2
Search problem components
• Initial state
• Actions
• Transition model
– What is the result of
performing a given action
in a given state?
• Goal state
• Path cost
– Assume that it is a sum of
nonnegative step costs
• The optimal solution is the sequence of actions that gives the
lowest path cost for reaching the goal
Initial
state
Goal
state
3
Example: Romania
• Initial state
– Arad
• Actions
– Go from one city to another
• Transition model
– If you go from city A to
city B, you end up in city B
• Goal state
– Bucharest
• Path cost
– Sum of edge costs
• On vacation in Romania; currently in Arad
• Flight leaves tomorrow from Bucharest
4
State space
• The initial state, actions, and transition model
define the state space of the problem
– The set of all states reachable from initial state by any
sequence of actions
– Can be represented as a directed graph where the
nodes are states and links between nodes are actions
• What is the state space for the Romania problem?
5
Example: Vacuum world
• States
– Agent location and dirt location
– How many possible states?
– What if there are n possible locations?
• Actions
– Left, right, suck
• Transition model
6
Vacuum world state space graph
•
7
Example: The 8-puzzle
• States
– Locations of tiles
• 8-puzzle: 181,440 states
• 15-puzzle: 1.3 trillion states
• 24-puzzle: 1025 states
• Actions
– Move blank left, right, up, down
• Path cost
– 1 per move
• Optimal solution of n-Puzzle is NP-hard
8
Example: Robot motion planning
• States
– Real-valued coordinates of robot joint angles
• Actions
– Continuous motions of robot joints
• Goal state
– Desired final configuration (e.g., object is grasped)
• Path cost
– Time to execute, smoothness of path, etc.
9
Other Real-World Examples
• Routing
• Touring
• VLSI layout
• Assembly sequencing
• Protein design
10
Tree Search
Let’s begin at the start node and expand it by
making a list of all possible successor states
Maintain a fringe or a list of unexpanded states
At each step, pick a state from the fringe to expand
Keep going until you reach the goal state
Try to expand as few states as possible
11
Search tree
• “What if” tree of possible actions
and outcomes
• The root node corresponds to the
starting state
• The children of a node
correspond to the successor
states of that node’s state
• A path through the tree
corresponds to a sequence of
actions
– A solution is a path ending in the
goal state
… … …
…
Starting
state
Successor
state
Action
Goal state
12
Tree Search Algorithm Outline
• Initialize the fringe using the starting state
• While the fringe is not empty
– Choose a fringe node to expand according to search strategy
– If the node contains the goal state, return solution
– Else expand the node and add its children to the fringe
13
Tree search example
14
Tree search example
15
Tree search example
Fringe
16
Search strategies
• A search strategy is defined by picking the order of node
expansion
• Strategies are evaluated along the following dimensions:
– Completeness: does it always find a solution if one exists?
– Optimality: does it always find a least-cost solution?
– Time complexity: number of nodes generated
– Space complexity: maximum number of nodes in memory
• Time and space complexity are measured in terms of
– b: maximum branching factor of the search tree
– d: depth of the least-cost solution
– m: maximum length of any path in the state space (may be infinite)
17
Uninformed search strategies
• Uninformed search strategies use only the
information available in the problem definition
• Breadth-first search
• Uniform-cost search
• Depth-first search
• Iterative deepening search
18
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
– fringe is a FIFO queue, i.e., new successors go at end
A
D F
B C
E G
19
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
– fringe is a FIFO queue, i.e., new successors go at end
A
D F
B C
E G
20
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
– fringe is a FIFO queue, i.e., new successors go at end
A
D F
B C
E G
21
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
– fringe is a FIFO queue, i.e., new successors go at end
A
D F
B C
E G
22
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
– fringe is a FIFO queue, i.e., new successors go at end
A
D F
B C
E G
23
Properties of breadth-first search
• Complete?
Yes (if branching factor b is finite)
• Optimal?
Yes – if cost = 1 per step
• Time?
Number of nodes in a b-ary tree of depth d: O(bd)
(d is the depth of the optimal solution)
• Space?
O(bd)
• Space is the bigger problem (more than time)
24
Uniform-cost search
• Expand least-cost unexpanded node
• Implementation: fringe is a queue ordered by path cost (priority
queue)
• Equivalent to breadth-first if step costs all equal
• Complete?
Yes, if step cost is greater than some positive constant ε
• Optimal?
Yes – nodes expanded in increasing order of path cost
• Time?
Number of nodes with path cost ≤ cost of optimal solution (C*), O(bC*/ ε)
This can be greater than O(bd): the search can explore long paths consisting
of small steps before exploring shorter paths consisting of larger steps
• Space?
O(bC*/ ε)
25
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
A
D F
B C
E G
26
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
A
D F
B C
E G
27
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
A
D F
B C
E G
28
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
A
D F
B C
E G
29
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
A
D F
B C
E G
30
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
A
D F
B C
E G
31
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
A
D F
B C
E G
32
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
A
D F
B C
E G
33
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
A
D F
B C
E G
34
Properties of depth-first search
• Complete?
Fails in infinite-depth spaces, spaces with loops
Modify to avoid repeated states along path
 complete in finite spaces
• Optimal?
No – returns the first solution it finds
• Time?
Could be the time to reach a solution at maximum depth m: O(bm)
Terrible if m is much larger than d
But if there are lots of solutions, may be much faster than BFS
• Space?
O(bm), i.e., linear space!
35
Iterative deepening search
• Use DFS as a subroutine
1. Check the root
2. Do a DFS searching for a path of length 1
3. If there is no path of length 1, do a DFS searching
for a path of length 2
4. If there is no path of length 2, do a DFS searching
for a path of length 3…
36
Iterative deepening search
37
Iterative deepening search
38
Iterative deepening search
39
Iterative deepening search
40
Properties of iterative deepening
search
• Complete?
Yes
• Optimal?
Yes, if step cost = 1
• Time?
(d+1)b0 + d b1 + (d-1)b2 + … + bd = O(bd)
• Space?
O(bd)
41
Informed search
• Idea: give the algorithm “hints” about the
desirability of different states
– Use an evaluation function to rank nodes and
select the most promising one for expansion
• Greedy best-first search
• A* search
42
Heuristic function
• Heuristic function h(n) estimates the cost of
reaching goal from node n
• Example: Start state
Goal state
43
Heuristic for the Romania problem
44
Greedy best-first search
• Expand the node that has the lowest value of
the heuristic function h(n)
45
Greedy best-first search example
46
Greedy best-first search example
47
Greedy best-first search example
48
Greedy best-first search example
49
Properties of greedy best-first search
• Complete?
No – can get stuck in loops
start
goal
50
Properties of greedy best-first search
• Complete?
No – can get stuck in loops
• Optimal?
No
51
Properties of greedy best-first search
• Complete?
No – can get stuck in loops
• Optimal?
No
• Time?
Worst case: O(bm)
Best case: O(bd) – If h(n) is 100% accurate
• Space?
Worst case: O(bm)
52
A* search
• Idea: avoid expanding paths that are already expensive
• The evaluation function f(n) is the estimated total cost
of the path through node n to the goal:
f(n) = g(n) + h(n)
g(n): cost so far to reach n (path cost)
h(n): estimated cost from n to goal (heuristic)
53
A* search example
54
A* search example
55
A* search example
56
A* search example
57
A* search example
58
A* search example
59
Properties of A*
• Complete?
Yes – unless there are infinitely many nodes with f(n) ≤ C*
• Optimal?
Yes
• Time?
Number of nodes for which f(n) ≤ C* (exponential)
• Space?
Exponential
60
Admissible heuristics
• A heuristic h(n) is admissible if for every node n, h(n)
≤ h*(n), where h*(n) is the true cost to reach the goal
state from n
• An admissible heuristic never overestimates the cost
to reach the goal, i.e., it is optimistic
• Example: straight line distance never overestimates
the actual road distance
• Theorem: If h(n) is admissible, A* is optimal
61
Designing heuristic functions
• Heuristics for the 8-puzzle
h1(n) = number of misplaced tiles
h2(n) = total Manhattan distance (number of squares from
desired location of each tile)
h1(start) = 8
h2(start) = 3+1+2+2+2+3+3+2 = 18
• Are h1 and h2 admissible? 62
Comparison of search strategies
Algorithm Complete? Optimal?
Time
complexity
Space
complexity
BFS
UCS
DFS
IDS
Greedy
A*
Yes
Yes
No
Yes
If all step
costs are equal
If all step
costs are equal
Yes
No
O(bd)
Number of nodes with g(n) ≤ C*
O(bm)
O(bd)
O(bd)
O(bm)
O(bd)
No No
Worst case: O(bm)
Yes Yes
Best case: O(bd)
Number of nodes with g(n)+h(n) ≤ C*
63

More Related Content

Similar to Chapter 3.pptx

Artificial intelligence(06)
Artificial intelligence(06)Artificial intelligence(06)
Artificial intelligence(06)Nazir Ahmed
 
Artificial intelligence(05)
Artificial intelligence(05)Artificial intelligence(05)
Artificial intelligence(05)Nazir Ahmed
 
Chapter3 Search
Chapter3 SearchChapter3 Search
Chapter3 SearchKhiem Ho
 
informed_search.pdf
informed_search.pdfinformed_search.pdf
informed_search.pdfSankarTerli
 
Introduction to artificial intelligence
Introduction to artificial intelligenceIntroduction to artificial intelligence
Introduction to artificial intelligencerishi ram khanal
 
2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt
2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt
2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.pptmmpnair0
 
uniformed (also called blind search algo)
uniformed (also called blind search algo)uniformed (also called blind search algo)
uniformed (also called blind search algo)ssuser2a76b5
 
Heuristic Searching Algorithms Artificial Intelligence.pptx
Heuristic Searching Algorithms Artificial Intelligence.pptxHeuristic Searching Algorithms Artificial Intelligence.pptx
Heuristic Searching Algorithms Artificial Intelligence.pptxSwagat Praharaj
 
uninformed search part 1.pptx
uninformed search part 1.pptxuninformed search part 1.pptx
uninformed search part 1.pptxMUZAMILALI48
 

Similar to Chapter 3.pptx (20)

Artificial intelligence(06)
Artificial intelligence(06)Artificial intelligence(06)
Artificial intelligence(06)
 
Search 1
Search 1Search 1
Search 1
 
Artificial intelligence(05)
Artificial intelligence(05)Artificial intelligence(05)
Artificial intelligence(05)
 
Chapter3 Search
Chapter3 SearchChapter3 Search
Chapter3 Search
 
informed_search.pdf
informed_search.pdfinformed_search.pdf
informed_search.pdf
 
Chap11 slides
Chap11 slidesChap11 slides
Chap11 slides
 
Lecture 3 Problem Solving.pptx
Lecture 3 Problem Solving.pptxLecture 3 Problem Solving.pptx
Lecture 3 Problem Solving.pptx
 
3.informed search
3.informed search3.informed search
3.informed search
 
l2.pptx
l2.pptxl2.pptx
l2.pptx
 
AI Lecture 3 (solving problems by searching)
AI Lecture 3 (solving problems by searching)AI Lecture 3 (solving problems by searching)
AI Lecture 3 (solving problems by searching)
 
M4 heuristics
M4 heuristicsM4 heuristics
M4 heuristics
 
Introduction to artificial intelligence
Introduction to artificial intelligenceIntroduction to artificial intelligence
Introduction to artificial intelligence
 
l2.pptx
l2.pptxl2.pptx
l2.pptx
 
c4.pptx
c4.pptxc4.pptx
c4.pptx
 
Final slide4 (bsc csit) chapter 4
Final slide4 (bsc csit) chapter 4Final slide4 (bsc csit) chapter 4
Final slide4 (bsc csit) chapter 4
 
2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt
2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt
2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt
 
uniformed (also called blind search algo)
uniformed (also called blind search algo)uniformed (also called blind search algo)
uniformed (also called blind search algo)
 
m4-heuristics.ppt
m4-heuristics.pptm4-heuristics.ppt
m4-heuristics.ppt
 
Heuristic Searching Algorithms Artificial Intelligence.pptx
Heuristic Searching Algorithms Artificial Intelligence.pptxHeuristic Searching Algorithms Artificial Intelligence.pptx
Heuristic Searching Algorithms Artificial Intelligence.pptx
 
uninformed search part 1.pptx
uninformed search part 1.pptxuninformed search part 1.pptx
uninformed search part 1.pptx
 

Recently uploaded

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 

Recently uploaded (20)

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 

Chapter 3.pptx

  • 2. Search We will consider the problem of designing goal-based agents in observable, deterministic, discrete, known environments The solution is a fixed sequence of actions Search is the process of looking for the sequence of actions that reaches the goal Once the agent begins executing the search solution, it can ignore its percepts (open-loop system) 2
  • 3. Search problem components • Initial state • Actions • Transition model – What is the result of performing a given action in a given state? • Goal state • Path cost – Assume that it is a sum of nonnegative step costs • The optimal solution is the sequence of actions that gives the lowest path cost for reaching the goal Initial state Goal state 3
  • 4. Example: Romania • Initial state – Arad • Actions – Go from one city to another • Transition model – If you go from city A to city B, you end up in city B • Goal state – Bucharest • Path cost – Sum of edge costs • On vacation in Romania; currently in Arad • Flight leaves tomorrow from Bucharest 4
  • 5. State space • The initial state, actions, and transition model define the state space of the problem – The set of all states reachable from initial state by any sequence of actions – Can be represented as a directed graph where the nodes are states and links between nodes are actions • What is the state space for the Romania problem? 5
  • 6. Example: Vacuum world • States – Agent location and dirt location – How many possible states? – What if there are n possible locations? • Actions – Left, right, suck • Transition model 6
  • 7. Vacuum world state space graph • 7
  • 8. Example: The 8-puzzle • States – Locations of tiles • 8-puzzle: 181,440 states • 15-puzzle: 1.3 trillion states • 24-puzzle: 1025 states • Actions – Move blank left, right, up, down • Path cost – 1 per move • Optimal solution of n-Puzzle is NP-hard 8
  • 9. Example: Robot motion planning • States – Real-valued coordinates of robot joint angles • Actions – Continuous motions of robot joints • Goal state – Desired final configuration (e.g., object is grasped) • Path cost – Time to execute, smoothness of path, etc. 9
  • 10. Other Real-World Examples • Routing • Touring • VLSI layout • Assembly sequencing • Protein design 10
  • 11. Tree Search Let’s begin at the start node and expand it by making a list of all possible successor states Maintain a fringe or a list of unexpanded states At each step, pick a state from the fringe to expand Keep going until you reach the goal state Try to expand as few states as possible 11
  • 12. Search tree • “What if” tree of possible actions and outcomes • The root node corresponds to the starting state • The children of a node correspond to the successor states of that node’s state • A path through the tree corresponds to a sequence of actions – A solution is a path ending in the goal state … … … … Starting state Successor state Action Goal state 12
  • 13. Tree Search Algorithm Outline • Initialize the fringe using the starting state • While the fringe is not empty – Choose a fringe node to expand according to search strategy – If the node contains the goal state, return solution – Else expand the node and add its children to the fringe 13
  • 17. Search strategies • A search strategy is defined by picking the order of node expansion • Strategies are evaluated along the following dimensions: – Completeness: does it always find a solution if one exists? – Optimality: does it always find a least-cost solution? – Time complexity: number of nodes generated – Space complexity: maximum number of nodes in memory • Time and space complexity are measured in terms of – b: maximum branching factor of the search tree – d: depth of the least-cost solution – m: maximum length of any path in the state space (may be infinite) 17
  • 18. Uninformed search strategies • Uninformed search strategies use only the information available in the problem definition • Breadth-first search • Uniform-cost search • Depth-first search • Iterative deepening search 18
  • 19. Breadth-first search • Expand shallowest unexpanded node • Implementation: – fringe is a FIFO queue, i.e., new successors go at end A D F B C E G 19
  • 20. Breadth-first search • Expand shallowest unexpanded node • Implementation: – fringe is a FIFO queue, i.e., new successors go at end A D F B C E G 20
  • 21. Breadth-first search • Expand shallowest unexpanded node • Implementation: – fringe is a FIFO queue, i.e., new successors go at end A D F B C E G 21
  • 22. Breadth-first search • Expand shallowest unexpanded node • Implementation: – fringe is a FIFO queue, i.e., new successors go at end A D F B C E G 22
  • 23. Breadth-first search • Expand shallowest unexpanded node • Implementation: – fringe is a FIFO queue, i.e., new successors go at end A D F B C E G 23
  • 24. Properties of breadth-first search • Complete? Yes (if branching factor b is finite) • Optimal? Yes – if cost = 1 per step • Time? Number of nodes in a b-ary tree of depth d: O(bd) (d is the depth of the optimal solution) • Space? O(bd) • Space is the bigger problem (more than time) 24
  • 25. Uniform-cost search • Expand least-cost unexpanded node • Implementation: fringe is a queue ordered by path cost (priority queue) • Equivalent to breadth-first if step costs all equal • Complete? Yes, if step cost is greater than some positive constant ε • Optimal? Yes – nodes expanded in increasing order of path cost • Time? Number of nodes with path cost ≤ cost of optimal solution (C*), O(bC*/ ε) This can be greater than O(bd): the search can explore long paths consisting of small steps before exploring shorter paths consisting of larger steps • Space? O(bC*/ ε) 25
  • 26. Depth-first search • Expand deepest unexpanded node • Implementation: – fringe = LIFO queue, i.e., put successors at front A D F B C E G 26
  • 27. Depth-first search • Expand deepest unexpanded node • Implementation: – fringe = LIFO queue, i.e., put successors at front A D F B C E G 27
  • 28. Depth-first search • Expand deepest unexpanded node • Implementation: – fringe = LIFO queue, i.e., put successors at front A D F B C E G 28
  • 29. Depth-first search • Expand deepest unexpanded node • Implementation: – fringe = LIFO queue, i.e., put successors at front A D F B C E G 29
  • 30. Depth-first search • Expand deepest unexpanded node • Implementation: – fringe = LIFO queue, i.e., put successors at front A D F B C E G 30
  • 31. Depth-first search • Expand deepest unexpanded node • Implementation: – fringe = LIFO queue, i.e., put successors at front A D F B C E G 31
  • 32. Depth-first search • Expand deepest unexpanded node • Implementation: – fringe = LIFO queue, i.e., put successors at front A D F B C E G 32
  • 33. Depth-first search • Expand deepest unexpanded node • Implementation: – fringe = LIFO queue, i.e., put successors at front A D F B C E G 33
  • 34. Depth-first search • Expand deepest unexpanded node • Implementation: – fringe = LIFO queue, i.e., put successors at front A D F B C E G 34
  • 35. Properties of depth-first search • Complete? Fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path  complete in finite spaces • Optimal? No – returns the first solution it finds • Time? Could be the time to reach a solution at maximum depth m: O(bm) Terrible if m is much larger than d But if there are lots of solutions, may be much faster than BFS • Space? O(bm), i.e., linear space! 35
  • 36. Iterative deepening search • Use DFS as a subroutine 1. Check the root 2. Do a DFS searching for a path of length 1 3. If there is no path of length 1, do a DFS searching for a path of length 2 4. If there is no path of length 2, do a DFS searching for a path of length 3… 36
  • 41. Properties of iterative deepening search • Complete? Yes • Optimal? Yes, if step cost = 1 • Time? (d+1)b0 + d b1 + (d-1)b2 + … + bd = O(bd) • Space? O(bd) 41
  • 42. Informed search • Idea: give the algorithm “hints” about the desirability of different states – Use an evaluation function to rank nodes and select the most promising one for expansion • Greedy best-first search • A* search 42
  • 43. Heuristic function • Heuristic function h(n) estimates the cost of reaching goal from node n • Example: Start state Goal state 43
  • 44. Heuristic for the Romania problem 44
  • 45. Greedy best-first search • Expand the node that has the lowest value of the heuristic function h(n) 45
  • 50. Properties of greedy best-first search • Complete? No – can get stuck in loops start goal 50
  • 51. Properties of greedy best-first search • Complete? No – can get stuck in loops • Optimal? No 51
  • 52. Properties of greedy best-first search • Complete? No – can get stuck in loops • Optimal? No • Time? Worst case: O(bm) Best case: O(bd) – If h(n) is 100% accurate • Space? Worst case: O(bm) 52
  • 53. A* search • Idea: avoid expanding paths that are already expensive • The evaluation function f(n) is the estimated total cost of the path through node n to the goal: f(n) = g(n) + h(n) g(n): cost so far to reach n (path cost) h(n): estimated cost from n to goal (heuristic) 53
  • 60. Properties of A* • Complete? Yes – unless there are infinitely many nodes with f(n) ≤ C* • Optimal? Yes • Time? Number of nodes for which f(n) ≤ C* (exponential) • Space? Exponential 60
  • 61. Admissible heuristics • A heuristic h(n) is admissible if for every node n, h(n) ≤ h*(n), where h*(n) is the true cost to reach the goal state from n • An admissible heuristic never overestimates the cost to reach the goal, i.e., it is optimistic • Example: straight line distance never overestimates the actual road distance • Theorem: If h(n) is admissible, A* is optimal 61
  • 62. Designing heuristic functions • Heuristics for the 8-puzzle h1(n) = number of misplaced tiles h2(n) = total Manhattan distance (number of squares from desired location of each tile) h1(start) = 8 h2(start) = 3+1+2+2+2+3+3+2 = 18 • Are h1 and h2 admissible? 62
  • 63. Comparison of search strategies Algorithm Complete? Optimal? Time complexity Space complexity BFS UCS DFS IDS Greedy A* Yes Yes No Yes If all step costs are equal If all step costs are equal Yes No O(bd) Number of nodes with g(n) ≤ C* O(bm) O(bd) O(bd) O(bm) O(bd) No No Worst case: O(bm) Yes Yes Best case: O(bd) Number of nodes with g(n)+h(n) ≤ C* 63