Table Of Contents

Previous topic

optimizer.py

Next topic

tabusearch.py

This Page

simulated_annealing.py

SIMO metaheuristic simulated annealing algorithm

>>> epsilon = 0.00001

class SimulatedAnnealing(Optimizer):

Simulated annealing heuristic optimization algorithm implementation. Example keyword arguments

repeats=10
initial_solutions=100
maximum_iterations=1000
starting_temperature=0.999
freezing_temperature=0.001
cooling_factor=0.95
iterations_per_temperature=100
iteration_multiplier=0.95
def __init__(self, logger, logname, optlogger, taskdef, simdbin, opdbin,
simdbout, opdbout, **keywords):

Initialize optimizer:

>>> from simo.optimization.simulated_annealing import SimulatedAnnealing
>>> execfile('optimization/test/mocks4optimizer.py')
>>> chart_path = 'optimization/test'

>>> sa = SimulatedAnnealing(
...     logger, logname, taskdef, simdbin, simdbout, False, False,
...     False, chart_path, True, 'test', True, keyword1='test-kw')
Called Logger.log_message(
    'optimization-test',
    'ERROR',
    'Parameter "repeats" missing!')
Called Logger.log_message(
    'optimization-test',
    'ERROR',
    'Parameter "initial_solutions" missing!')
Called Logger.log_message(
    'optimization-test',
    'ERROR',
    'Parameter "maximum_iterations" missing!')
Called Logger.log_message(
    'optimization-test',
    'ERROR',
    'Parameter "starting_temperature" missing!')
Called Logger.log_message(
    'optimization-test',
    'ERROR',
    'Parameter "freezing_temperature" missing!')
Called Logger.log_message(
    'optimization-test',
    'ERROR',
    'Parameter "cooling_factor" missing!')
Called Logger.log_message(
    'optimization-test',
    'ERROR',
    'Parameter "iterations_per_temperature" missing!')
Called Logger.log_message(
    'optimization-test',
    'ERROR',
    'Parameter "iteration_multiplier" missing!')

>>> sa = SimulatedAnnealing(
...     logger, logname, taskdef, simdbin, simdbout, False, False,
...     False, chart_path, True, 'test', True,
...     repeats=2,
...     initial_solutions=5,
...     maximum_iterations=20,
...     starting_temperature=0.999,
...     freezing_temperature=0.001,
...     cooling_factor=0.95,
...     iterations_per_temperature=100,
...     iteration_multiplier=0.95)

def optimize(self):

Run simulated annealinf optimization algorithm

def _run_SA(self, iteration):

Run SA algorithm for a single iteration/repeat

Parameters:

iteration -- current simulated iteration as int
>>> sa._stat_logger = ologger  # replace stat logger with a mock
>>> sa._data = omatrix2  # replace data handler with a mock
>>> sa._analyze_data()  
Called OMatrix.analyze_data(
    <Mock ... SimInputDB>,
    <bound method SimulatedAnnealing._add_info of
    <simo.optimization.simulated_annealing.SimulatedAnnealing object at ...>>)
True
>>> sa.set_data(0)  
Called OMatrix.construct_data(0)
True
>>> sa._curr_U = 0.5  # set current utility
>>> sa._best_U = 0.5  # set best utility
>>> sa._run_SA()  
Called OMatrix.solution_utility(array([...]))
Called OMatrix.solution_feasibility(array([...]))
Called OMatrix.compare_utilities(0.5, 1.0)
Called OMatrix.compare_utilities(0.5, 1.0)
Called OLogger.add_round(array([...]), 1.0, 1.0)
...