Skip to content

feat: PopulationManager — generation loop + parent sampling (#155)#420

Open
yxlyx wants to merge 1 commit intomainfrom
feat/155-population-manager
Open

feat: PopulationManager — generation loop + parent sampling (#155)#420
yxlyx wants to merge 1 commit intomainfrom
feat/155-population-manager

Conversation

@yxlyx
Copy link
Copy Markdown
Collaborator

@yxlyx yxlyx commented Apr 10, 2026

Summary

  • EvolverConfig: problem_statement, fitness_cmd, max_generations (10), population_size (4), crossover_every_n (3), timeout, early_stop_threshold (1.0)
  • PopulationManager: Orchestrates the inner evolutionary loop:
    • addOrganism() / sortByFitness() / best() — population management
    • shouldStopEarly() — checks if any organism meets threshold
    • useCrossover(gen) — determines whether to use CrossoverMutator
    • selectParents(count, rng) — fitness-proportional sampling
    • nextId() — monotonic organism ID generator
    • run() — generation loop with early stopping
  • EvolverResult: best_organism, generations_run, total_evaluated, converged
  • Also adds Organism and FailureCase types (prerequisites from evolver.zig: core types — Organism, Population, LearningLog, EvaluationResult #149/evolver.zig: Mutator — LLM-driven mutation with failure cases + learning log #153)

Test plan

  • zig test src/evolver.zig — 28/28 tests pass
  • best() returns highest-fitness organism
  • best() on empty population returns null
  • shouldStopEarly: fires when organism exceeds threshold
  • useCrossover: fires every N generations, disabled when N=0
  • selectParents: biases toward high-fitness organisms (>50% selection rate)
  • nextId: monotonically increasing
  • run() with early stop: converges immediately, 0 generations
  • run() without convergence: runs all generations
  • EvolverConfig defaults are correct

Closes #155

Made with Cursor

… orchestration (#155)

Adds PopulationManager, EvolverConfig, and EvolverResult to evolver.zig:
- EvolverConfig: problem_statement, fitness_cmd, max_generations,
  population_size, crossover_every_n, timeout, early_stop_threshold
- PopulationManager: maintains sorted organism population with
  addOrganism, sortByFitness, best, shouldStopEarly, useCrossover,
  selectParents (fitness-proportional), nextId, and run() orchestrator
- EvolverResult: best_organism, generations_run, total_evaluated, converged

Also adds Organism and FailureCase types (prerequisite from #149/#153).

10 new tests covering: best selection, empty population, early stopping,
crossover scheduling, disabled crossover, fitness-proportional parent
selection bias, ID generation, run with early stop, run without
convergence, and EvolverConfig defaults.
All 28 evolver tests pass.

Made-with: Cursor
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.

evolver.zig: PopulationManager — generation loop, parent sampling, evolution orchestration

1 participant