SlideShare a Scribd company logo
1
Dr. Sohail Iqbal
Special Thanks to our KGH Dr. Seemab Latif for AI material and guidance!
Problem Solving using Search
2
AI: Representation and Problem Solving
Informed Search
Slide credits: CMU AI, http://ai.berkeley.edu
3
Uninformed vs Informed Search
4
This week
•Informed Search
• Heuristics
• Greedy Search
• A* Search
5
Search Heuristics
A heuristic is:
 A function that estimates how close a state is to a goal.
 Designed for a particular search problem.
 Examples: Manhattan distance, Euclidean distance for
pathing.
10
5
11.2
6
Effect of heuristics
Guide search towards the goal instead of all over the place
Start Goal
Start Goal
Uninformed
Informed
7
Example: Euclidean distance to Bucharest
h(state)  value
8
Greedy Search
9
• Expand the node that seems closest…(order frontier by h)
• What can possibly go wrong?
Sibiu-Fagaras-Bucharest =
99+211 = 310
Sibiu-Rimnicu Vilcea-Pitesti-Bucharest =
80+97+101 = 278
1000000
Recap: Greedy Search
You did it!
10
Recap:
11
UCS= Uniform Cost Search
• Uniform Cost Search (UCS) is a type of uninformed search that
performs a search based on the lowest path cost.
• If we reduce the scope of Dijkstra’s algorithm from “Finding the
shortest path from one node to all other nodes in the graph.” to
• “Finding the shortest path from Start to Goal nodes.”
12
What if we use Dijkstra’s
algorithm for Problem solving?
Any modifications recommended?
13
A* Search
14
A* Search
UCS/BFS Greedy
A*
15
A2 A3
C1 C2
B1 B3
16
A* in 4 x 4 Maze
with
H: hopeful distance
G: Ground distance
F: Full dist G+H
17
Combining UCS and Greedy
• Uniform-cost orders by path cost, or backward/ground cost g(n)
• Greedy orders by goal proximity, or forward/hopeful cost h(n)
• A* Search orders by the sum: f(n) = g(n) + h(n)
S a d
b
G
h=5
h=6
h=2
1
8
1
1
2
h=6
h=0
c
h=7
3
e h=1
1
Example: Teg Grenager
S
a
b
c
e
d
d
G
G
g = 0
h=6
g = 1
h=5
g = 2
h=6
g = 3
h=7
g = 4
h=2
g = 6
h=0
g = 9
h=1
g = 10
h=2
g = 12
h=0
19
Path followed: S,A,E,D,G
Solution path: S,A,E,D,G
Path Cost: 1+8+1+2 = 12
Current Open Closee
- S(6) -
S(6) A(5) -
AA(5) B(6)D(2)E(1) S
E(1) B(6)D(2) S,A
D(2) G(0)B(6) S,A,E,
G(0) Goal nodee S,A,E,D
20
Current Open Closee
- S(0) -
S A(1) -
A(1) B(2)D(4)E(9) S
B(2) C(3) D(4)E(9) S,A
C(3) D(4)E(9) S,A,B
D(4) G(6)E(9) S,A,B,C
G(6) Goal node S,A,B,C,D
Path followed: S,A,B,C,D,G
Solution path: S,A,D,G
Path Cost: 1+3+2 = 6
21
A*
S a d
b
G
h=5
h=6
h=2
1
8
1
1
2
h=6
h=0
c
h=7
3
e h=1
1
24
function UNIFORM-COST-SEARCH(problem) returns a solution, or failure
initialize the explored set to be empty
initialize the frontier as a priority queue using g(n) as the priority
add initial state of problem to frontier with priority g(S) = 0
loop do
if the frontier is empty then
return failure
choose a node and remove it from the frontier
if the node contains a goal state then
return the corresponding solution
add the node state to the explored set
for each resulting child from node
if the child state is not already in the frontier or explored set then
add child to the frontier
else if the child is already in the frontier with higher g(n) then
replace that frontier node with child
25
function A-STAR-SEARCH(problem) returns a solution, or failure
initialize the explored set to be empty
initialize the frontier as a priority queue using f(n) = g(n) + h(n) as the priority
add initial state of problem to frontier with priority f(S) = 0 + h(S)
loop do
if the frontier is empty then
return failure
choose a node and remove it from the frontier
if the node contains a goal state then
return the corresponding solution
add the node state to the explored set
for each resulting child from node
if the child state is not already in the frontier or explored set then
add child to the frontier
else if the child is already in the frontier with higher f(n) then
replace that frontier node with child
26
A* Search Algorithms
• A* Tree Search
• Same tree search algorithm but with a frontier that is a priority queue using
priority f(n) = g(n) + h(n)
• A* Graph Search
• Same as UCS graph search algorithm but with a frontier that is a priority
queue using priority f(n) = g(n) + h(n)
27
UCS vs A* Contours
UCS vs A* Contours
A* expands mainly toward the goal, but
does hedge its bets to ensure optimality.
Start Goal
Start Goal
28
Optimality of A* Tree Search
29
A* Tree Search
S
A
C
G
1
3
1
3
h=2
h=4
h=1
h=0
S (0+2)
A (1+4)
C (2+1)
G (5+0)
C (3+1)
G (6+0)
State space graph Search tree
30
Optimality of A* Tree Search: Blocking
Proof:
• Imagine B is on the frontier
• Some ancestor n of A is on the frontier,
too (Maybe the start state; maybe A
itself!)
• Claim: n will be explored before B
1. f(n) is less than or equal to f(A)
f(n) = g(n) + h(n) Definition of f-cost
f(n)  g(A) Admissibility of h
…
g(A) = f(A) h = 0 at a goal
A
B
n
31
Optimality of A* Tree Search: Blocking
Proof:
• Imagine B is on the frontier
• Some ancestor n of A is on the frontier,
too (Maybe the start state; maybe A
itself!)
• Claim: n will be explored before B
1. f(n) is less than or equal to f(A)
2. f(A) is less than f(B)
…
A
B
n
g(A) < g(B) Suboptimality of B
f(A) < f(B) h = 0 at a goal
32
Optimality of A* Tree Search
Assume:
• A is an optimal goal node
• B is a suboptimal goal node
• h is admissible
Claim:
• A will be chosen for exploration (popped off the frontier) before B
…
A
B
33
Optimality of A* Tree Search: Blocking
Proof:
• Imagine B is on the frontier
• Some ancestor n of A is on the frontier, too
(Maybe the start state; maybe A itself!)
• Claim: n will be explored before B
1. f(n) is less than or equal to f(A)
2. f(A) is less than f(B)
3. n is explored before B
• All ancestors of A are explored before B
• A is explored before B
• A* search is optimal
…
A
B
n
f(n)  f(A) < f(B)
34
A*: Summary
• A* uses both backward costs and (estimates of) forward costs
• A* is optimal with admissible/consistent heuristics
• Heuristic design is key: often use relaxed problems
35
In-Class Activity
• Q1: Practice creating heuristics and running Greedy and A* search
• Q2: Walk through Lego Robot Example in a maze on floor tiles
36
Reading
Be Ready for Quiz 2 on Solving Problem from Chapter 3 from topics we covered!
37
Helpful Videos
• Animation of parent Dijkstra’s algorithm
https://www.youtube.com/watch?v=wtdtkJgcYUM
The Hidden Beauty of A* Algorithm:
https://www.youtube.com/watch?v=A60q6dcoCjw
38
39
Appendix-1
40
Appendix-2
41
Source: https://youtu.be/bMl0kFUR19s?si=0lHBDlqfCcGuT0xc

