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 Make Some Bees Swarm

Make a new C++ project and add SFML—which you saw here—so you can draw the bees buzzing. The code with this book has a Bees static library for the algorithm. This is called by a unit test project and a main project named ABC. Make the library first, and feel free to add tests as you go. The tests aren’t shown here.

Code Your ABC

Start by defining a Coordinate class:

 struct​ Coordinate
 {
 double​ x;
 double​ y;
 };

You need a Bee class with a home, current position, a favored food spot, and a role. They start out at home. Add a buzz to drive how far the bees move each time. You’ll fill in the remaining parts to this shortly:

 class​ Bee
 {
 public​:
 explicit​ Bee(Role role, ...

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