Fitness Arena

The Fitness Arena is where mutants fight for survival. Every mutant spawned by HezGene must pass through a 5-Ring Gauntlet before it can be considered as a replacement for the original function.

The 5-Ring Gauntlet

Ring 1: Correctness

The most critical ring. The mutant must produce 100% identical outputs to the original for all test inputs. If a mutant changes behavior in any way — even by a single decimal place — it is immediately killed.

Ring 2: Speed

The mutant is benchmarked against the original across hundreds of executions using high-precision timers. Speed is measured in milliseconds with statistical averaging to eliminate noise.

Ring 3: Memory

Using Python's tracemalloc, the arena measures exact byte allocations for both the original and the mutant. Lower memory usage is rewarded.

Ring 4: Edge Cases

The arena fuzz-tests the mutant with extreme and unexpected inputs: None, empty lists, massive integers, negative numbers, special characters. The mutant must handle all of them gracefully.

Ring 5: Readability

Readability is scored using cyclomatic complexity and line count. A mutant that is faster but more complex gets a lower readability score. The final fitness is a weighted combination of all five rings.

Fitness scoring

RingWeightMetric
CorrectnessPass/Fail (gate)Output equality
Speed30%Execution time (ms)
Memory20%Peak allocation (bytes)
Edge Cases25%Fuzz test pass rate
Readability25%Complexity + line count
Correctness is a gate
If a mutant fails the correctness ring, it is eliminated immediately — regardless of how much faster or smaller it is. HezGene never trades correctness for performance.

Tournament selection

After all mutants are scored, the tournament manager compares the best mutant against the original. The mutant must exceed a minimum improvement threshold (default: 0.1%) to be selected as the winner. This prevents trivially small optimizations from triggering unnecessary file changes.

Previous
Evolution
How the evolutionary loop works
AST Mutations
Deterministic codebase changes
Next