object
simulated_annealing(Problem,RandomAlgorithm)
Problem- Problem object implementingsimulated_annealing_protocol.RandomAlgorithm- Random number generator algorithm for thefast_randomlibrary (e.g.xoshiro128pp,xoshiro256ss,well512a, …).
Simulated annealing optimization algorithm. Parameterized by a problem object implementing the simulated_annealing_protocol protocol and by a random number generator algorithm for the fast_random library. The algorithm minimizes the energy (cost) function defined by the problem. Custom cooling schedules, stop conditions, delta-energy neighbor generation, progress reporting, and reheating restarts can be defined by the problem object or configured via options; suitable defaults are used otherwise.
logtalk_load(simulated_annealing(loader))static, context_switching_calls
Algorithm: Simulated annealing is a probabilistic metaheuristic for global optimization. It explores the solution space by iteratively generating neighbor states and accepting them based on an energy-dependent probability that decreases over time as the temperature cools.
Acceptance criterion: Uses the standard Boltzmann acceptance criterion: a worse neighbor is accepted with probability
exp(-DeltaE / Temperature).Default cooling schedule: Geometric cooling:
NewTemp is Temp * 0.995. Override by definingcooling_schedule/3in the problem object.Default stop condition: The search stops when the maximum number of steps is reached or the temperature drops below the minimum temperature. Override by defining
stop_condition/3in the problem object.Delta-energy optimization: If the problem object defines
neighbor_state/3, the algorithm uses the returned delta energy directly instead of callingstate_energy/2on the neighbor. This is useful when computing the energy change is cheaper than recomputing the full energy.Progress reporting: If the problem object defines
progress/5, it is called periodically with the current step, temperature, best energy, acceptance rate, and improvement rate. The reporting interval is controlled by theupdates(N)option. A final report is always produced when the loop terminates.Best state tracking: The algorithm tracks the best state found across all iterations and across all restart cycles, not just the final state.
Seed control: The
seed(S)option initializes the random number generator for reproducible runs.Reheating restart: The
restarts(N)option runs N additional SA cycles after the first. Each restart reheats the temperature to the initial value and begins from the best state found so far, allowing the search to escape local minima. Statistics accumulate across all cycles.Auto-temperature estimation: The
estimate_temperature/1-2predicates sample random neighbor transitions and compute an initial temperature that would produce a target acceptance rate. This avoids manual tuning of the initial temperature.
Public predicates
estimate_temperature/1
Estimates an initial temperature for the problem using default options (200 samples, 80% target acceptance rate).
staticestimate_temperature(Temperature)estimate_temperature(-float) - oneestimate_temperature/2
Estimates an initial temperature by sampling random neighbor transitions. The temperature is computed so that the Boltzmann acceptance probability for the average uphill move equals the target acceptance rate. Sampling starts from the problem initial state and follows a random walk.
staticestimate_temperature(Temperature,Options)estimate_temperature(-float,+list(compound)) - one
samples(N)option: Number of random neighbor transitions to sample (default:200).
acceptance_rate(P)option: Target initial acceptance rate as an integer percentage between 1 and 99 (default:80).
run/2
Runs the simulated annealing algorithm using default options and returns the best state found and its energy.
staticrun(BestState,BestEnergy)run(-term,-number) - onerun/3
Runs the simulated annealing algorithm using the given options and returns the best state found and its energy.
staticrun(BestState,BestEnergy,Options)run(-term,-number,+list(compound)) - one
max_steps(N)option: Maximum number of iterations per cycle (default:10000).
min_temperature(T)option: Minimum temperature floor; search stops when temperature drops below this value (default:0.001).
updates(N)option: Number of progress reports during the run. Set to0to disable. Progress is reported by callingprogress/5on the problem object (default:0).
seed(S)option: Positive integer seed for the random number generator, enabling reproducible runs (default: none).
restarts(N)option: Number of additional SA cycles after the first. Each restart reheats the temperature and begins from the best state found so far (default:0).
run/4
Runs the simulated annealing algorithm using the given options, returns the best state found and its energy, and returns run statistics.
staticrun(BestState,BestEnergy,Statistics,Options)run(-term,-number,-list(compound),+list(compound)) - one
Statistics list: A list of
Key(Value)pairs:steps(N)is the number of steps executed,acceptances(A)is the number of accepted moves,improvements(I)is the number of moves that improved the best energy, andfinal_temperature(T)is the temperature at termination.
Protected predicates
(no local declarations; see entity ancestors if any)
Private predicates
(no local declarations; see entity ancestors if any)
Operators
(none)