In a genetic algorithm, mutation makes a small, fairly random change to a chromosome. Alongside crossover, it creates variation among candidate solutions. In biology, environmental pressures can favor individuals whose mutations improve survival; the pressure does not cause the mutation itself. section 5.1 section 5.3
Mutation in a generic genetic algorithm:
- Gives each individual a chance of mutation in each generation; the chance is configurable. section 5.3
- Leaves the specific change to the chromosome’s mutation implementation. section 5.3
Changing a letter chromosome
For SEND+MORE=MONEY, mutation either swaps two randomly chosen gene positions or puts a random letter in a randomly chosen position. 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 Chromosome protocol makes mutation an operation each chromosome type must implement. section 5.3











