Adding Mutation to our Genetic Algorithm

Get to know how to implement the mutation process.

Including the mutation step

Despite initializing your population to a seemingly random distribution, eventually, the parents became too genetically similar to make any improvements during the crossover process. This illustrates the importance of including the mutation step in our algorithm and how vital exploration is to informed search techniques.

After the crossover function in the algorithm, add the following:

|> mutation.()

Now, the structure of the algorithm looks like this:

|> fitness.()
|> selection.()
|> crossover.()
|> mutation.()
|> algorithm.(algorithm)

Mutation is similar to the other functions in that it accepts a population as a parameter.

Note: We only want to mutate a small percentage of your population — this is to preserve the progress that has already been made.

To incorporate mutation to our algorithm, add the following function below the crossover definition:

Get hands-on with 1200+ tech skills courses.