ku nlp structures and strategies for state space search33 3.2.3depth-first and breadth-first search...
TRANSCRIPT
Structures and Strategies for State Space Search
1
KU NLPKU NLP
3.2.3Depth-First and Breadth-First Search
A search algorithm must determine the order in
which states are examined.
Breadth-first search explores the space A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U
(Figure 3.13, p100, tp34) Figure 3.15 (p 103, tp37)
Depth-first search goes deeper into the search
space whenever this is possible. A, B, E, K, S, L, T, F, M, C, G, N, H, O, P, U, D, I, Q, J, R
(Figure 3.13, p100, tp34) Figure 3.17 (p 105, tp42)
Structures and Strategies for State Space Search
3
KU NLPKU NLP
Breadth-First Search (1)
Procedure breadth_first_search;begin open := [Start]; closed := []; while open [] do
begin remove leftmost state from open, call it X;
if X is a goal then return(success) else begin
generate children of X;put X on closed;
/* loop check */ eliminate children of X on open or closed;/* queue */ put remaining children on right end of open
endend
return(failure)end.
Structures and Strategies for State Space Search
4
KU NLPKU NLP
Breadth-First Search(2)
1. open=[A]; closed=[]
2. open=[B,C,D]; closed=[A]
3. open=[C,D,E,F]; closed=[B,A]
4. open=[D,E,F,G,H]; closed=[C,B,A]
5. open=[E,F,G,H,I,J]; closed=[D,C,B,A]
6. open=[F,G,H,I,J,K,L]; closed=[E,D,C,B,A]
7. open=[G,H,I,J,K,L,M] (as L is already on open);
closed=[F,E,D,C,B,A]
8. open=[H,I,J,K,L,M,N]; closed=[G,F,E,D,C,B,A]
9. And so on until either U is found or open=[]
Structures and Strategies for State Space Search
6
KU NLPKU NLP
Breadth-First Search (4)
OPEN lists states that have been generated but whose children have not been examined.
CLOSED records states that have already been examined.
OPEN is maintained as a queue, FIFO data structure. States are added to the right of the list and removed from the left
Breadth-first search is guaranteed to find the shortest path from the start state to the goal.
If the path is required for a solution, we can store ancestor information along with each state. open = [(D,A), (E,B), (F,B), (G,C), (H,C)] closed = [(C,A), (B,A), (A,nil)]
Structures and Strategies for State Space Search
7
KU NLPKU NLP
Depth-First Search (1)
Procedure depth_first_search;begin open := [Start]; closed := []; while open [] do
begin remove leftmost state from open, call it X;
if X is a goal then return(success) else begin
generate children of X;put X on closed;eliminate children of X on open or closed;put remaining children on left end of open
endend
return(failure)end.
Structures and Strategies for State Space Search
8
KU NLPKU NLP
Depth-First Search (2)
1. open=[A]; closed=[]
2. open=[B,C,D]; closed=[A]
3. open=[E,F,C,D]; closed=[B,A]
4. open=[K,L,F,C,D]; closed=[E,B,A]
5. open=[S,L,F,C,D]; closed=[K,E,B,A]
6. open=[L,F,C,D]; closed=[S,K,E,B,A]
7. open=[T,F,C,D]; closed=[L,S,K,E,B,A]
8. open=[F,C,D]; closed=[T,L,S,K,E,B,A]
9. open=[M,C,D], as L is already on closed; closed=[F,T,L,S,K,E,B,A]
10. open=[C,D]; closed=[M,F,T,L,S,K,E,B,A]
11. open=[G,H,D]; closed=[C,M,F,T,L,S,K,E,B,A]
Structures and Strategies for State Space Search
9
KU NLPKU NLP
Depth-First Search (3)
OPEN is maintained as a stack, or LIFO data
structure. The state are both added and removed from the left end of
OPEN.
is not guaranteed to find the shortest path.
Structures and Strategies for State Space Search
11
KU NLPKU NLP
Depth-First vs. Breadth-First
The choice depends on the specific problem being solved.
Significant features include the importance of finding the
shortest path, the branching of the state space, the
available time and space resources, the average length of
paths to a goal node, and whether we want all solutions or
only the first solution.
Breadth-First always finds the shortest path to a goal node. If there is a bad branching factor, the combinatorial explosion
may prevent the algorithm from finding a solution.
Depth-First may not waste time searching a large number of shallow state
in the graph. can get lost deep in a graph missing shorter paths to goal.
Structures and Strategies for State Space Search
12
KU NLPKU NLP
3.3 Using the State Space to Represent Reasoning with the Predicate Calculus
3.3.1 State Space Description of a Logical System
3.3.2 AND/OR Graphs
3.3.3 Further Examples and Applications MACSYMA (integration) Where is Fred? The Financial Advisor English Grammar
Structures and Strategies for State Space Search
13
KU NLPKU NLP
3.3.1 State Space Description of a Logical System (p107)
Predicate calculus can be used as the formal
specification language for making nodes
distinguishable as well as for mapping the nodes
of a graph onto the state space.
Inference rules can be used to create and
describe the arcs between states.
Problems in the predicate calculus, such as
determining whether a particular expression is a
logical consequence of a given set of assertions,
may be solved using search.
Structures and Strategies for State Space Search
14
KU NLPKU NLP
Example 3.3.1 propositional calculus (1)
A set of assertions : qp; rp; vq; sr; tr;
su; s; t;
State space graph of a set of implications
p
q r u
v
the arcs correspond to logical implications () propositions given true (s and t) correspond to the given dat
a of the problem
t s
Structures and Strategies for State Space Search
15
KU NLPKU NLP
Example 3.3.1 propositional calculus (2)
Propositions that are logical consequences of the
given set of assertions correspond to the nodes t
hat may be reached along a directed path from a
state representing a true proposition. [s,r,p] corresponds to the sequence of inferences:
s and sr yields r.r and rp yields p.
Determining whether a given proposition is a logi
cal consequence of a set of propositions become
s a problem of finding a path from a boxed node t
o the goal node.
Structures and Strategies for State Space Search
16
KU NLPKU NLP
3.3.2 And/Or graphs (1)
If the premises of an implication are connected b
y an operator, they are called AND nodes, and t
he arcs from this node are joined by a curved link
.
qrp is represented by
And/Or graph is actually a specialization of a type
of graph known as a hypergraph, which connects
nodes by sets of arcs.
Structures and Strategies for State Space Search
17
KU NLPKU NLP
3.3.2 And/Or graphs (2)
Definition : HYPERGRAPH
A hypergraph consists of :
N, a set of nodes.
H, a set of hyperarcs.
Hyperarcs are also known as k-connections, where K is the cardinality of the set of descendant nodes.
If k=1, OR node, If k>1, AND nodes.
Structures and Strategies for State Space Search
19
KU NLPKU NLP
And/Or graph Search
operator(and nodes) indicates a problem decom
position in which the problem is broken into subp
roblems such that all of the subproblems must be
solved to solve the original problem.
operator indicates a selection, a point at which
a choice may be made between alternative proble
m-solving strategies.
Structures and Strategies for State Space Search
20
KU NLPKU NLP
Example 3.3.3: Integration (1)
One example of an and/or graph is a program for symbolically integrating mathematical functions. (Fig. 3.22, p112, tp53)
In performing integrations, break an expression into sub-expressions that may be integrated independently and then combine the results algebraically into one solution expression. Decomposition of a problem into independent subproblems can b
e represented by AND nodes in the graph.
Simplification of an expression can be done by various algebraic substitutions A number of different substitutions are represented by OR nodes
of the graph.
An obvious example of Goal-directed search
Structures and Strategies for State Space Search
22
KU NLPKU NLP
Example 3.3.4: “Where is fred?”(1)
Given facts and rules1. collie(fred).
2. master(fred, sam).
3. day(saturday).
4. (warm(saturday)).
5. trained(fred).
6. X[spaniel(X) (collie(X) trained(X)) gooddog(X)]
7. (X,Y,Z)[goodog(X) master(X,Y) location(Y,Z) location(X,Z)]
8. day(saturday) warm(saturday) location(sam, park).
9. day(saturday) (warm(saturday)) location(sam, museum).
Structures and Strategies for State Space Search
24
KU NLPKU NLP
Example 3.3.4: “Where is fred?”(3)
To determine Fred’s location caluse 7: location(fred, Z) The premises of the rule 7 must be proved. gooddog(fred) master(fred,Y) location(Y,Z). rule 6 & fact 1 & fact 5 gooddog(fred) is proved. master(fred,sam) by fact 2. {sam/Y} location(sam, Z) must be proved. Rule 7 is failed (because gooddog(sam) is not true) rule 8 is failed. (because warm(saturday) is not true) rule 9 & fact 3 & fact 4 location(sam, museum) Location(fred, museum)
Goal driven search of the AND/OR graph
Structures and Strategies for State Space Search
25
KU NLPKU NLP
Example 3.3.5: Investment Advice
an example of goal directed depth first search wit
h backtracking
Goal: investment(X) try investment(savings). must prove savings_account(inadequate). amount_saved(X) dependents(Y) greater(X, minsaving
s(Y)) (given X=20,000, Y=2) greater(X,minsavings(Y)) is false. backtrack to investment(stocks). savings_account(adequate) income(adequate). both are proved true.
Structures and Strategies for State Space Search
27
KU NLPKU NLP
Example 3.3.6: English Grammar(1)
A set of rewrite rules for parsing sentences can
be represented by AND/OR graph.
The rules are used to parse sequence of words,
i.e. to determine whether they are well-formed
sentences.
Simple subset of English grammar:1. Sentence NP VP 6. ART a2. NP N 7. ART the3. NP ART N 8. N man4. VP V 9. N dog5. VP V NP 10. V likes11. V bites
Structures and Strategies for State Space Search
29
KU NLPKU NLP
Example 3.3.6: English Grammar(3)
AND/OR graph(Fig. 3.25, tp60) define rewrite rules AND nodes correspond to RHS of the rule. Multiple rules with the same conclusion from the OR node.
An expression is well formed in a grammar if it
consists entirely of terminal symbols and there is a
series of substitutions in the expression using
rewrite rules that reduce it to the SENTENCE
symbol.
A date-driven parsing algorithm parse the input
sentence constructing the parse tree. “The dog bites the man.” (Fig. 3.26, p119, tp62)
Rewrite rules are used to generate legal sentences.