ch3 blind search

63
Structures and Strategies for State Space Search 1 Ch 3. Structures and Strategies for State Space Search Introduction Graph Theory  Structures for state space search  state space representation of problems Strategies for state space search  Data-Driven and Goal-Driven Search  Implementing Graph Search  Depth-First and Breadth-First Search  Depth-First Search with Iterative Deepening Using the State Space to Represent Reasoning with the Predicate Calculus  State Space Description of a Logical System  AND/OR graphs  Examples and Applications

Upload: christian-bunag

Post on 29-Nov-2014

280 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ch3 Blind Search

Structures and Strategies for State Space Search 1

Ch 3. Structures and Strategies for State Space Search

IntroductionGraph Theory

Structures for state space searchstate space representation of problems

Strategies for state space searchData-Driven and Goal-Driven SearchImplementing Graph SearchDepth-First and Breadth-First SearchDepth-First Search with Iterative Deepening

Using the State Space to Represent Reasoning with the Predicate Calculus

State Space Description of a Logical SystemAND/OR graphsExamples and Applications

Page 2: Ch3 Blind Search

Structures and Strategies for State Space Search 2

Introduction(1)

Questions for designing search algorithmsIs the problem solver guaranteed to find a solution?Will the problem solver always terminate?When a solution is found, is it guaranteed to be optimal?What is the complexity of the search process?How can the interpreter most effectively reduce search complexity?How can the interpreter effectively utilize a representation language?

State space search is the tool for answering these questions.

Page 3: Ch3 Blind Search

Structures and Strategies for State Space Search 3

Introduction(2)

A graph consists of nodes and a set of arcs or links connecting pairs of nodes.Nodes are used to represent discrete states.

A configuration of a game board. (tic-tac-toe, p43)

Arcs are used to represent transitions between states.

Legal moves of a game

Leonhard Euler invented graph theory to solve the “bridge of Königsberg problem”

Is there a walk around the city that crosses each bridge exactly once. (Fig. 3.1, P82)

Page 4: Ch3 Blind Search

Structures and Strategies for State Space Search 4

State space representation of Tic-tac-toe

Page 5: Ch3 Blind Search

Structures and Strategies for State Space Search 5

Königsberg Bridge System (1)

Page 6: Ch3 Blind Search

Structures and Strategies for State Space Search 6

Königsberg Bridge System (2)

Euler focused on the degree of the nodes of the graph

Even degree node has an even number of arcs joining it to neighboring nodes.Odd degree node has an odd number of arcs.

Unless a graph contained either exactly zero or two nodes of odd degree, the walk was impossible.

No odd dgree node: the walk start at the first and end at the same nodeTwo odd degree nodes: the walk could start at the first and end at the second

Page 7: Ch3 Blind Search

Structures and Strategies for State Space Search 7

Definition of Graph(1)

A graph consists of nodes and arcs(Fig. 3.3, p85)A set of nodes N1, N2, …, Nn … need not be finite.A set of arcs connects pairs of nodes.

A directed graph has an indicated direction for traversing each arc(Fig. 3.3, p85)

If a directed arc connects Nj and Nk, then Nj is called the parent of Nk and Nk is called the child of Nj.

A rooted graph has a unique node Ns from which all paths in the graph originate (Fig. 3.4, p86)

A tip or leaf node is a node without children.

An ordered sequence of nodes [N1, N2, N3, … Nn] is called a path of length n-1 in the graph

Page 8: Ch3 Blind Search

Structures and Strategies for State Space Search 8

Definition of Graph (2)

On a path in a rooted graph, a node is said to be an ancestor of all nodes positioned after it (to its right) as well as a descendant of all nodes before it (to its left).A path that contains any node more than once is said to contain a cycle or loop.A tree is a graph in which there is a unique path between every pair of nodesTwo nodes in a graph are said to be connected if a path exists that includes them both.

Page 9: Ch3 Blind Search

Structures and Strategies for State Space Search 9

State Space Representation of Problems(1)

In the state space representation of a problem, the nodes of a graph corresponds to partial problem solution states, the arcs corresponds to steps in a problem-solving process.

State space search characterize problem solving as the process of finding a solution path from the start state to a goal.

Page 10: Ch3 Blind Search

Structures and Strategies for State Space Search 10

State Space Representation of Problems(2)

Definition : STATE SPACE SEARCHA state space is represented by a four tuple [N, A, S, GD] where

N is the set of states. A is the set of steps between states S is the start state(S) of the problem.GD is the goal state(S) of the problem. The states in GD are described:1. A measurable property of the states. (winning board in tic-tac-toe)2. A property of the path.(shortest path in traveling salesman problem)

