A cooling schedule, or annealing schedule, controls how temperature decreases during simulated annealing. It helps balance exploration of the search space against exploitation of promising solutions. The idea comes from physical annealing, where temperature and cooling rate are carefully controlled. section 5.2.4 section 5.2.1
At high temperatures, the algorithm is more likely to accept worse moves and explore broadly. At low temperatures, it accepts fewer such moves and searches more locally. Too high a starting temperature can resemble random search; too low a temperature can trap the search in a local minimum. section 5.2.4 section 5.2.5
Configure the annealing process with four linked choices:
- Starting temperature: choose a problem-dependent value that permits enough early exploration. section 5.2.4
- Temperature decrement: choose a schedule and its cooling settings. Available options in one implementation include linear, geometric, logarithmic, exponential, and linear inverse. section 5.2.4 section 5.3
- Iterations per temperature: decide how much search to perform before cooling again. section 5.2.4
- Final temperature: set the endpoint for cooling. section 5.2.4
If the maximum possible objective change is unknown, try a high temperature that accepts nearly all changes, then reduce it quickly until roughly 50%–60% of worse moves are accepted. Use that temperature as the starting point for slower cooling. section 5.2.4
Function optimization settings
For continuous function optimization, one configuration uses a geometric schedule with initial_temp=1000, final_temp=0.0001, cooling_alpha=0.9, and max_iter_per_temp=100. Change these settings and compare their effect on performance rather than assuming they suit every objective. section 5.3
Listing 5.2 Continuous function optimization using SA
import random
import math
import numpy as np
from optalgotools.algorithms import SimulatedAnnealing
from optalgotools.problems import ProblemBase, ContinuousFunctionBase
def simple_example(x): #1
return (x-6)**2 #1
simple_example_bounds = np.asarray([[0, 31]]) #1
simple_example_obj = ContinuousFunctionBase(simple_example, simple_example_ #1
simple_example_bounds) #1
sa = SimulatedAnnealing(max_iter=1000, max_iter_per_temp=100, #1
initial_ temp=1000, final_temp=0.0001, cooling_schedule='geometric', #1
cooling_alpha=0.9, debug=1) #1
sa.run(simple_example_obj) #1
def Bohachevsky(x_1, x_2): #2
return x_1**2 +2*(x_2**2)-0.3*np.cos(3*np.pi*x_1)-0.4*np.cos(4*np. #2
pi*x_2)+0.7 #2
Bohachevsky_bounds = np.asarray([[-100, 100], [-100, 100]]) #2
Bohachevsky_obj = ContinuousFunctionBase(Bohachevsky, Bohachevsky_bounds, 5) #2
sa.run(Bohachevsky_obj) #2
def bukin(x_1, x_2): #3
return 100*math.sqrt(abs(x_2-0.01*x_1**2)) + 0.01 * abs(x_1 + 10) #3
bukin_bounds = np.asarray([[-15, -5], [-3, 3]]) #3
bukin_obj = ContinuousFunctionBase(bukin, bukin_bounds, 5) #3
sa.run(bukin_obj) #3
def gramacy_and_lee(x): #4
return math.sin(10*pi*x)/(2*x) + (x-1)**4 #4
gramacy_and_lee_bounds = np.asarray([[0.5, 2.5]]) #4
gramacy_and_lee_obj = ContinuousFunctionBase(gramacy_and_lee, gramacy_and_ #4
lee_bounds, .1) #4
sa.run(gramacy_and_lee_obj) #4
def griewank(*x): #5
x = np.asarray(x) #5
return np.sum(x**2/4000) - np.prod(np.cos(x/np.sqrt(np.asarray(range(1, #5
len(x)+1))))) + 1 #5
griewank_bounds = np.asarray([[-600, 600]]) #5
griewank_1d=ContinuousFunctionBase(griewank, griewank_bounds, 10) #5
sa.run(griewank_1d) #5
griewank_bounds_2d = np.asarray([[-600, 600]]*2) #6
griewank_2d=ContinuousFunctionBase(griewank, griewank_bounds_2d, #6
(griewank_bounds_2d[:, 1] - griewank_bounds_2d[:, 0])/10) #6
sa.run(griewank_2d) #6
griewank_bounds_3d = np.asarray([[-600, 600]]*3) #7
griewank_3d=ContinuousFunctionBase(griewank, griewank_bounds_3d, #7
(griewank_bounds_3d[:, 1] - griewank_bounds_3d[:, 0])/10) #7
sa.run(griewank_3d) #7
#1 Quadratic function SA-based solution
#2 Bohachevsky SA-based solution
#3 Bukin SA-based solution
#4 Gramacy & Lee SA-based solution
#5 Griewank 1D SA-based solution
#6 Griewank 2D SA-based solution
#7 Griewank 3D SA-based solution
See the geometric schedule configured in a Python simulated annealing solver. section 5.3
Delivery routing
A semi-truck routing run uses linear cooling, starting at 85 and ending at 0.0001, with up to 100 iterations per temperature. Its route is 227.17 km, compared with 593.88 km for the initial route. Experiment with other schedules and compare both route length and run time; the result does not guarantee feasibility or optimality. section 5.6
A schedule can also adapt during the search: use different cooling schemes in different phases, cool after accepted moves, or try reheating when progress stalls. These are tuning options, not guarantees of a better solution. section 5.2.5 section 5.7
