Parallel evolution with multiple populations and migration.
use fugue_evo::algorithms::island::{
IslandModel, IslandModelBuilder, IslandConfig,
MigrationTopology, MigrationPolicy
};| Method | Type | Description |
|---|---|---|
bounds(bounds) |
MultiBounds |
Search space bounds |
selection(sel) |
impl SelectionOperator |
Selection operator |
crossover(cx) |
impl CrossoverOperator |
Crossover operator |
mutation(mut) |
impl MutationOperator |
Mutation operator |
fitness(fit) |
impl Fitness |
Fitness function |
| Method | Type | Default | Description |
|---|---|---|---|
num_islands(n) |
usize |
4 | Number of islands |
island_population_size(n) |
usize |
50 | Population per island |
topology(t) |
MigrationTopology |
Ring | Connection pattern |
migration_interval(n) |
usize |
25 | Generations between migrations |
migration_policy(p) |
MigrationPolicy |
Best(2) | What to migrate |
pub enum MigrationTopology {
/// Each island connects to 2 neighbors
Ring,
/// Central hub connects to all
Star,
/// Every island connects to every other
FullyConnected,
}1 ←→ 2
↕ ↕
4 ←→ 3
2 3
\ /
1 (hub)
/ \
5 4
1 ←→ 2
↕ ✕ ↕
4 ←→ 3
pub enum MigrationPolicy {
/// Send n best individuals
Best(usize),
/// Send n random individuals
Random(usize),
/// Replace n worst with immigrants
ReplaceWorst(usize),
}use fugue_evo::prelude::*;
let mut model = IslandModelBuilder::<RealVector, _, _, _, _, f64>::new()
.num_islands(4)
.island_population_size(50)
.topology(MigrationTopology::Ring)
.migration_interval(25)
.migration_policy(MigrationPolicy::Best(2))
.bounds(MultiBounds::symmetric(5.12, 20))
.selection(TournamentSelection::new(3))
.crossover(SbxCrossover::new(15.0))
.mutation(PolynomialMutation::new(20.0))
.fitness(Rastrigin::new(20))
.build(&mut rng)?;
let best = model.run(200, &mut rng)?;
println!("Best fitness: {}", best.fitness_value());let mut model = IslandModelBuilder::new()
// ... configuration
.build(&mut rng)?;
for gen in 0..max_generations {
model.step(&mut rng)?;
if gen % 50 == 0 {
println!("Generation {}: best on each island:", gen);
for (i, island) in model.islands.iter().enumerate() {
let best = island.best().unwrap();
println!(" Island {}: {:.6}", i, best.fitness_value());
}
}
}// Trigger migration outside normal interval
model.migrate(&mut rng);pub struct IslandModel<G, F, S, C, M, Fit> {
pub islands: Vec<Population<G, F>>,
pub generation: usize,
pub config: IslandConfig,
// ...
}pub struct IslandConfig {
pub num_islands: usize,
pub island_population_size: usize,
pub topology: MigrationTopology,
pub migration_interval: usize,
pub migration_policy: MigrationPolicy,
}Each migration event:
- Each island selects emigrants (per policy)
- Emigrants sent to neighbors (per topology)
- Immigrants replace worst individuals
Total population remains constant.
- Island count: 4-8 typically sufficient
- Migration interval: 20-50 generations
- Migration size: 1-5 individuals
- Topology: Ring for diversity, Fully Connected for speed