Cartesian genetic programming

Also known as: CGP

On this page 7

Cartesian genetic programming (CGP) is a form of genetic programming in which a program is represented as a directed acyclic graph whose nodes are arranged on a two-dimensional grid and encoded as a fixed-length string of integers. Within evolutionary computation, CGP is known for its compact genotype, its large proportion of inactive genes and its strong performance on problems such as digital circuit design and image processing.

The method was introduced by Julian F. Miller and colleagues in the late 1990s, originally for evolving digital circuits. The name refers to the Cartesian coordinates of the grid: every node has a column and a row position, and the position limits which earlier nodes it may receive inputs from.

How CGP encodes a program as a graph

CGP encodes a program by listing, for each grid node, a function gene and one or more connection genes, followed by output genes that point to the nodes producing the final results. The function gene selects an operation from a predefined function set, such as addition, logical AND or an image filter, while each connection gene names a program input or an earlier node as the source of an argument.

Decoding works backward from the outputs. The decoder follows connection genes recursively and marks every node it reaches as active; nodes that no output depends on are inactive and do not contribute to the phenotype. This genotype-phenotype mapping is many-to-one, because numerous genomes decode to the same executable graph. Since node outputs can feed several later nodes, CGP naturally reuses intermediate results, which tree-based representations cannot do without duplication.

The following table lists the main parameters that define a CGP genome.

ParameterMeaningCommon setting
Number of columnsWidth of the node gridOften 50 to several thousand
Number of rowsHeight of the node gridFrequently 1 in modern practice
Levels-backHow many columns back a node may connectOften equal to columns
ArityInputs per nodeMaximum arity of the function set
Function setAvailable node operationsProblem-specific primitives
Core parameters of a CGP representation

Evolutionary search in CGP

CGP is usually evolved with a simple (1 + λ) evolution strategy, most often with λ = 4, combined with point mutation and no crossover. In each generation, four offspring are produced by mutating the parent; the best offspring replaces the parent when its fitness is equal or better, which allows the search to move across plateaus of identical fitness.

That acceptance rule exploits neutral drift. Mutations that change inactive genes leave fitness unchanged but alter the hidden material that later mutations can activate. Studies of CGP have repeatedly reported that removing neutral drift degrades performance, and that genomes with many more nodes than needed often search more efficiently because they contain more neutral variation.

ComponentTypical choiceEffect
Selection scheme(1 + 4) strategyStrong exploitation with neutral moves
MutationPoint mutation of a few percent of genesSmall steps through genotype space
Active-gene mutationMutate until an active gene changesAvoids wasted fitness evaluations
CrossoverUsually omittedStandard crossover often disrupts graphs
Typical operators and settings in standard CGP

Because the genome has a fixed length, the number of active nodes is bounded by the grid size. As a result, CGP shows little or no bloat, the uncontrolled growth of program size that affects tree-based genetic programming.

CGP compared with other genetic programming forms

CGP differs from tree-based genetic programming and grammatical evolution primarily in its graph representation and its fixed genome length. Each representation influences what kinds of programs are easy to find and which operators work well.

ApproachRepresentationSize controlNode reuse
Tree-based GPVariable-size syntax treesNeeds bloat controlNo
Grammatical evolutionInteger codons mapped by a grammarBounded by wrapping rulesLimited
Linear GPSequence of register instructionsVariable lengthYes, through registers
Cartesian GPFixed-length integer graphBounded by grid sizeYes
Comparison of program representations in evolutionary computation

A practical consequence is that CGP is well suited to multi-output problems, such as a full adder or a set of image channels, because several outputs can share the same internal nodes. Tree-based genetic programming typically needs one tree per output or special constructs to achieve similar sharing.

Variants and extensions of CGP

Several extensions broaden CGP beyond its original feed-forward circuit setting. They modify the connection rules, add modularity or change the type of values that nodes process.

  • Embedded CGP (ECGP) automatically acquires and reuses modules, similar to subroutines.
  • Recurrent CGP permits feedback connections, enabling programs with memory for time-series tasks.
  • Self-modifying CGP includes functions that change the program during execution, supporting general solutions to problem families.
  • Mixed-type CGP lets nodes operate on scalars and vectors, which is useful for image and signal processing.
  • CGP for artificial neural networks evolves network topology and weights, a form of neuroevolution.

These variants keep the integer-graph core of the method, which is why tools and theoretical results developed for standard CGP often transfer to them with minor changes.

Applications, strengths and limitations

CGP has proven most effective where solutions are naturally graphs of reusable operations. Its best-known results include evolved digital circuits that use fewer gates than conventional designs, image filters for noise removal and medical image analysis, and compact controllers for game playing.

Application areaWhat is evolvedWhy CGP fits
Digital circuit designGate-level combinational circuitsGraphs map directly to circuits
Approximate computingLow-power arithmetic circuitsTrade accuracy for energy precisely
Image processingFilter pipelines and classifiersNode reuse across channels
Symbolic regressionMathematical expressionsCompact formulas without bloat
Where CGP is commonly applied

The main limitations are sensitivity to the function set, the difficulty of designing effective crossover and the cost of fitness evaluation on large datasets. Genome size must also be chosen in advance; a grid that is too small can prevent good solutions from being represented, while an extremely large one slows decoding.

The simple explanation

Cartesian genetic programming lets a computer breed small programs. Each program is a set of building blocks placed in a row. Every block does one simple job, such as adding two numbers. Each block takes its inputs from blocks placed earlier.

Many blocks are not connected to the final answer. They sit unused, like spare parts in a drawer. A small random change can suddenly connect a spare part. This is how new ideas appear. The computer keeps the best program and tries again. Over many rounds, good programs emerge.

How it is used in practice

A hardware research team needs a low-power 8-bit multiplier for a hearing-aid chip, where small arithmetic errors are acceptable but battery life is critical. The engineers seed CGP with a conventional multiplier circuit encoded as a single-row genome of several hundred nodes, using a function set of two-input logic gates.

The fitness function rewards fewer transistors and lower estimated power, subject to a mean error limit of about one percent. A (1 + 4) strategy runs for millions of generations on a compute cluster, and neutral mutations gradually rewire inactive gates into useful shortcuts.

The final circuit uses roughly a third less power than the exact design while staying within the error budget. After formal verification of its error profile, the team integrates it into the chip, demonstrating approximate computing through evolved hardware.