Professional Documents
Culture Documents
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
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
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
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
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
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
A B C
3AC
2AB 1AC
A B C
3AC
A B C
3AC
A B C
3AC
GOOD LUCK