Chapter3 State Space Search

Preview:

Citation preview

Artificial IntelligenceArtificial Intelligence

Chapter 3Chapter 3

Structures and Strategies For State Structures and Strategies For State Space SearchSpace Search

Contents

• Introduction• Structures for State Space search

•Graph Theory•The Finite State Machine•State representation of problems

• Strategies for Space State Search•Data driven – Goal driven search•Depth Search – Breadth search•Depth First search with Iterative Deepening

• Using the State Space to represent Reasoning with the propositional and predicate calculus

•And /Or Graphs•Examples

Introduction The importance of the problem space

The choice of a problem space makes a big difference

in fact, finding a good abstraction is half of the problem

Intelligence is needed to figure out what problem space to use

the human problem solver is conducting a search in the space of problem spaces

Introduction

The theory of state space search is a primary tool for representing a problem as a state space graph , using graph theory to analyze the structure and complexity of the problem and the search procedure we employ to solve it

The city of Königsberg Swiss Leonhard Euler 18th cen Problem: if there is a walk around the city that

crosses each bridge exactly once?

RepresentationsEuler’s invented Graph of the Königsberg

bridge system- Euler Path

rb : river bank

I : island

b : bridge

Graph theoryNodes rb - iLinkes arcs - bEULER noted WALK WAS IMPOSSIBLE UNLESS A GRAPH HAS EXACTLY ZERO OR TWO NODES OF ODD DEGREESDegree no of arcs joining a node

Representing Königsberg bridge system- using predicate calculus

Predicate calculus: connect(X, Y, Z)connect(i1, i2, b1) connect(i2, i1, b1)

connect(rb1, i1, b2) connect(i1, rb1, b2)

connect(rb1, i1, b3) connect(i1, rb1, b3)

connect(rb1, i2, b4) connect(i2, rb1, b4)

connect(rb2, i1, b5) connect(i1, rb2, b5)

connect(rb2, i1, b6) connect(i1, rb2, b6)

connect(rb2, i2, b7) connect(i2, rb2, b7)

Connect :tow lands connected by a particular bridge

Graph Theory

A graph consists of a set of finite nodes N1,N2… and a set of arcs connecting the nodes

Arcs are orded pairs of nodes ie arc(N3,N4)… . If a directed arc connects Nj and Nk,

Nj is called the parent, and Nk is called the child. If Nj is also connected to Ni, Nk and Nj are siblings.

A rooted tree has a unique node which has no parents called the root. Each node in a rooted tree has a unique parent.

The edge in the rooted tree are directed away from the root

The path in a rooted tree is of length n-1 for a sequence of nodes (N1,N2,…,Nn.)

Graph Theory (cont’d)

On the path of the rooted tree a node is called an ancestor of all node after it and a descendant of all nodes before it

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 are said to be connected if a path exists that includes them both.

Tip or Leaf node is the node that has no children

Strucures for State Space Search

A labeled directed graph

Family relationships in a rooted tree

a is ancestor of g, h and i

(e f g h I j) Leaves or tips

a is Root

b is parent of( e f)

(g, h , i) children of c

