primordial_opt/lib.rs
1//! Genetic algorithm library with composable selection, crossover, and mutation operators.
2//!
3//! # Overview
4//!
5//! `primordial-opt` provides building blocks for evolutionary optimization:
6//!
7//! - [`Chromosome`] - Binary representation with fitness caching
8//! - [`selection`] - Parent selection (`rank`, `tournament`, `roulette`, `nsga2`)
9//! - [`crossover`] - Recombination operators (`single_point`)
10//! - [`mutation`] - Mutation operators (`bit_flip`, `fill_random`)
11//! - [`run_ga`] - High-level GA runner with configurable parameters
12//!
13//! # Quick Start
14//!
15//! Use [`run_ga`] for a complete GA loop:
16//!
17//! ```ignore
18//! use primordial_opt::{run_ga, GaConfig};
19//!
20//! let result = run_ga(
21//! &GaConfig::default().population_size(100).generations(500),
22//! 16, // chromosome size in bytes
23//! |c| vec![fitness(c)], // fitness function
24//! |p| println!("Gen {}", p.generation), // progress callback
25//! &mut rng,
26//! );
27//! ```
28//!
29//! # Low-Level API
30//!
31//! For custom GA loops, use the individual operators:
32//!
33//! ```ignore
34//! use primordial_opt::{Chromosome, selection, crossover, mutation};
35//!
36//! let parents: Vec<_> = selection::rank(&population).take(50).collect();
37//! let (mut c1, mut c2) = crossover::single_point(&parents[0], &parents[1], &mut rng);
38//! mutation::bit_flip(&mut c1, 0.01, &mut rng);
39//! ```
40
41mod chromosome;
42mod runner;
43
44pub use chromosome::Chromosome;
45pub use runner::{run_ga, GaConfig, GaResult, Progress};
46
47pub mod crossover;
48pub mod mutation;
49pub mod selection;