Skip to content

Genetic Algorithm

Guled edited this page Mar 17, 2017 · 2 revisions

MLKit provides a few classes in order to help you create programs that use genetic algorithms. There are two main classes that you will be using frequently which includes the BiologicalProcessManager and Population classes. These classes both provide static methods that manipulate the genes of your Genome objects. Let's go through each class and protocol provided:

BiologicalProcessManager.swift

The BiologicalProcessManager class provides static methods that handle operations such as crossover and mutation. The operations that are provided for you include:

  • One-Point Crossover
  • Scramble Mutation
  • Swap Mutation
  • Insert Mutation
  • Inverse Mutation

Population.swift

The Population class provides a static method that handles choosing parents from a population of individuals. The selectParents method implements tournament selection to choose the parents within a population.

Genome.swift

MLKit provides you with a protocol to help you define a Genome object. The Genome protocol requires you to include a fitness value and a genotypeRepresentation for your Genome conforming objects. The Genome protocol does not provide a fitness evaluation function because there are many ways to evaluate fitness and so this gives you the freedom of implementing a method within your Genome conforming object to evaluate the fitness of an individual.

An example project is provided which includes an example of a genetic algorithm running as well as a neural network. An step-by-step explanation of how the example project was constructed is located here.