spejman/gga4r — pull request #5 by hstove (2013-10-06 23:34:37+00:00)
Title: Flattens result of a chromosome's recombination method

When using gga4r, I followed the example in the readme to return an array of a chromosome's `recombination` method. From the [README](https://github.com/spejman/gga4r#introduction):

~~~ruby
def recombine(c2)
# some code...
[StringPopulation.new(c1_a + c2_b), StringPopulation.new(c2_a + c1_b)]
end
~~~

When running a genetic algorithm with this chromosome, on the second evolution, an error is thrown because the chromosome in the population is an `Array`, which can't respond to a `recombine` or `mutate` method. A workaround for this is to simply return a chromosome as the result of `recombine`, but I wanted to also allow for returning multiple chromosomes. My fix for this situation is to accept a `multi_recombination` option in `GeneticAlgorithm.new`. When this option is set to `true`, you can return an array of chromosomes in a `recombine` method, similar to the above provided example.

I've also added tests to demonstrate this error. To reproduce, follow these steps:

~~~bash
git reset a095eee
cd test
ruby gga4r_test.rb
~~~