More Related Content

PPTX
CS767_Lecture_03.pptx
PDF
informed_search.pdf
PPT
Different Search Techniques used in AI.ppt
PPT
ai and search algorithms general on a* and searching
PPT
Jarrar.lecture notes.aai.2011s.ch4.informedsearch
PPT
M4 heuristics
PPT
m4-heuristics.ppt
CS767_Lecture_03.pptx
informed_search.pdf
Different Search Techniques used in AI.ppt
ai and search algorithms general on a* and searching
Jarrar.lecture notes.aai.2011s.ch4.informedsearch
M4 heuristics
m4-heuristics.ppt

Similar to 04 Problem Solving in AI (1)-artificial intelligence.pptx (20)

PPT
Presentacion nro 1 redes y comunicaciones de datos
PPT
HEURISTIC SEARCH IN ARTIFICIAL INTELLEGENCE
PPT
What is A-Star (A*) Algorithm in Artificial astar.ppt
PPT
cps170_search CPS 170: Artificial Intelligence http://www.cs.duke.edu/courses...
PPT
cps170_search.ppt. This ppt talk about search algorithm
PPT
Ch2 3-informed (heuristic) search
PPTX
Final slide (bsc csit) chapter 5
PPTX
BFS,DFS, BEST FIRST,A-STAR,AO-STAR SEARCH.pptx
PPTX
AI UNIT-1-BREADTH and BEST FIRST SEARCH.pptx
PPT
Ch4: Searching Techniques 6_2018_12_25!05_35_25_PM.ppt
PPTX
Jarrar: Informed Search
PPTX
Artificial intelligence(06)
PPTX
Artificial intelligence(06)
PDF
Heuristic search
PPT
problem solving for AI and Machine Learning
PPTX
Final slide4 (bsc csit) chapter 4
PPT
Uniformed tree searching
PDF
shamwari dzerwendo.mmmmmmfmmfmfkksrkrttkt
PDF
Heuristic search for AI CSE EVE dsfdsf sdfdsfsdf sdfdsfdsfsd sdfsdfds
Presentacion nro 1 redes y comunicaciones de datos
HEURISTIC SEARCH IN ARTIFICIAL INTELLEGENCE
What is A-Star (A*) Algorithm in Artificial astar.ppt
cps170_search CPS 170: Artificial Intelligence http://www.cs.duke.edu/courses...
cps170_search.ppt. This ppt talk about search algorithm
Ch2 3-informed (heuristic) search
Final slide (bsc csit) chapter 5
BFS,DFS, BEST FIRST,A-STAR,AO-STAR SEARCH.pptx
AI UNIT-1-BREADTH and BEST FIRST SEARCH.pptx
Ch4: Searching Techniques 6_2018_12_25!05_35_25_PM.ppt
Jarrar: Informed Search
Artificial intelligence(06)
Artificial intelligence(06)
Heuristic search
problem solving for AI and Machine Learning
Final slide4 (bsc csit) chapter 4
Uniformed tree searching
shamwari dzerwendo.mmmmmmfmmfmfkksrkrttkt
Heuristic search for AI CSE EVE dsfdsf sdfdsfsdf sdfdsfdsfsd sdfsdfds
Ad

