liveBook · Manning

Gene

As explained in Advanced Algorithms and Data Structures

A gene is an individual position in a genetic-algorithm chromosome that represents one optimization variable and its assigned value.

A gene is one position in a genetic-algorithm chromosome. It holds a value for one optimization variable; the complete chromosome encodes a candidate solution. In a 0–1 knapsack problem, each gene corresponds to an item: 1 puts it in the crate, and 0 leaves it out. section 18.1.2

Choose gene values to match the problem. Knapsack genes are bits. For the traveling salesperson problem, each gene holds a vertex index, and the chromosome must contain each index exactly once. For maximum flow, one gene per edge holds a value from zero to that edge’s capacity; this range alone does not guarantee a valid flow. section 18.1.2 section 18.2.1 section 18.4.1

Operators must preserve the encoding’s constraints. Bit-string crossover can copy stretches of genes, but doing that to two vertex permutations may duplicate vertices. A permutation-safe crossover copies an initial stretch from one parent, then takes only unused vertices from the other. Mutation can change genes independently, allowing a population to reach values that crossover alone cannot produce when every parent agrees at a position. section 18.2.3 section 18.1.8

Listing 18.9 0-1 knapsack: Bit-wise mutation
function knapsackMutation(chromosome, mutationChance)   #1
  for i in {0,..,|chromosome|} do                       #2
    if random() < mutationChance then
      chromosome[i] ← 1 – chromosome[i]                 #3
  return chromosome

Bit-wise knapsack mutation visits each gene and, with a given chance, replaces its value with 1 minus that value. section 18.1.8

Gene values may also constrain one another. Knapsack item choices are mostly independent, though a weight limit can create an indirect dependency. In a vertex permutation, assigning one index rules it out everywhere else. This interaction between variables is called epistasis. A bit-wise mutation pass visits every gene, so its running time grows with chromosome length; choosing the encoding also determines which constraint checks and repairs other operators need. section 18.1.10 section 18.1.8 section 18.1.2

How Advanced Algorithms and Data Structures covers it

How deep it goes
Develops binary and permutation encodings with mutation and crossover operations; sketches maximum-flow genes without implementing that algorithm.
Examples
Uses knapsack item bits, traveling-salesperson vertex permutations, and maximum-flow edge values.
What it assumes
Assumes an optimization problem with candidate solutions while defining genes through concrete chromosome encodings.
What you can do after
Build it from scratch: choose gene domains and adapt mutation and crossover to preserve encoding constraints.
How it connects
Connects genes to chromosomes, fitness, natural selection, crossover, mutation, and epistasis.

Also explained in

Compare how 5 books explain gene →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Advanced Algorithms and Data Structures. The section links point to the parts of the book it draws on.