You are on page 1of 75

# Artificial Intelligence

Chapter 3
Structures and Strategies For State
Space 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 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? .

b EULER noted WALK WAS IMPOSSIBLE UNLESS A GRAPH HAS EXACTLY ZERO OR TWO NODES OF ODD DEGREES Degree no of arcs joining a node .Representations Euler’s invented Graph of the Königsberg bridge system.i Linkes arcs .Euler Path rb : river bank I : island b : bridge Graph theory Nodes rb .

i1. b2) connect(rb1. rb2. b7) Connect :tow lands connected by a particular bridge . i2. b3)connect(i1. i1. rb1. b1) connect(rb1. i1. rb1. b5) connect(rb2. b3) connect(rb1. b4)connect(i2. rb1. i1. b1) connect(i2. i2. i2. Y.using predicate calculus  Predicate calculus: connect(X. b2)connect(i1. rb2. Z) connect(i1. i1. b5)connect(i1. b7)connect(i2. b6) connect(rb2. rb2.Representing Königsberg bridge system. b6)connect(i1. b4) connect(rb2.

Graph Theory  A graph consists of a set of finite nodes N1. Each node in a rooted tree has a unique parent. and Nk is called the child. Nk and Nj are siblings.N4)… .  A rooted tree has a unique node which has no parents called the root. If Nj is also connected to Ni.  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.  If a directed arc connects Nj and Nk.Nn.N2… and a set of arcs connecting the nodes  Arcs are orded pairs of nodes ie arc(N3.) .….N2. Nj is called the parent.

 Two nodes are said to be connected if a path exists that includes them both.)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.  Tip or Leaf node is the node that has no children .

Strucures for State Space Search .

A labeled directed graph .

h Root and i b is parent (b . d ) of( e f) are siblings (e f g h I j) Leaves or (g. h .Family relationships in a rooted tree a is a is ancestor of g. c . i) children b.e) are( tips of c connected .

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.org/wiki/Finite-state_machine  . parsing and other engineering applications. among which electronic design automation. communication protocol design. state machines or hierarchies of state machines are sometimes used to describe neurological systems and in linguistics — to describe the grammars of natural languages.wikipedia. In biology and artificial intelligence research.Finite State Machine  Finite-state machines can solve a large number of problems.

)Finite State Machine (FSM .

Flip Flop FSM (a) The finite state graph for a flip flop and (b) its transition matrix. .

 FSM Used to recognize component of a formal language .path  F : State transaction function  FSM is an abstract model of computation. I .The Finite State Machine  The Finite State Machine is finite directed connected graph (S. F):  S : Set of states – nodes  I : Set of input values .

String Recognition ”Example for FSM for recognizing all strings contain the exact sequence “abc Starting Accepting state (a)The finite state graph (b)The transition matrix for string recognition example (c)This called Moore machine – FS accepting M .

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 .

 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 .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.arcs  The problem space can be viewed as a graph where the states are the nodes and the arcs represent the operators.with initial state  a set of operators (legal moves)which can change one state into another .

State Space and Search .

goal can be reached by different states •No cycle •Complexity = 9! .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 .

The 8-puzzle problem as state space search  states: possible board positions  operators: one for sliding each square in each of four directions. . or. 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. better. we need the path.

State Space of the 8-Puzzle
• generated by “move
blank” operations
∀↑ -- up
∀→ -- left
∀↓ -- down
∀← -- left
• Cycles may occur:so
it’s a graph-multiple
parents

The travelling salesperson problem

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

The travelling salesperson problem

Complexity = (n-1)!

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

B. A). . at a cost of 550. is not the shortest path. C. D. A) defeated the heuristic.Other techniques for solving TSP – Branch & bound with complexity=(1. The comparatively high cost of arc (C.26)n Greedy nearest neighbour( E.

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 .

of rules match 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.

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

http://en.org/wiki/Dipmeter .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.wikipedia. It measures the amount of absorption of a high frequency inductively coupled magnetic field by nearby object.Data Driven search  Data Driven is suggested if  All or most of the data are given (PROSPECTOR .

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

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 .

Uniform Cost •guarantee that solution is found •Heuristic search  search process takes place by traversing search space with applied rules (information). Searching Strategies •Blind search  traversing backtracking the search space until the goal nodes is found (might be doing exhaustive search). •Techniques: Greedy Best First Search. •Techniques : Breadth First. A* Algorithm •There is no guarantee that solution is found.Depth first. TIN 5013: Artificial Intelligence . Interactive Deepening search.

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) .Backtracking Search  Search – find a path from start until reaches a goal (quit) or dead end (backtrack)  Backtrack – when the path is dead.

Backtrack algorithm Stack : From left Stack : From left 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 .

Backtracking search of a hypothetical state space space. .

states are added to the right and removed from the left FIFO 43 1 2 Order of search : A . E . D . F . The Breadth-first search  Breadth-first search  When a state is examined. C . 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. B . G .

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 .

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

Depth-first search5 4 3 ……. .

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 .

maximum path length m .) 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.

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

