Skip to content

Commit 90c5a62

Browse files
committed
Add MutationType::Discrete for completeness to visualize_mutation_types
1 parent 8384141 commit 90c5a62

4 files changed

Lines changed: 46 additions & 7 deletions

File tree

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,22 @@ Run with `cargo run --example [EXAMPLE_BASENAME] --release`
129129
* Custom Mutate implementation
130130
* See [examples/evolve_milp_custom_mutate](../main/examples/evolve_milp_custom_mutate.rs)
131131

132+
## Heterogeneous Genotype Support
133+
134+
MultiRangeGenotype supports heterogeneous chromosomes that mix different gene
135+
semantics (continuous values, discrete choices, booleans) within a single
136+
numeric type `T`.
137+
132138
## Mutation Type Visualization
133139

134-
The library supports various mutation strategies that affect how the genetic algorithm explores the search space. The visualization below shows how different mutation types explore a 2D search space when searching for a target point:
140+
The library supports various mutation strategies that affect how the genetic
141+
algorithm explores the search space. Random leads to the best results overall.
142+
Random is the default and is supported by all Genotypes.
143+
144+
But for continues genotypes (RangeGenotype and MultiRangeGenotype) there are
145+
several alternatives. These might converge faster, but are all more sensitive to
146+
local optima than Random. The visualization below shows how different mutation
147+
types explore a 2D search space when searching for a target point:
135148

136149
![Mutation Types Exploration Patterns](examples/visualize_mutation_types.png)
137150

@@ -141,15 +154,10 @@ The visualization demonstrates:
141154
- **RangeScaled**: Adaptive exploration that starts broad and narrows down (funnel-like convergence)
142155
- **Step**: Fixed-step local search in cardinal directions
143156
- **StepScaled**: Grid-like exploration with progressively finer resolution
157+
- **Discrete**: ListGenotype behaviour, for categories in heterogeneous genotypes
144158

145159
Run the example with `cargo run --example visualize_mutation_types --release` to generate this visualization.
146160

147-
## Heterogeneous Genotype Support
148-
149-
MultiRangeGenotype supports heterogeneous chromosomes that mix different gene
150-
semantics (continuous values, discrete choices, booleans) within a single
151-
numeric type `T`.
152-
153161
## Performance considerations
154162

155163
For the Evolve strategy:
180 KB
Loading

examples/visualize_mutation_types.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ fn main() {
309309
);
310310
reporters.push(("StepScaled (halving)".to_string(), reporter));
311311

312+
// Discrete mutation - like ListGenotype for categories
313+
println!("Running Discrete mutation...");
314+
let reporter = run_evolution(MutationType::Discrete, "Discrete".to_string(), 50);
315+
reporters.push((
316+
"Discrete (floored integers, map to categories)".to_string(),
317+
reporter,
318+
));
319+
312320
// Generate visualization
313321
println!("\nGenerating visualization...");
314322
if let Err(e) = generate_plot(reporters, "examples/visualize_mutation_types.png") {
@@ -321,5 +329,6 @@ fn main() {
321329
println!("- RangeScaled: Funnel-like convergence, broad exploration then fine-tuning");
322330
println!("- Step: Local search with fixed step, smooth but may get stuck");
323331
println!("- StepScaled: Grid-like exploration with progressively finer resolution");
332+
println!("- Discrete: ListGenotype behaviour, for categories in heterogeneous genotypes");
324333
println!("Color gradient: Blue (early) → Green (late) generations");
325334
}

src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@
115115
//! different gene semantics (continuous values, discrete choices, booleans) within a single
116116
//! numeric type `T`.
117117
//!
118+
//! ## [MutationType](crate::genotype::MutationType) Visualization
119+
//!
120+
//! The library supports various mutation strategies that affect how the genetic
121+
//! algorithm explores the search space. Random leads to the best results overall.
122+
//! Random is the default and is supported by all Genotypes.
123+
//!
124+
//! But for continues genotypes ([RangeGenotype](crate::genotype::RangeGenotype) and
125+
//! [MultiRangeGenotype](crate::genotype::MultiRangeGenotype)) there are several alternatives.
126+
//! These might converge faster, but are all more sensitive to local optima than Random. The
127+
//! visualization example shows how different mutation types explore a 2D search space when searching
128+
//! for a target point:
129+
//!
130+
//! The visualization demonstrates:
131+
//! - **Random**: Chaotic exploration, can jump anywhere in search space
132+
//! - **Range**: Local search with fixed radius around current position
133+
//! - **RangeScaled**: Adaptive exploration that starts broad and narrows down (funnel-like convergence)
134+
//! - **Step**: Fixed-step local search in cardinal directions
135+
//! - **StepScaled**: Grid-like exploration with progressively finer resolution
136+
//! - **Discrete**: ListGenotype behaviour, for categories in heterogeneous genotypes
137+
//!
138+
//! Run the example with `cargo run --example visualize_mutation_types --release` to generate the visualization.
139+
//!
118140
//! ## Performance considerations
119141
//!
120142
//! For the [Evolve](strategy::evolve::Evolve) strategy:

0 commit comments

Comments
 (0)