Professional Documents
Culture Documents
New1 2
New1 2
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 Example Domains
15 puzzle 1 2 3
10^13 states 4 5 6 7
First solved by [Korf 85] with IDA* 8 9 1011
and Manhattan distance 12131415
24 puzzle 1 2 3 4
10^24 states 5 6 7 8 9
First solved by [Korf 96] 1011121314
1516171819
2021222324
Famous Example Domains
Rubik’s cube
10^19 states
First solved by [Korf 97]
7
Different Domain Types
Exponential Domains Polynomial (Quadratic)
Domains
Example .Permutation puzzles Path-finding in Maps, GPS
Sequence alignment
Space size N N=O(bd) N=O(d2)
of states # 1015 1,000,000
Solution Optimal Suboptimal
Search time Days (optimal) Real time (suboptimal)
Start-Goal Goal specific Any two states
8
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 untill 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:
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 than 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 than one
queen per row, so we may assign each queen to a
separate row, now we’ll 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 than 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 don’t 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.
Branching Factor and Solution Depth
The branching factor of a node :
is the number of children it has, not counting its parent if
the operator is reversible.
is a function of the problem space.
The branching factor of a problem space :
is the average number of children of the nodes in the
space.
The solution depth in a single-agent problem:
is the length of the shortest path from the initial node to a
goal node.
is a function of the particular problem instance.
Types of Problem Spaces
There are several types of problem
spaces:
State space (OR graphs)
Problem Reduction Space (AND graphs)
Games (AND/OR Graphs)
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.
For example: Rubik’s Cube, the Sliding-Tile Puzzle, either
a forward or backward search are possible.
This can be considered as an OR graph because the
solution picks one branch at each node.
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.
This is an AND graph
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
4 3
3 2 2 1
2 1 1 0 1 0 0
1 0 0 0 0
OR nodes x
AND nodes x
0
Solution subgraph for AND/OR trees
In general, a solution to an AND/OR graph is a sub
graph with the following properties:
It contains the root node. For every OR node included
in the solution sub graph, one child is included.
For every AND 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
Game # of nodes
8-Puzzle 9!
15-Puzzle 16!
24-Puzzle 25!
Rubik’s Cube- 2x2x2 3,265,920
Rubik’s Cube- 3x3x3 4.32x1019
N-city TSP n!
Checkers 1020
Chess 1040
N-Queens n!
Combinatorial Explosion
The combinatorial explosion of the number of possible
states as a function of problem size is a key
characteristic that separates artificial intelligence
search algorithms in other areas of computer science.
Techniques that rely on storing all possibilities in
memory, or even generating all possibilities, are out of
the question except for the smallest of these problems.
As a result, the problem-space graphs of AI problems
are usually represented implicitly by specifying an
initial state and a set of operators to generate new
states.
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 4 primary measures of efficiency of a
search algorithm:
The completeness of the algorithm
(whether it returns a solution in the end??)
The quality of the solution returned.
Optimal, near-optimal (e-optimal) or sub optimal
1 2
3 4c 5c 6c
7 8 9 10
c 11 12 13 14
O(bd)
Space Complexity
To report the solution we need to store all nodes
generated.
1 2
3 4c 9c 10
c
5 6 7 8c 11 12 13 14
56
DFS - recursive implementation
0
1 8
2 5c 9c 12
c
3 4 6 7c 10 11 13 14
DFS is time-limited rather than space-limited.
Time Complexity and Solution
Quality
DFS generate the same set of nodes as BFS.
O(bd)
However, on infinite tree DFS may not terminate.
For example: Eight puzzle contain 181,440 nodes but
every path is infinitely long and thus DFS will never end.
Time Complexity and Solution
Quality
The solution for infinite tree is to impose an artificial
Cutoff depth on the search.
If the chosen cutoff depth is less than d, the
algorithm won’t find a solution.
If the cutoff depth is greater than d, time complexity
is larger than BFS.
The first solution DFS found may not be the optimal
one.
Depth-First Iterative-Deepening
(DFID)
Combines the best features of BFS and DFS.
DFID first performs a DFS to depth one. Then
starts over executing DFS to depth two.
Continue to run DFS to successively greater
depth until a solution is found.
Depth-First Iterative-Deepening
(DFID)
0
1,3,9 2,6,16
4,10 c
5,13 c
7,17 8,20
11 12 14 c
15 18 19 21 22
time complexity
space complexity
Optimality of DFID-
Solution Quality
up
down
Pruning duplicate Nodes in DFS
More Efficient FSM allowed sequences of moves up only or
down only . And sequences of moves left only or right only.
Time complexity of DFS controlled by this FSM, like BFS, is
O(r2).
up
down
Node Generation Times
BFS, DFS, DFID generates asymptotically the same
number of nodes on a tree.
DFS, DFID are more efficient than BFS.
The amount of time to generate a node is
proportional to the size of the state representation.
If DFS is implemented as a recursive program, a
move would require only a constant time, instead of
time linear in the number of tiles.
This advantage of DFS, becomes increasingly
significant the larger state description.
Backward Search
The root node represent the goal state, and we
could search backward until we reach the initial
state.
Requirements:
The goal state represented explicitly.
We be able to reason backwards about the
operators.
Bidirectional Search
Main idea:
Simultaneously search forward from the initial state and backward
from the goal state, until the two search frontiers meet at a
common state.
S G
Solution Quality
Bidirectional search guarantees finding a
shortest path from the initial state to the goal
state, if one exist.
Assume that there is a solution of length d and
the both searches are breadth-first.
When the forward search has proceeded to
depth k, its frontier will contain all nodes at
depth k from the initial state.
Solution Quality
When the backward search has proceeded to depth d-
k, its frontier will contain all states at depth d-k from
the goal state.
State s reached along an optimal solution path at
depth k from the initial state and at depth d-k from the
goal state.
The state s is in the frontier of both searches and the
algorithm will find the match and return the optimal
solution.
Time Complexity
If the two search frontiers meet in the middle, each
search proceeds to depth d/2 before they meet.
The total number of nodes generated is O(2bd/2) = O(bd/2).
But this isn’t the asymptotic time complexity
because we have to compare every new node with
the opposite search frontier.
Naively, compare each node with the all opposite
search frontier cost us O(bd/2).
Time Complexity
The time complexity of the whole algorithm
becomes O(bd).
More efficiently is using hash tables.
In the average case:
The time to do hashing and compare will be constant.
the asymptotically time complexity is O(bd/2).
Space Complexity
The simplest implementation of bidirectional is to use one
search in BFS, and the search in other direction can be
DFS such as DFID.
At least one of the frontiers must be sorted in memory.
The space complexity of bidirectional search is dominated
by BFS search and is O(bd/2).
Bidirectional search is space bound.
Bidirectional search is much more time efficient than
unidirectional search.
Perimeter Search
A special kind of bidirectional search.
A bredth first search up to depth d is performed
backwards from the goal state. (this is the perimeter P)
Then any search is performed from the initial state
towards the perimeter nodes.
Once the perimeter is reached the search can stop.
S
G