v2026.6.1
All Bundles
Bundle Classic AI algorithms: graph search, adversarial game search, optimization and tabular reinforcement learning (-lib ai)

SimulatedAnnealing

Simulated annealing over a numeric state vector: a random coordinate is perturbed uniformly within +/- step_size, worse states are accepted with probability e^(-delta/T), and the temperature cools geometrically. Seeded for reproducible runs.

Example

sa := SimulatedAnnealing->New(10.0, 0.95, 0.5, 7);
best := sa->Run(energy, start, 2000);

Operations

GetBestEnergy #

Gets the best (lowest) energy seen during the last run.

method : public : GetBestEnergy() ~ Float

Return

TypeDescription
Floatbest energy

New # constructor

Constructor

New(initial_temperature:Float, cooling:Float, step_size:Float, seed:Int)

Parameters

NameTypeDescription
initial_temperatureFloatstarting temperature (> 0)
coolingFloatgeometric cooling factor per iteration (0..1)
step_sizeFloatmaximum coordinate perturbation
seedIntPRNG seed for reproducible runs

Run #

Minimizes the energy starting from the given state.

method : public : Run(energy:EnergyFunction, start:Float[], iterations:Int) ~ Float[]

Parameters

NameTypeDescription
energyEnergyFunctionenergy function (lower is better)
startFloatstarting state (copied, not modified)
iterationsIntannealing steps

Return

TypeDescription
Floatbest state found, or Nil on invalid input