From 362de191b447cffb4117c97385f903ef3b50b20f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Mar 2026 11:41:59 +0000 Subject: [PATCH 1/3] Initial plan From 820b77f181b5c14e49f473de37598642c9f927c9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Mar 2026 11:44:39 +0000 Subject: [PATCH 2/3] Fix ActionIfIsolated::DoNothing hang when all species are isolated Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com> --- genetic-rs-common/src/builtin/repopulator.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/genetic-rs-common/src/builtin/repopulator.rs b/genetic-rs-common/src/builtin/repopulator.rs index 99a46ca..3fad2a8 100644 --- a/genetic-rs-common/src/builtin/repopulator.rs +++ b/genetic-rs-common/src/builtin/repopulator.rs @@ -177,8 +177,9 @@ mod speciation { /// This can be used to prevent species from going extinct due to bad luck in crossover. pub enum ActionIfIsolated { /// Do nothing, allowing the species to go extinct if the genome is not fit enough. - /// Note that if all species have only one member (not likely, but possible), - /// this can result in the repopulator hanging. + /// If *all* species happen to be isolated (no species has ≥ 2 members), the + /// repopulator automatically falls back to [`CrossoverRepopulator`] to avoid + /// an infinite loop. DoNothing, /// Perform crossover between the genome and itself to create a new member of the species. @@ -261,6 +262,17 @@ mod speciation { let population = SpeciatedPopulation::from_genomes(genomes, self.speciation_threshold, &self.ctx); + // When DoNothing is selected, the loop skips isolated species without + // making progress. If *all* species are isolated there are no eligible + // pairs and the loop would never terminate. Fall back to the inner + // repopulator in that case. + if matches!(self.action_if_isolated, ActionIfIsolated::DoNothing) + && !population.species.iter().any(|s| s.len() >= 2) + { + self.inner.repopulate(genomes, target_size); + return; + } + let amount_to_make = target_size - initial_size; let mut species_cycle = population.round_robin_enumerate(); From 12340c1dffe24a71cdf9d815f84eebb76cb64c60 Mon Sep 17 00:00:00 2001 From: Tristan Murphy <72839119+HyperCodec@users.noreply.github.com> Date: Tue, 10 Mar 2026 11:52:16 +0000 Subject: [PATCH 3/3] fix doc comment --- genetic-rs-common/src/builtin/repopulator.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/genetic-rs-common/src/builtin/repopulator.rs b/genetic-rs-common/src/builtin/repopulator.rs index 3fad2a8..624719c 100644 --- a/genetic-rs-common/src/builtin/repopulator.rs +++ b/genetic-rs-common/src/builtin/repopulator.rs @@ -177,7 +177,7 @@ mod speciation { /// This can be used to prevent species from going extinct due to bad luck in crossover. pub enum ActionIfIsolated { /// Do nothing, allowing the species to go extinct if the genome is not fit enough. - /// If *all* species happen to be isolated (no species has ≥ 2 members), the + /// If all species happen to be isolated (no species has >= 2 members), the /// repopulator automatically falls back to [`CrossoverRepopulator`] to avoid /// an infinite loop. DoNothing, @@ -262,10 +262,7 @@ mod speciation { let population = SpeciatedPopulation::from_genomes(genomes, self.speciation_threshold, &self.ctx); - // When DoNothing is selected, the loop skips isolated species without - // making progress. If *all* species are isolated there are no eligible - // pairs and the loop would never terminate. Fall back to the inner - // repopulator in that case. + // if all species are isolated, we fall back to the inner crossover repopulator to avoid an infinite loop. if matches!(self.action_if_isolated, ActionIfIsolated::DoNothing) && !population.species.iter().any(|s| s.len() >= 2) {