Title: Chapter 3: State Space Search
1Chapter 3 State Space Search
- AI uses state space search to find solutions to
problems - State space search uses state space graphs to
represent problems - this representation may be used instead of or in
addition to representation in predicate calculus - Graph theory allows us to analyze the structure
and complexity of problems and search strategies - A graph is a set of nodes and a set of arcs that
connect pairs of nodes - In state space search, a node in a graph
represents a state of the world or a state in the
solution of a problem - An arc represents a transition between states
- a chess move (arc) changes the game board from
one state to another - a robot arm moving a block (arc) changes the
blocks world from one state to another - a rule (arc) like If its raining, take an
umbrella, changes the state of the known world
2Euler and the Bridges of Konigsberg
- Problem Can we walk through the city of
Konigsberg and cross each of its seven bridges
exactly once?
3Representing the Problem as a Graph
- This graphical representation allowed Euler to
consider the degree of a node - the degree of a node is the number of arcs
entering it - The walk is impossible for any graph unless it
has exactly zero or two nodes of odd degree - with no odd degree nodes, you can start and end
at the same node - with two odd degree nodes, you can start at one
and end at the other - The predicate calculus representation does not
let us see this principle!
4Graph Definitions
5More Graph Definitions
6The Finite State Machine
- A finite state machine (FSM) is one type of
graphical representation used to show how
transitions from one state to another can be made - In AI, they are primarily used in natural
language processing - Outside of AI, they are used in compiler
construction to recognize valid syntax and in
circuit design for building counters and flip
flops - Informally, you begin at some initial state of
the world, and you transition through other
states based on input received - In AI, you usually want to transition into a goal
state - In other applications (for example, a counter),
you may just want to continue cycling through
states indefinitely - The following example FSM accepts strings of
a,b,c,d containing abc
7State Space
- A state space is a more general graphical
representation than a FSM
8State Space Graph for Tic Tac Toe
9Tic Tac Toe
- The graph for tic tac toe is a directed acyclic
graph (DAG) - The start state (usually drawn at the top) is an
empty board - A goal state is any state with three Xs in a row
- The path from the start state to a goal state
tells the moves needed to win the game - There are 9! (362,880) different paths through
the graph - Exhaustive search is a strategy that simply looks
at all the paths to find the best one - This might work for tic tac toe, but for larger
problems with factorial or exponential
complexity, heuristics are needed - Chess has 10120 possible game paths
10The 8-Puzzle
- This puzzle is based on a childrens game in
which there are 15 tiles to arrange in numerical
order. (The original is called the 15-Puzzle.) - A start state has the tiles scrambled there are
many possible start states, each with its own
graph - To represent the problem as simply as possible,
think of moving the blank - The state space graph is directed, but unlike in
tic tac toe, there can be cycles - Solving the puzzle means finding a path from the
start state to the goal state
11Partial State Space for the 8-Puzzle
12Traveling Salesperson Problem
- This is a classical problem in which the goal is
for a salesperson to visit several cities and
return home in the most efficient order - Exhaustive search has complexity (N-1)! for N
cities
13Strategies to Make Search Tractable
- Branch and bound is a technique in which branches
are pruned if the cost of a partial path exceeds
the lowest cost path found so far - This is faster and can not eliminate any good
paths - This may not be fast enough for large N
- A heuristic approach is finding a path by always
choosing to visit the nearest unvisited city - This is very fast but is not guaranteed to be
optimal in terms of cost - Often, it is good enough
-
14Data-Driven and Goal-Driven Search Strategies
- We do not always search in the same way. There
are different strategies, depending on the
problem at hand. - In data-driven search (forward chaining), we
start with facts and a set of rules for changing
states - Rules are applied to obtain new facts, in an
iterative cycle, until a path to a goal state is
found (or we fail) - In goal-driven search (backward chaining), we
start with our goal (or hypothesis) and work
backwards - We consider the subgoals that could have led to
the goal, the subgoals that could have led to
those subgoals, and so on, until we get to the
initial facts (or we fail) - One strategy or the other may be more efficient
or better suited to a particular problem, or the
strategies may be combined to solve the same
problem
15Choosing a Search Strategy
- Data-driven search may be best if
- Most of the initial data is given in the problem
statement - Ex PROSPECTOR analyzes geographic data to
determine where ore deposits may be found - There are a lot of potential goals, but facts
limit which goals apply - Ex DENTRAL finds the molecular structure of
organic compounds using mass spectrographic data
the structure depends on the data - An initial goal or hypothesis is difficult to
formulate - Ex Theres no way for DENDRAL to guess what the
structure might be initially - Ex We may be interested in any type of finding,
as in data mining applications (e.g., grocery
store shopping pattern analysis)
16Goal-Driven Search
- Goal-driven search may be best if
- A goal or hypothesis is given in the problem
statement - Ex Does the patient have appendicitis?
- Many rules apply to the facts of the problem,
leading to many possible conclusions and goals - Ex In proving a mathematical theorem, we want to
focus on relevant rules, not blindly apply all
mathematical principles - All relevant facts are not initially known
- In diagnosis or troubleshooting, you may need to
gather additional facts - The goal youre working on suggests facts to
acquire - Ex A physician will order only necessary tests
for a patient, and a computer technician will
perform only relevant diagnostics
17Implementing Graph Search Backtracking
- Backtracking search begins at the start state and
systematically traverses the state space graph
until it either finds a solution or searches the
entire graph - The backtracking algorithm makes use of
- CS, the current state, a node in the graph
- SL, the state list, an ordered list of nodes on
the path currently being tried - When a goal state is found, SL contains the path
to that goal state from the start state - Depending on the problem, you may just want the
solution stored at the goal state node, or you
may want to know the whole path - NSL, new state list, an ordered list of nodes
waiting to be evaluated - DE, dead end list, a list of nodes that have been
evaluated and shown not to lead to goal states - This list is maintained for efficiency, so that
no dead end node is evaluated more than once - The algorithm, as presented, is for data-driven
search. For goal-driven search, you could start
with the goal state and work backwards to the
start state.
18The Backtracking Algorithm
19Backtracking Example
20Depth-First and Breadth First Search
- The backtracking algorithm implements a kind of
depth-first search - Depth-first search proceeds down a graph, so that
a nodes children are considered before its
siblings - Breadth-first search proceeds across a graph,
examining one level of a graph at a time. Here,
a nodes siblings are considered before its
children - The breadth-first search uses two lists
- Open is a first-in-first-out (FIFO) list, or
queue, which lists nodes that have been
generated, but whose children have not been
examined - The FIFO quality ensures that search proceeds
across the graph - Closed is a list of nodes which have already been
examined - Unlike in the backtracking algorithm, there is no
SL state list that maintains the path from start
to goal. If desired, bookkeeping can be added to
track each nodes parent and trace the path. - An advantage of breadth-first search is that,
since it searches across levels, it is guaranteed
to find the shortest path to a goal. - A disadvantage is that there are BN nodes per
level of a graph , where B is the average number
of children per node and N is the level. Storing
a whole level on open gives exponential space
complexity. (Dont try this with chess!)
21Breadth First Search Algorithm
22Breadth-First Search Example
23Depth-First Search
- Depth-first search is more space efficient, but
it is not guaranteed to find a shortest path from
start to goal - Depth-first search can also get stuck, if the
graph has infinitely deep paths - This can happen for problems where the graph is
not set in advance, but generated a node at a
time as the problem is worked through - The generalized depth-first search algorithm is a
simplification of the backtracking algorithm.
24Depth-First Search Algorithm
25Depth-First Search with Iterative Deepening
- Depth-first search with iterative deepening
combines the best features of depth-first and
breadth-first search - Start with a depth-first search, but set a depth
bound n (a limit) on how many levels down into
the graph the search can go - The search starts with a depth-first search with
depth bound n 1 - This is the same as a breadth-first search that
stops after the first level - If a goal is not found, the depth bound is set to
2 and the algorithm repeats - The algorithm iterates until either a goal state
is found or the depth bound n is reached - This algorithm is guaranteed to find a shortest
path solution (if one exists in the first n
levels), like breadth-first search, and has only
linear space complexity, like depth-first search - Space used is Bn, where B is the average number
of children per node - Breadth-first search, depth-first search, and
depth-first search with iterative deepening all
have exponential time complexity O(Bn) - Heuristic searches (next chapter) can be used
when B and/or n are large
26Example of DFS with Iterative Deepening
27Representing Reasoning with State Space Graphs
- In propositional calculus, let each proposition
be a node and each implication be a directed arc - Then, to see if a proposition is true, just find
a path in the graph between the unknown
proposition and propositions that are known to be
true - You can use data-driven (forward) or goal-driven
(backward) search - You can use depth-first or breadth-first search
28And/Or Graphs
- Logical statements contain ands and ors
- The first example showed only ors
- When a proposition contains ands, arcs are linked
together to show that both or all of them must be
true to make the implication - An and/or graph is a kind of hypergraph, a graph
in which each hyperarc is formed by linking one
or more nodes to another node
29Predicate Calculus Example
30Example of Goal-Driven Search in an And/Or Tree
- ? W location(fred, W) Wheres Fred?