Chapter 4 Evaluating Solutions and Populations
Genetic Algorithms in Elixir — by Sean Moriarity (34 / 101)
👈 What You Learned | TOC | Optimizing Cargo Loads 👉
Every problem has an objective. The goal of optimization is to maximize or minimize a value. The goal of search is to find a path to an objective. The common thread between optimization and search is an objective.
Your objective is your final destination — the end goal of your genetic algorithm. Sometimes, you might not know exactly what your end goal looks like, but you still need a way to know if you’re moving in the right direction. If you’ve ever played the game “Hot or Cold,” you understand what this looks like. You search for an object and somebody gives you clues to its location by telling you whether you’re “hot” — close to the object — or “cold” — further from the object. “Hot” and “cold” are basic assessments of your current location — they help you continue moving in the right direction without actually knowing where you’re going.
In genetic algorithms, fitness functions tell you how “hot” or “cold” you are. You use them as a barometer to measure your progress toward the best solution.
That’s why each new generation in a genetic algorithm starts with an evaluation of the current population. The evaluation step is crucial in ensuring your algorithm is progressing toward the best solution. In Chapter 2, Breaking Down Genetic Algorithms, you defined the evolve/3…