liveBook · Manning

Population

As explained in Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

A population in a genetic algorithm is a collection of candidate solutions maintained as a group during evolution.

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.

How Classic Computer Science Problems in Swift: Essential techniques for practicing programmers covers it

How deep it goes
Defines population structure and gives implementation steps, while leaving population-size and probability choices configurable.
Examples
Uses antibiotic-resistant bacteria, random chromosome arrays, fitness caches, roulette selection, tournament selection, crossover, and mutation.
What it assumes
Introduces the biological analogy while assuming enough Swift familiarity to work with generic classes, arrays, and protocols.
What you can do after
Operate/configure a GeneticAlgorithm population by choosing its size, selection method, crossover chance, mutation chance, and generation limit.
How it connects
Connects population with chromosomes, genes, fitness functions, generations, selection, crossover, mutation, and natural selection.

Also explained in

Compare how 9 books explain population →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Computer Science Problems in Swift: Essential techniques for practicing programmers. The section links point to the parts of the book it draws on.