Blind . 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.get exponentail time complexity for worst case .

)Iterative Deepening DFS (ID-DFS TIN 5013: Artificial Intelligence .

uninformed search. or weak methods .”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.

Using the State Space to Represent Reasoning with propositional and predicate Calculus State Space Description of a Logical System AND/OR Graphs Further Examples and Applications MACSYMA (integration) Where is Fred? The Financial Advisor English Grammar .

. such as determining whether a particular expression is a logical consequence of a given set of assertions.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. may be solved using search.  Inference rules can be used to create and describe the arcs between states.  Problems in the predicate calculus.

r.  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. r and r→p yields p.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. .p] corresponds to the sequence of inferences: s and s→r yields r.

. t → r.  State space graph of a set of implications  the arcs correspond to logical implications (→) Boxed nodes  propositions given true (s and t) correspond to the given data of the problem and represented as boxed nodes. r → p. t. s → u. s. s → r. propositional calculus A set of assertions : q → p. v → q.

Logical Operators General Name Formal Name Symbols Not Negation ¬ And Conjunction ∧ Or Disjunction ∨ If… Then/Implies Conditional → If and only if Biconditional ↔ .

The Truth Table P Q NOT AND OR Implies Biconditional )¬(P P^Q PvQ PQ P  Q T T F T T T T T F F F T F F F T T F T T F F F T F F T T .

chocolate). variables_2.…)  Example: “She likes chocolate”  likes (she.  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))] .Predicate Calculus Logic  Basic idea : operator (variables_1.

.And/Or graphs  If the premises of an implication are connected by an ∧ operator. they are called AND nodes.  And/Or graph is actually a specialization of a type of graph known as a hypergraph. and the arcs from this node are joined by a curved link. 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 .

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 of a set of propositional calculus expressions.

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. a point at which a choice may be made between alternative problem-solving strategies.  ∨ operator indicates a selection. .

Examples and Applications for and/or graph searching  Macsyma  “Where is fred?”  An English Language Parser and Sentence Generator  The Financial Advisor Revisited .

and/or graph And/or graph of part of the state space for integrating a function (goal directed) . MACSYMA : An Example for goal directed.

“Where is fred?”: Example for Checking English sentences Goal-directed and/or graph The facts and rules of this example are given as English sentences followed by their predicate calculus equivalents: .

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

An English Language Parser and Sentence Generator: A parser needs : Grammar rules Terminals : dictionary of words in the language ( a . etc) have been written more than once to simplify drawing the graph. dog . art. the . likes . man . Some of the nodes (np. bites) And/or graph for the grammar. .

” •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 . Parse tree for the sentence “The dog bites the man.

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 A 1 10 5 5 S B G The goal state is achieved and the 15 path S-B-G is returned. . In relation to C path cost. Backtracking SEARCH Current level: 210n/a TIN 5013: Artificial Intelligence . C15 Nodes expanded: 3210 CurrentFINISHED action: Expanding Waiting…. Press space to begin the search Size of Queue: 031 Queue: Empty S 10G A. B. UCS has found the optimal route. 11 GC . G B. Press space to end.11C.