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

HillClimbing

Random-restart stochastic hill climbing over a numeric state vector: each step perturbs one random coordinate and keeps strict improvements; when no improvement is found for `patience` consecutive steps the search restarts from a random point within +/- restart_range of the start. Seeded for reproducible runs.

Example

hc := HillClimbing->New(0.5, 50, 5.0, 7);
best := hc->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(step_size:Float, patience:Int, restart_range:Float, seed:Int)

Parameters

NameTypeDescription
step_sizeFloatmaximum coordinate perturbation
patienceIntsteps without improvement before a restart
restart_rangeFloatrestart sampling half-range around the start state
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)
iterationsInttotal climbing steps across restarts

Return

TypeDescription
Floatbest state found, or Nil on invalid input