A solution path is a path through this graph from S to GD.

Page 11: Ch3 Blind Search

Structures and Strategies for State Space Search 11

Tic-tac-toe (1)

The set of states are all different configurations of Xs and Os that the game can have. [N]

39 ways to arrange {blank, X, O} in nine spaces.

Arcs(steps) are generated by legal moves of the game, alternating between placing an X and an O in an unused location [A]

The start state is an empty board. [S]

The goal state is a board state having three Xs in a row, column, or diagonal. [GD]

Fig II.5 (p 43)

Page 12: Ch3 Blind Search

Structures and Strategies for State Space Search 12

Tic-tac-toe (2)

Page 13: Ch3 Blind Search

Structures and Strategies for State Space Search 13

Tic-tac-toe (3)

There are no cycles in the state space because the directed arcs of the graph do not allow a move to be undone.

The complexity of the problem : 9!(362,880) different path can be generated.

Need heuristics to reduce the search complexity. e.g. My possible winning lines – Opponent’s possible wining lines (Fig 4.16, p149)

Chess has 10120 possible game paths

Page 14: Ch3 Blind Search

Structures and Strategies for State Space Search 14

Possible Heuristic for Tic-tac-toe

Page 15: Ch3 Blind Search

Structures and Strategies for State Space Search 15

The 8-puzzle (1)

The set of states are all different configurations of 9 tiles (9!).

The legal moves are : move the blank tile up(↑), right(→), down(↓), and the left(←).

make sure that it does not move the blank off the board.All four moves are not applicable at all times.

The start state (e.g. Fig. 3.6, p90)

The goal state(e.g. Fig. 3.5, p89)

unlike tic-tac-toe, cycles are possible in the 8-puzzle.

Applicable heuristics (Fig. 4.8, p132)

Page 16: Ch3 Blind Search

Structures and Strategies for State Space Search 16

The 8 puzzle (2)

Page 17: Ch3 Blind Search

Structures and Strategies for State Space Search 17

Possible Heuristic for 8-puzzle

Page 18: Ch3 Blind Search

Structures and Strategies for State Space Search 18

The Traveling Salesperson(1)

The goal of the problem is to find the shortest path for the salesperson to travel, visiting each city, and then returning to the starting city.

The goal description requires a complete circuit with minimum cost.

The complexity of exhaustive search is (N-1)!, where N is the number of cities(Fig 3.8, p93)

Techniques for reducing the search complexity.Branch and Bound, The Nearest neighbor.

Page 19: Ch3 Blind Search

Structures and Strategies for State Space Search 19

The Traveling Salesperson(2)

Page 20: Ch3 Blind Search

Structures and Strategies for State Space Search 20

The Traveling Salesperson(3)

Branch and Bound technique1. Generate paths while keeping track of the best path found so

far.2. Use this value as a bound3. As paths are constructed one city at a time, examine each

partially completed path by guessing the best possible extension of the path (the branch).

4. If the branch has greater cost than the bound, it eliminates the partial path and all of its possible extensions.

The “Nearest Neighbor” techniqueGo to the closest unvisited city.(A E D B C A) is not the shortest path (Fig. 3.9, p93)

Other examples of State Space representationBlocks world (p 289), FWGC problem (p 622)

Page 21: Ch3 Blind Search

Structures and Strategies for State Space Search 21

The Traveling Salesperson(4)

Page 22: Ch3 Blind Search

Structures and Strategies for State Space Search 22

3.2.1 Data-Driven and Goal-Driven Search (1)

Data-driven search(forward chaining) takes the facts of the problem and applies the rules and legal moves to produce new facts that lead to a goal.

Goal-driven search (backward chaining) focused on the goal, finds the rules that could produce the goal, and chains backward through successive rules and subgoals to the given facts of the problem.

Both problem solvers search the same state space graph. The search order and the actual number of states searched can differ.

Page 23: Ch3 Blind Search

Structures and Strategies for State Space Search 23

3.2.1 Data-Driven and Goal-Driven Search (2)

The preferred strategy is determined by the properties of the problem: complexity of the rules, “shape” of the state space, the nature and availability of the problem data.

Confirming or denying the statement “I am a descendant of Thomas Jefferson.”

Assume that Thomas Jefferson was born about 250 years ago and that 25 years per generation and that 3 children per family I -> Jefferson (backward) 210 ancestorsJefferson -> I (forward) 310 nodes of family

Page 24: Ch3 Blind Search

Structures and Strategies for State Space Search 24

Goal-Driven Search is Suggested(1)

