Overview
Selection determines which bots pass their genes to the next generation. The system uses two complementary mechanisms:- Elitism: Guaranteed survival of the best performers
- Tournament Selection: Probabilistic selection favoring high fitness
Elitism
The topELITE_COUNT bots survive unchanged into the next generation.
genetic/evolution.py
Why Elitism?
Preserves Best Solutions
Preserves Best Solutions
Without elitism, the best genome could be lost due to crossover/mutation randomness. Elitism guarantees monotonic improvement in best fitness.
Accelerates Convergence
Accelerates Convergence
By keeping proven winners, the population converges faster toward profitable strategies.
Provides Baseline
Provides Baseline
Elite genomes serve as performance benchmarks for the rest of the population.
genetic/config.py
Elite genomes still receive a new ID and have their generation number incremented, but their gene values remain identical.
Tournament Selection
For the remaining 90 slots (after elitism and before immigration), parents are chosen via tournament selection.Algorithm
Implementation
genetic/evolution.py
Selection Pressure
Tournament size controls selection pressure:| Tournament Size | Selection Pressure | Best Bot Selection Probability |
|---|---|---|
| 1 | None (random) | 1% |
| 3 | Low | ~9% |
| 7 (default) | Medium | ~26% |
| 15 | High | ~58% |
| 100 | Maximum | 100% (always best) |
t=7, the best bot has:
Why Tournament Selection?
Balances Exploration and Exploitation
Balances Exploration and Exploitation
Tournament size 7 gives strong bias toward fit individuals while still allowing diversity.
No Fitness Scaling Required
No Fitness Scaling Required
Unlike roulette-wheel selection, tournament works with negative fitness values and doesn’t require normalization.
Simple and Efficient
Simple and Efficient
O(k) complexity per selection, no sorting required.
Tunable Pressure
Tunable Pressure
Easy to adjust selection pressure by changing tournament size.
Breeding Process
After elitism, the remaining slots are filled through breeding:genetic/evolution.py
Crossover vs Clone
WithCROSSOVER_RATE = 0.7:
- 70% of offspring: Created by combining two parents via crossover
- 30% of offspring: Cloned from single parent (asexual reproduction)
- Preserves good genomes that might be disrupted by crossover
- Allows incremental improvement via mutation alone
- Maintains diversity when crossover would create similar offspring
Immigration
The final 5 genomes are completely random (“immigrants”):genetic/evolution.py
Why Immigration?
Prevents Premature Convergence
Prevents Premature Convergence
If the population gets stuck in a local optimum, immigration introduces fresh genetic material.
Explores Distant Regions
Explores Distant Regions
Random genomes can discover strategies the current population would never reach through crossover/mutation.
Maintains Diversity
Maintains Diversity
Continuous injection of new genes prevents the population from becoming too homogeneous.
- Too much immigration (greater than 10%) wastes slots on likely poor performers
- Too little immigration (less than 2%) risks getting stuck in local optima
- 5% is a balanced middle ground
Generation Composition
Each generation of 100 genomes consists of:Selection Statistics
Expected number of offspring per bot, by rank:| Fitness Rank | Elite? | Expected Offspring | Total Copies in Next Gen |
|---|---|---|---|
| 1 (Best) | Yes | ~3.2 | ~4.2 (including elite) |
| 2 | Yes | ~2.8 | ~3.8 |
| 3 | Yes | ~2.5 | ~3.5 |
| 4 | Yes | ~2.2 | ~3.2 |
| 5 | Yes | ~2.0 | ~3.0 |
| 10 | No | ~1.5 | ~1.5 |
| 25 | No | ~0.9 | ~0.9 |
| 50 (Median) | No | ~0.4 | ~0.4 |
| 75 | No | ~0.1 | ~0.1 |
| 100 (Worst) | No | ~0.01 | ~0.01 |
The best bot appears in the next generation on average 4.2 times (1 elite copy + 3.2 as parent in breeding).
Selection Pressure Over Time
As generations progress:Early Generations (0-10)
- High diversity, wide fitness distribution
- Tournament selection explores many strategies
- Immigration finds new niches
Mid Generations (10-50)
- Convergence toward profitable signals
- Elites dominate breeding pool
- Mutation fine-tunes parameters
Configuration Reference
genetic/config.py
Tuning Selection Pressure
Increase Exploitation (faster convergence)
- Increase
ELITE_COUNTto 10 - Increase
TOURNAMENT_SIZEto 15 - Decrease
IMMIGRATION_COUNTto 2 - Increase
CROSSOVER_RATEto 0.9
Increase Exploration (more diversity)
- Decrease
ELITE_COUNTto 2 - Decrease
TOURNAMENT_SIZEto 3 - Increase
IMMIGRATION_COUNTto 10 - Decrease
CROSSOVER_RATEto 0.5
Next Steps
Evolution Operators
Crossover and mutation implementation
Fitness Evaluation
How bots are scored
Analysis
Analyze selection effectiveness