Professional Documents
Culture Documents
Artificial Intelligence
Artificial Intelligence
Artificial Intelligence
Artificial Intelligence
Module 1
Definition
It is the study of how to make computers do things which at the moment people do
better. It fails to include some areas of potentially large impact namely problems that
cannot now be solved well by either computers or people.
Intelligence +System AI
Applications of AI
2. Autonomous control
The ALLVINN computer vision system was trained to steer a car to keep it following a
lane. It was placed in CMU’s NAVLAB computer controlled minivan and used to navigate
across the United States. NAVLAB has video camera that transmit rode images to ALVINN
which then computes the best direction to steer based on experience from previous training
runs.
3. Diagnosis
Medical digenesis program was able to digonise various diseases and gave
explanation for diagnosis.
4. Logistics Planning
To do automated logistic planning and scheduling for transportation. This involved
up to 50,000 vehicles, cargo,and people at a time, and had to account for starting points,
destitionantons , routs and confict resolution among all parameters. The A I planning
technique took one hour to generate plans.
5. Robotics
The A I technique was able to create three dimensional models of a patients internal
anatomy.
6. Game playing :We can buy machines that can play master level chess for a few hundred
dollars. There is some AI in them, but they play well against people mainly through brute
force computation--looking at hundreds of thousands of positions. To beat a world
champion by brute force and known reliable heuristics requires being able to look at 200
million positions per second.
7. Speech recognition
In the 1990s, computer speech recognition reached a practical level for limited
purposes. Thus United Airlines has replaced its keyboard tree for flight information by a
system using speech recognition of flight numbers and city names. It is quite convenient.
On the other hand, while it is possible to instruct some computers using speech, most
users have gone back to the keyboard and the mouse as still more convenient.
Just getting a sequence of words into a computer is not enough. Parsing sentences is
not enough either. The computer has to be provided with an understanding of the domain
the text is about, and this is presently possible only for very limited domains.
9. Computer vision
The world is composed of three-dimensional objects, but the inputs to the human eye
and computers' TV cameras are two dimensional. Some useful programs can work solely in
two dimensions, but full computer vision requires partial three-dimensional information
that is not just a set of two-dimensional views. At present there are only limited ways of
representing three-dimensional information directly, and they are not as good as what
humans evidently use.
One of the most feasible kinds of expert system given the present knowledge of AI is
to put some information in one of a fixed set of categories using several sources of
information. An example is advising whether to accept a proposed credit card purchase.
Information is available about the owner of the credit card, his record of payment and also
about the item he is buying and about the establishment from which he is buying it (e.g.,
about whether there have been previous credit card frauds at this establishment).
State space search is a powerful technique for solving problems. However, in order to
apply this technique we need to formulate the problem. A problem can be defined formally
by 4 components:
Initial state :- Specify one or more states within that space that describe possible
situations from which the problem solving process may start. These states are called
the initial sates.
Successor function S(x) :- Description of all possible actions available. Given a
particular state x, S(x) returns a set of < action, successor> ordered pairs in which
each action is one of the legal actions in state x and each successor is a state that
can be reached from x by applying the action.
Goal Test :– Goal states are one or more states that would be acceptable as solutions
to the problem. Goal test determines whether a given state is a goal state. They may
or may not be explicitly specified.
Path cost :- Function that assigns a numeric cost to a path. It is usually the sum of
the costs of individual actions along the path. Step cost of taking action ‘a’ to go from
state ‘x’ to ‘y’ is denoted by c(x,a,y).
Problem Space is the environment in which search takes place. Problem Instance is
the problem space combined with initial and goal state.
State space is the set of all states reachable from the initial state.(initial state +
successor function).State space forms a graph in which nodes are states and the arcs
between nodes are actions. A path in state space is a sequence of states connected by a
sequence of actions.
A solution is a sequence of actions (path) leading from the initial state to a goal state.
Solution quality is measured by the path cost function. An Optimal solution has the
lowest path cost among all solutions.
5
Example Problems
1. 8 Puzzle
The eight puzzle consists of a three by three board with eight numbered tiles and a
blank space. A tile adjacent to the blank space can slide into the space. A game consists of
a starting position and a specified goal position. The goal is to transform the starting
position into the goal position by sliding the tiles around. The object is to figure out the
steps needed to get from one configuration of the tiles to another.
Arrange the tiles so that all the tiles are in the correct positions. You do this by
moving tiles. You can move a tile up, down, left, or right, so long as the following
conditions are met:
A) there's no other tile blocking you in the direction of the movement; and
B) you're not trying to move outside of the boundaries/edges.
For example, suppose we wanted to get from the initial state to the goal state given below.
and the is a blank tile you can slide around. This 8 puzzle instance can be solved in 5
steps.
1. States – A state description specifies the location of each of the eight tiles and the blank
in one of the nine squares.
2. Initial state – Any state can be designated as the initial state. Any given goal can be
reached from exactly half of the possible initial states.
3. Successor function. – generates the legal states that result from trying the four
actions(blank moves left, right, up, down).
4. Goal test – this checks whether the state matches the goal configuration.
5. Path cost - Number of actions to reach goal.
2. 8-Queens Problem
6
If we want to find a single solution, it is not difficult. If we want to find all possible
solutions, the problem is difficult and backtrack method is the only known method. For 8-
queen, we have 92 solutions. If we exclude symmetry, there are 12 solutions.
7 X
6 X
5 X
4 X
3 X
2 X
1 X
0 X
0 1 2 3 4 5 6 7
Although efficient special purpose algorithms exist for this problem and the whole ‘n’
queens family, it remains an interesting test problem for search algorithms. There are 2
main kinds of formulation.
In either case the path cost is of no interest because only the final state counts.
For eg: Incremental formulation
1. States - Any arrangement of 0 to 8 queens on the board
2. Initial state - No queens on the board
3. Successor function - Add a queen to any empty square
4. Goal test - 8 queens on board and none attacked
3. Water-Jug Problem
7
You are given two jugs a 4-gallon one and other 3-gallon one. Neither has any
measuring marker on it. There is a pump that can be used to fill the jugs with water. The
Problem : How can you get exactly 2 gallons of water into the 4-gallon jug?
The State Space for this problem can be described as a set of Ordered pairs of
integers (x, y) such that x = 0, 1, 2, 3, or 4 and y = 0, 1, 2 , or 3; x represents the number of
gallons of water in the 4-gallon jug and y represents the number of gallons of water in the
3-gallon jug.
The Start State is (0, 0).The Goal States are (2, 0), (2, 1), (2, 2), (2, 3).The actions
include:
Refer figure 2.3 : – Production rules for water jug problem and figure 2.4 :- one
solution to water jug problem in page no 28 in the text book Artificial Intelligence of
ELAINE RICH 3rd EDDICTION.
The solution for the water jug problem is obtained by applying the rules in the order
2-9-2-7-5-9
ISSUES
1. The issue in Rule 3 and Rule 4 is that should they or should they not be
included in the list of available operators. Emptying an unmeasured amount of water on to
the ground is certainly allowed by the problem statement. But doing so will never get us
closer to a solution.
2. Rule 11 and Rule 12 raises another issue. To explain this issue just analyses
figure 2.4. Once the state (4, 2) is reached it is obvious what to do next. The decide 2
gallons have been produced, but they are in wrong jug so the thing to do is to move them
(Rule 11). But before that can be done the water that is already in 4 gallon jug must be
emptied out ( Rule 12). But these rules do not actually add power to the system since the
operations they describe are already provided by rule 9 ( in the case of rule 11) and by rule
5 ( in the case of rule 12). In fact depending on the control strategy that is used for
selecting rules to use during problem solving, the use of these rules may d grade
performance.
1. Define a state space that contains all possible configurations of the relevant object
eg: Rules
2. Specify one or more state with in the space as start state. This is termed as initial
state.
8
3. Specify one or more state that would be acceptable as solution to the problem.
These state is termed as goal state.
4. Set of assumptions
Eg:- in water jug problem we assumed that we can fill a jug from the pump, we can
pour the water out of jug on to the ground, there are no other measuring devises available
and there are no measuring markers on the jug.
Route finding problem is defined in terms of specified locations and transitions along
links between them. Route finding algorithms are used in a variety of applications such as
routing in computer networks, military operations planning and airline travel planning
system. These problems are typically complex to explain.
This is also a Route finding problem. A salesperson has to visit a number of cities.
(S)He can start at any city and must finish at that same city. The salesperson must visit
each city only once. A simple control structure could in principle solve the problem. It
would simply explore all possible paths in the tree and return the one with the shortest
length. This approach will work for very short list of cities. But it breaks down quickly as
the no of cities grows.
If there are n cities then the number of possible paths among them is 1*2*3*4………
*(n-1) or (n-1)! .The time required to examine a single path is proportional to n!. Assume
there are 35 cities to visit. To solve this problem he would take more time than he would be
willing to send. This phenomenon is called combinatorial explosion.
We can beat this using a simple strategy called Branch and bound. Begin generating
complete paths keeping track of the shortest path found so far. Give up exploring any path
as soon as its partial length becomes greater than the shortest path found so far. Using
this technique we are still guaranteed to find the shortest path. Although this algorithm is
efficient than the first one it still requires exponential time.
3. VLSI layout
layout and channel routing. The aim is to place the cells on the chip so that they do not
overlap and so that there is room for the connecting wires to be placed between the cells.
Channel routing finds a specific route for each wire through the gaps between the cells.
4. Robot Navigation
The aim is to find an order in which to assemble the parts of some object .If the
wrong order is chosen there will be no way to add some part later in the sequence without
undoing some of the work already done.
6. Protein Design
The goal is to find a sequence of amino acids that will fold in to three dimensional
protein.
7. Internet Searching
A Path Cost
This function assigns a numeric cost to each path. The step cost of taking action a to go
from state x to state y is denoted by c(x,a,y).
A solution is a path from the initial state to goal state. An optimal solution has the lowest
path cost among all solutions.
10
We can now draw a part of a search space by showing the initial state at the top of an
upside-down tree, with each "level" consisting of states that result from applying operators
to states in the level above:
Problem solving agents decide what to do by finding sequences of actions that lead to
desirable states. Search algorithms classified as
1. Uninformed Search/Blind Search - in the sense that they are given no information
about the problem other than its problem definition.
2. Informed Search/Heuristic Search – ones that have some idea of where to look for
solutions.
An agent first formulates a goal and a problem, searches for a sequence of actions
that would solve the problem .The process of looking for such a sequence is called search. A
search algorithm takes a problem as input and returns a solution in the form of an action
sequence
Solution can be found out by searching in state space. We can generate a search
tree that is generated by the initial state and the successor function that together define
the state space. The root of search tree is a search node corresponding to the initial state.
The first step is to find whether it is a goal state. If it is not we need to consider other
states. This is done by expanding the current state ie applying the successor function to
the current state thereby generating a new set of states.
We continue choosing, testing and expanding until either a solution is found or there
are no more states to be expanded. The choice of which state to expand is determined by
search strategy. Nodes are usually represented by a data structure with 5 components as:
1. State – the state in the state space to which the node corresponds
2. Parent node – node in the search tree that generated this node
3. Action – action that was applied to the parent to generate the node.
4. Path cost – cost of the path from the initial state to the node as indicated by parent
pointers
5. Depth – no of steps along the path from the initial state.
Collection of nodes that have been generated but not yet expanded is called fringe.
Each element of the fringe is a leaf node i.e. a node with no successors in the tree.
Problem Characteristics
ò(x2 + 3x + sin2x.cos2x)dx
We can solve this problem by breaking down it into 3 smaller problems each of which
we can be solved independently. Decomposable problem can be solved easily. This can
be solved by a simple integration program that works as follows. At each step it checks
to see whether the problem it is working on is immediately solvable. If so then the
answer is returned directly. If the problem is not easily solvable, the integrator checks to
see whether it can decompose the problem into smaller problems. If it can it creates
those problems and calls itself recursively on them. The problem tree is shown below:
In attempting to solve the 8-Puzzle we might make a stupid move. But we can
backtrack and undo the move.
An additional step must be performed to undo each incorrect step. The control
mechanism for an 8-Puzzle solver must keep track of the order in which operations are
performed so that the operations can be undone one at a time if necessary.
Problem Classification
1) Ignorable problems - in which solution steps can be ignored. For eg in the case of
Theorem Proving a lemma that has been proved can be ignored for next steps.
Ignorable problems can be solved using a simple control structure that never
backtracks. Such a control structure is easy to implement.
In Bridge we cannot know exactly where all the cards are or what the other players
will do on their turns. What we would like to do is to plan the entire hand before making
the first play. These problems are called uncertain outcome problems.
One of the hardest types of problems to solve is the irrecoverable uncertain outcome.
Eg : controlling a robot arm.
Different reasoning paths lead to the answer. It does not matter which path we
follow. For eg in the case of travelling Salesman Problem we have to try all paths to find the
shortest one. Any-path problems can be solved in a reasonable amount of time using
heuristics that suggest good paths to explore. If the heuristics are not perfect the search for
the solution may not be as directly as possible. For best-path problems, much more
14
exhaustive search will be performed. Best –path problems are computationally harder than
any – path problems.
Consider the problem of playing chess. Suppose you had unlimited computing power
available. How much knowledge would be required by a perfect program? It requires just
the rules for determining legal moves and some simple control mechanism that implements
an appropriate search procedure. In this case knowledge is important only to constrain the
search for a solution.
But now consider the problem of scanning daily newspaper to decide who will win in
the upcoming elections. Suppose you had unlimited computing power available .But in this
case lot of knowledge is required even to be able to recognize a solution.
For eg while proving mathematical theorem it should be made sure that the proof exists.
If there is that much difficult it may not know where to start.
In the case of water Jug Problem solution is a path to the state. The path that leads
to the goal must be reported.
Search Strategies
Breath-first search
Uniform-cost search
Depth-first search
Depth-limited search
15
Hill climbing
Simulated annealing
Best-first search
A* search
Uninformed/Blind Search
It is a simple strategy in which root node is expanded first then all successors of root
node are expanded next and then their successors and so on. Consider again the search
space shown.
Let us suppose that the state labeled G is a goal state in this space, and that, as shown, no
operators apply to the states I, J, E, F and H.
A program will start with the initial state A, and try to find the goal by applying
operators to that state, and then to the states B and/or C that result, and so forth. The
idea is to find a goal state, and often one is also interested in finding the goal state as fast
as possible, or in finding a solution that requires the minimum number of steps, or satisfies
some other requirements.
One approach to deciding which states that operators will be applied to is called
"Breadth-First Search". In a breadth-first search, all of the states at one level of the tree are
considered before any of the states at the next lower level. So for the simple search state
pictured above, the states would be applied in the order as indicated below:
Algorithm: Note:
b) If the new state is a goal state, terminate with success and return that
state.
c) Otherwise add the new state to the end of NODE-LIST
Usually BFS is implemented using data structure called queue. You add the newly
formed paths to the back of the list. When you remove them to expand them, you remove
them from the front.
Completeness: Does it always find a solution if one exists? YES, if shallowest goal node is
at some finite depth d
Time complexity: Assume a state space where every state has b successors. Root node
has b successors, each node at the next level has again b successors (total b 2), and so on.
Assume solution is at depth d. In Worst case we would expand all but the last node at
depth d since the goal itself is not expanded generating b d+1 –b nodes at level d+1.Then total
number of nodes generated is
Space complexity: If each node is retained in memory space complexity will be same as
that of time complexity i.e. O (bd+1)
Advantages:
1. BFS will not get trapped anywhere .This contrasts with DFS which may follow a
single unfruitful path for a very long time before the path actually terminates in a
state that has no successors.
2. If there is solution then BFS is guaranteed to find it. Furthermore if there are
multiple solutions then a minimal solution will be found. This is guaranteed by the
fact that longer paths are never explored until all shorter ones have already been
examined. This contrasts with DFS which may find a long path to a solution in one
part of the tree when a shorter path exists in some other unexplored part of the tree.
Disadvantages:
Uniform-cost search is similar to breadth-first search. BFS is optimal when all the
step costs are equal, because it always expands the shallowest unexpanded node. By a
simple extension we can find an algorithm that is optimal with any step cost function.
Instead of expanding the shallowest node UCS expands the node with lowest path cost.
UCS is the same as BFS when all step-costs are equal. This is implemented by means of a
queue ordered by path cost.
17
We associate with each node n a cost g(n) that measures the cost of getting to node n
from the start node. g(start) = 0. If ni is a successor of n, then g(ni) = g(n) + c(n,ni) , where
c(n,ni) is the cost of going from node n to node ni .
Time complexity: Assume C* the cost of the optimal solution. Assume that every action
C*/ ε
costs at least ε. In the Worst-case time complexity will be O (b )
Optimality: It will be optimal since nodes expanded in order of increasing path cost. (Also
if complete)
Advantage:
Disadvantages:
DFS is another control strategy which always expands the deepest node. We could
pursue a single branch of the tree until it yields a solution or until a decision to terminate
the path is made. In depth-first search, the search is conducted from the start state as far
as it can be carried until either a dead-end or the goal is reached. If a dead-end is reached,
backtracking occurs.
The most recently created state from which alternative moves are available will be
revisited and a new state is created. This form of backtracking is called chronological
backtracking because the order in which steps are undone depends only on the temporal
sequence in which steps where originally made. Specifically the most recent step is always
the first to be undone. This form of backtracking is what is usually meant by the simple
backtracking. An example is shown below:
18
In a depth-first search, after operators are applied to a state, one of the resultant
states is considered next. So the order in which the states of the simple example space will
be considered is:
Algorithm:
1. If the initial state is a goal state, terminate with success and return that state.
a) Generate a successor E of the initial state. If there are no more successors signal
failure.
b) Call DFS with E as initial state.
c) If success is returned signal success otherwise continue in this loop
Usually DFS is implemented using a stack.(LIFO). In a stack, new elements are added to
the front of the list rather than the back, but when the remove the paths to expand them,
you still remove them from the front. The result of this is that DFS explores one path,
ignoring alternatives, until it either finds the goal or it can’t go anywhere else.
19
Completeness: Does it always find a solution if one exists? NO, unless search space is
finite and no loops are possible.
Time complexity: O(bm ) .Terrible if m is much larger than d (depth of optimal solution).
But if many solutions are present, then faster than BF-search
Space complexity: O(bm) .Backtracking search uses even less memory. In that it
generates only one successor instead of all
Optimality: No, unless search space is finite and no loops are possible.
Advantages:
1. DFS requires less memory since only the nodes on the current path are stored. This
contrasts with BFS where all of the tree that has so far been generated must be
stored. Once a node has been expanded it can be removed from memory as soon as
all its descendants have been fully explored.
2. Easily programmed: function call stack does most of the work of maintaining state of
the search.
3. DFS may find a solution without examining much of the search space at all. This
contrasts with BFS in which all parts of the tree must be examined to level ‘n’ before
any nodes at level ‘n+1’ can be examined. This is particularly significant if many
acceptable solutions exist. DFS can stop when one of them is found.
Disadvantages:
1. May find a sub-optimal solution (one that is deeper or more costly than the best
solution).
2. Incomplete: without a depth bound, may not find a solution even if one exists.
A variant of DFS called backtracking search uses still lesser memory. In backtracking
only one successor is generated at a time rather than all successors. Each partially
expanded node remembers which successor to generate next. In this way only O(m)
memory is needed rather than O(bm) where b is the branching factor and m is the
maximum depth.
Depth-first search can spend much time (perhaps infinite time) exploring a very deep
path that does not contain a solution, when a shallow solution exists. An easy way to solve
this problem is to put a maximum depth limit ‘l’ on the search ie nodes at depth limit are
treated as if they have no successors. Beyond the depth limit, a failure is generated
automatically without exploring any deeper. This approach is called depth limited search.
The depth limit solves the infinite path problem.
20
If a solution exists at depth d or less, then d -limited DFS will find the solution, and
the algorithm is very efficient in space. However, depth-limited DFS is not complete: If a
solution exists but only at depth greater than d, then depth-limited DFS will not find the
solution.
For eg : in the case of a TSP consider a map with 20 cities. Therefore we know that if
there is a solution it must be of length 19 at the longest so l =19 is a possible choice. But
if we study the map carefully we can see that any city can be reached from any other city in
at most 9 steps .This is known as diameter of state space gives us a better depth limit
which leads to a more efficient depth limited search.
Algorithm :
1. Determine the vertex where the search should start and assign the maximum search
depth
2. Check if the current vertex is within the maximum search depth
o If not: Do nothing
o If yes:
1. Expand the vertex and save all of its successors in a stack
2. Call DLS recursively for all vertices of the stack and go back to Step 2
Completeness : In general the algorithm is not complete since it does not find any solution
that lies beyond the given search depth. But if you choose the maximum search depth to be
greater than the depth of a solution the algorithm becomes complete.
Optimality: Depth-limited search is not optimal. It still has the problem of depth-first
search that it first explores one path to its end, thereby possibly finding a solution that is
more expensive than some solution in another path.
Problems:
21
The main advantage of this algorithm in game tree searching is that the earlier
searches tend to improve the commonly used heuristics, such as the killer heuristic and
alpha-beta pruning, so that a more accurate estimate of the score of various nodes at the
final depth search can occur, and the search completes more quickly since it is done in a
better order (it can be shown that alpha-beta pruning works much better if the moves are
generated with the moves likely to be the best moves evaluated first). An eg : is shown
below:
22
In an iterative deepening search, the nodes on the bottom level are expanded once,
those on the next to bottom level are expanded twice, and so on, up to the root of the
search tree, which is expanded d + 1 times. So the total number of expansions in an
iterative deepening search is
Node generation:
level d: once
level d-1: 2
level d-2: 3
………….
level 2: d-1
level 1: d
In general, iterative deepening is the preferred search method when there is a large
search space and the depth of the solution is not known. Iterative deepening essentially
throws away the results of every depth-limited search before going on to the next. This
means that iterative deepening simulates breadth-first search, but with only linear space
complexity.
Algorithm :
1. Set DEPTH-LIMIT = 0
2. Conduct depth-first search to a depth of DEPTH-LIMIT If a solution path is found,
then return it.
3. Increment DEPTH-LIMIT by 1 and go to step 2.
Advantages:
Disadvantage:
1. Some computer time is wasted re-exploring the higher parts of the search tree.
However, this actually is not a very high cost.
6. Bi-Directional Search
This does not come without a price: Aside from the complexity of searching two times
in parallel, we have to decide which search tree to extend at each step; we have to be able
to travel backwards from goal to initial state - which may not be possible without extra
work; and we need an efficient way to find the intersection of the two search trees. This
additional complexity means that the A* search algorithm is often a better choice if we have
a reasonable heuristic.
It is implemented by having one or both of the searches check each node before it is
expanded to see if it is in the fringe of the other search tree. At least one of the search tree
needs to be kept in memory so that membership check can be done hence the space
/ 2
complexity is also O(bd ).This space requirement is the most significant weakness of
bidirectional search. The algorithm is complete and optimal if both searches are BF.
Completeness: Yes
Space Complexity: O(bd/2) need to retain at least that many nodes to guarantee
completeness
b = branching factor
d = depth of the shallowest solution
m = maximum depth of the search tree
l = depth limit
ε = step-cost
C* = cost of the optimal solution
In hill climbing the basic idea is to always head towards a state which is better than the current one
Algorithm:
1. Evaluate the initial state. If it is also a goal state, then return it and quit. Otherwise continue with initial
state as the current state
2. Loop until a solution is found or there are no new operators left to be applied in the current state:
a) Select an operator that has not yet been applied to the current state and apply it to produce a new
state
ii. If it is not a goal state but it is better than current state, then make it the current state
iii. If it is not better than the current state, then continue in the loop
The key difference between this algorithm and the one we gave for generate and test is the use of an
evaluation function as a way to inject task specific knowledge into the control process. For the algorithm to
work, a precise definition of better must be provided. In some cases, it means a higher value of heuristic
function. In others it means a lower value.
25
A useful variation on simple hill climbing considers all the moves from the current state and selects the
best one as the next state. This method is called Steepest-Ascent Hill Climbing or Gradient Search. This is
a case in which hill climbing can also operate on a continuous space: in that case, the algorithm is called
gradient ascent (or gradient descent if the function is minimized).Steepest ascent hill climbing is similar to
best first search but the latter tries all possible extensions of the current path in order whereas simple hill
climbing only tries one.
Algorithm:
1. Evaluate the initial state. If it is also a goal state, then return it and quit. Otherwise continue with initial
state as the current state
2. Loop until a solution is found or until a complete iteration produces no change to the current state:
a) Let SUCC be a state such that any possible successor of the current state will be better than
SUCC
ii. Evaluate the new state. If it is a goal state, then return it and quit. If it is not a goal state,
compare it to SUCC. If it is better, then set SUCC to this state. If it is not better, leave
SUCC alone.
c) If the SUCC is better than the current state, then set the current state to SUCC
In simple hill climbing, the first closer node is chosen whereas in steepest ascent hill climbing all
successors are compared and the closest to the solution is chosen. Both forms fail if there is no closer node. This
may happen if there are local maxima in the search space which are not solutions. Both basic and steepest
ascent hill climbing may fail to find a solution. Either algorithm may terminate not by finding a goal state but
by getting to a state from which no better states can be generated. This will happen if the program has reached
either a local maxima, a ridge or a plateau.
Simulated Annealing
Simulated Annealing is a variation of hill climbing in which, at the beginning of the process, some
downhill moves may be made. The idea is to do enough exploration of the whole space early on, so that the
final solution is relatively insensitive to the starting state. This should lower the chances of getting caught at a
local maximum, or plateau, or a ridge.
In order to be compatible with standard usage inn discussions of simulated annealing we make 2
notational changes for the duration of this section. We use the term objective function in place of the term
heuristic function. And we attempt to minimize rather than maximize the value of the objective function.
Simulated Annealing as a computational process is patterned after the physical process of annealing in
which physical substances such as metals are melted (i.e. raised to high energy levels) and then gradually
cooled until some solid state is reached. The goal of the process is to produce a minimal-energy final state.
Physical substances usually move from higher energy configurations to lower ones, so the valley descending
occurs naturally. But there is some probability that a transition to a higher energy state will occur. This
probability is given by the function
p = e-DE/kT
where DE = positive change in energy level
T = temperature
k = Boltzmann’s constant
Thus in the physical valley descending that occurs during annealing, the probability of a large uphill
move is lower than the probability of a small one. Also, the probability that an uphill move will be made
decreases as the temperature decreases. Thus such moves are more likely during the beginning of the processes
when the temperature is high, and they become less likely at the end as the temperature becomes lower.
26
The rate at which the system is cooled is called annealing schedule. Physical annealing processes are
very sensitive to the annealing schedule. If cooling occurs too rapidly, stable regions of high energy will form.
In other words a local but not global minimum is reached. If however a slower schedule is used a uniform
crystalline structure which corresponds to a global minimum is more likely to develop.
p1 = e-DE/T
The algorithm for simulated annealing is only slightly different from the simple hill climbing procedure. The
three differences are:
The annealing schedule must be maintained
Move to worse states may be accepted
It is a god idea to maintain, in addition to the current state, the best state found so far. Then if the final
state is worse than the earlier state, the earlier state is till available.
Algorithm:
1. Evaluate the initial state. If it is also a goal state, then return it and quit. Otherwise continue with initial
state as the current state.
2. Initialize BEST-SO-FAR to the current state.
3. Initialize T according to the annealing schedule.
4. Loop until a solution is found or there are no new operators left to be applied in the current state:
a) Select an operator that has not yet been applied to the current state and apply it to produce a new
state.
b) Evaluate the new state. Compute
DE = Value of current state – Value of new state
i. If the new state is a goal state, then return it and quit.
ii. If it is not a goal state but it is better than the current state, then make it the current state.
Also set BEST-SO-FAR to this new state.
iii. If it is not better than the current state, then make it the current state with the probability
p1 as defined above. This step is usually implemented by invoking a random number
generator to produce a number in the range [0,1]. If that number is less than p 1, then the
move is accepted. Otherwise, do nothing.
c) Revise T as necessary according to the annealing schedule
5. Return BEST-SO-FAR as the answer.
To implement this revised algorithm, it is necessary to select an annealing schedule which has 3 components.
1) The initial value to be used for temperature
2) The criteria that will be used to decide when the temperature of the system should be reduced
3) The amount by which the temperature will be reduced each time it is changed.
There may also be a fourth component of the schedule namely when to quit. Simulated annealing is
often used to solve problems in which number of moves from a given state is very large. For such problems, it
may not make sense to try all possible moves. Instead, it may be useful to exploit some criterion involving the
number of moves that have been tried since an improvement was found.
While designing a schedule the first thing to notice is that as T approaches zero, the probability of
accepting a move to a worse state goes to zero and simulated annealing becomes identical to hill climbing. The
second thing to notice is that what really matters in computing the probability of accepting a move is the ratio
DE/T. Thus it is important that values of T be scaled so that this ratio is meaningful.
27
A problem with hill climbing is that it will find only local maxima. Local maximum is a state that is
better than all of its neighbours, but is not better than some other states far away. At a local maximum, all moves
appear to make things worse. Local maxima are particularly frustrating because they often occur within sight of
a solution. In this case they are called foothills. Unless the heuristic is good / smooth, it need not reach a global
maximum. Other local search algorithms try to overcome this problem such as stochastic hill climbing, random
walks and simulated annealing. One way to solve this problem with standard hill climbing is to iterate the hill
climbing.
2) Plateau
Another problem with Hill climbing is called the Plateau problem. This occurs when we get to a "flat"
part of the search space, i.e. we have a path where the heuristics are all very close together and we end up
wandering aimlessly. It is a flat area of search space in which a whole set of neighboring states have the same
value. On a plateau it is not possible to determine the best direction in which to move by making local
comparisons.
3) Ridges
A ridge is a curve in the search place that leads to a maximum. But the orientation of the ridge compared
to the available moves that are used to climb is such that each move will lead to a smaller point. In other words
to the algorithm each point on a ridge looks a like a local maximum even though the point is part of a curve
leading to a better optimum. It is an area of the search space that is higher than surrounding areas and that itself
has a slope. However, two moves executed serially may increase the height.
Figure above shows a one dimensional state space landscape in which elevation corresponds to the
objective function or heuristic function. The aim is to find the global maxima. Hill climbing search modifies the
current state to try to improve it, as shown by the arrow.
28
• Make a big jump in some direction to try to get to a new section of the search space. This is
particularly good way of dealing with plateaus. If the only rules available describe single small steps,
apply them several times in the same direction.
• Apply 2 or more rules before doing the test. This corresponds to moving in several directions at once.
This is particularly good strategy of dealing with ridges.