Title: Uninformed Search Methods for Deterministic, partially Accessible Problems
1Uninformed Search Methods forDeterministic,
partially Accessible Problems
2Searching for Solutions
- Search consists of choosing a state, testing if
it is a goal state, and if not then expanding the
state (i.e., generating a new set of states).
Repeat until no more states to expand. - Search strategy The choice of which state to
expand next. - Uninformed search strategy One that has no
information about the cost from a current state
to a goal (although it can use information from
the start state to the current state). - Search tree A data structure representing the
search process. A search tree consists of nodes
(corresponding to states) connected by
edges/arcs. (We distinguish nodes from states
two nodes can represent the same state. A state
is a representation of a physical configuration.) - Fringe (frontier) The collection of nodes in a
search tree waiting to be expanded. - 2 examples Wireless Ad Hoc Routing, and 8-Puzzle
3Important Note
- A path in the search tree represents a partial
solution. - If we reach a leaf (goal) node then the path
represents a whole solution.
4Example Problem
Neamt
Oradea
Iasi
Zerind
Sibiu
Arad
Fagaras
Vaslui
Timisoara
Rimnicu Vilcea
Lugoj
Bucharest
Urziceni
Mehadia
Hirsova
Pitesti
Dobreta
Eforie
Giurgiu
Craiova
5A Search Tree for This Problem
Arad
1. The root node (initial state)
Arad
2. After expanding Arad
Sibiu
Timisoara
Zerind
Arad
3. After expanding Sibiu
Sibiu
Timisoara
Zerind
Arad
Fagaras
Oradea
Rimnicu Vilcea
6General Search Algorithm
- function GENERAL-SEARCH(problem, strategy)
- returns a solution, or failure
- initialize the search tree using the initial
state of problem - loop do
- if there are no candidates for expansion then
return fail - choose a leaf node for expansion according to
strategy - if the node contains a goal state then return
solution - else expand node and add resulting nodes to
search tree - end
7An Implementation of the General Search Algorithm
- function GENERAL-SEARCH(problem, QUEUING-FN)
- returns a solution, or failure
- nodes MAKE-QUEUE(MAKE-NODE(INITIAL-STATEprobl
em)) - loop do
- if nodes is empty then return failure
- node REMOVE-FRONT(nodes)
- if GOAL-TESTproblem applied to STATE(node)
succeeds - then return node
- nodes QUEUING-FN(nodes, EXPAND(node,
-
OPERATORSproblem)) - end
8Criteria for Evaluating Search Strategies
- Criteria
- Completeness is the strategy guaranteed to find
a solution when there is one? - Time complexity how long does it take to find a
solution? - Space complexity how much memory does it need to
perform the search? - Optimality does the strategy find the
highest-quality solution when there are several
different solutions? - Time and space complexity measured in terms of
- b maximum branching factor in search tree
- d depth of least-cost solution
- m maximum depth of search space (may be
infinite)
9Breadth-First Search
- Expand shallowest unexpanded node first.
- QUEUING-FN put successors at end of queue.
- Algorithm
- Expand start state.
- Expand all states reachable from start state in
exactly 1 step. - Expand all states reachable from start state in
exactly 2 steps. - Keep doing this until goal state reached.
10Breadth-First Search to Find a Route in Romania
Arad
Queue ((Arad 0))
11Breadth-First Search to Find a Route in Romania
Arad
Sibiu
Timisoara
Zerind
Queue ((Sibiu 1) (Timisoara 1) (Zerind 1))
12Breadth-First Search to Find a Route in Romania
Arad
Sibiu
Timisoara
Zerind
(Arad)
Fagaras
Oradea
Rimnicu Vilcea
Oradea
(Arad)
Lugoj
(Arad)
Queue ((Timisoara 1) (Zerind 1) (Arad 2)
(Fagaras 2) (Oradea 2) (Rimnicu 2)) ((Zerind 1)
(Arad 2) (Fagaras 2) (Oradea 2) (Rimnicu 2)
(Lugoj 2) (Arad 2)) ((Arad 2) (Fagaras 2) (Oradea
2) (Rimnicu 2) (Lugoj 2) (Arad 2) (Oradea 2)
(Arad 2))
Note Can search forward from start state or
backward from goal state.
13Breadth-First Search
- It is complete.
- It will always find the shallowest goal first.
- It has time and space complexity of O(bd).
14Uniform Cost Search(Least-Cost Breadth-First
Search)
- Expand least-cost unexpanded node first.
- QUEUING-FN insert in order of increasing path
cost (this is a priority queue). - The cost to get to a node n (the path cost) is
g(n). - Breadth-first search is just uniform cost search
with g(n) depth(n).
15Uniform Cost Search to Find a Route in Romania
Arad
Queue ((Arad 0))
16Uniform Cost Search to Find a Route in Romania
Arad
75
140
118
Sibiu
Timisoara
Zerind
Queue ((Zerind 75) (Timisoara 118) (Sibiu 140))
17Uniform Cost Search to Find a Route in Romania
Arad
75
140
118
Zerind
Timisoara
Sibiu
75
71
Oradea
(Arad)
Queue ((Timisoara 118) (Sibiu 140) (Oradea 146)
(Arad 150))
18Uniform Cost Search to Find a Route in Romania
Arad
75
140
118
Zerind
Timisoara
Sibiu
75
71
111
118
Oradea
(Arad)
Lugoj
(Arad)
Queue ((Sibiu 140) (Oradea 146) (Arad 150)
(Lugoj 229) (Arad 236))
19Uniform Cost Search to Find a Route in Romania
Arad
140
75
118
Sibiu
Timisoara
Zerind
75
71
(Arad)
Fagaras
Oradea
Rimnicu Vilcea
Oradea
(Arad)
111
118
Lugoj
(Arad)
20Uniform Cost Search
- It is complete
- It has time and space complexity of O(bd).
21Uniform Cost Search Optimality
- Uniform cost search will always find the cheapest
solution provided that the cost of a path never
decreases as we follow the path. - This occurs if every operator/action has a
non-negative cost. - If some operator has a negative cost then you
must conduct an exhaustive search.
22Depth-First Search
- Expand deepest unexpanded node first.
- QUEUING-FN put successors at front of queue
(this is really a stack, so can use recursion to
do this implicitly). - Algorithm
- Always expand from the most recently expanded
node, if it has any untried successors. Else,
back up to the previous node on the current path.
23Depth-First Search to Find a Route in Romania
Arad
Queue ((Arad 0))
24Depth-First Search to Find a Route in Romania
Arad
Sibiu
Timisoara
Zerind
Queue ((Sibiu 1) (Timisoara 1) (Zerind 1))
25Depth-First Search to Find a Route in Romania
Arad
Sibiu
Timisoara
Zerind
(Arad)
Fagaras
Oradea
Rimnicu Vilcea
Queue ((Arad 2) (Fagaras 2) (Oradea 2) (Rimnicu
2) (Timisoara 1) (Zerind 1))
26Depth-First Search to Find a Route in Romania
Arad
Sibiu
Timisoara
Zerind
(Arad)
Fagaras
Oradea
Rimnicu Vilcea
Sibiu
Zerind
Timisoara
Queue ((Sibiu 3) (Timisoara 3) (Zerind 3)
(Fagaras 2) (Oradea 2) (Rimnicu 2) (Timisoara 1)
(Zerind 1))
Note This example illustrates the need to check
for state repetition to avoid infinite
cyclic excursions.
27Depth-First Search to Find a Route in Romania
Arad
Sibiu
Timisoara
Zerind
(Arad)
Fagaras
Oradea
Rimnicu Vilcea
Bucharest
Sibiu
Queue ((Bucharest 3) (Sibiu 3) (Oradea 2)
(Rimnicu 2) (Timisoara 1) (Zerind 1))
28Depth-First Search on the 8 Queens
Blue Conflict!
29Depth-First Search
- It is neither complete or optimal.
- It has time complexity of O(bm).
- But space complexity is only O(bm).
30Depth-Limited Depth-First Search
- Depth-limit for search is set at depth (level) l.
- Nodes at depth (level) l have no successors in
the search tree. - It is not optimal. It is complete if d lt l.
- It has time complexity of O(bl).
- But space complexity is only O(bl).
31Iterative Deepening Search
- function ITERATIVE-DEEPENING SEARCH(problem)
- returns a solution sequence
- inputs problem, a problem
- for depth 0 to infinite do
- if DEPTH-LIMITED-SEARCH(problem, depth)
succeeds - then return its result
- end
- return failure
32Iterative Deepening Search
- Combines the benefits of depth-first and
breadth-first search. - It is complete and optimal.
- It has time complexity of O(bd).
- But space complexity is only O(bd).
33Iterative Deepening Search to Find a Route in
Romania
l 0
Arad
34Iterative Deepening
l 1
Arad
35Iterative Deepening
l 1
Arad
Sibiu
Timisoara
Zerind
36Iterative Deepening
l 2
Arad
37Iterative Deepening
l 2
Arad
Sibiu
Timisoara
Zerind
38Iterative Deepening
Arad
l 2
Sibiu
Timisoara
Zerind
(Arad)
Fagaras
Oradea
Rimnicu Vilcea
39Iterative Deepening
Arad
l 2
Sibiu
Timisoara
Zerind
(Arad)
Fagaras
Oradea
Rimnicu Vilcea
(Arad)
Lugoj
40Iterative Deepening
Arad
l 2
Sibiu
Timisoara
Zerind
Oradea
(Arad)
Fagaras
Oradea
Rimnicu Vilcea
(Arad)
(Arad)
Lugoj
41Iterative Deepening Efficiency
- Iterative deepening looks inefficient because so
many states are expanded multiple times. In
practice this is not that bad, because by far
most of the nodes are at the bottom level. - For a branching factor b of 2, this might double
the search time. - For a branching factor b of 10, this might add
10 to the search time.
42Bidirectional Search with Breadth-First Search
- Algorithm
- Simultaneously
- Do a breadth-first search for goal state from
initial state. - Do a breadth-first search for initial state from
goal state. - Stop when a common node is found between the two
search fringes. - It is complete and optimal. Time and space
complexity are O(bd/2).
43Big Oh Comparison Between Uniformed Search
Strategies
Breadth- first
Uniform cost
Depth- first
Depth- limited
Iterative Deepening
Bi- directional
Time
Space
Optimal?
Complete?
44Uniform-Cost Search Re-visited
- How does uniform-cost handle graphs, where nodes
(such as goal nodes) are repeated in the search
tree, and you could visit a more expensive route
to the goal first?
45Uniform-Cost Algorithm
- 1. Search queue Q is empty.
- 2. Place the start state s in Q with path cost
0. - 3. If Q is empty, return failure.
- 4. Take node n from Q with lowest path cost.
- (Keep Q sorted by path cost and pick the
first element). - If n is a goal node, stop and return solution.
- (contd next slide)
46Uniform-Cost Algorithm (contd)
- 6. Generate successors of node n.
- 7. For each successor n of n do
- a) Compute path-cost(n) path-cost(n)
cost(n,n). - b) If n is new (never generated before), add n
to Q with its path cost. - c) If node n is already in Q with a higher path
cost, replace it with current (new) path cost,
and place it in sorted order in Q. - End for
- 8. Go back to step 3.
If you wish to keep track of solution path,
maintain a list of visited nodes with (node,
path-cost, parent-of-node) information, and add
node to visited list as soon as you place it in Q.
47Uniform-cost search in action
s
5
4
Queue ((s,0)) ((a,4),(b,5)) ((b,5),(g,13)) ((e,6)
,(c,10),(g,13)) ((g,7),(c,10),(g,13))
b
a
1
5
9
e
1
c
g
8
g
f
9
d
(also save the path to these nodes)
Assuming all edge costs positive, this is
complete and optimal.
48Uniform-Cost A seemingly deceptive example
s
2
1
4
Note that this still finds the optimal path
because when the yellow node is expanded, G1
will have higher cost than G2. This will cause
G2 to (finally) move to the front of the queue
and get tested to see if it is a goal node. It
satisfies the goal test, and search
terminates. The shortest path to the goal
is found.
a
b
1
c
1
Goal G2
d
1
Queue ((s,0)) ((a,1),(b,2)) ((c,2),(b,2)) ((b,2),
(d,3)) ((d,3),(g2,6)) ((e,4),(g2,6)) ((f,5),(g2,6)
) ((g2,6),(g1,25))
e
1
f
20
Goal G1
49Conclusions
- Breadth-first
- Time requirements are high.
- Memory requirements tend to be even more of a
problem than time. - On the other hand, it is optimal provided the
path cost is a non-decreasing function of the
depth of the node. - Uniform-cost
- Finds the cheapest solution -- if every operator
has a non-negative cost. - Typically more efficient than breadth-first when
costs vary.
50Conclusions
- Depth-first
- Has very modest memory requirements.
- Depth-first may be faster than breadth-first.
- Drawbacks Neither complete nor optimal. Should
be avoided for search trees with large or
infinite maximum depths. - Depth-limited
- Avoids problems with large or infinite
maximum-depth search trees. - However its still not complete or optimal. Its
only complete if - l lt d (i.e., the depth limit is less than
or equal to the depth of the solution).
51Conclusions
- Iterative deepening
- Incurs the overhead of multiple expansions.
- Nevertheless, iterative deepening is usually the
preferred search method when there is a large
search space and the depth of the solution is not
known. - Bidirectional search
- Requires
- Explicit goal states
- An efficient way to check each new node to see if
its already in the search tree of the other half
of the search - Invertible operators (should be easy to generate
predecessors of a state) - As with breadth-first search, its complete and
optimal. - Its more time and space efficient than
uni-directional searches.