A goal or hypothesis is given in the problem statement or can easily be formulated.

Mathematics theorem prover, diagnostic systems

Early selection of a goal can eliminate most branches, making goal-driven search more effective in pruning the space. (Fig. 3.10 p95)

Mathematics theorem prover. (p94)

Problem data are not given but must be acquired.A medical diagnosis program. (p94)

Page 25: Ch3 Blind Search

Structures and Strategies for State Space Search 25

Goal-Driven Search is Suggested(2)

Page 26: Ch3 Blind Search

Structures and Strategies for State Space Search 26

Data-driven Search is Appropriate

All or most of the data are given in the initial problem statement.

PROSPECTOR interpreting geological data.

There are only a few ways to use the facts and given information.

DENDRAL finding the molecular structure of organic compounds. For any organic compound, enormous number of possible structures. The mass spectrographic data on a compound allow DENDRAL to eliminate most of possible structures.

Branching factor, availability of data, and ease of determining potential goals are carefully analyzed to determine the direction of search.

Page 27: Ch3 Blind Search

Structures and Strategies for State Space Search 27

Backtracking Search Algorithm

Backtracking is a technique for systematically trying all paths through a state space.

Search begins at the start state and pursues a path until it reaches either a goal or a “dead end”. If it finds a goal, returns the solution path. If it reaches a dead end, it backtracks to the most recent node on the path

Figure 3.12 (p 98)A→B→E→H→I→F→J→C→G

Page 28: Ch3 Blind Search

Structures and Strategies for State Space Search 28

Backtracking Search Example

Page 29: Ch3 Blind Search

Structures and Strategies for State Space Search 29

Function Backtrack (1)

BeginSL:=[start]; % state list (the states in the current pathpath)NSL:=[start]; % new state list(Nodes awaiting evaluation)

% nodes whose children are not yet been generatedDE:=[ ]; % dead ends (states whose descendants have failed to %

contain a goal node)CS:=start; % current statewhile NSL is not [ ] % while there are states to be tried

do beginif CS=goal

then return (SL) % on success, return list of states in pathif CS has no children (except nodes already on DE, SL, NSL)

then beginwhile SL is not empty and CS=the first element of SL

do begin

Page 30: Ch3 Blind Search

Structures and Strategies for State Space Search 30

Function Backtrack (2)

do begin add CS to DE;remove first element from SL; % backtrackremove first element from NSL;CS:=first element of NSL;

endadd CS to SL;

endelse begin % when CS has children

% the first child becomes new current state% and the rest are placed on NSL for future.

place children of CS (except nodes on DE) on NSL;CS:=first element of NSL;add CS to SL;

endendreturn FAIL;

end

Page 31: Ch3 Blind Search

Structures and Strategies for State Space Search 31

Function Backtrack (3)

Page 32: Ch3 Blind Search

Structures and Strategies for State Space Search 32

Ideas used in Backtrack algorithm

The list NSL is used to allow the algorithm to backtrack to any of these states.

The list DE is used to prevent the algorithm from retrying useless paths.

The list SL is used to keep track of the current solution path.

Explicit checks for membership of new states in these lists to prevent looping.

Page 33: Ch3 Blind Search

Structures and Strategies for State Space Search 33

Depth-First and Breadth-First Search

A search algorithm must determine the order in which states are examined.

Breadth-first search explores the spaceA, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U

(Figure 3.13, p100)Figure 3.15 (p 103)

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)

Figure 3.17 (p 105)

Page 34: Ch3 Blind Search

Structures and Strategies for State Space Search 34

Search Example

Page 35: Ch3 Blind Search

Structures and Strategies for State Space Search 35

Breadth-First Search (1)

Procedure breadth_first_search;begin

open := [Start];closed := [];while open ≠ [] do

beginremove 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 right end of open

endend

return(failure)end.

Page 36: Ch3 Blind Search

Structures and Strategies for State Space Search 36

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=[]

Page 37: Ch3 Blind Search

Structures and Strategies for State Space Search 37

Breadth first search (3)

Page 38: Ch3 Blind Search

Structures and Strategies for State Space Search 38

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 leftFigure 3.14 (p.101)

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)]

Page 39: Ch3 Blind Search

Structures and Strategies for State Space Search 39

Depth-First Search (1)

Procedure depth_first_search;begin

open := [Start];closed := [];while open ≠ [] do

beginremove 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.

Page 40: Ch3 Blind Search

Structures and Strategies for State Space Search 40

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]

Page 41: Ch3 Blind Search

Structures and Strategies for State Space Search 41

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.Figure 3.16 (p.104)

