pub fn simulated_annealing<A: 'static + Send + Sync, T: 'static + Copy + Send + Sync + Default + SampleUniform + PartialOrd + Sub<Output = T> + ToPrimitive + FromPrimitive, const N: usize>(
    ranges: [Range<T>; N],
    f: fn(_: &[T; N], _: Option<Arc<A>>) -> f64,
    evaluation_data: Option<Arc<A>>,
    polling: Option<Polling>,
    threads: Option<usize>,
    starting_temperature: f64,
    minimum_temperature: f64,
    cooling_schedule: CoolingSchedule,
    samples_per_temperature: u64,
    variance: f64
) -> [T; N]
Expand description

Simulated annealing

Run simulated annealing starting at temperature 100. decaying with a fast cooling schedule until reach a minimum temperature of 1., taking 100 samples at each temperature, with a variance in sampling of 1..

use std::sync::Arc;
use simple_optimization::{simulated_annealing, Polling};
fn simple_function(list: &[f64; 3], _: Option<Arc<()>>) -> f64 {
 list.iter().sum()
}
let best = simulated_annealing(
    [0f64..10f64, 5f64..15f64, 10f64..20f64], // Value ranges.
    simple_function, // Evaluation function.
    None, // No additional evaluation data.
    // By using `new` this defaults to polling every `10ms`, we don't print progress `false` and exit early if `19.` or less is reached.
    Some(Polling::new(false,Some(17.))),
    None, // We don't specify the number of threads.
    100., // Starting temperature is `100.`.
    1., // Minimum temperature is `1.`.
    simple_optimization::CoolingSchedule::Fast, // Use fast cooling schedule.
    // Take `100` samples per temperature
    // This is split between threads, so each thread only samples
    //  `100/n` at each temperature.
    100,
    1., // Variance in sampling.
);
assert!(simple_function(&best, None) < 19.);