A population is the group of candidate solutions maintained in one generation of a genetic algorithm. Each candidate is a chromosome composed of genes, and its fitness measures how well it solves the target problem. Better-performing chromosomes are more likely to reproduce, while crossover and mutation produce the next population. section 5.1
A genetic algorithm evolves its population through a repeating cycle:
- Create an initial population of random chromosomes. section 5.3
- Measure each chromosome's fitness and stop early if one reaches the threshold. section 5.3
- Select parents, favoring chromosomes with higher fitness through roulette or tournament selection. section 5.3
- Apply crossover and mutation to form a replacement population, then repeat until the generation limit or a satisfactory solution is reached. section 5.3
Representing a population in Swift
A generic GeneticAlgorithm stores the current generation as an array: `private var population: [ChromosomeType]`. Its initializer creates the requested number of random chromosomes, while a fitness cache stores the current fitness value for each individual. Reproduction builds a new array until it matches the old population's size, then mutation considers every individual.








