I'm building a simple "Hello, World!" genetic algorithm for learning purposes. My population is a group of random strings. Through mutation and crossover the strings evolve to be "Hello, World!". For some reason my population will sit at a fitness score and seemingly never evolve. Other times, my population will reach the target genes, "Hello, World". I'm using random selection and one point crossover. Although, this also happens when I use tournament and roulette wheel selection.
Question:
Why is my population becoming stale and not reaching the target genes even though I am diversifying the population through mutation? Is it because of the random nature of the genetic algorithm or a mistake in my code?
E.g.
Every chromosome in the population will end up having the genes "HellV, Wor`dL". Even after 10,000 generations the genes are the same. Other times, the genes reach the target genes "Hello, World!" after ~33 generations.
- Note: The code below works as expected when using Java. When using Java, the population always achieves the target genes. Also, I just started learning C++ today so it's highly possible there is a flaw in my code that I'm just not seeing.
Population Size: 333
Elitism: true
Elitism Percentage: 25%
Mutation Probability: 20%
Crossover Probability: 95%
Selection Type: Random
Crossover Type: One Point
EDIT: I've removed the code from this post and instead added a link to my github due to the fact that it is several hundred lines of code.
GAChromosome? Where is stuff defined? - Barry