ku nlp artificial intelligence1 ch 3. structures and strategies for state space search q...

32
Artificial Intelligence 1 KU NLP KU NLP 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: diana-marshall

Post on 20-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 1

KU NLPKU NLP

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

Page 2: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 2

KU NLPKU NLP

Introduction(1)

Questions for designing search algorithms Is 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: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 3

KU NLPKU NLP

Introduction(2)

A graph consists of nodes and a set of arcs or lin

ks connecting pairs of nodes.

Nodes are used to represent discrete states. A configuration of a game board. (tic-tac-toe, p43, tp4)

Arcs are used to represent transitions between st

ates. Legal moves of a game

Leonhard Euler invented graph theory to solve th

e “bridge of Königsberg problem” Is there a walk around the city that crosses each bridge exac

tly once. (Fig. 3.1, P82, tp5)

Page 4: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 4

KU NLPKU NLP

State space representation of Tic-tac-toe (p 43)

Page 5: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 5

KU NLPKU NLP

Königsberg Bridge System (p82)

Page 6: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 6

KU NLPKU NLP

Königsberg Bridge System

Euler focused on the degree of the nodes of the g

raph Even degree node has an even number of arcs joining it to n

eighboring nodes. Odd degree node has an odd number of arcs.

Unless a graph contained either exactly zero or t

wo nodes of odd degree, the walk was impossible

. No odd dgree node: the walk start at the first and end at the

same node Two odd degree nodes: the walk could start at the first and e

nd at the second

Page 7: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 7

KU NLPKU NLP

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 e

ach arc(Fig. 3.3, p85)

If a directed arc connects Nj and Nk, then Nj is called the pa

rent of Nk and Nk is called the child of Nj.

A rooted graph has a unique node Ns from which all paths i

n 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: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 8

KU NLPKU NLP

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 nodes

Two nodes in a graph are said to be connected if

a path exists that includes them both.

Page 9: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 9

KU NLPKU NLP

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: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 10

KU NLPKU NLP

State Space Representation of Problems(2)

Definition : STATE SPACE SEARCH

A 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 sales ma

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

Page 11: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 11

KU NLPKU NLP

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, tp12)

Page 12: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 12

KU NLPKU NLP

Tic-tac-toe (2)

Page 13: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 13

KU NLPKU NLP

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, tp14)

Chess has 10120 possible game paths

Page 14: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 14

KU NLPKU NLP

Possible Heuristic for Tic-tac-toe

Page 15: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 15

KU NLPKU NLP

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, tp16)

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, tp17)

Page 16: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 16

KU NLPKU NLP

The 8 puzzle (2)

Page 17: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 17

KU NLPKU NLP

Possible Heuristic for 8-puzzle

Page 18: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 18

KU NLPKU NLP

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: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 19

KU NLPKU NLP

The Traveling Salesperson(2)

Page 20: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 20

KU NLPKU NLP

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” technique Go to the closest unvisited city. (A E D B C A) is not the shortest path (Fig. 3.9, p93, tp21)

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

Page 21: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 21

KU NLPKU NLP

The Traveling Salesperson(4)

Page 22: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 22

KU NLPKU NLP

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 goa

l, finds the rules that could produce the goal, and chains ba

ckward through successive rules and subgoals to the given

facts of the problem.

Both problem solvers search the same state space graph. T

he search order and the actual number of states searched c

an differ.

Page 23: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 23

KU NLPKU NLP

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 임꺽정 .” Assume that 임꺽정 was born about 250 years ago and that

25 years per generation and that 3 children per family I -> 임꺽정 (backward) 210 ancestors 임꺽정 -> I (forward) 310 nodes of family

Page 24: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 24

KU NLPKU NLP

Goal-Driven Search is Suggested(1)

A goal or hypothesis is given in the problem state

ment or can easily be formulated. Mathematics theorem prover, diagnostic systems

Early selection of a goal can eliminate most branc

hes, making goal-driven search more effective in

pruning the space. (Fig.3.10 p95, tp25) Mathematics theorem prover: total # of rules to produce a gi

ven theorem is much smaller than # of rules that may be applied to the entire set of axioms

Problem data are not given but must be acquired. A medical diagnosis program: Doctor order only diagnostic t

ests that are necessary to confirm or deny a hypothesis

Page 25: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 25

KU NLPKU NLP

Goal-Driven Search is Suggested(2)

Page 26: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 26

KU NLPKU NLP

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: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 27

KU NLPKU NLP

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, tp28)ABEHIFJCG

Page 28: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 28

KU NLPKU NLP

Backtracking Search Example

Page 29: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 29

KU NLPKU NLP

Function Backtrack (1)

Begin

SL:=[start]; % state list (the states in the current pathpath)

NSL:=[start]; % new state list(Nodes awaiting evaluation)

% nodes whose children are not yet been generated

DE:=[ ]; % dead ends (states whose descendants have failed to % contain a goal node)

CS:=start; % current state

while NSL is not [ ] % while there are states to be tried

do begin

if CS=goal

then return (SL) % on success, return list of states in path

if CS has no children (except nodes already on DE, SL, NSL)

then begin

while SL is not empty and CS=the first element of SL

do begin

Page 30: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 30

KU NLPKU NLP

Function Backtrack (2)

do begin add CS to DE; remove first element from SL; % backtrack remove first element from NSL; CS:=first element of NSL; end add CS to SL; end else 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; end end return FAIL;end

Page 31: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 31

KU NLPKU NLP

Function Backtrack (3)

Page 32: KU NLP Artificial Intelligence1 Ch 3. Structures and Strategies for State Space Search q Introduction q Graph Theory  Structures for state space search

Artificial Intelligence 32

KU NLPKU NLP

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.