Expand description
heuropt — a practical Rust toolkit for heuristic single-,
multi-, and many-objective optimization.
The crate aims to make three things obvious:
- Define a problem by implementing
Problem. - Run a built-in optimizer — pick from 33 algorithms in
algorithmscovering 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). - Or implement your own by implementing
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.mdin the repository.
§Optional features
serde— derivesSerialize/Deserializeon the core data types (Candidate,Population,Evaluation, …) and enables theheuropt::explorerJSON export module for the heuropt-explorer webapp.parallel— rayon-backed parallel population evaluation in every population-based algorithm. Seeded runs stay bit- identical to serial mode.async— adds theAsyncProblemandAsyncPartialProblemtraits and arun_async(&problem, concurrency).awaitmethod on every algorithm. Use this when yourevaluatedoes IO (HTTP, RPC, subprocess) — see the Async evaluation cookbook recipe.
§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());Modules§
- algorithms
- Built-in reference optimizers.
- core
- Concrete data types and the
Problemtrait that the rest of the crate is built on. - metrics
- Quality metrics for Pareto fronts.
- operators
- Built-in operators for common decision types.
- pareto
- Pareto utilities: dominance, fronts, sorting, crowding, and an archive.
- prelude
- Common imports for users of
heuropt. - selection
- Reusable selection helpers used by built-in algorithms.
- traits
- The small set of traits that user code and built-in algorithms implement.