Simulated Annealing

Example:


from bejoor.physics_based import SimulatedAnnealing

def func(sol):
    return (sol[1]**sol[0] + sol[2]**sol[0] - sol[3]**sol[0] - sol[4]**sol[0]) ** 2


solution_vector =  [{"type": "integer", "lower_bound": 2, "upper_bound": 10}] + \
                   [{"type": "float", "lower_bound": 0.0, "upper_bound": 1.0}] *4


# without target objective value
sa= SimulatedAnnealing(objective_function=func, solution_vector_size=5,
                 solution_vector=solution_vector, optimization_side="min",
                 initial_temperature=1000, cooling_rate=0.9,
                 population_size=10000, epochs=100)
sa.run()

print(f'Best Global Objective Value: {sa.global_best_objective_value}')
print(f'Best Global Solution: {sa.global_best_solution}')

Parameters:

  • objective_function: Objective function needs to be optimized.
  • solution_vector_size: Vector size of the candidate solutions.
  • solution_vector: A vector which determines the types of each variable in solution vectors.
  • optimization_side: Determines maximize or minimize the objective function.
  • target_objective_value: Target Objective value.
  • target_objective_lower_bound: Target Objective lower bound.
  • target_objective_upper_bound: Target Objective upper bound.
  • population_size: Number of individuals in the population.
  • epochs: Number of generations to run the algorithm.
  • initial_temperature: The starting temperature for the annealing process.
  • cooling_rate: The rate at which the temperature decreases.

BibTeX citation to the algorithm


@article{kirkpatrick1983optimization,
  title={Optimization by simulated annealing},
  author={Kirkpatrick, Scott and Gelatt Jr, C Daniel and Vecchi, Mario P},
  journal={science},
  volume={220},
  number={4598},
  pages={671--680},
  year={1983},
  publisher={American association for the advancement of science}
}

More useful resources about the algorithm: