Upload
others
View
5
Download
0
Embed Size (px)
Citation preview
Solving problems by
Searching
By
Dr. Budditha Hettige
Department of Computer Engineering
Outline
• Problem solving
• Search – an approach to problem solving
• Uninformed search
– Breadth-first (BF)
– Uniform cost (UC)
– Depth-first (DF)
– Depth limited(DL)
– Iterative deepening(ID)
– Bidirectional (BD)
• Informed search
AI: Searching
Problem solving
• Problem solving as a process of transforming a set of states
through actions/operations
• Components of a problem
– States
– Actions/operations/successor function
– Goal test
– Path cost
AI: Searching
State space
• State space consists of all possible states together with
actions
• States are represented by nodes, while actions are by arcs
• State space can be a tree or a graph
• A path from initial state to goal state in the state space is
called a solution
AI: Searching
Examples – state space
• Robot navigation
• Water jug problem
• Monkey–banana Problem
• Farmer, wolf, goat and cabbage
• 8-puzzel
AI: Searching
Assumptions
• World States
• Actions as transitions between states
• Goal Formulation: A set of states
• Problem Formulation:
– The sequence of required actions to move from current
state to a goal state
AI: Searching
Example
Search through the path
• States?
• Actions?
• Goal test?
• Path cost?
AI: Searching
Example
Farmer, Wolf, Goat and Cabbage problem
AI: Searching
Example: Romania
AI: Searching
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
AI: Searching
Vacuum World
States: The state is determined by both the agent location and the dirt locations. The agent is in one of two locations, each of which might or might not contain dirt. Thus there are 2 * 22 = 8 possible world states. A larger environment with n locations has n * 22 states.
Initial State: Any state can be designated as the initial state.
Actions: In this simple environment, each state has just three actions: Left, Right, and Suck. Larger environments might also include Up and Down.
Transition Model: The actions have their expected effects, except that moving Left in the leftmost square, moving Right in the rightmost square, and Sucking in a clean square have no effect.
Goal Test: This checks whether all the squares are clean.
Path Cost: Each steps costs 1, so the path cost is the number of steps in the path.
AI: Searching
Example: Vacuum World
• Single-state Problem:–You know all.
• Start in #5–Solution? [Right, Clean]
Example: vacuum world
• Multiple State Problem
– Sensorless
• Start in {1,2,3,4,5,6,7,8}
– Solution?
[Right, Clean, Left, Clean]
AI: Searching
Example: vacuum world
• Contingency
– Nondeterminism: Cleaning may
dirty a clean carpet.
– Partially observable: Location, dirt at current location.
– Percept: [L, Clean], i.e., start in #5 or #7
Solution?
[Right, if dirt then Clean]
AI: Searching
Vacuum world state space graph
• States? Dirt and robot location
• Actions? Left, Right, Clean
• Goal test? No dirt at all locations
• Path cost? 1 per action
AI: Searching
Example: The 8-puzzle
• States? Locations of tiles • Actions? Move blank left, right, up, down • Goal test? Given• Path cost? 1 per move
AI: Searching
Search - real world applications
• Route finding problem
• Traveling salesman problem
• VLSI layout design
• Automatic assembling
AI: Searching
Search algorithms
• A search algorithm defines how to find a path from
initial state to goal state
• All algorithms tell how to move from the current node to
next node
• Some algorithms provide just systematic ways to
explore the state space, while others tell how to
explore effectively
• In implementing search, it is easy to handle two list as
– OPEN – node to be visited (fringe)
– CLOSED – node already visited
AI: Searching
Evaluating Search algorithms
• Completeness – ability to find a solution when there is a
solution
• Optimality – ability to find the highest quality solution
• Time complexity – how long does it take
• Space complexity – how much memory is required
AI: Searching
Search strategies
• Uninformed search (blind search)
– Systematic way to explore a state space
– No information (uninformed) to explore effectively
– There are six algorithms
• Informed search (heuristic search)
– Preference of the use of operators
– Best-first search
AI: Searching
Uninformed search
• Breadth-first (BF)
• Uniform cost (UC)
• Depth-first (DF)
• Depth limited(DL)
• Iterative deepening(ID)
• Bidirectional (BD)
AI: Searching
Breadth-first
• Explore the state space layer by layer
• Explores all of the neighbor nodes at the present depth prior
to moving on to the nodes at the next depth level
• Algorithm using OPEN and CLOSE lists
• Example
AI: Searching
Breadth-first search algorithms
AI: Searching
Features-BFS
• Find the shallowest goal first
• Its Optimal and Complete
• Worst-case performance O(b {d})
• Worst-case space complexity O(b{d})
AI: Searching
Features – BFS contd..
• Take b=10, 10,000 nodes/second, 1000 bytes/node
• Depth Nodes Time Memory
2 1100 .11seconds 1MB
4 111,100 11seconds 106MB
6 107 19min 10GB
8 109 31hours 1TB
12 1013 35years 10petabytes
• Memory requirement is a bigger problem than timeE.g. for depth 8, 31 hours is not too big yet 1 terabytes is a huge memory requirement
• Time requirement is still importantE.g. For depth 12, 35 years
AI: Searching
Uniform Cost Search
• Version of BFS
• Expand the lowest cost node rather than lowest-depth node on the fringe
• Note that each time total cost must be considered
• Uniform-cost search is complete, such as if there is a solution, UCS will find it.
• Uniform-cost search is always optimal as it only selects a path with the lowest path cost.
• UCS is also
– Complete
– guarantee to find the minimum cost pat
– Space complexity - O(bd+1)
– Time complexity - O(bd)
AI: Searching
Depth-first search
• Explore a branch deep in
• The algorithm starts at the root node and explores as far as
possible along each branch before backtracking.
• Algorithm using OPEN and CLOSE
• Example
AI: Searching
Depth-first search algorithm
AI: Searching
Features of DFS
• Not complete
• Not optimal
• Space complexity O(bd)
• Modest memory requirement
– Consider a tree with branching factor 3
• Time complexity O(bd)
AI: Searching
Comparison
Criteria BFS UCS DFS DLS IDS BDS
Complete? Yes Yes No No Yes Yes
Optimal Yes Yes No No Yes Yes
Time O(bd+1) O(bd) O(bm) O(bl) O(bd) O(bd/2)
Space O(bd+1) O(bd+1) O(bm) O(bl) O(bm) O(bd/2)
AI: Searching
Informed Search
• Informed search is also called heuristic search
• General approach is best-first search
• Node is selected for expansion on the basis of
evaluation function f(n).
• Essential component of evaluation function is a
heuristic function h(n)
– h(n) = estimated cost of the cheapest path from
node n to a goal node
– If n is the goal node, then h(n) =0
AI: Searching
Greedy best-first search
• Expand the node that is closest to the goal
• Thus f(n)=h(n)
• In a route finding problem h(n) can be the straight-line
distance heuristic.
• Consider the following route finding problem
AI: Searching
Map
Arad
Zerind
Rimnicu
Sibiu Fagaras
Timisora
Lugoj
Oradea
DobretaCraiova
Oradea
Petesti
Bucharest
Urziceni
Vaslui
IasiNeamt
Hirsova
75
71
118
111
70
75
120
146 138
97
101
90
151
9921180
85
142
9287
98
140
AI: Searching
Straight-line distances to Bucharest
• Arad 366, Bucharest-0, Craiova-160
• Dobreta-242, Fagaras-176, Giurgui-77
• Iasi-226, Neamt-234, Oradea-380
• Petesti-100, Rimnicu-193
• Sibui-253, Timosoara-329, Zerind-374
AI: Searching
Example – Greedy search
Arad
366
Arad
Timisoara ZerindSibiu
253 329 374
(a) The initial state
(b) After expanding Arad
AI: Searching
Greedy search- Cont’d
Arad
Timisoara ZerindSibiu
329 374
Arad Fagaras Orade
a
Rimnicu
Vilcea
366 176 380 193
(c) After expanding Sibiu
AI: Searching
Greedy search- Cont’d
Arad
Timisoara Zerin
d
Sibi
u
329 374
Arad Fagara
s
Orade
aRimnicu
Vilcea366 380
193
Buchares
t
Sibiu
253 0
(d) After expanding Fagaras
AI: Searching
Comments on Greedy search
• Greedy best-first search is not optimal, path via sibiu,
Fagaras to Bucharest is 32Km longer than Path through
Rimnica and Pitesti.
• Further problems:
– Consider getting from Iasi to Fagaras
– Heuristic suggest that Neamt be expanded first, since it
is the closet to Fagaras
– But Neamt is a dead end
AI: Searching
A* Search
• f(n) = g(n) + h(n)
– f(n) – estimated cost of the cheapest solution through n
– g(n) – cost to reach to the node
– h(n) – cost to get from the node to the goal
• This is in fact a combination Greedy search (due to h(n)),
and uniform cost search (due to g(n)).
• Worst-case performance O(b{d})
• Worst-case space O(b{d})
AI: Searching
Example - A*
Arad
366=0+366
Arad
Timisoara ZerindSibiu
393=140+253447=118+329 449=75+374
(a) The initial state
(b) After expanding Arad
AI: Searching
A*- Cont’d
Arad
Timisoara ZerindSibi
u
449=75+374
Arad Fagaras Orade
a
Rimnicu
Vilcea
646=280+366415=239+176
671=291+380413=220+193
(c) After expanding Sibiu
AI: Searching
A*- Cont’d
(d) After expanding Rimnicu Vilcea
Sibiu
Arad Fagaras Oradea Rimnicu
Vilcea646=280+366 671=291+380
417=317+100
SibiuCraiova
526=366+160 553=300+253
Pitesti
415=239+176
AI: Searching
A*- Cont’d
(d) After expanding Fagaras
Sibiu
Arad Fagara
s
Oradea Rimnicu
Vilcea
646=280+366 671=291+380
BucharestSibiu
591=338+253450=450+0 417=317+100
SibiuCraiov
a526=366+160 553=300+253
Pitesti
AI: Searching
A*- Cont’d
(f) After expanding Pitesti
Sibiu
Arad Fagara
s
Orade
aRimnicu
Vilcea646=280+366 671=291+380
Buchares
t
Sibiu
591=338+253450=450+0
SibiuCraiova
526=366+160 553=300+253
Pitest
i
Buchares
t
Rimnicu
VilceaCraiov
a607=414+193
615=455+160418=418+0
AI: Searching
Comments on A*
• Note how A* find the path through Rimnica and Pitesti.
• So A* is complete and optimal
• Note: A* can be improved with iterative deepening search,
in which depth limit is the f-cost
AI: Searching