Professional Documents
Culture Documents
Lec 4
Lec 4
Intelligence
Simulated Annealing
Prof Salwani Abdullah
salwani@ukm.edu.my
Simulated Annealing (SA)
• In hill-climbing (HC)
– moves are always to better states
– this gets stuck in local optima
• To escape a local optimum we must allow
worsening moves
• Possible solutions
• Final Temperature
• Temperature Decrement
• Temperature Decrement
• Temperature Decrement
– We need to compromise
– We can either do this by doing a large number
of iterations at a few temperatures, a small
number of iterations at many temperatures or
a balance between the two
SA Cooling Schedule - Temperature Decrement
• Temperature Decrement
– Linear
•temp = temp - x
– Geometric
•temp = temp * x
•Experience has shown that x should be between 0.8 and
0.99, with better results being found in the higher end of
the range. Of course, the higher the value of x, the
longer it will take to decrement the temperature to the
stopping criterion
SA Cooling Schedule - Iterations
What if n = 1000?
SA for TSP
Initialization:
T0 = 0.95; Tf = 0.1; MaxIter = 100;
Delta = (T0-Tf)/(MaxIter) = 0.0085;
T = T0 ;
iter = 1;
Initial solution construction phase:
//Generate an initial solution at random
//Note that a solution is represented as a
sequence of cities (path)
Sol = C-B-A-D-E-C
f(Sol) = 6+1+4+1+5= 17
Solbest = Sol = C-B-A-D-E-C
f(Solbest) = f(Sol) = 17
Improvement phase:
//in the do while loop
do while (iter <=MaxIter)
//generate a new solution using a swap
neighbourhood structure i.e., swap.
Assume we swap between cities A and C in the
Sol = C-B-A-D-E-C.
First iteration
Sol* = A-B-C-D-E-A;
f(Sol*) = 1+6+4+1+3=15
if f(Sol*) better than f(Sol) // 15 < 17 -> true
Sol = Sol* = A-B-C-D-E-A
f(Sol) = f(Sol*) = 15
if f(Sol*) better than f(Solbest)
Solbest = Sol* = A-B-C-D-E-A
f(Solbest) = f(Sol*) = 15
//Update T
T = T – Delta = 0.95-0.0085=0.9442
if exp(-c/T) > r
//assume exp (-1/0.9442) = 0.000013
T=T-Delta=0.9357-0.0085=0.9272;
SA for TSP
17.5
17
16.5
Distance
16
15.5
15
14.5
0 1 2 3 4 5 6 7 8 9 10
Iteration
f(Sol)
Fourth iteration:
Sol = A-B-D-C-E-A
Sol* = ???
…
//repeat the process until the maximum number
of iteration is met.
//return the best solution and the quality of the
best solution.
End of Simulated Annealing