W Chapter3
W Chapter3
Solving Problems by
Searching
CS361 Artificial Intelligence
Dr. Khaled Wassif
Spring 2023
◼ 8-Puzzle 2 1 3 1 2 3
4 7 6 4 5 6
◼ N-Queens 5 8 7 8
boat
◼ The River Problem Farmer, Wolf,
Duck and Corn
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 3- 4
By Dr. Khaled Wassif
Map Searching (navigation)
◼ On touring holiday in Romania; currently in Arad.
◼ Flight leaves tomorrow from Bucharest
– Non-refundable ticket.
◼ Formulate goal:
– be in Bucharest on time
◼ Formulate problem:
– states: various cities
– actions: drive between cities
◼ Find solution (action sequences):
– sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 3- 5
By Dr. Khaled Wassif
Problem-Solving Agents
◼ A kind of goal-based agents that decide what to do by
finding sequences of actions that lead to desirable states.
◼ Goals help to organize behavior by limiting the
objectives that the agent is trying to achieve.
◼ Goal formulation is the first step in problem solving,
based on the current situation and the agent’s performance
measure.
– As well as formulating a goal, the agent may wish to decide
on some other factors that affect the desirability of different
ways of achieving the goal.
◼ Problem formulation is the process of deciding what
actions and states to consider, given the goal formulation.
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 3- 6
By Dr. Khaled Wassif
Problem-Solving Agents (cont.)
◼ An agent with several immediate options of unknown
value can decide what to do by first examining different
possible sequences of actions that lead to states of
known value, and then choosing the best sequences.
– This process of looking for such a sequence is called search.
– A search algorithm takes a problem as input and returns a
solution in the form of an action sequence.
– Once a solution is found, the actions it recommends can be
carried out through the execution phase.
◼ Thus, the agent design is simply consists of “formulate,
search, execute” phases.
– Once the solution has been executed, the agent will formulate
a new goal.
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 3- 7
By Dr. Khaled Wassif
Problem-Solving Agents
◼ states?
◼ actions?
◼ goal test?
◼ path cost?
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 3- 23
By Dr. Khaled Wassif
Vacuum World State Space Graph
◼ states?
◼ actions?
◼ goal test?
◼ path cost?
◼ states?
◼ actions?
◼ goal test?
◼ path cost?
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 3- 27
By Dr. Khaled Wassif
Example: robotic assembly
5 2
1 4 1 7
Goal state
4 5
5 2
[5] [2]
5 2
[5] [2]
1 7
[3] [9]
5 2
[5] [2]
1 7
[3] [9]
4 5
[7] [8]
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 3- 57
By Dr. Khaled Wassif
Uniform-cost Search (cont.)
[x] = g(n)
path cost of node n
5 2
[5] [2]
1 4 1 7
[6] [3] [9]
[9]
4 5
[7] [8]
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 3- 58
By Dr. Khaled Wassif
Uniform-cost Search (cont.)
5 2
[5] [2]
1 4 1 7
[6] [3] [9]
[9]
Goal state 4 5
path cost
g(n)=[6] [7] [8]
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 3- 59
By Dr. Khaled Wassif
Uniform-cost Search (cont.)
5 2
[5] [2]
1 4 1 7
[6] [3] [9]
[9]
Goal state 4 5
path cost
g(n)=[6] [7] [8]
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 3- 60
By Dr. Khaled Wassif
Uniform-cost Search (cont.)
Goal state
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 3- 75
By Dr. Khaled Wassif
Depth-first Search (cont.)
◼ DFS is incomplete:
– In tree-search version, it can make a wrong choice if left
subtree were of unbounded depth but contained no solutions,
it would never terminate.
– But, the graph-search version, which avoids repeated states
and redundant paths, is complete only in finite state spaces.
◼ DFS is not optimal:
– It will explore the entire left subtree even if a goal node near
the root.
◼ Time complexity of DFS is O(bm) in worst case.
– But if solutions are dense, may be much faster than BFS.
◼ Space complexity of DFS is O(bm), i.e., linear space!
– It needs to store only a single path from the root to a leaf
node, along with the remaining unexpanded sibling nodes for
each node on the path.
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 3- 76
By Dr. Khaled Wassif
Depth-limited Search (DLS)
◼ Alleviate the problem of DFS in infinite state spaces by
supplying it with a predetermined depth limit l.
– Nodes at depth l are treated as if they have no successors.
◼ DLS can be implemented as a simple modification to
the general tree- or graph-search algorithm; or instead
implemented as a simple recursive algorithm.
– It can terminate with two kinds of failure: standard failure or
the cutoff value indicate no solution within the depth limit.
◼ DLS is incomplete when the shallowest goal is beyond
the depth limit (l < d).
◼ DLS also is not optimal if l > d.
◼ Time complexity of DLS is O(b l) in worst case.
◼ Space complexity of DLS is O(bl).
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 3- 77
By Dr. Khaled Wassif
Recursive Depth-limited Search
Goal
state
g(n)
h(n)
◼ Complete? Yes
– Unless there are infinitely many nodes with f ≤ f(G).
– h1(S) = ?
– h2(S) = ?
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 4- 113
By Dr. Khaled Wassif
Admissible Heuristics
◼ E.g., for the 8-puzzle:
– h1(n) = number of misplaced tiles
– h2(n) = total Manhattan distance
(i.e., sum of the distances of tiles from their goal positions)
– h1(S) = 8
– h2(S) = 3+1+2+2+2+3+3+2 = 18
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 4- 114
By Dr. Khaled Wassif
Dominance Heuristics
◼ If h1 and h2 are both admissible and h2(n) ≥ h1(n) for
all n then h2 dominates h1 .
◼ Domination translates directly into efficiency
– h2 is better for search
◼ Typical search costs: (average number of nodes expanded)
– d=12
» IDS = 3,644,035 nodes
» A*(h1) = 227 nodes
» A*(h2) = 73 nodes
– d=24
» IDS = too many nodes
» A*(h1) = 39,135 nodes
» A*(h2) = 1,641 nodes
AI: A modern Approach © 2010 S. Russell and P. Norving Slide 4- 115
By Dr. Khaled Wassif
Comparison of Search Costs for
∗
IDS and A Algorithms with h1, h2