Recently uploaded (20)

PPTX
modul_python (1).pptx for professional and student
PDF
Systems Analysis and Design, 12th Edition by Scott Tilley Test Bank.pdf
PDF
Introduction to the R Programming Language
PPTX
Qualitative Qantitative and Mixed Methods.pptx
PDF
Data Engineering Interview Questions & Answers Cloud Data Stacks (AWS, Azure,...
PPTX
Copy of 16 Timeline & Flowchart Templates – HubSpot.pptx
PPTX
sac 451hinhgsgshssjsjsjheegdggeegegdggddgeg.pptx
PPTX
FMIS 108 and AISlaudon_mis17_ppt_ch11.pptx
PPTX
Topic 5 Presentation 5 Lesson 5 Corporate Fin
DOCX
Factor Analysis Word Document Presentation
PPTX
Pilar Kemerdekaan dan Identi Bangsa.pptx
PDF
Business Analytics and business intelligence.pdf
PDF
REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON+256765750853/0705037305
PDF
Optimise Shopper Experiences with a Strong Data Estate.pdf
PDF
Microsoft Core Cloud Services powerpoint
PPTX
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
PPT
lectureusjsjdhdsjjshdshshddhdhddhhd1.ppt
PPTX
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
PDF
annual-report-2024-2025 original latest.
PDF
Tetra Pak Index 2023 - The future of health and nutrition - Full report.pdf
modul_python (1).pptx for professional and student
Systems Analysis and Design, 12th Edition by Scott Tilley Test Bank.pdf
Introduction to the R Programming Language
Qualitative Qantitative and Mixed Methods.pptx
Data Engineering Interview Questions & Answers Cloud Data Stacks (AWS, Azure,...
Copy of 16 Timeline & Flowchart Templates – HubSpot.pptx
sac 451hinhgsgshssjsjsjheegdggeegegdggddgeg.pptx
FMIS 108 and AISlaudon_mis17_ppt_ch11.pptx
Topic 5 Presentation 5 Lesson 5 Corporate Fin
Factor Analysis Word Document Presentation
Pilar Kemerdekaan dan Identi Bangsa.pptx
Business Analytics and business intelligence.pdf
REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON+256765750853/0705037305
Optimise Shopper Experiences with a Strong Data Estate.pdf
Microsoft Core Cloud Services powerpoint
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
lectureusjsjdhdsjjshdshshddhdhddhhd1.ppt
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
annual-report-2024-2025 original latest.
Tetra Pak Index 2023 - The future of health and nutrition - Full report.pdf
Ad

04 Problem Solving in AI (1)-artificial intelligence.pptx

  • 1. 1 Dr. Sohail Iqbal Special Thanks to our KGH Dr. Seemab Latif for AI material and guidance! Problem Solving using Search
  • 2. 2 AI: Representation and Problem Solving Informed Search Slide credits: CMU AI, http://ai.berkeley.edu
  • 4. 4 This week •Informed Search • Heuristics • Greedy Search • A* Search
  • 5. 5 Search Heuristics A heuristic is:  A function that estimates how close a state is to a goal.  Designed for a particular search problem.  Examples: Manhattan distance, Euclidean distance for pathing. 10 5 11.2
  • 6. 6 Effect of heuristics Guide search towards the goal instead of all over the place Start Goal Start Goal Uninformed Informed
  • 7. 7 Example: Euclidean distance to Bucharest h(state)  value
  • 9. 9 • Expand the node that seems closest…(order frontier by h) • What can possibly go wrong? Sibiu-Fagaras-Bucharest = 99+211 = 310 Sibiu-Rimnicu Vilcea-Pitesti-Bucharest = 80+97+101 = 278 1000000 Recap: Greedy Search You did it!
  • 11. 11 UCS= Uniform Cost Search • Uniform Cost Search (UCS) is a type of uninformed search that performs a search based on the lowest path cost. • If we reduce the scope of Dijkstra’s algorithm from “Finding the shortest path from one node to all other nodes in the graph.” to • “Finding the shortest path from Start to Goal nodes.”
  • 12. 12 What if we use Dijkstra’s algorithm for Problem solving? Any modifications recommended?
  • 16. 16 A* in 4 x 4 Maze with H: hopeful distance G: Ground distance F: Full dist G+H
  • 17. 17 Combining UCS and Greedy • Uniform-cost orders by path cost, or backward/ground cost g(n) • Greedy orders by goal proximity, or forward/hopeful cost h(n) • A* Search orders by the sum: f(n) = g(n) + h(n) S a d b G h=5 h=6 h=2 1 8 1 1 2 h=6 h=0 c h=7 3 e h=1 1 Example: Teg Grenager S a b c e d d G G g = 0 h=6 g = 1 h=5 g = 2 h=6 g = 3 h=7 g = 4 h=2 g = 6 h=0 g = 9 h=1 g = 10 h=2 g = 12 h=0
  • 18. 19 Path followed: S,A,E,D,G Solution path: S,A,E,D,G Path Cost: 1+8+1+2 = 12 Current Open Closee - S(6) - S(6) A(5) - AA(5) B(6)D(2)E(1) S E(1) B(6)D(2) S,A D(2) G(0)B(6) S,A,E, G(0) Goal nodee S,A,E,D
  • 19. 20 Current Open Closee - S(0) - S A(1) - A(1) B(2)D(4)E(9) S B(2) C(3) D(4)E(9) S,A C(3) D(4)E(9) S,A,B D(4) G(6)E(9) S,A,B,C G(6) Goal node S,A,B,C,D Path followed: S,A,B,C,D,G Solution path: S,A,D,G Path Cost: 1+3+2 = 6
  • 21. 24 function UNIFORM-COST-SEARCH(problem) returns a solution, or failure initialize the explored set to be empty initialize the frontier as a priority queue using g(n) as the priority add initial state of problem to frontier with priority g(S) = 0 loop do if the frontier is empty then return failure choose a node and remove it from the frontier if the node contains a goal state then return the corresponding solution add the node state to the explored set for each resulting child from node if the child state is not already in the frontier or explored set then add child to the frontier else if the child is already in the frontier with higher g(n) then replace that frontier node with child
  • 22. 25 function A-STAR-SEARCH(problem) returns a solution, or failure initialize the explored set to be empty initialize the frontier as a priority queue using f(n) = g(n) + h(n) as the priority add initial state of problem to frontier with priority f(S) = 0 + h(S) loop do if the frontier is empty then return failure choose a node and remove it from the frontier if the node contains a goal state then return the corresponding solution add the node state to the explored set for each resulting child from node if the child state is not already in the frontier or explored set then add child to the frontier else if the child is already in the frontier with higher f(n) then replace that frontier node with child
  • 23. 26 A* Search Algorithms • A* Tree Search • Same tree search algorithm but with a frontier that is a priority queue using priority f(n) = g(n) + h(n) • A* Graph Search • Same as UCS graph search algorithm but with a frontier that is a priority queue using priority f(n) = g(n) + h(n)
  • 24. 27 UCS vs A* Contours UCS vs A* Contours A* expands mainly toward the goal, but does hedge its bets to ensure optimality. Start Goal Start Goal
  • 25. 28 Optimality of A* Tree Search
  • 26. 29 A* Tree Search S A C G 1 3 1 3 h=2 h=4 h=1 h=0 S (0+2) A (1+4) C (2+1) G (5+0) C (3+1) G (6+0) State space graph Search tree
  • 27. 30 Optimality of A* Tree Search: Blocking Proof: • Imagine B is on the frontier • Some ancestor n of A is on the frontier, too (Maybe the start state; maybe A itself!) • Claim: n will be explored before B 1. f(n) is less than or equal to f(A) f(n) = g(n) + h(n) Definition of f-cost f(n)  g(A) Admissibility of h … g(A) = f(A) h = 0 at a goal A B n
  • 28. 31 Optimality of A* Tree Search: Blocking Proof: • Imagine B is on the frontier • Some ancestor n of A is on the frontier, too (Maybe the start state; maybe A itself!) • Claim: n will be explored before B 1. f(n) is less than or equal to f(A) 2. f(A) is less than f(B) … A B n g(A) < g(B) Suboptimality of B f(A) < f(B) h = 0 at a goal
  • 29. 32 Optimality of A* Tree Search Assume: • A is an optimal goal node • B is a suboptimal goal node • h is admissible Claim: • A will be chosen for exploration (popped off the frontier) before B … A B
  • 30. 33 Optimality of A* Tree Search: Blocking Proof: • Imagine B is on the frontier • Some ancestor n of A is on the frontier, too (Maybe the start state; maybe A itself!) • Claim: n will be explored before B 1. f(n) is less than or equal to f(A) 2. f(A) is less than f(B) 3. n is explored before B • All ancestors of A are explored before B • A is explored before B • A* search is optimal … A B n f(n)  f(A) < f(B)
  • 31. 34 A*: Summary • A* uses both backward costs and (estimates of) forward costs • A* is optimal with admissible/consistent heuristics • Heuristic design is key: often use relaxed problems
  • 32. 35 In-Class Activity • Q1: Practice creating heuristics and running Greedy and A* search • Q2: Walk through Lego Robot Example in a maze on floor tiles
  • 33. 36 Reading Be Ready for Quiz 2 on Solving Problem from Chapter 3 from topics we covered!
  • 34. 37 Helpful Videos • Animation of parent Dijkstra’s algorithm https://www.youtube.com/watch?v=wtdtkJgcYUM The Hidden Beauty of A* Algorithm: https://www.youtube.com/watch?v=A60q6dcoCjw
  • 35. 38

Editor's Notes

  • #14: Notes: these images licensed from iStockphoto for UC Berkeley use. UCS is Uniform Cost Search similar to Dijkstra’s algo
  • #15: The statement describes how the **A*** search algorithm manages the nodes (or points) during its search process by maintaining two lists: ### 1. **Closed List**: - The closed list contains all the **nodes that have already been visited** and fully expanded. - Once a node is placed in the closed list, it means the algorithm has processed all possible paths from that node, and it will not revisit this node again. - This helps avoid loops and ensures that the algorithm doesn't waste time re-exploring paths that have already been checked. ### 2. **Open List**: - The open list is a **priority queue** (often implemented using a min-heap) containing all the **nodes that are yet to be visited** but have been discovered. - Each node in this list has a **priority value**, determined by the evaluation function \( f(n) = g(n) + h(n) \), where: - \( g(n) \) is the cost to reach the node \( n \) from the start. - \( h(n) \) is the heuristic estimate of the cost to reach the goal from node \( n \). - The node with the lowest \( f(n) \) value (i.e., the node that seems to offer the best path towards the goal) is selected for exploration next. - The open list is **updated dynamically**, meaning every time a new node is discovered or a better path to a previously discovered node is found, the open list is adjusted (or "updated") to reflect the new state of the search. ### How They Work Together: - The algorithm starts by adding the initial node to the **open list**. - It then repeatedly selects the node with the **lowest \( f(n) \)** from the open list, processes it (expands it by exploring its neighbors), and moves it to the **closed list**. - Each neighbor of the current node is either added to the **open list** if it's a new node or updated if a better path to that node is found. - This process continues until the goal is found, or the open list is empty, meaning no path exists. ### Summary: - **Closed list**: Holds nodes that have been visited and fully processed (explored). - **Open list**: Holds nodes that have been discovered but not yet fully processed. It's organized as a priority queue based on the estimated total cost \( f(n) \), and it is dynamically updated as the search progresses.