![Page 1: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/1.jpg)
Artificial IntelligenceCSC348 Unit 3: Problem Solving and Search
Syedur RahmanLecturer, CSE Department
North South [email protected]
![Page 2: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/2.jpg)
2
Artificial Intelligence: Lecture Notes
The lecture notes from the introductory lecture and this unit will be available shortly from the following URL:
� http://www.geocities.com/syedatnsu/
Acknowledgements
�These lecture notes contain material from the following sources
� Intelligent Systems by S.Clark, 2005
� Logical Programming and Artificial Intelligence by S. Kapetanakis, 2004
� Artificial Intelligence: A modern approach by S. Russell and P. Norvig, International Edition, 2nd edition
© 2006 Syedur Rahman
![Page 3: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/3.jpg)
3
Unit 3: Problem Solving and Search
� Problem Solving Agents
� Problem Formulation and Search Spaces
� Tree Search Algorithm
�Breadth First Search
�Depth First Search
�Depth Limited Search
�Uniform Cost Search
� Iteratively Deepening Search
�Best First Search
�A* Search
![Page 4: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/4.jpg)
4
Problem-solving agent
� Four general steps in problem solving:
�Goal formulation
�What are the successful world states
�Problem formulation
�What actions and states to consider given the goal
�Search
�Examine different possible sequences of actions that lead to states of known value and then choose the best sequence
�Execute
�Perform actions on the basis of the solution
![Page 5: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/5.jpg)
5
Example: Romania
![Page 6: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/6.jpg)
6
Example: Romania
� On holiday in Romania; currently in Arad
�Flight leaves tomorrow from Bucharest
� Formulate goal
�Be in Bucharest
� Formulate problem
�States: various cities
�Actions: drive between cities
� Find solution
�Sequence of cities; e.g. Arad, Sibiu, Fagaras, Bucharest,
…
![Page 7: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/7.jpg)
7
Problem type
�Given how we have defined the problem:
�Environment is fully observable
�Environment is deterministic
�Environment is sequential
�Environment is static
�Environment is discrete
�Environment is single-agent
![Page 8: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/8.jpg)
8
Problem formulation
� A problem is defined by:
� An initial state, e.g. In(Arad)
� A successor function S(X)= set of action-state pairs
� e.g. S(In(Arad))={(Go(Sibiu), In(Sibiu)), (Go(Zerind), In(Zerind)),…}
initial state + successor function = state space
� Goal test
� Explicit, e.g. x=‘In(Bucharest)’
� Implicit, e.g. checkmate(x)
� Path cost (assume additive)
� e.g. sum of distances, number of actions executed, …
� c(x,a,y) is the step cost, assumed to be >= 0
A solution is a sequence of actions from initial to goal state;
the optimal solution has the lowest path cost
![Page 9: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/9.jpg)
9
Example: 8-puzzle
� States??
� Initial state??
� Actions??
� Goal test??
� Path cost??
![Page 10: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/10.jpg)
10
Example: 8-puzzle
� States: location of each tile plus blank
� Initial state: Any state can be initial
� Actions: Move blank {Left, Right, Up, Down}
� Goal test: Check whether goal configuration is reached
� Path cost: Number of actions to reach goal
![Page 11: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/11.jpg)
11
Example: 8-queens problem
Incremental formulation vs. complete-state formulation
� States??
� Initial state??
� Actions??
� Goal test??
� Path cost??
![Page 12: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/12.jpg)
12
Example: 8-queens problem
Incremental formulation
� States: Any arrangement of 0 to 8 queens on the board
� Initial state: No queens
� Actions: Add queen to any empty square
� Goal test: 8 queens on board and none attacked
� Path cost: N/A
3 x 1014 possible sequences to investigate
![Page 13: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/13.jpg)
13
Example: 8-queens problem
Incremental formulation (alternative)
� States?? n (0≤ n≤ 8) queens on the board, one per column in the nleftmost columns with no queen attacking any other
� Actions?? Add queen in leftmost empty column such that is not attacking any other queen
� 2057 possible sequences to investigate; solutions are easy to find
�But with 100 queens the problem is much harder
![Page 14: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/14.jpg)
14
Real World Examples
�Route-finding problems
� Touring problems
� Travelling Salesman problem
�VLSI layout problem
�Robot navigation
�Automatic assembly sequencing
� Internet searching
![Page 15: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/15.jpg)
15
Basic search algorithms
� How do we find the solutions of previous problems?
�Search the state space
�State space can be represented by a search tree
�Root of the tree is the initial state
�Children generated through successor function
�In general we may have a search graph rather than tree
(same state can be reached through multiple paths)
![Page 16: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/16.jpg)
16
Simple tree search example
function TREE-SEARCH(problem, strategy) return a solution or failure
Initialize search tree to the initial state of the problem
do
if no candidates for expansion then return failure
choose leaf node for expansion according to strategy
if node contains goal state then return solution
else expand the node and add resulting nodes to the search tree
enddo
![Page 17: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/17.jpg)
17
Simple tree search example
function TREE-SEARCH(problem, strategy) return a solution or failure
Initialize search tree to the initial state of the problem
do
if no candidates for expansion then return failure
choose leaf node for expansion according to strategy
if node contains goal state then return solution
else expand the node and add resulting nodes to the search tree
enddo
![Page 18: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/18.jpg)
18
Simple tree search example
function TREE-SEARCH(problem, strategy) return a solution or failure
Initialize search tree to the initial state of the problem
do
if no candidates for expansion then return failure
choose leaf node for expansion according to strategy
if node contains goal state then return solution
else expand the node and add resulting nodes to the search tree
enddo
←←←← Determines search process
![Page 19: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/19.jpg)
19
State space vs. search tree
� A state corresponds to a configuration of the world
� A node is a data structure in a search tree
�e.g. node= <state, parent-node, action, path-cost, depth>
![Page 20: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/20.jpg)
20
Search strategies
� A search strategy is defined by picking the order of node expansion
� Problem-solving performance is measured in four ways:
� Completeness: Is a solution found if one exists?
� Optimality: Does the strategy find the optimal solution?
� Time Complexity: How long does it take to find a solution?
� Space Complexity: How much memory is needed to perform the search?
� Time and space complexity are measured in terms of problem difficulty defined by:
� b - branching factor of the search tree
� d - depth of the shallowest goal node
� m - maximum length of any path in the state space
![Page 21: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/21.jpg)
21
Uninformed search strategies
� Uninformed search (or blind search)
�Strategies have no additional information about states beyond that provided in the problem definition
�Informed (or heuristic) search strategies know whether one state is more promising than another
� Uninformed strategies (defined by order in which nodes are expanded):
�Breadth-first search
�Uniform-cost search
�Depth-first search
�Depth-limited search
�Iterative deepening search
�Bidirectional search
![Page 22: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/22.jpg)
22
Breadth-first search
� Expand shallowest unexpanded node
� Implementation: fringe is a FIFO queue
A
![Page 23: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/23.jpg)
23
Breadth-first search
� Expand shallowest unexpanded node
� Implementation: fringe is a FIFO queue
A
B C
![Page 24: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/24.jpg)
24
Breadth-first search
� Expand shallowest unexpanded node
� Implementation: fringe is a FIFO queue
A
B C
D E
![Page 25: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/25.jpg)
25
Breadth-first search
� Expand shallowest unexpanded node
� Implementation: fringe is a FIFO queue
A
B C
DE F G
![Page 26: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/26.jpg)
26
Breadth-first search
�Completeness: is a solution always found if one exists?
�YES
�If shallowest goal node is at some finite depth
d
�If branching factor b is finite
�BF search is optimal if the path cost is a non-
decreasing function of the depth of the node
![Page 27: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/27.jpg)
27
Breadth-first search
� Time complexity
� Assume a state space where every state has b successors
�Assume solution is at depth d
�Worst case: expand all but the last node at depth d
�Total number of nodes generated:
� Space complexity: every node generated must remain in
memory, so same as time complexity
b + b2
+ b3
+ ...+ bd
+ (bd +1− b) = O(bd +1)
![Page 28: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/28.jpg)
28
Breadth-first search
� Memory requirements are a bigger problem than execution time
� Exponential complexity search problems cannot be solved by BF
search (or any uninformed search method) for any but the smallest
instances
1 exabyte3523 years101514
10 petabytes35 years101312
101 terabytes129 days101110
1 terabyte31 hours1098
10 gigabytes19 minutes1076
106 megabytes11 seconds1111004
1 megabyte0.11 seconds11002
MEMORYTIMENODESDEPTH
![Page 29: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/29.jpg)
29
Uniform-cost search
� Extension of BF-search:
�Expand node with lowest path cost
� Implementation: fringe = queue ordered by path
cost
�UC-search is the same as BF-search when all step-
costs are equal
![Page 30: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/30.jpg)
30
Uniform-cost search
� Completeness:
�YES, if step-cost > ε
� Time and space complexity:
�Assume C* is the cost of the optimal solution
�Assume that every action costs at least ε
�Worst-case:
� Optimality:
�nodes expanded in order of increasing path cost
�YES, if complete
O(bC */ε )
![Page 31: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/31.jpg)
31
Depth-first search
� Expand deepest unexpanded node
� Implementation: fringe is a LIFO queue (=stack)
A
![Page 32: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/32.jpg)
32
Depth-first search
� Expand deepest unexpanded node
� Implementation: fringe is a LIFO queue (=stack)
A
B C
![Page 33: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/33.jpg)
33
Depth-first search
� Expand deepest unexpanded node
� Implementation: fringe is a LIFO queue (=stack)
A
B C
D E
![Page 34: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/34.jpg)
34
Depth-first search
� Expand deepest unexpanded node
� Implementation: fringe is a LIFO queue (=stack)
AB C
D E
H I
![Page 35: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/35.jpg)
35
Depth-first search
� Expand deepest unexpanded node
� Implementation: fringe is a LIFO queue (=stack)
A
BC
D E
H I
![Page 36: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/36.jpg)
36
Depth-first search
� Expand deepest unexpanded node
� Implementation: fringe is a LIFO queue (=stack)
AB
C
D E
H I
![Page 37: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/37.jpg)
37
Depth-first search
� Expand deepest unexpanded node
� Implementation: fringe is a LIFO queue (=stack)
A
B C
D E
H I J K
![Page 38: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/38.jpg)
38
Depth-first search
� Expand deepest unexpanded node
� Implementation: fringe is a LIFO queue (=stack)
A
B C
D E
H I J K
![Page 39: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/39.jpg)
39
Depth-first search
� Expand deepest unexpanded node
� Implementation: fringe is a LIFO queue (=stack)
A
B C
D E
H I J K
![Page 40: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/40.jpg)
40
Depth-first search
� Expand deepest unexpanded node
� Implementation: fringe is a LIFO queue (=stack)
A
B C
D E
H I J K
F H
![Page 41: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/41.jpg)
41
Depth-first search
� Expand deepest unexpanded node
� Implementation: fringe is a LIFO queue (=stack)
A
B C
D E
H I J K
F H
L M
![Page 42: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/42.jpg)
42
Depth-first search
� Expand deepest unexpanded node
� Implementation: fringe is a LIFO queue (=stack)
A
B C
D E
H I J K
F H
L M
![Page 43: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/43.jpg)
43
DF-search: evaluation
�Completeness:
�Is a solution always found if one exists?
�No (unless search space is finite and no loops are
possible)
�Optimality:
�Is the least-cost solution always found?
�No
![Page 44: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/44.jpg)
44
DF-search: evaluation
� Time complexity:
�In general, time is terrible if m (maximal depth)
is much larger than d (depth of shallowest
solution)
�But if there exist many solutions then faster than
BF-search
� Space complexity:
�Backtracking search uses even less memory (one
successor instead of all b)
O(bm +1)
O(bm )
![Page 45: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/45.jpg)
45
Depth-limited search
�DF-search with depth limit l
�i.e. nodes at depth l have no successors
�Problem knowledge can be used
� Solves the infinite-path problem
� If l < d then incompleteness results
� Time complexity:
� Space complexity:O(bl )
O(bl)
![Page 46: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/46.jpg)
46
Depth-limited search with l=2
![Page 47: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/47.jpg)
47
![Page 48: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/48.jpg)
48
![Page 49: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/49.jpg)
49
G
![Page 50: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/50.jpg)
50
Depth-limited algorithm
function DEPTH-LIMITED-SEARCH(problem,limit) return a solution or failure/cutoff
return RECURSIVE-DLS(MAKE-NODE(INITIAL-STATE[problem]),problem,limit)
function RECURSIVE-DLS(node, problem, limit) return a solution or failure/cutoff
cutoff_occurred? ← false
if GOAL-TEST[problem](STATE[node]) then return SOLUTION(node)
else if DEPTH[node] == limit then return cutoff
else for each successor in EXPAND(node, problem) do
result ← RECURSIVE-DLS(successor, problem, limit)
if result == cutoff then cutoff_occurred? ← true
else if result ≠ failure then return result
if cutoff_occurred? then return cutoff else return failure
![Page 51: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/51.jpg)
51
Iterative deepening search
�A general strategy to find best depth limit l
�Goal is found at depth d, the depth of the
shallowest goal-node
�Often used in combination with DF-search
�Combines benefits of DF- and BF-search
![Page 52: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/52.jpg)
52
Iterative deepening search
function ITERATIVE_DEEPENING_SEARCH(problem) return a solution or failure
inputs: problem
for depth ← 0 to ∞ do
result ← DEPTH-LIMITED_SEARCH(problem, depth)
if result ≠ cuttoff then return result
![Page 53: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/53.jpg)
53
ID-search, example
� Limit=0
![Page 54: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/54.jpg)
54
ID-search, example
� Limit=1
![Page 55: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/55.jpg)
55
ID-search, example
� Limit=2
![Page 56: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/56.jpg)
56
ID-search, example
� Limit=3
![Page 57: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/57.jpg)
57
ID search: evaluation
� Time complexity:
�Algorithm seems costly due to repeated generation of certain states
�Node generation:
�level d: once
�level d-1: 2
�level d-2: 3
�…
�level 2: d-1
�level 1: d
N(IDS) = (d)b + (d −1)b2+ ...+ (1)bd
N(BFS) = b + b2
+ ...+ bd
+ (bd +1− b)
O(bd )
N(IDS) = 50 + 400 + 3000 + 20000 +100000 =123450
N(BFS) =10 +100 +1000 +10000 +100000 + 999990 =1111100
Comparison for b=10 and d=5, solution at far right
![Page 58: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/58.jpg)
58
Summary of algorithms
YES
bd/2
bd/2
YES*
Bidirectional
search
NO
bm
bm
NO
Depth-First
YESNOYES*YES*Optimal?
bdblbC*/ebd+1Space
bdblbC*/ebd+1Time
YESYES,
if l ≥ d
YES*YES*Complete?
Iterative
deepening
Depth-limitedUniform-costBreadth-FirstCriterion
![Page 59: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/59.jpg)
59
Repeated states
� Failure to detect repeated states can turn solvable problems
into unsolvable ones
![Page 60: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/60.jpg)
60
Graph search algorithm
�Closed list stores all expanded nodes
function GRAPH-SEARCH(problem,fringe) return a solution or failure
closed ← an empty set
fringe ← INSERT(MAKE-NODE(INITIAL-STATE[problem]), fringe)
loop do
if EMPTY?(fringe) then return failure
node ← REMOVE-FIRST(fringe)
if GOAL-TEST[problem] applied to STATE[node] succeeds
then return SOLUTION(node)
if STATE[node] is not in closed then
add STATE[node] to closed
fringe ← INSERT-ALL(EXPAND(node, problem), fringe)
![Page 61: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/61.jpg)
61
Graph search, evaluation
� Optimality:
�GRAPH-SEARCH discards newly discovered paths
�This may result in a sub-optimal solution, except when uniform-cost search or BF-search with constant step cost is used
� Time and space complexity:
�proportional to the size of the state space
(may be much smaller than O(bd))
�DF- and ID-search with closed list no longer have linear space requirements since all nodes are stored in the closed list
![Page 62: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/62.jpg)
62
Best-first search
�Node is selected for expansion based on an
evaluation function f(n)
� Evaluation function estimates distance to the goal
�Choose node which appears best
� Implementation:
�fringe is a priority queue sorted in ascending
order of f-values
![Page 63: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/63.jpg)
63
A heuristic function h(n)
� Dictionary defn: “A rule of thumb, simplification,
or educated guess that reduces or limits the search
for solutions in domains that are difficult and
poorly understood”
� For best-first search:
h(n) = estimated cost of the cheapest path from
node n to goal node
![Page 64: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/64.jpg)
64
Romania with step costs in km
� hSLD=straight-line distance
heuristic
� hSLD cannot be computed
from the problem
description itself
� In greedy best-first
search f(n)=h(n)
�Expand node that is
closest to goal
![Page 65: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/65.jpg)
65
Greedy search example
� Greedy search to solve the Arad to Bucharest problem
Arad (366)
![Page 66: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/66.jpg)
66
Greedy search example
� Greedy best-first search will select Sibiu
Arad
Sibiu(253)
Timisoara
(329)
Zerind(374)
![Page 67: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/67.jpg)
67
Greedy search example
� Greedy best-first search will select Fagaras
Arad
Sibiu
Arad
(366)Fagaras
(176)
Oradea
(380)
Rimnicu Vilcea
(193)
![Page 68: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/68.jpg)
68
Greedy search example
� Goal reached
�For this example no node is expanded that is not on the
solution path
�But not optimal (see Arad, Sibiu, Rimnicu Vilcea,
Pitesti)
Arad
Sibiu
Fagaras
Sibiu
(253)
Bucharest
(0)
![Page 69: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/69.jpg)
69
Greedy search: evaluation
� Complete or optimal: no
�Minimizing h(n) can result in false starts, e.g. Iasi to
Fagaras
�Check on repeated states
![Page 70: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/70.jpg)
70
Greedy search: evaluation
� Time and space complexity:
�In the worst case all the nodes in the search tree
are generated:
(m is maximum depth of search tree and b is
branching factor)
�But: choice of a good heuristic can give dramatic
improvement
O(bm )
![Page 71: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/71.jpg)
71
A* search
� Best-known form of best-first search
� Idea: avoid expanding paths that are already expensive
� Evaluation function f(n)=g(n) + h(n)
�g(n): the cost (so far) to reach the node
�h(n): estimated cost to get from the node to the goal
�f(n): estimated total cost of path through n to goal
� A* search is both complete and optimal if h(n) satisfies
certain conditions
![Page 72: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/72.jpg)
72
A* search
�A* search is optimal if h(n) is an admissible heuristic
�A heuristic is admissible if it never overestimatesthe cost to reach the goal
�h(n) <= h*(n) where h*(n) is the true cost from n
�Admissible heuristics are optimistic about the cost of solving the problem
� e.g. hSLD(n) never overestimates the actual road distance
![Page 73: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/73.jpg)
73
Romania example
![Page 74: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/74.jpg)
74
A* search example
![Page 75: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/75.jpg)
75
A* search example
![Page 76: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/76.jpg)
76
A* search example
![Page 77: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/77.jpg)
77
A* search example
![Page 78: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/78.jpg)
78
A* search example
![Page 79: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/79.jpg)
79
A* search example
![Page 80: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/80.jpg)
80
A* and GRAPH-SEARCH
� GRAPH-SEARCH discards new paths to a repeated state
�So may discard the optimal path
� Solutions:
�Remove more expensive of the two paths
�But requires extra book-keeping
�Ensure that the optimal path to any repeated state is always the first one followed
�Requires extra condition on h(n): consistency(or monotonicity)
![Page 81: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/81.jpg)
81
Consistency
� A heuristic is consistent if
� If h is consistent, we have
� i.e. f(n) is nondecreasing along any path
�and so A* using GRAPH-SEARCH expands nodes in non-decreasing order of f(n)
h(n) ≤ c(n,a,n') + h(n')
f (n') = g(n') + h(n')
= g(n) + c(n,a,n') + h(n')
≥ g(n) + h(n)
≥ f (n)
![Page 82: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/82.jpg)
82
A* search: evaluation
�Complete: yes
�Unless there are infinitely many nodes with
f<f(G)
�Since bands of increasing f are added
�Optimal: yes
�A* is optimally efficient for any given h(n): no
other optimal algorithm is guaranteed to expand
fewer nodes
![Page 83: Artificial Intelligence - Tripod.comsyedatnsu.tripod.com/ai-3.pdf · Artificial Intelligence CSC348 Unit 3: Problem Solving and Search Syedur Rahman Lecturer, CSE Department North](https://reader030.vdocuments.us/reader030/viewer/2022040412/5f0584737e708231d4135afb/html5/thumbnails/83.jpg)
83
A* search: evaluation
� Time complexity:
�number of nodes expanded is still exponential in
length of solution
� Space complexity:
�All generated nodes are kept in memory
�A* usually runs out of space before running out
of time