Optimizing Cargo Loads

Learn how to use a genetic algorithm to optimize the cargo load example.

Overview of evaluation of population

Every problem has an objective. The goal of optimization is to maximize or minimize a value. The goal of the search is to find a path to an objective. The common thread between optimization and search is an objective.

Our objective is our final destination — the end goal of our genetic algorithm. Sometimes, we might not know exactly what the end goal looks like, but we still need a way to know if we’re moving in the right direction. If you’ve ever played the game “Hot or cold,” you understand what this looks like. As a refresher of the rules, 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 us how “hot” or “cold” we are. We 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 the lesson Understanding Hyperparameters, we defined the evolve/3 function in lib/genetic.ex. Recall that function:

Get hands-on with 1200+ tech skills courses.