Chapter S:III (continued)

Chapter S:III
(continued)
III. Basic Search Algorithms
q Graph Search Basics
q Hill-Climbing
q Depth-First Search
q Backtracking
q Breadth-First Search
q Uniform-Cost Search
q Depth-First Search of AND-OR Graphs
S:III-69
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Breadth-First Search (BFS)
[UCS]
Breadth-first search is an uninformed, systematic search strategy.
BFS characteristics:
q
Nodes at upper levels in G are preferred.
q
Node expansion happens in levels of equal depth.
q
Terminates (on locally finite graphs) with a solution, if one exists.
q
Determines a goal node that is closest to the start node s, measured in the
number of edges on a solution path.
S:III-70
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Remarks:
q Operationalization of BFS: The OPEN list is organized as a queue, i.e., nodes are explored
in a FIFO (first in first out) manner. [OPEN list DFS] [OPEN list UCS]
q By enqueuing newly generated successors in OPEN (insertion at the tail) instead of
pushing them (insertion at the head), DFS is turned into BFS.
S:III-71
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Breadth-First Search
Algorithm:
BFS
Input:
s. Start node representing the initial problem.
successors(n). Returns the successors of node n.
?(n). Predicate that is True if n is a goal node.
⊥ (n). Predicate that is True if n is a dead end.
Output:
A goal node or the symbol Fail.
S:III-72
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Breadth-First Search
BFS(s, successors, ?, ⊥)
1. push(s, OPEN);
2. LOOP
3.
IF ( (OPEN = ∅) OR memory _exhausted() ) THEN RETURN(Fail);
4.
n = pop(OPEN);
push(n, CLOSED);
FOREACH n0 IN successors(n) DO
// Expand n.
0
enqueue(n , OPEN);
// Insert node at the end of OPEN.
0
set_backpointer (n , n);
IF ?(n0 ) THEN RETURN(n0 );
IF ⊥ (n0 )
THEN
remove_last(OPEN);
cleanup_closed();
ENDIF
ENDDO
6. ENDLOOP
5.
S:III-73
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Breadth-First Search
BFS(s, successors, ?, ⊥)
1. push(s, OPEN);
2. LOOP
3.
IF ( (OPEN = ∅) OR memory _exhausted() ) THEN RETURN(Fail);
4.
n = pop(OPEN);
push(n, CLOSED);
FOREACH n0 IN successors(n) DO
// Expand n.
0
enqueue(n , OPEN);
// Insert node at the end of OPEN.
0
set_backpointer (n , n);
IF ?(n0 ) THEN RETURN(n0 );
IF ⊥ (n0 )
THEN
remove_last(OPEN);
cleanup_closed();
ENDIF
ENDDO
6. ENDLOOP
5.
S:III-74
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Breadth-First Search
Discussion
BFS issue:
q
S:III-75
Unlike depth-first search, BFS has to store the explored part of the graph
completely. Q. Why?
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Breadth-First Search
Discussion
BFS issue:
q
Unlike depth-first search, BFS has to store the explored part of the graph
completely. Q. Why?
Breadth-first search can be the favorite strategy in certain situations:
S:III-76
Basic Search Algorithms
x
OPEN
x
CLOSED
x
Dead end
x
Goal
© STEIN/LETTMANN 1998-2015
Breadth-First Search
Example: 4-Queens Problem
BFS node processing sequence:
a
i
Q
Q
Q
Q
x
OPEN
x
CLOSED
x
Dead end
x
Goal
e
b
c
d
j
k
f
g
h
i
S:III-77
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Breadth-First Search
Example: 4-Queens Problem
BFS node processing sequence:
a
i
Q
Q
Q
Q
x
OPEN
x
CLOSED
x
Dead end
x
Goal
e
b
c
d
j
k
f
g
k
h
a
i
Compare to the DFS strategy:
b
c
f
d
e
j
g
h
i
S:III-78
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Uniform-Cost Search
[BFS]
Uniform-cost search is an uninformed, systematic search strategy.
Uniform-cost search characteristics:
q
Node expansion happens in levels of equal costs:
A node n with cost CPs−n will not be expanded as long as a non-expanded
node n0 with CPs−n0 < CPs−n resides on the OPEN list.
≈ Application of the BFS strategy to solve optimization problems.
S:III-79
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Remarks:
q Operationalization of uniform-cost search: The OPEN list is organized as a heap, and
nodes are explored wrt. the cheapest cost. [OPEN list DFS] [OPEN list BFS]
q The notation CPs−n is an abbreviation for CPs−n (s) and (in this uniform-cost search) defines
the sum cost of a path from s to n. [S:III Graph Search Basics]
q Uniform-cost search is also called cheapest-first search.
S:III-80
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Uniform-Cost Search
Uniform-Cost Search for Optimization: Generic
Setting:
The search space graph contains several solution paths.
q
Task:
q
Determine the cheapest path from s to some goal γ ∈ Γ.
Approach:
q
Continue search with the cheapest partial solution obtained so far.
q
Continue search only until the costs of the partial solutions exceed the
currently optimum cost. Keyword: Early Pruning
Prerequisite:
q
S:III-81
The accumulated cost on each path increase monotonically.
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Uniform-Cost Search
Uniform-Cost Search for Optimization: Example
Determine the minimum column sum of a matrix:
S:III-82
8
3
6
7
6
5
9
8
5
3
7
8
1
2
4
6
Basic Search Algorithms
s
8
3
6
7
© STEIN/LETTMANN 1998-2015
Uniform-Cost Search
Uniform-Cost Search for Optimization: Example
Determine the minimum column sum of a matrix:
8
3
6
7
6
5
9
8
5
3
7
8
1
2
4
6
s
8
3
6
7
Comparison of uniform-cost search (left) and DFS (right):
s
s
20
S:III-83
13
8
3
6
7
8
3
6
7
14
8
15
15
6
5
9
8
11
5
3
13
1
2
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
The different search space representations entail different termination tests:
q
State-space graph: analyze a single node (leaf node of a path)
q
AND-OR graph: analyze a set of nodes (leaf nodes of a particular subgraph)
S:III-84
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
The different search space representations entail different termination tests:
q
State-space graph: analyze a single node (leaf node of a path)
q
AND-OR graph: analyze a set of nodes (leaf nodes of a particular subgraph)
Recall the termination test in AND-OR graph:
q
We have to answer the question: Allows the currently known subgraph of the
search space graph for the instantiation of a solution graph?
q
To do: Propagate knowledge about solved or unsolvable problems using the
solved- or unsolvable-labeling procedure.
q
Nodes whose labels have been propagated can be discarded.
Approach: Use DFS for the labeling.
S:III-85
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Solved Labeling Using DFS
s
-
- +
-
+ -
+ -
unsolved / solved rest problem
S:III-86
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Solved Labeling Using DFS
s
(1)
-
- +
-
+ -
+ -
unsolved / solved rest problem
S:III-87
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Solved Labeling Using DFS
s
(1)
s
(2)
(1)
-
- +
-
+ -
+ -
-
+
+ -
+ -
unsolved / solved rest problem
S:III-88
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Solved Labeling Using DFS
s
(1)
s
(2)
(1)
-
- +
-
+ -
+ -
-
+
+ -
+ -
unsolved / solved rest problem
s
(2)
(1)
(3)
deleted nodes
S:III-89
+
+
Basic Search Algorithms
+ -
+ © STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Solved Labeling Using DFS
s
(1)
s
(2)
(1)
-
- +
-
+ -
+ -
-
+
+ -
+ -
unsolved / solved rest problem
s
(2)
(1)
(3)
+
(2)
(1)
(3)
(4)
deleted nodes
s
current path
deleted nodes
+
S:III-90
+
+
Basic Search Algorithms
+ -
+ -
-
+
+
+
+ -
+ -
© STEIN/LETTMANN 1998-2015
Remarks:
q Depth-first search realizes a recursive solution graph search, similar to the inductive
solution graph definition.
q If a solution graph has to fulfill additional constraints (due to optimality requirements or
particularities of the domain), a DFS-based solution labeling can be applied only if the
imposed constraint fulfillment can be checked recursively as well.
If a recursive constraint analysis is infeasible, we may transform the problem-reduction
graph into a state-space graph (as shown for the counterfeit problem) and then apply DFS
on the transformed graph.
S:III-91
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Solution Labeling Using DFS
(1)
s
(L (L))
+ -
S:III-92
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Solution Labeling Using DFS
(1)
s
(1)
(2)
(L (L))
s
(L (L))
(L (L))
(R (L))
+ -
S:III-93
Basic Search Algorithms
+ -
+
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Solution Labeling Using DFS
(1)
s
(1)
(2)
s
(L (L))
(L (L))
(L (L))
(R (L))
+ -
(1)
(2)
(3)
s
+ -
+
(R (L (L)) (R (L)))
(L (L))
(L (L))
(R (L))
(R (L))
+ S:III-94
Basic Search Algorithms
+
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Solution Labeling Using DFS
(1)
s
(1)
(2)
s
(L (L))
(L (L))
(L (L))
(R (L))
+ -
(1)
(2)
(3)
s
+ -
(R (L (L)) (R (L)))
(L (L))
(L (L))
(R (L))
(1)
(2)
(3)
(4)
s
+
(R (L(R
(L))(L(R
(L)))
(L))
(R (L)))
(L (L))
(L (L))
(R (L))
(R (L))
+ S:III-95
Basic Search Algorithms
+
(R (L))
+ -
+
© STEIN/LETTMANN 1998-2015
Remarks:
q If in DFS nodes are discarded soon after their labels have been propagated, a code for
reconstructing the solution graph needs to be propagated as well.
q In the shown illustration the code describes the chosen operators (L or R), whereas the
nesting level of the parentheses indicates the depth of the tree.
S:III-96
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Redundant Problem Solving
DFS cannot exploit the compact encoding of problem-reduction representations.
Reason: AND-OR graphs contain only a single instance of identical subproblems,
DFS maintains only a path from s to the current node.
Ü Identical subproblems may be encountered on different paths and solved
several times by DFS.
Ü If AND-OR graphs are searched with DFS, redundancy cannot be avoided.
S:III-97
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Redundant Problem Solving
DFS cannot exploit the compact encoding of problem-reduction representations.
Reason: AND-OR graphs contain only a single instance of identical subproblems,
DFS maintains only a path from s to the current node.
Ü Identical subproblems may be encountered on different paths and solved
several times by DFS.
Ü If AND-OR graphs are searched with DFS, redundancy cannot be avoided.
AND-OR graph (left) and its exploration (= enfolding) with DFS (right):
s
s
t0
A
+
A
B
...
...
t1
B
+
A
+
S:III-98
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Remarks:
q With a complete occurrence check, i.e., an occurrence check that considers all explored
nodes so far, recurring subproblems can be identified.
q A complete occurrence check entails a memory consumption similar to BFS, which renders
such a check very unattractive—if not impossible. In most cases the small memory footprint
of DFS along with a usually manageable effort for resolving (a small number of) recurring
problems makes DFS superior to BFS when searching AND-OR graphs.
q Recall that by omitting an occurrence check we cannot identify loops in the search space
graph.
q The path from s to the current node, i.e., the partial solution path, is also called traversal
path [Pearl 84]. Recall that DFS stores the partial solution path on the CLOSED list.
q A partial occurrence check, which is limited to the nodes on the traversal path, is both
computationally manageable and prohibits infinite loops caused by recurrent problem
solving: Nodes that are encountered twice on the traversal path are discarded.
S:III-99
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Dealing with Cycles (1)
AND-OR graph (left) and its exploration (= enfolding) with DFS (right):
S:III-100
Basic Search Algorithms
s
A
A
+
B
...
s
+
B
A
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Dealing with Cycles (1)
AND-OR graph (left) and its exploration (= enfolding) with DFS (right):
S:III-101
Basic Search Algorithms
s
A
A
+
B
...
s
+
B
(partial)
ocurrence check
A
+
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Dealing with Cycles (2)
AND-OR graph (left) and its exploration (= enfolding) with DFS (right):
s
A
B
+
S:III-102
Basic Search Algorithms
+
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Dealing with Cycles (2)
AND-OR graph (left) and its exploration (= enfolding) with DFS (right):
s
s
t0
A
B
+
A
Basic Search Algorithms
B
+
(partial)
ocurrence check
S:III-103
t1
A
B
A
+
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Dealing with Cycles (2)
AND-OR graph (left) and its exploration (= enfolding) with DFS (right):
s
s
t0
A
B
+
A
Basic Search Algorithms
B
B
+
(partial)
ocurrence check
S:III-104
t1
A
A
+
B
© STEIN/LETTMANN 1998-2015
Depth-First Search of AND-OR Graphs
Dealing with Cycles (2)
AND-OR graph (left) and its exploration (= enfolding) with DFS (right):
s
s
t0
A
B
+
A
Basic Search Algorithms
B
B
+
(partial)
ocurrence check
S:III-105
t1
A
A
+
B
+
© STEIN/LETTMANN 1998-2015
Remarks:
q Q. Why does the discarding of recurring nodes (partial occurrence check) not compromise
the soundness of solved-labeling?
q Recapitulation. When searching an AND-OR graph with DFS, a partial occurrence check
cannot address the issue of redundant problem solving in general.
q Given the previous AND-OR graph (2), breadth-first search would have found a solution in
depth 2 already.
S:III-106
Basic Search Algorithms
© STEIN/LETTMANN 1998-2015