...

/

Implementing Common Mutation Strategies

Implementing Common Mutation Strategies

Learn about different mutation strategies and how to implement them.

Different types of mutation

We’ll likely only ever need to work with a few mutation strategies depending on the genotype of our solutions. The mutation strategy we use has less of an impact on our algorithm than, say, crossover strategy or selection strategy. The presence of mutation matters more, assuming that the mutation strategy we choose maintains the validity of our solutions.

In this lesson, we’ll learn how to implement three different types of mutation that we can use for binary, permutation, and real-value genotypes. At the end of this lesson, we’ll find a list of other common mutation strategies to research and implement individually.

Flip mutation

Flip mutation, also known as a bit-flip mutation, is the type of mutation proposed in Holland’s original genetic algorithm. It’s simple and effective on binary genotypes. Flip mutation “flips” some or all of the bits in the chromosome. So, if a gene is a 1, it’s flipped to a 0. If a gene is a 0, it’s flipped to a 1.

The following image depicts flip mutation:

Flip mutation can be implemented in a few lines of code using Elixir’s Enum library. First, at the top of the Toolbox.Mutation module, add the following line:

use Bitwise

We’ll use a module in the Elixir standard library called Bitwise to work with bitwise operations. Bitwise is applicable here because the flip mutation is essentially just a bitwise XOR between 1 and the value of a gene. XOR with 1 produces the desired flip because 1 XOR 1 is 0 and 0 XOR 1 is 1.

To ...

Access this course and 1400+ top-rated courses and projects.