Crafting Fitness Functions

Genetic Algorithms in Elixir — by Sean Moriarity (40 / 101)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Applying Termination Criteria to Shipping | TOC | Exploring Different Types of Optimization 👉

In the previous few sections, you explored the importance of evaluation through the context of a modified knapsack problem. While the problem shows the importance of crafting a good fitness function, you learned only one way to evaluate a specific type of problem. Countless problems exist, each requiring unique evaluation tools. Unfortunately, you can’t generalize one fitness function to all problems. You need to fully understand what fitness functions aim to accomplish.

Understanding Fitness

Recall from Chapter 1, Writing Your First Genetic Algorithm, the problem of being lost in the woods. Some of the trees are marked indicating how close you are to escaping the woods. The markings on the trees show the value of your current position — they tell you how to navigate the woods and where to go next. Without this information, it’s likely you’d never escape.

Fitness is, in essence, the same as the markings on the trees. Specifically, fitness is the value assigned to a particular chromosome based on the criteria defined in the fitness function. Consider this: you’re lost in the woods again, only this time, the trees aren’t marked. Instead, you have a guide who tells you how close to civilization you are after every step. In this example, the guide acts as…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.