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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! # Frostfire
//!
//! A modular, mathematically rigorous, performant, reusable simulated annealing optimization engine.
//!
//! ## Overview
//!
//! Simulated annealing is a probabilistic technique for approximating the global optimum
//! of a given function. It is often used when the search space is discrete and finding
//! an approximate global optimum is more important than finding a precise local optimum.
//!
//! This library provides a modular framework for implementing simulated annealing solutions
//! with a focus on:
//!
//! - Mathematical rigor and correctness
//! - Deterministic behavior (when seeded)
//! - Performance through zero-cost abstractions
//! - Modular and reusable components
//!
//! ## Core Components
//!
//! - `State`: Represents a candidate solution in the search space
//! - `Energy`: Defines the cost function to be minimized
//! - `Schedule`: Controls the cooling process during annealing
//! - `Annealer`: The main engine that performs the optimization
//!
//! ## Example
//!
//! ```rust
//! use frostfire::prelude::*;
//! use rand::Rng;
//!
//! // Define your problem state
//! #[derive(Clone)]
//! struct MyState(Vec<f64>);
//!
//! impl State for MyState {
//! 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
//! }
//! }
//!
//! // Define your energy/cost function
//! struct MyEnergy;
//!
//! impl Energy for MyEnergy {
//! type State = MyState;
//!
//! fn cost(&self, state: &Self::State) -> f64 {
//! // Simple quadratic function
//! state.0.iter().map(|x| x * x).sum()
//! }
//! }
//!
//! // Run the annealer (not executed in doc tests)
//! # fn main() {
//! let initial_state = MyState(vec![1.0, 1.0, 1.0]);
//! let energy = MyEnergy;
//! let schedule = GeometricSchedule::new(100.0, 0.95);
//!
//! let mut annealer = Annealer::new(
//! initial_state,
//! energy,
//! schedule,
//! seeded_rng(42),
//! 10000,
//! );
//!
//! let (best_state, best_energy) = annealer.run();
//! # }
//! ```
// Re-export core components for convenient access
pub use crateAnnealer;
pub use crateEnergy;
pub use crate;
pub use crateState;
pub use cratetransition;
pub use crateseeded_rng;