pub struct SimulatedAnnealing<F, R> { /* private fields */ }
Expand description

Simulated Annealing

Simulated Annealing (SA) is a stochastic optimization method which imitates annealing in metallurgy. Parameter vectors are randomly modified in each iteration, where the degree of modification depends on the current temperature. The algorithm starts with a high temperature (a lot of modification and hence movement in parameter space) and continuously cools down as the iterations progress, hence narrowing down in the search. Under certain conditions, reannealing (increasing the temperature) can be performed. Solutions which are better than the previous one are always accepted and solutions which are worse are accepted with a probability proportional to the cost function value difference of previous to current parameter vector. These measures allow the algorithm to explore the parameter space in a large and a small scale and hence it is able to overcome local minima.

The initial temperature has to be provided by the user as well as the a initial parameter vector (via configure of Executor.

The cooling schedule can be set with SimulatedAnnealing::with_temp_func. For the available choices please see SATempFunc.

Reannealing can be performed if no new best solution was found for N iterations (SimulatedAnnealing::with_reannealing_best), or if no new accepted solution was found for N iterations (SimulatedAnnealing::with_reannealing_accepted) or every N iterations without any other conditions (SimulatedAnnealing::with_reannealing_fixed).

The user-provided problem must implement Anneal which defines how parameter vectors are modified. Please see the Simulated Annealing example for one approach to do so for floating point parameters.

Requirements on the optimization problem

The optimization problem is required to implement CostFunction.

References

Wikipedia

S Kirkpatrick, CD Gelatt Jr, MP Vecchi. (1983). “Optimization by Simulated Annealing”. Science 13 May 1983, Vol. 220, Issue 4598, pp. 671-680 DOI: 10.1126/science.220.4598.671

Implementations

Construct a new instance of SimulatedAnnealing

Takes the initial temperature as input, which must be >0.

Uses the Xoshiro256PlusPlus RNG internally. For use of another RNG, consider using SimulatedAnnealing::new_with_rng.

Example
let sa = SimulatedAnnealing::new(100.0f64)?;

Construct a new instance of SimulatedAnnealing

Takes the initial temperature as input, which must be >0. Requires a RNG which must implement rand::Rng (and serde::Serialize if the serde1 feature is enabled).

Example
let sa = SimulatedAnnealing::new_with_rng(100.0f64, my_rng)?;

Set temperature function

The temperature function defines how the temperature is decreased over the course of the iterations. See SATempFunc for the available options. Defaults to SATempFunc::TemperatureFast.

Example
let sa = SimulatedAnnealing::new(100.0f64)?.with_temp_func(SATempFunc::Boltzmann);

If there are no accepted solutions for iter iterations, the algorithm stops.

Defaults to std::u64::MAX.

Example
let sa = SimulatedAnnealing::new(100.0f64)?.with_stall_accepted(1000);

If there are no new best solutions for iter iterations, the algorithm stops.

Defaults to std::u64::MAX.

Example
let sa = SimulatedAnnealing::new(100.0f64)?.with_stall_best(2000);

Set number of iterations after which reannealing is performed

Every iter iterations, reannealing (resetting temperature to its initial value) will be performed. This may help in overcoming local minima.

Defaults to std::u64::MAX.

Example
let sa = SimulatedAnnealing::new(100.0f64)?.with_reannealing_fixed(5000);

Set the number of iterations that need to pass after the last accepted solution was found for reannealing to be performed.

If no new accepted solution is found for iter iterations, reannealing (resetting temperature to its initial value) is performed. This may help in overcoming local minima.

Defaults to std::u64::MAX.

Example
let sa = SimulatedAnnealing::new(100.0f64)?.with_reannealing_accepted(5000);

Set the number of iterations that need to pass after the last best solution was found for reannealing to be performed.

If no new best solution is found for iter iterations, reannealing (resetting temperature to its initial value) is performed. This may help in overcoming local minima.

Defaults to std::u64::MAX.

Example
let sa = SimulatedAnnealing::new(100.0f64)?.with_reannealing_best(5000);

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more

Perform one iteration of SA algorithm

Name of the solver. Mainly used in Observers.
Initializes the algorithm. Read more
Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more
Checks whether basic termination reasons apply. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.