You are on page 1of 43

State spaces

A state space consists of


A (possibly infinite) set of states
The start state represents the initial problem
Each state represents some configuration

reachable from the start state


Some states may be goal states (solutions)

A set of operators
Applying an operator to a state transforms it to
another state in the state space
Not all operators are applicable to all states

State spaces are used extensively in Artificial


Intelligence (AI)
2
State Space
The states represent situations of the problem.
The operators represent actions in the world.
forward search:
search the root of the problem space represents the
start state, and the search proceeds forward to a goal state.
backward search : the root of the problem space represents
the goal state, and the search proceeds backward to the initial
state.

For example: in Rubiks Cube and the Sliding-Tile Puzzle,


either a forward or backward search are possible.
In state space search a state space is formally
represented as a
tuple S:<S,A,Action(s),Result(s,a),Cost(s,a)>}, in
which:
S is the set of all possible states;
A is the set of possible action, not related to a particular
state but regarding all the state space;
Action(s), is the function that establish which action is
possible to perform in a certain state;
Result(s,a) is the function that return the state reached
performing action a in state s
Cost(s,a)is the cost of performing an action a in state s.
In many state spaces is a constant, but this is not true in
general.
4
Example 1: Maze
A maze can be represented as a state space
Each state represents where you are in the maze
The start state represents your starting position
The goal state represents the exit from the maze
Operators (for a rectangular maze) are: move north,
move south, move east, and move west
Each operator takes you to a new state (maze location)
Operators may not always apply, because of walls in
the maze

5
Example 2: The 15-puzzle

Start state:
The start state is some (almost)
3 10 13 7
random configuration of the tiles
9 14 6 1
4 15 2
The goal state is as shown
11 8 5 Operators are
12 Move empty space up
Goal state:
Move empty space down
1 2 3
Move empty space right
5 6 4 7 8
9 10 11 12 Move empty space left

13 14 Operators apply if not against edge


15
6
States
A state can be represented by the number of
missionaries and cannibals on each side of the
river
Initial state: 3m,3c,canoe / 0m,0c
Goal state: 0m,0c / 3m,3c,canoe
We assume that crossing the river is a simple
procedure that always works (so we dont have to
represent the canoe being in the middle of the river)
However, this is redundant; we only need to
represent how many missionaries/cannibals are on
one side of the river
Initial state: 3m,3c,canoe
Goal state: 0m,0c
7
Operations
An operation takes us from one state to another
Here are five possible operations:
Canoe takes 1 missionary across river (1m)
Canoe takes 1 cannibal across river (1c)
Canoe takes 2 missionaries across river (2m)
Canoe takes 2 cannibals across river (2c)
Canoe takes 1 missionary and 1 cannibal across
river (1m1c)
We dont have to specify west to east or east to
west because only one of these will be possible at
any given time
8
State-space searching
Most problems in AI can be cast as searches on a
state space
The space can be tree-shaped or graph-shaped
If a graph, need some way to keep track of where
you have been, so as to avoid loops
The state space is often very, very large
We can minimize the size of the search space by
careful choice of operators
Exhaustive searches don't workwe need
heuristics

9
The basic search algorithm
Initialize: put the start node into OPEN
while OPEN is not empty
take a node N from OPEN
if N is a goal node, report success
put the children of N onto OPEN
Report failure
If OPEN is a stack, this is a depth-first search
If OPEN is a queue, this is a breadth-first search
If OPEN is a priority queue, sorted according to
most promising first, we have a best-first search

10
Heuristic searching
All the previous searches have been blind searches
They make no use of any knowledge of the problem
If we know something about the problem, we can
usually do much, much better
Example: 15-puzzle
For each piece, figure out how many moves away it is
from its goal position, if no other piece were in the
way
The total of these gives a measure of distance from
goal
This is a heuristic measure

11
Heuristics
A heuristic is a rule of thumb for deciding which
choice might be best
There is no general theory for finding heuristics,
because every problem is different
Choice of heuristics depends on knowledge of the
problem space

