Repository navigation
Rewrite speciation feature - #144
Conversation
There was a problem hiding this comment.
Pull request overview
This PR rewrites the speciation system to use a divergence-based Speciated trait and shared SpeciatedPopulation grouping, then applies it to new speciated eliminator/repopulator implementations and updates the speciation example accordingly.
Changes:
- Introduces
Speciated(divergence + context) andSpeciatedPopulationutilities behind thespeciationfeature. - Reworks the speciated crossover repopulator to use divergence-based grouping and configurable “isolated species” handling.
- Adds a
SpeciatedFitnessEliminatorthat normalizes fitness by species size and updates the speciation example to demonstrate the new approach.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| genetic-rs/examples/speciation.rs | Updates the example genome/speciation logic to use divergence + new speciated eliminator/repopulator. |
| genetic-rs-common/src/speciation.rs | Adds the core Speciated trait and SpeciatedPopulation helpers (grouping + iterators). |
| genetic-rs-common/src/prelude.rs | Re-exports Speciated when the speciation feature is enabled. |
| genetic-rs-common/src/lib.rs | Adds the speciation module behind the speciation feature. |
| genetic-rs-common/src/builtin/repopulator.rs | Rewrites SpeciatedCrossoverRepopulator around SpeciatedPopulation and adds defaults. |
| genetic-rs-common/src/builtin/eliminator.rs | Adds closure-based FitnessObserver impl and introduces SpeciatedFitnessEliminator. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if species.len() < 2 { | ||
| match self.action_if_isolated { | ||
| ActionIfIsolated::DoNothing => continue, | ||
| ActionIfIsolated::CrossoverSelf => { |
There was a problem hiding this comment.
ActionIfIsolated::DoNothing can cause repopulate to hang: when a species has <2 members, this branch continues without incrementing i, so if all species are isolated (e.g., strict threshold), the loop never terminates. Consider detecting the “no eligible pairs” case and either fall back to another action, delegate to inner.repopulate, or return/panic with a clear error.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
| pub struct SpeciatedPopulation { | ||
| /// The species in this population. Each species is a vector of indices into the original genome vector. | ||
| /// The first genome in a species is its representation (i.e. the one that gets compared to other genomes to determine | ||
| /// if they belong in the species) | ||
| pub species: Vec<Vec<usize>>, | ||
|
|
||
| /// The threshold used to determine if a genome belongs in a species. If the divergence between a genome and the representative genome | ||
| /// of a species is less than this threshold, then the genome belongs in that species. | ||
| pub threshold: f32, | ||
| } |
There was a problem hiding this comment.
SpeciatedPopulation exposes species and threshold as public fields, but methods like round_robin* assume invariants (e.g., every species entry is non-empty). External callers can construct/modify a population into an invalid state and trigger panics via indexing/modulo-by-zero. Consider making the fields private and exposing read-only accessors / constructors that enforce invariants.
|
@HyperCodec I've opened a new pull request, #145, to work on those changes. Once the pull request is ready, I'll request review from you. |
Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
Fix ActionIfIsolated::DoNothing infinite loop when all species are isolated
Complete rewrite, should make the feature actually viable.