Understanding and Creating Chromosomes

Get to know what chromosomes are and how structs can be used to represent them.

Using structs to represent chromosomes

In the lesson Building a Framework for Genetic Algorithms, we designed a framework for writing genetic algorithms. The framework we designed generalized the steps common to all genetic algorithms. The purpose of this exercise was both to better understand the structure of genetic algorithms and optimization problems and to make it easier for us to write genetic algorithms in the future.

The chromosomes we created in the previous chapters are enumerable objects that represent solutions to a problem. At the most fundamental level, this is correct. However, in practice, this isn’t a viable implementation.

Consider this: we’re attempting to solve a problem in which the age of the chromosome determines its fitness. One reason we’d do this is to ensure enough variance between generations. Ideally, we’d persist older chromosomes between generations to a certain point before killing them off once they’ve reached a certain age. In this respect, we ensure an equal distribution of both old and young chromosomes and, thus, naturally occurring variance in the population.

Get hands-on with 1200+ tech skills courses.