Skip to content
All library documents

Binary Genetic Algorithms: Encoding, Gray Code, Selection, Crossover, and Mutation

Article MQL5 articles

Summary

This article introduces design choices in population optimization, focusing on binary genetic algorithms. It compares real-valued and binary encodings of optimization parameters, describing the flexibility of real numbers and the bitwise operations enabled by binary strings. It then explains Gray code, where adjacent integer values differ by one bit, as a way to reduce irregular transitions in binary search spaces. The discussion also outlines approaches to selection, crossover, and mutation, including several forms of bit-level mutation.

The article illustrates encoding a bounded real parameter by shifting it into a nonnegative range and representing integer and fractional portions separately. It offers conceptual examples and implementation-oriented discussion in MQL5, but provides no benchmark showing that Gray encoding or a particular operator improves optimization results. These are general algorithm-building techniques; their usefulness depends on the objective, encoding precision, and chosen search operators.

Key ideas

  • Genetic algorithms can encode parameters directly as real values or as binary strings, each with different tradeoffs.
  • Binary encoding supports bitwise search operations but requires converting encoded values back to the optimization domain.
  • Gray code makes adjacent integer values differ by one bit, potentially smoothing local changes in the encoded search space.
  • A bounded real parameter can be shifted to a nonnegative range and encoded using separate integer and fractional parts.
  • Selection, crossover, and mutation define how a population chooses, combines, and changes candidate solutions.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.