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
89
//! `heuropt` — a practical Rust toolkit for heuristic single-,
//! multi-, and many-objective optimization.
//!
//! The crate aims to make three things obvious:
//!
//! 1. **Define a problem** by implementing [`Problem`](crate::core::Problem).
//! 2. **Run a built-in optimizer** — pick from 33 algorithms in
//! [`algorithms`] covering single-objective continuous (CMA-ES,
//! Differential Evolution, Nelder-Mead, …), multi-objective
//! (NSGA-II, MOPSO, IBEA, MOEA/D, …), many-objective (NSGA-III,
//! GrEA, RVEA, …), and sample-efficient regimes (Bayesian
//! Optimization, TPE, Hyperband).
//! 3. **Or implement your own** by implementing
//! [`Optimizer`](crate::traits::Optimizer). The trait is one
//! method long.
//!
//! ## Where to read more
//!
//! - **User guide / cookbook / comparison vs pymoo & friends:**
//! <https://swaits.github.io/heuropt/>.
//! - **Algorithm selection:** the README's decision tree, or the
//! "Choosing an algorithm" book chapter.
//! - **Design rationale:** `docs/heuropt_tech_design_spec.md` in the
//! repository.
//!
//! ## Optional features
//!
//! - `serde` — derives `Serialize` / `Deserialize` on the core data
//! types ([`Candidate`](crate::core::Candidate),
//! [`Population`](crate::core::Population),
//! [`Evaluation`](crate::core::Evaluation), …) and enables the
//! [`heuropt::explorer`](crate::explorer) JSON export module for the
//! [heuropt-explorer](https://swaits.github.io/heuropt-explorer/)
//! webapp.
//! - `parallel` — rayon-backed parallel population evaluation in
//! every population-based algorithm. Seeded runs stay bit-
//! identical to serial mode.
//! - `async` — adds the
//! [`AsyncProblem`](crate::core::async_problem::AsyncProblem) and
//! [`AsyncPartialProblem`](crate::core::async_problem::AsyncPartialProblem)
//! traits and a `run_async(&problem, concurrency).await` method on
//! every algorithm. Use this when your `evaluate` does IO (HTTP,
//! RPC, subprocess) — see the [Async evaluation cookbook recipe](https://swaits.github.io/heuropt/cookbook/async.html).
//!
//! # Quick example
//!
//! ```
//! use heuropt::prelude::*;
//!
//! struct Toy;
//!
//! impl Problem for Toy {
//! type Decision = Vec<f64>;
//!
//! fn objectives(&self) -> ObjectiveSpace {
//! ObjectiveSpace::new(vec![
//! Objective::minimize("f1"),
//! Objective::minimize("f2"),
//! ])
//! }
//!
//! fn evaluate(&self, x: &Vec<f64>) -> Evaluation {
//! Evaluation::new(vec![x[0] * x[0], (x[0] - 2.0).powi(2)])
//! }
//! }
//!
//! let initializer = RealBounds::new(vec![(-5.0, 5.0)]);
//! let variation = GaussianMutation { sigma: 0.2 };
//! let config = Nsga2Config { population_size: 30, generations: 10, seed: 42 };
//! let mut opt = Nsga2::new(config, initializer, variation);
//! let result = opt.run(&Toy);
//! assert_eq!(result.population.len(), 30);
//! assert!(!result.pareto_front.is_empty());
//! ```
pub
pub