liveBook · Manning

GeneticAlgorithm

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

A book-specific generic implementation of a genetic algorithm that operates on types conforming to Chromosome.

GeneticAlgorithm is a generic implementation that evolves a population of Chromosome values. Each generation evaluates fitness, selects parents, creates children through crossover, mutates individuals, and replaces the population until a threshold or generation limit is reached. section 5.3

Configure the algorithm with:

A configured run

An initializer can create a population with a target threshold, run for at most 100 generations, mutate each individual with probability 0.01, cross children with probability 0.7, and use four-person tournaments by default.

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

How deep it goes
Explains configuration, selection, caching, reproduction, mutation, stopping, and best-solution tracking without formal analysis.
Examples
Uses a Chromosome protocol, configurable initializer defaults, roulette-wheel selection, and tournament selection as implementation examples.
What it assumes
Assumes familiarity with generic types, protocols, fitness values, random selection, and mutation-based population search.
What you can do after
Build it from scratch as a generic GeneticAlgorithm over a type implementing the required Chromosome operations.
How it connects
Connects Chromosome values with fitness, crossover, mutation, roulette-wheel selection, and tournament selection.

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.