This library contains a behavior that you can use in your simulation to perform a maximizing optimzation search.
Simulated Annealing
Simulated Annealing is a stochastic search algorithm inspired by the annealing, or cooling, of atomic crystals in a solid. Each time step it randomly selects a "neighboring" solution and checks its fitness. If it's an improvement, it will automatically "move" to that solution, and if not, it still has a chance of doing so proportional to the current "temperature" of the optimization.
Integrating Into a Simulation
For the behavior to function, you'll need to write at least one custom behavior, and set a number of parameters in globals.json.
Global Parameters
The following parameters are needed for the @hash/sa-search/simulated_annealing.py
behavior to function properly:
temp_reduction_rate
- number: The rate at which the "temperature" of the search decreasesstop_temp
- number: The "temperature" at which the search ends
Custom Behaviors
Your optimizing agent must have at least one custom behavior running before @hash/sa-search/simulated_annealing.py
. This behavior must determine the "neighboring" solutions based on the current solution. In the spatial example in this project, literal neighbors are used.
This behavior must assign this list of solutions to state["neighboring_solutions"]
, and must ensure that each solution has a fitness
field with a valid numerical value.
Initialization
To begin a Simulated Annealing optimization, initialize an agent with the proper behaviors and following fields:
{
"behaviors": [
"<custom>",
"@hash/sa-search/simulated_annealing.py",
...
],
"temp": 1,
"fitness": 0,
"neighboring_solutions": []
}