methods/crossover
Crossover methods for genetic algorithms.
These methods implement the crossover strategies described in the Instinct algorithm, enabling the creation of offspring with unique combinations of parent traits.
Read this file as an inheritance-policy shelf: each method answers a different question about how aggressively two parents should be mixed.
SINGLE_POINTpreserves one contiguous prefix from one parent and the remaining suffix from the other,TWO_POINTpreserves a middle segment boundary instead of only one split,UNIFORMtreats each gene as an independent coin flip,AVERAGEblends compatible numeric genes instead of copying segments.
A practical chooser for first experiments:
- start with
UNIFORMwhen you want broad mixing and do not need contiguous blocks of structure to stay together, - use
SINGLE_POINTorTWO_POINTwhen adjacency matters and you want to preserve larger parent segments, - choose
AVERAGEwhen the genome is meaningfully numeric and interpolation is more useful than hard parent switching.
Minimal workflow:
const broadMixing = crossover.UNIFORM;
const oneCut = crossover.SINGLE_POINT;
const twoCut = {
...crossover.TWO_POINT,
config: [0.25, 0.75],
};
const blendedOffspring = crossover.AVERAGE;
flowchart LR Parents[Two parent genomes] --> Segment[Segment-preserving crossover] Parents --> GeneWise[Gene-wise crossover] Parents --> Blend[Numeric blending] Segment --> Single[SINGLE_POINT] Segment --> Double[TWO_POINT] GeneWise --> Uniform[UNIFORM] Blend --> Average[AVERAGE]