Crate primordial_opt

Crate primordial_opt 

Source
Expand description

Genetic algorithm library with composable selection, crossover, and mutation operators.

§Overview

primordial-opt provides building blocks for evolutionary optimization:

  • Chromosome - Binary representation with fitness caching
  • selection - Parent selection (rank, tournament, roulette, nsga2)
  • crossover - Recombination operators (single_point)
  • mutation - Mutation operators (bit_flip, fill_random)
  • run_ga - High-level GA runner with configurable parameters

§Quick Start

Use run_ga for a complete GA loop:

use primordial_opt::{run_ga, GaConfig};

let result = run_ga(
    &GaConfig::default().population_size(100).generations(500),
    16,  // chromosome size in bytes
    |c| vec![fitness(c)],  // fitness function
    |p| println!("Gen {}", p.generation),  // progress callback
    &mut rng,
);

§Low-Level API

For custom GA loops, use the individual operators:

use primordial_opt::{Chromosome, selection, crossover, mutation};

let parents: Vec<_> = selection::rank(&population).take(50).collect();
let (mut c1, mut c2) = crossover::single_point(&parents[0], &parents[1], &mut rng);
mutation::bit_flip(&mut c1, 0.01, &mut rng);

Modules§

crossover
Crossover operators for genetic recombination.
mutation
Mutation operators for introducing genetic variation.
selection
Selection operators for parent selection in genetic algorithms.

Structs§

Chromosome
A binary chromosome for genetic algorithms.
GaConfig
Configuration for the genetic algorithm.
GaResult
Result of running the genetic algorithm.
Progress
Progress snapshot passed to the callback each generation.

Functions§

run_ga
Runs a genetic algorithm loop.