Expand description
§hill_descent_lib
A genetic algorithm library for n-dimensional optimization problems.
This library implements a spatial genetic algorithm that divides the search space into adaptive regions, allowing efficient exploration of complex fitness landscapes. It’s particularly well-suited for optimization problems where gradient information is unavailable or unreliable.
§Quick Start
use hill_descent_lib::{GlobalConstants, SingleValuedFunction, setup_world};
use std::ops::RangeInclusive;
// Define your fitness function (lower is better)
#[derive(Debug)]
struct Quadratic;
impl SingleValuedFunction for Quadratic {
fn single_run(&self, params: &[f64]) -> f64 {
// Minimize: x² + y²
params[0].powi(2) + params[1].powi(2)
}
}
// Set up and run optimization
use hill_descent_lib::TrainingData;
let bounds = vec![-10.0..=10.0, -10.0..=10.0];
let constants = GlobalConstants::new(100, 10);
let mut world = setup_world(&bounds, constants, Box::new(Quadratic));
for _ in 0..100 {
world.training_run(TrainingData::None { floor_value: 0.0 });
}
println!("Best score: {}", world.get_best_score());§Core Concepts
- World: The main optimization container that manages the population and search space
- Organisms: Individual solutions with genetic material (DNA) that evolve over generations
- Regions: Spatial partitions of the search space that adapt based on organism distribution
- Fitness Function: User-defined function to minimize (implement
SingleValuedFunction)
§Features
- N-dimensional optimization (tested with 100+ dimensions)
- Adaptive spatial regions for efficient exploration
- Deterministic results via seeded RNG
- Parallel processing with Rayon
- Optional tracing support (feature:
enable-tracing)
§Algorithm Overview
- Initialization: Random population within specified bounds
- Evaluation: Each organism scored by fitness function
- Regional Competition: Organisms compete within their spatial regions
- Reproduction: Better organisms get more offspring via sexual reproduction
- Mutation: Genetic variation through adaptive mutation
- Adaptation: Regions dynamically adjust based on population distribution
The algorithm automatically manages carrying capacity, organism aging, mutation rates, and search space expansion.
Re-exports§
pub use parameters::GlobalConstants;pub use training_data::TrainingData;pub use world::World;pub use world::format_score;pub use world::single_valued_function::SingleValuedFunction;pub use world::world_function::WorldFunction;
Modules§
- parameters
- Configuration and parameter types for genetic algorithm control.
- training_
data - Training data configuration for optimization runs.
- world
- The main simulation container and fitness evaluation interfaces.
Macros§
Functions§
- setup_
world - Creates and initializes a new optimization world.