(b , c , d ) are siblings

)b,e (are connected

Finite State Machine Finite-state machines can solve a large number of problems, among which

electronic design automation, communication protocol design, parsing and other engineering applications. In biology and artificial intelligence research, state machines or hierarchies of state machines are sometimes used to describe neurological systems and in linguistics — to describe the grammars of natural languages.

There are several action types: Entry action

which is performed when entering the state Exit action

which is performed when exiting the state Input action

which is performed depending on present state and input conditions Transition action

which is performed when performing a certain transition

http://en.wikipedia.org/wiki/Finite-state_machine

Finite State Machine (FSM)

(a) The finite state graph for a flip flop and

(b) its transition matrix.

Flip Flop FSM

The Finite State Machine

The Finite State Machine is finite directed connected graph (S, I , F): S : Set of states – nodes I : Set of input values - path F : State transaction function

FSM is an abstract model of computation. FSM Used to recognize component of a

formal language

(a)The finite state graph

(b)The transition matrix for string recognition example

(c)This called Moore machine – FS accepting M

String RecognitionExample for FSM for recognizing all strings contain the exact sequence “abc”

Starting

Accepting state

Finite State Accepting Machine

There are tow FSM techniques Deterministic FSM: transition function for any input value to a state gives a unique

next state Probabilistic FSM: the transition function defines a distribution of output states for

each input to a state

The State Space representation of Problems The problem space consists of: a state space which is a set of states representing the possible

configurations of the world- with initial state a set of operators (legal moves)which can change one state into

another - arcs The problem space can be viewed as a graph where the states

are the nodes and the arcs represent the operators. Pathes are searched until either the goal description is satisfied

or abandoned It is important to choose the best path according too the needs of

the problem

State Space and Search

State Space of Tic – Tac – Toe

•Start state : empty board

•Goal state:board with 3x’s in row column diagonal

•States are all possible configuration of X’s O’s

•It’s a directed graph rather than a tree - goal can be reached by different states

•No cycle

•Complexity = 9!

The 8-puzzle problem as state space search

states: possible board positions operators: one for sliding each square in

each of four directions,or, better, one for moving the blank square in each of four directions

initial state: some given board position goal state: some given board position Note: the “solution” is not interesting here, we

need the path.

• generated by “move blank” operations

-- up

-- left

-- down

-- left

• Cycles may occur:so it’s a graph-multiple parents

State Space of the 8-Puzzle

The travelling salesperson problem

Find the shortest path for the salesperson to travel, visiting each city and returning to the starting city

Search for the travelling salesperson problem. Each arc is marked with the total weight of all paths from the start node (A) to its endpoint.

The goal is the lowest – cost path - Goal 2 reach path not a state

The travelling salesperson problem

Complexity = (n-1)!

Other techniques for solving TSP –

Branch & bound with complexity=(1.26)n

Greedy nearest neighbour( E, D, B, C, A), at a cost of 550, is not the shortest path. The comparatively high cost of arc (C, A) defeated the heuristic.

Strategies for State Space Search

Data-driven search – forward chaining Begin with the given facts and a set of legal rules for

changing states Apply rules to facts to produce new facts Continue until it generate a path that satisfies the goal

condition Goal-driven search – backward chaining

Begin with the goal and a set of facts and legal rules Search rules that generate this goal Determine conditions must be true to use these rules (sub

goals) Continue until it works back to the facts of the problem

Goal Driven search

Goal driven is suggested if : A Goal is given or easily be formulated

(diagnostic systems) (theorem to be proved) Data are not given but acquired by solver Large no. of rules match the facts of the problem

State space in which goal-directed search effectively prunes extraneous search paths.

Goal-driven Search

Data Driven search

Data Driven is suggested if All or most of the data are given (PROSPECTOR

- Dipmeter) Large no of goals but few ways to use facts Difficult to form a goal

Dipmeter" is a measuring instrument to measure resonant frequency of radio frequency circuits. It measures the amount of absorption of a high frequency inductively coupled magnetic field by nearby object. http://en.wikipedia.org/wiki/Dipmeter

State space in which data-directed search prunes irrelevant data and their consequents and determines one of a number of possible goals.

Data-driven Search

GDS & DDS

Both goal-driven and data-driven search the same state space graph

Order and no. of states are different Preferred strategy is determined by:

Complexity of the rules Shape of state space Availability of problem data

Searching Strategies

•Heuristic search search process takes place by traversing search space with applied rules (information).

•Techniques: Greedy Best First Search, A* Algorithm

•There is no guarantee that solution is found.

•Blind search traversing backtracking the search space until the goal nodes is found (might be doing exhaustive search).

•Techniques : Breadth First,Depth first, Interactive Deepening search. Uniform Cost •guarantee that solution is found

Backtracking Search Search – find a path from start until reaches a

goal (quit) or dead end (backtrack) Backtrack – when the path is dead, try others

Backtrack to the most recent node

on the path having unexamined siblings Continue until find goal or

all children been searched

(backtrack fails back)

Backtrack algorithm

SL: start list-if the goal is found have the solution path

NSL : nodes waiting evaluation DE: dead end CS :state to evaluate : goal state

Stack : From left

Stack : From left

Backtracking search of a hypothetical state space space.

The Breadth-first search

Breadth-first search When a state is examined, all of its children are examined after

any of its siblings (all nodes in a given level before any node in the next level)

Explore the search space in a level-by-level fashion queue structured- states are added to the right and removed

from the left FIFO

1 234

Order of search : A , B , C , D , E , F , G

The breadth-first search algorithm

A trace of breadth-first search

The graph at iteration 6 of breadth-first search. States on open and closed are highlighted

Breadth-first search of the 8-puzzle, showing order in which states were removed from open

Depth-first search

Depth-first search When a state is examined, all of its children and

their descendants are examined before any of its siblings

Go deeper into the search space where possible Stack structure descendant states are added and

removed from the left of (open) list- LIFO

Depth-first search34

5

…….

The depth-first search algorithm

A trace of depth-first search

The graph at iteration 6 of depth-first search. States on open and closed are highlighted

Depth-first search of 8-puzzle with a depth bound of 5

Evaluation Criteria (Russel – Norvig)

completeness Is the problem solver guaranteed to find a solution?

time complexity how long does it take to find the solution?

space complexity memory required for the search

optimality When the solution is found is it guranteed to be optimal?

main factors for complexity considerations: branching factor b, depth d of the shallowest goal node,

maximum path length m

Comparison between breadth- and depth-first search (Luger)

Choosing between depends on the problem properties (shortest path-branching factor-available time length – no of needed sol’s-

Breadth-first Always find the shortest path to a goal- High branching factor (high no of

children for a state-in open list-

(need memory), complexity Bn child on n level

Depth-first More efficient (gets quickly into a deep search space) suitable for graphs

with many branches Complexity B*N (open contains just the children of a single state) May get lost missing shorter path or stuck with infinite long path does not

lead to goal

Depth – first Search with Iterative Deepening

Use the the depth search with depth bound 1-if it fails another search with depth bound 2 Solution lies within a certain depth or time constraints Level by level search = shortest path & space usage =in n

level = B*n Guaranteed to find a shortest solution (BFS) & space

usage = B*n Complexity O(b*n) Time complexity = O(B^n) = no of nodes grows

exponentaily

All these strategies- Blind - get exponentail time complexity for worst case

Iterative Deepening DFS (ID-DFS)

“Blind search”

BFS and DFS are blind in the sense that they have no knowledge about the problem at all other than the problem space

Such techniques are also called brute-force search, uninformed search, or weak methods

Using the State Space to Represent Reasoning with propositional and

predicate Calculus

State Space Description of a Logical SystemAND/OR GraphsFurther Examples and Applications

MACSYMA (integration)Where is Fred?The Financial AdvisorEnglish Grammar

State Space Description of a Logical System

The propositional and 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.

propositional calculus 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 sr yields r.r and rp yields p.

Determining whether a given proposition is a logical

consequence of a set of propositions becomes a

problem of finding a path from a boxed node to the

goal node.

propositional calculus 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

the arcs correspond to logical implications () propositions given true (s and t) correspond to

the given data of the problem and represented as boxed nodes.

Boxed nodes

Logical Operators

General NameFormal NameSymbols

NotNegation

AndConjunction

OrDisjunction

If… Then/ImpliesConditional

If and only ifBiconditional

The Truth Table

PQNOT(P)

ANDP ^ Q

ORP v Q

ImpliesP Q

BiconditionalP Q

TTFTTTT

TFFFTFF

FTTFTTF

FFTFFTT

Predicate Calculus Logic

Basic idea : operator (variables_1, variables_2,…) Example: “She likes chocolate” likes (she,

chocolate). Universal quantifier (X) to show all object is

true [Eg: All students (X (student (X))] Existential quantifier (X) to show existence /

partial object is true [ Eg: Some people ( X (people (X))]

And/Or graphs 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.

And/Or graph is actually a specialization of a type

of graph known as a hypergraph, which connects

nodes by sets of arcs.

And/or graph

• And/or graph of expression q r p

Or – separate arcs

• And/or graph of the expression q r → p

• and -- connected

, :operators

HYPERGRAGH

And/or graph of a set of propositional calculus expressions.

a

b

c

a b d

b d f

a c e

f g

a e h

•Is h true? Example for goal directed strategy

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.

Examples and Applications for and/or graph searching

Macsyma “Where is fred?” An English Language Parser and Sentence

Generator The Financial Advisor Revisited

MACSYMA : An Example for goal directed- and/or graph

And/or graph of part of the state space for integrating a function (goal directed)And/or graph of part of the state space for integrating a function (goal directed)

The facts and rules of this example are given as English sentences followed by their predicate calculus equivalents:

“Where is fred?”: Example for Checking English sentences Goal-directed and/or graph

The solution subgraph showing that Fred is at the museum.

An English Language Parser and Sentence Generator

Rewrite rules and transform it into another the pattern on one site of the with the pattern on the other side : For changing expression from language to

another Determine if sentences are well-formed

sentences

Rules for a simple subset of English grammar are:

And/or graph for the grammar. Some of the nodes (np, art, etc) have been written more than once to simplify drawing the graph.

An English Language Parser and Sentence Generator:

A parser needs :

Grammar rules

Terminals : dictionary of words in the language ( a , the , man , dog , likes , bites)

Parse tree for the sentence “The dog bites the man.”

•A Well –Formed expression in the grammar consists of terminals and that can be reduce to the sentence symbol

•Use data –driven parsing (maching right hand side and replace by the pattern on left

•Parsing is important for natural Languages– structuring compilers and interpretors for computer languages

Generating legal sentences by a goal driven search Begin with sentence as top level goal and end when no more

rules to apply Create all acceptable sentence

A sentence ia a np followed by a vp(1) Np is replaced by n (2) giving n vp Man is the first n available (8) giving man vp Np is satisfied and vp is attemped (3) replace vp with v giving

man v Replace v with likes (10 Man likes the first acceptable sentence – there are 80 correct

sentences Repeat until all possible state space has been searched

Parsing and generating can be used for completing sentences (correctnes not symentic)

And/or graph searched by the financial advisor.

Blind Search: Uniform-Cost

S

Size of Queue: 0

Nodes expanded: 0

Queue: Empty

Current action: Waiting…. Current level: n/a

Press space to begin the search

Current action: Expanding Current level: 0

Queue: SSize of Queue: 1

A

B

C

Size of Queue: 3 Queue: A, B, C

1

15

5

Nodes expanded: 1

S

Current level: 1

G

10A

Nodes expanded: 2

Queue: B, G11, C

Current action: Backtracking Current level: 0Current level: 1Current action: Expanding

5

Nodes expanded: 3

Queue: G10, G11, C15

B

Current level: 2

Queue: EmptySize of Queue: 0

FINISHED SEARCH

GGGGG

The goal state is achieved and the path S-B-G is returned. In relation to path cost, UCS has found the optimal route. Press space to end.