The desire to learn more about GA has sparkled again, and instead of reading a lot and doing nothing, I've decided to start the other way around: pick a problem and try to solve it.
I've picked the Magic Square problem. For encoding the chromosomes I am using Permutation Encoding, and the following methods for Mutation() and NewChild(parent1, parent2, pivot) .
My selection algorithm is a bit weird, and is adapted from examples found on the Internet.
The score is calculated based on the square of the difference of the sum of rows/columns/diagonals and the magic constant, like this.
What I've noticed is that it converges very fast, and stops improving once it reaches a score of 1..7 (less is better).
I am seeing this as: it reaches a local optimum, a potential well, if you can call it that way, and won't jump over the near-by hill because the mutations are not different enough?
I've tried changing the mutation rate 5 - 80%, leaving an elite group of 10-20% in the chromosome population, changing the population size from 16-32 chromosomes, but no luck.
What am I doing wrong? What improvements can I use to make the population score converge to zero?
If required, I can post the full source code, if someone finds it useful or would like to play with it.
Update: Here is what the convergence rate looks like for a cube of size 5, with a crossover rate of 60% and a mutation rate of 10%: