1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! State representation for simulated annealing.
//!
//! The `State` trait represents a candidate solution in the search space.
//! It provides methods for generating neighboring states during the annealing process.
use Rng;
/// The `State` trait defines the representation of a candidate solution
/// in the simulated annealing process.
///
/// Implementors must provide a method to generate a neighboring state,
/// which is a slight modification of the current state according to some
/// problem-specific rule.
///
/// # Examples
///
/// ```
/// use frostfire::prelude::*;
/// use rand::Rng;
///
/// #[derive(Clone)]
/// struct VectorState(Vec<f64>);
///
/// impl State for VectorState {
/// fn neighbor(&self, rng: &mut impl Rng) -> Self {
/// let mut new_state = self.clone();
/// let idx = rng.gen_range(0..new_state.0.len());
/// new_state.0[idx] += rng.gen_range(-0.1..0.1);
/// new_state
/// }
/// }
/// ```