12
Best-first searching
Use the same basic search algorithm
Choose from OPEN the best node, that is, the one
that seems to be closest to a goal
Generally, even very poor heuristics are
significantly better than blind search, but...
No guarantee that the best path will be found
No guarantee on the space requirements

13
Problems

There are 3 general categories of problems in AI:

Single-agent pathfinding problems.


Two-player games.
Constraint satisfaction problems.
Single Agent Pathfinding Problems
In these problems, in each case, we have a single
problem-solver making the decisions, and the task is to
find a sequence of primitive steps that take us from the
initial location to the goal location.
Famous examples:
Rubiks Cube (Erno Rubik, 1975).
Sliding-Tile puzzle.
Navigation - Travelling Salesman Problem.
Two-Player Games
In a two-player game, one must consider the moves
of an opponent, and the ultimate goal is a strategy
that will guarantee a win whenever possible.
Two-player perfect information have received the
most attention of the researchers till now. But,
nowadays, researchers are starting to consider more
complex games, many of them involve an element of
chance.
The best Chess, Checkers, and Othello players in the
world are computer programs!
Constraint-Satisfaction Problems
In these problems, we also have a single-agent
making all the decisions, but here we are not
concerned with the sequence of steps required to
reach the solution, but simply the solution itself.
The task is to identify a state of the problem, such that
all the constraints of the problem are satisfied.
Famous Examples:
Eight Queens Problem.
Number Partitioning.
Problem Spaces
A problem space consists of a set of states of a
problem and a set of operators that change the
state.
State : a symbolic structure that represents a single
configuration of the problem in a sufficient detail to
allow problem solving to proceed.
Operator : a function that takes a state and maps it to
another state.
Problem Spaces
Not all operators are applicable to all states. The
conditions that must be true in order for an operator to be
legally applied to a state are known as the preconditions of
the operator.
Examples:
8-Puzzle:
states:
states the different permutations of the tiles.
operators:
operators moving the blank tile up, down, right
or left.
Chess:
states: the different locations of the pieces on
the board.
operators:
operators legal moves according to chess rules.
Problem Spaces
A problem instance:
instance consists of a problem space,
an initial state, and a set of goal states.
There may be a single goal state, or a set of goal
states, anyone of which would satisfy the goal
criteria. In addition, the goal could be stated explicitly
or implicitly, by giving a rule of determining when the
goal has been reached.
All 4 combinations are possible:

[single\set of goal state(s)] [explicit\implicit].


Problem Spaces
For Constraint Satisfaction Problems, the goal will
always be represented implicitly, since an explicit
description is the solution itself.
Example:
4-Queens has 2 different goal states. Here the goal is
stated explicitly.
Q Q Q

Q Q

Q Q
Q Q
Problem Representation
For some problems, the choice of a problem space is not
so obvious.
The choice of representation for a problem can have an
enormous impact on the efficiency of solving the
problem.
There are no algorithms for problem representation. One
general rule is that a smaller representation, in the sense
of fewer states to search, is often better then a larger
one.
Problem Representation
For example, in the 8-Queens problem, when every
state is an assignment of the 8 queens on the board:
The number of possibilities with all 8 queens on the
board is 64 choose 8, which is over 4 billion.
billion
The solution of the problem prohibits more then one
queen per row, so we may assign each queen to a
separate row, now well have 88 > 16 million
possibilities.
Same goes for not allowing 2 queens in the same
column either, this reduces the space to 8!, which is
only 40,320 possibilities.
Problem-Space Graphs

A Problem-Space Graph is a mathematical


abstraction often used to represent a problem
space:
The states are represented by nodes of the
graph.
The operators are represented by edges
between nodes.
Edges may be undirected or directed.
Problem-Space Graphs
Example: a small part of the 8-puzzle problem-space
graph:
1 2 3
8 4
7 6 5

1 3 1 2 3 1 2 3 1 2 3
8 2 4 8 4 8 6 4 8 4
7 6 5 7 6 5 7 5 7 6 5