is not guaranteed to find the shortest path.

Page 42: Ch3 Blind Search

Structures and Strategies for State Space Search 42

Depth first search (4)

Page 43: Ch3 Blind Search

Structures and Strategies for State Space Search 43

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-Firstmay 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.

Page 44: Ch3 Blind Search

Structures and Strategies for State Space Search 44

Depth-First Search with Iterative Deepening

Depth-First Search with Iterative Deepeningperforms a depth-first search of the space with a depth bound of 1. If it fails to find a goal, it performs another depth-first search with a depth bound of 2. This continues, increasing the depth bound by one at each iteration.

Best-First Searchorders the states on the OPEN list according to some measure of their heuristic merit.

Page 45: Ch3 Blind Search

Structures and Strategies for State Space Search 45

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 ApplicationsMACSYMA (integration)Where is Fred?The Financial AdvisorEnglish Grammar

Page 46: Ch3 Blind Search

Structures and Strategies for State Space Search 46

3.3.1 State Space Description of a Logical System (p107)

Predicate calculus can be used as the formalspecification 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.

Page 47: Ch3 Blind Search

Structures and Strategies for State Space Search 47

Example 3.3.1 propositional calculus (1)

A set of assertions : q⇒p; r⇒p; v⇒q; s⇒r; t⇒r;s⇒u; 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 data of the problem

t s

Page 48: Ch3 Blind Search

Structures and Strategies for State Space Search 48

Example 3.3.1 propositional calculus (2)

Propositions that are logical consequences of the given set of assertions correspond to the nodes that 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 s⇒r yields r.r and r⇒p yields p.

Determining whether a given proposition is a logical consequence of a set of propositionsbecomes a problem of finding a path from a boxed node to the goal node.

Page 49: Ch3 Blind Search

Structures and Strategies for State Space Search 49

3.3.2 And/Or graphs (1)

If the premises of an implication are connected by an ∧ operator, they are called AND nodes, and the arcs from this node are joined by a curved link.q∧r⇒p 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.

Page 50: Ch3 Blind Search

Structures and Strategies for State Space Search 50

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.

Page 51: Ch3 Blind Search

Structures and Strategies for State Space Search 51

3.3.2 AND/OR graphs (3)

Page 52: Ch3 Blind Search

Structures and Strategies for State Space Search 52

And/Or graph Search

∧ operator(and nodes) indicates a problem decomposition in which the problem is broken into subproblems 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 problem-solving strategies.

Page 53: Ch3 Blind Search

Structures and Strategies for State Space Search 53

Example 3.3.3: Integration (1)

One example of an and/or graph is a program for symbolically integrating mathematical functions. (Fig. 3.22)In performing integrations, break an expression intosub-expressions that may be integrated independently and then combine the results algebraically into one solution expression.

Decomposition of a problem into independent subproblems can be 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

Page 54: Ch3 Blind Search

Structures and Strategies for State Space Search 54

Example 3.3.3: Integration (2)

Page 55: Ch3 Blind Search

Structures and Strategies for State Space Search 55

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[spanied(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).

Page 56: Ch3 Blind Search

Structures and Strategies for State Space Search 56

Example 3.3.4: “Where is fred?”(2)

Page 57: Ch3 Blind Search

Structures and Strategies for State Space Search 57

Example 3.3.4: “Where is fred?”(3)

To determine Fred’s locationcaluse 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.rule 9 & fact 3 & fact 4 ⇒ location(sam, museum)Location(fred, museum)

Goal driven search of the AND/OR graph

Page 58: Ch3 Blind Search

Structures and Strategies for State Space Search 58

Example 3.3.5: Investment Advice

an example of goal directed depth first search with backtracking

Goal: investment(X)try investment(savings).must prove savings_account(inadequate).amount_saved(X) ∧ dependents(Y) ∧ ¬ greater(X, minsavings(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.

Page 59: Ch3 Blind Search

Structures and Strategies for State Space Search 59

Example 3.3.5: Investment Advice

Page 60: Ch3 Blind Search

Structures and Strategies for State Space Search 60

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

Page 61: Ch3 Blind Search

Structures and Strategies for State Space Search 61

Example 3.3.6: English Grammar(2)

Page 62: Ch3 Blind Search

Structures and Strategies for State Space Search 62

Example 3.3.6: English Grammar(3)

AND/OR graph(Fig. 3.25) define rewrite rulesAND 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)

Rewrite rules are used to generate legal sentences.

Page 63: Ch3 Blind Search

Structures and Strategies for State Space Search 63

Example 3.3.6: English Grammar(4)