O'Reilly logo

Genetic Algorithms and Machine Learning for Programmers by Frances Buontempo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Let’s Find the Best Starting Row

Each of your CAs will use a Row of 32 cells:

 typedef​ std::array<​bool​, 32> Row;

The array has a fixed size. You can use a vector, as you did in the previous chapter, if you want to dynamically change the row size. You’ll need to experiment with the parameters for your GA if you change this.

Each CA works via a rule acting on a Row. If you make an abstract Rule, you’ll be able to polymorphically swap your CA for use in the same genetic algorithm. To do this, use a virtual operator() to transform a Row:

 class​ Rule
 {
 public​:
 virtual​ Row ​operator​()(​const​ Row & cells) ​const​ = 0;
 };

To make a concrete rule, you override the virtual function. Your first CA will use a StaticRule ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required