What are some ways to crossover in a Genetic Algorithm?

240 views Asked by At

Here is a very small example I'll give:

Suppose I have my population of size 4. Now, let's say that I sort them based on their fitness and I decide to drop the last 2 (so now my population size is 2). Now I would need to go back to the original size but first I would have to create offspring.

Let's say I have this: (not written in any specific language)

population = [[2.2],[49.7],[34.1],[25.39]] //original population, I would run this under a fitness function
sortedPopulation = [[49.7],[25.39],[2.2],[34.1]] //sorted population based upon their fitness
best = [[49.7],[25.39]] //updated population with the last 2 elements being dropped (because they are the 2 worst)

At this point, I'm trying to figure out how I can crossover and create offspring. After the offspring, I will generate some more Doubles to get back to the original population size (which I already know how to do). What are some ways to crossover? And what would the result of the crossover actually look like?

I also want to make sure that there is a method that will work for any # of elements in the population's elements. For instance, if each of the elements were 2 double's, then how would I create offspring from something like this:

best = [[3.3,92.56],[10.5,15.01]]
1

There are 1 answers

8
Patrik Kula On

if you are working with integers its good idea to work with them as binary... then you can for example swap last 2 bits as crossover, swap every second bit, etc... or even better as Gray code (https://en.wikipedia.org/wiki/Gray_code) or you might get stuck on Hamming's barrier (https://en.wikipedia.org/wiki/Hamming_distance)

hope it helps ^^ Patrik