title: Population becomes stale - Genetic Algorithm
body: <p>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.</p>
  
  <p><strong>Question:</strong><br/>
  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?</p>
  
  <p><strong>E.g.</strong><br />
  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.</p>
  
  <ul>
  <li><strong><em>Note:</strong>
  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.</em></li>
  </ul>
  
  <p>Population Size: 333<br />
  Elitism: true<br />
  Elitism Percentage: 25%<br />
  Mutation Probability: 20%<br />
  Crossover Probability: 95%<br />
  Selection Type: Random <br />
  Crossover Type: One Point</p>
  
  <p><strong>EDIT:</strong>
  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.</p>
  
  <p><a href="https://github.com/MotivatedCreation/Genetic-Algorithm/tree/master/c%2B%2B_src" rel="nofollow">Genetic Algorithm - C++</a></p>