Adding the Missing Pieces to Functions

Get to know about the missing pieces about the evolve and run functions.

Filling in the blanks

Remember that we left blanks in the evolve and run functions, and that none of the functions we called in evolve took parameters? It’s time to fill in these blanks.

The functions initialize/2 and evaluate/2 take extra parameters aside from a population. Because we won’t be calling these functions individually outside the module, we can take these parameters inside the run and evolve functions and pass them to initialize and evaluate from there.

We need to take the following parameters into both run and evaluate: fitness_function, genotype, and max_fitness. Additionally, with the required parameters in place, we can fill in the blanks left in the outline of the run and evolve functions.

The new modified versions of these functions look like the following:

Get hands-on with 1200+ tech skills courses.