Skip to content

Rewrite speciation feature - #144

Merged
HyperCodec merged 18 commits into
devfrom
speciation-rewrite
Mar 10, 2026
Merged

HyperCodec merged 18 commits into
devfrom
speciation-rewrite

Conversation

@HyperCodec

Copy link
Copy Markdown
Owner

Complete rewrite, should make the feature actually viable.

@HyperCodec HyperCodec self-assigned this Mar 9, 2026
@HyperCodec HyperCodec linked an issue Mar 9, 2026 that may be closed by this pull request
@HyperCodec
HyperCodec marked this pull request as ready for review March 9, 2026 18:30
@HyperCodec
HyperCodec requested a review from Copilot March 9, 2026 18:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and SpeciatedPopulation utilities behind the speciation feature.
  • Reworks the speciated crossover repopulator to use divergence-based grouping and configurable “isolated species” handling.
  • Adds a SpeciatedFitnessEliminator that 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.

Comment thread genetic-rs-common/src/speciation.rs Resolved
Comment thread genetic-rs-common/src/speciation.rs Resolved
Comment thread genetic-rs/examples/speciation.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +272 to +275
if species.len() < 2 {
match self.action_if_isolated {
ActionIfIsolated::DoNothing => continue,
ActionIfIsolated::CrossoverSelf => {

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +19 to +28
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,
}

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

Copilot AI commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

@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.

Copilot AI and others added 3 commits March 10, 2026 11:44
Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
Fix ActionIfIsolated::DoNothing infinite loop when all species are isolated
@HyperCodec
HyperCodec merged commit 5bdd52d into dev Mar 10, 2026
3 checks passed
@HyperCodec
HyperCodec deleted the speciation-rewrite branch March 10, 2026 11:55

This branch was previously deployed

1 inactive deployment
testing — 2f79778f Deployed Mar 10, 2026 by HyperCodec via Unit Testing #230
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve speciation algorithm and interface

3 participants