Genetic operators: encoding, selection, crossover and mutation
Clear, exam-focused notes on genetic operators in genetic algorithms: encoding, selection, crossover and mutation, with definitions, formulas, worked examples and common mistakes.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Genetic operators are the building blocks of a Genetic Algorithm (GA). Engineers use them to encode solutions, select promising candidates, and create new candidate solutions by recombination and random change — all while keeping enough diversity to search the design space. Good choice and tuning of operators decides whether a GA finds a correct, efficient engineering solution or gets stuck.
Key ideas
Define terms before use.
- Chromosome: a representation of one candidate solution (usually a string or other data structure). When I say chromosome I mean the encoded form used inside the GA, not necessarily a biological chromosome.
- Gene: a component (position) inside a chromosome that encodes a part of the solution.
- Allele: a possible value a gene can take.
- Encoding: the method used to convert a real problem solution into chromosomes suitable for GA operators. Common encodings: binary encoding (strings of 0/1), real-valued encoding (vectors of real numbers), permutation encoding (ordered lists, used for routing/ordering problems), and tree encoding (used in Genetic Programming).
Encoding: choose an encoding that preserves problem structure and allows operators to produce valid solutions. For example, permutation encoding must use permutation-aware crossover to avoid invalid children.
Selection: Selection is the process that chooses parent chromosomes for reproduction based on their fitness. The goal is to bias the population toward higher fitness while keeping diversity.
- Fitness: a non-negative scalar that measures how good a chromosome is for the problem.
- Common selection methods: roulette-wheel (fitness-proportionate) selection, rank selection, tournament selection, stochastic universal sampling. Tournament size t controls selection pressure: larger t increases bias toward fitter individuals. State assumptions: for roulette-wheel selection we assume fitness values are non-negative and not all zero. For minimization problems or when objective values can be negative, transform to non-negative fitness (e.g., f_i = 1/(1 + cost_i) or shift-scale f_i' = f_i - min_j f_j + ε with ε > 0), or prefer rank/tournament selection to avoid dependence on absolute fitness.
Crossover (recombination): Crossover combines genetic information from two parents to produce one or more children. Typical crossover operators:
- One-point crossover: choose one cut-point, swap tail segments.
- Two-point crossover: choose two cut-points, swap the middle segment.
- Uniform crossover: choose each gene from parent A or B with some mixing probability (often 0.5).
- For permutation encodings use specialized crossovers like order crossover (OX) or partially mapped crossover (PMX).
Mutation: Mutation introduces random changes in chromosomes to maintain genetic diversity. For binary encoding a common operator flips bits with probability pm (mutation rate). For real-valued encoding mutation adds a small random perturbation (Gaussian or uniform). For permutation encodings, use permutation-preserving mutation operators such as swap, insertion, inversion, or scramble.
Exact statement (Schema Theorem, classical form) — assume binary encoding, proportional selection, one-point crossover and independent bitwise mutation with probability pm. For a schema H (a template with some fixed positions and "don't care" symbols), denote:
- m(H,t) = number of individuals matching H at generation t
- f(H) = average fitness of individuals matching H
- f-bar = average fitness of whole population
- pc = crossover probability
- pm = per-bit mutation probability
- o(H) = order of H (number of fixed positions)
- d(H) = defining length of H (distance between leftmost and rightmost fixed positions)
- l = chromosome length Then the schema theorem gives a lower bound on expected copies next generation: E[m(H,t+1)] >= m(H,t) * (f(H) / f-bar) * (1 - pc * (d(H) / (l - 1)) - pm * o(H)). Assumptions: proportional selection, independent effects of crossover and mutation, one-point crossover used to derive the disruption probability pc*(d(H)/(l-1)). This is a lower bound because new instances of H can also be created by crossover/mutation (not counted here). The term 1 - pmo(H) comes from the mutation survival probability (1 - pm)^{o(H)} ≥ 1 - pmo(H).
What to draw (diagrams requested in exams):
- For one-point crossover: draw two horizontal strings of bits (Parent A above, Parent B below), label bit positions 1..l, mark a vertical cut between position k and k+1, then draw the two child strings showing swapped tails. Label parents, cut-point k, children.
- For two-point crossover: draw two vertical cuts at positions k1 and k2 (1 ≤ k1 < k2 < l), swap the middle segment between k1+1 and k2, and show the resulting children with k1 and k2 labeled.
- For roulette-wheel selection: draw a circle (like a pie) partitioned into slices proportional to fitness values; show random spins mapping to selected parent index.
Design notes and assumptions engineers often use: choose encoding to minimize the number of invalid offspring; tune pc large (e.g. 0.6–0.9) to encourage recombination and pm small (e.g. 1/n where n is chromosome length) to introduce limited random change; include elitism (copy the best e individuals unchanged each generation) to preserve top solutions.
Formulas
p_i = f_i / sum_j f_j — p_i is probability of selecting individual i by roulette-wheel; f_i is its fitness; applies when fitness values are non-negative and at least one positive.
E[number of bit flips per chromosome] = n * p_m — n is chromosome length (number of bits), p_m is bitwise mutation probability; unitless; applies for independent per-bit mutation.
Prob(no mutation in chromosome) = (1 - p_m)^n — probability a chromosome remains unchanged after mutation.
Expected survivors of schema H (lower bound) = m(H,t) * (f(H) / f̄) * (1 - p_c * d(H) / (l - 1) - p_m * o(H)) — schema theorem lower bound; see Key ideas for definitions and assumptions.
P(winner is a particular individual of rank r in deterministic tournament selection of size t, sampling with replacement from a population of size N) = ((N - r + 1)/N)^t - ((N - r)/N)^t — assumes unique ranks and random tie-breaking; for the best individual (r = 1) this reduces to 1 - (1 - 1/N)^t.
Worked examples
Example 1 — Roulette-wheel selection (numerical, exam style) Problem data: population size N = 5. Fitness values f = [2, 3, 5, 0, 5]. Use roulette-wheel selection to compute selection probabilities and expected number of copies when selecting N parents (with replacement). Steps:
- Compute sum of fitness: sum f = 2 + 3 + 5 + 0 + 5 = 15.
- Compute probabilities: p1 = 2/15, p2 = 3/15, p3 = 5/15, p4 = 0/15, p5 = 5/15.
- Numeric values: p1 = 0.1333..., p2 = 0.2, p3 = 0.3333..., p4 = 0, p5 = 0.3333... .
- Expected number of copies in N picks: E_i = N * p_i. So E1 = 5 * 0.1333 = 0.6667, E2 = 1.0, E3 = 1.6667, E4 = 0, E5 = 1.6667. Final answer: Selection probabilities: [0.1333, 0.2, 0.3333, 0, 0.3333]; expected copies: [0.6667, 1.0, 1.6667, 0, 1.6667].
Example 2 — One-point crossover (theory + small numeric example) Problem: binary chromosomes length l = 10. Parents: A = 11001 01100, B = 00111 10011 (spaces added to show groups of 5). Choose one-point crossover at position k = 4 (i.e., after 4th bit). Steps:
- Draw parents as two lines of 10 bits, label positions 1..10.
- Cut after position 4. Swap tails.
- Child1 = first 4 bits of A + last 6 bits of B = A[1..4] + B[5..10]. A[1..4] = 1100; B[5..10]=1 10011 => B[5..10]=110011; so child1 = 1100 110011 -> combined: 1100110011.
- Child2 = first 4 bits of B + last 6 bits of A = B[1..4] + A[5..10]. B[1..4]=0011; A[5..10]=101100 -> child2 = 0011 101100 -> 0011101100. Final answer: Children: 1100110011 and 0011101100.
Example 3 — Mutation expectations (numerical) Problem: chromosome length n = 20, per-bit mutation pm = 0.01. Steps:
- Expected number of bit flips = n * pm = 20 * 0.01 = 0.2 flips per chromosome on average.
- Probability a given chromosome remains unchanged = (1 - pm)^n = (0.99)^20 ≈ 0.8179. Final answer: Expected flips = 0.2, probability of no mutation ≈ 0.8179.
Common mistakes
- Confusing selection probability p_i with expected number of copies; p_i is per-draw probability, expected copies in N draws is N·p_i.
- Forgetting assumptions of schema theorem (proportional selection, one-point crossover), and treating it as an exact equality rather than a lower bound.
- Using too large mutation rate (destroys building blocks) or too small (no diversity); forgetting rule-of-thumb pm ≈ 1/n.
For your exam
Types of questions you will see:
- Definitions and short notes: define encoding types, selection methods, crossover and mutation operators with sketches.
- Derivations: derive roulette-wheel selection probabilities; derive expected number of mutations; show the schema theorem inequality and explain each term and assumption.
- Numericals: compute selection probabilities, expected copies, result of specific crossover and mutation operations on given chromosomes.
- Programs/algorithms: write pseudocode for selection (roulette-wheel or tournament), or implement one-point crossover & bit-flip mutation.
- Diagrams: draw parents and children for one-point and two-point crossover; draw roulette wheel. What a full-marks answer includes: clear definitions of terms, explicit assumptions, stepwise derivations, labeled diagrams where required, correct numeric computations with units/units N/A explained, and comments on limitations (e.g., when a method may produce invalid solutions).
Quick check
- If chromosome length n = 50 and pm = 0.02, what is expected number of bit flips per chromosome? 2) In roulette-wheel selection with fitnesses [1,1,2], what are selection probabilities? 3) For a schema H with m(H,t)=10, f(H)=6, f̄=3, pc=0.8, d(H)=4, l=10, pm=0.01, o(H)=3, compute the schema theorem lower bound for E[m(H,t+1)]. Answers: 1) 1.0 flips (500.02 = 1.0). 2) probabilities [0.25, 0.25, 0.5]. 3) first compute (f(H)/f̄)=2.0; disruption term = pc(d(H)/(l-1)) + pmo(H) = 0.8(4/9) + 0.013 = 0.80.444444... + 0.03 = 0.355555... + 0.03 = 0.385555...; multiplier = 1 - 0.385555... = 0.614444...; therefore bound = 10 * 2.0 * 0.614444... = 12.288888... ≈ 12.289.
(Reviewer note: I am careful with definitions and numeric arithmetic; see verify list below for items to check.)
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?