1 3 1 3 1 2 1 2 3 1 2 3 1 2 3 2 3 1 2 3
8 2 4 8 2 4 8 4 3 8 4 5 8 6 4 8 6 4 1 8 4 7 8 4
7 6 5 7 6 5 7 6 5 7 6 7 5 7 5 7 6 5 6 5
Problem-Space Graphs
In most problems spaces there is more then one path
between a pair of nodes.
Detecting when the same state has been
regenerated via a different path requires saving all
the previously generated states, and comparing
newly generated states against the saved states.
Many search algorithms dont detect when a state
has previously been generated. The cost of this is
that any state that can be reached by 2 different
paths will be represented by duplicate nodes. The
benefits are memory savings and simplicity.
Types of Problem Spaces
There are several types of problem
spaces:
Statespace
Problem Reduction Space
AND/OR Graphs
Problem Reduction Space
In a problem reduction space, the nodes represent
problems to be solved or goals to be achieved, and the
edges represent the decomposition of the problem into
subproblems.
This is best illustrated by the example of the Towers of
Hanoi problem.

AA BB C C
Problem Reduction Space
The root node, labeled 3AC represents the original
problem of transferring all 3 disks from peg A to peg C.
The goal can be decomposed into three subgoals: 2AB,
1AC, 2BC. In order to achieve the goal, all 3 subgoals must
be achieved.

3AC

2AB 1AC 2BC

1AC 1AB 1CB 1BA 1BC 1AC


Problem Reduction Space

A B C

3AC
Problem Reduction Space

A B C

3AC

2AB

1AC
Problem Reduction Space

A B C

3AC

2AB

1AC 1AB
Problem Reduction Space

A B C

3AC

2AB

1AC 1AB 1CB


Problem Reduction Space

A B C

3AC

2AB 1AC

1AC 1AB 1CB


Problem Reduction Space

A B C

3AC

2AB 1AC 2BC

1AC 1AB 1CB 1BA


Problem Reduction Space

A B C

3AC

2AB 1AC 2BC

1AC 1AB 1CB 1BA 1BC


Problem Reduction Space

A B C

3AC

2AB 1AC 2BC

1AC 1AB 1CB 1BA 1BC 1AC


AND/OR Graphs
An AND graph consists entirely of AND nodes, and in
order to solve a problem represented by it, you need
to solve the problems represented by all of his
children (Hanoi towers example).
An OR graph consists entirely of OR nodes, and in
order to solve the problem represented by it, you only
need to solve the problem represented by one of his
children (Eight Puzzle Tree example).
AND/OR Graphs
An AND/OR graph consists of both AND nodes and
OR nodes.
One source of AND/OR graphs is a problem where
the effect of an action cannot be predicted in
advanced, as in an interaction with the physical world.
Example:
the counterfeit-coin problem.
Solution subgraph for AND/OR trees
In general, a solution to an AND/OR graph is a
subgraph with the following properties:
It contains the root node. For every OR node included
in the solution subgraph, one child is included.
For every OR node included in the solution subgraph,
all the children are included.
Every terminal node in the solution subgraph is a
solved node.
Solutions
The notion of a solution is different for the different
problem types:
For a path-finding problem, an optimal solution is a solution
of lowest cost.
For a CSP, if there is a cost function associated with a state
of the problem, an optimal solution would again be one of
lowest cost.
For a 2-player game:
If the solution is simply a move to be made, an optimal

solution would be the best possible move that can be made


in a given situation.
If the solution is considered a complete strategy subgraph,

then an optimal solution might be one that forces a win in


the fewest number of moves in the worst case.
Search Algorithms
This course will focus on systematic search
algorithms that are applicable to the different problem
types, so that a central concern is their efficiency.
There are 3 primary measures of efficiency of a
search algorithm:
The quality of the solution returned, is it optimal or not.
The running time of the algorithm.
The amount of memory required by the algorithm
Enough for Today

GOOD LUCK

You might also like