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 ...
Get Genetic Algorithms and Machine Learning for Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.