Crossover combines genetic material from two parent chromosomes to produce offspring. A genetic algorithm applies it probabilistically during each generation, alongside selection and mutation. section 5.1 section 5.3
A typical crossover implementation proceeds as follows:
- Choose two parent chromosomes of the same type. section 5.3
- Select a random crossing point in each chromosome’s gene sequence. section 5.5
- Exchange the sequence pieces to form two children: each receives one prefix and the other parent’s suffix. section 5.5
- Insert the children into the replacement population when the configured crossover chance allows it. section 5.3
SEND+MORE=MONEY
With a crossing point at position 4, the first child takes the first four genes from one parent and the final six from the other; the second child reverses those segments. The resulting children combine letter arrangements that can later be evaluated and mutated. section 5.5
public protocol Chromosome {
var fitness: Double { get } // how well does this individual solve
the problem?
init(from: Self) // must be able to copy itself
static func randomInstance() -> Self
func crossover(other: Self)
-> (child1: Self, child2: Self) // combine with other to form children
func mutate() // make a small change somewhere
func prettyPrint()
}
The Swift protocol makes crossover an explicit responsibility of every chromosome, returning two children from two same-type parents. section 5.3






