Am developing a genetic algorithm in Java, that like all of them, requires the crossover of two parent chromosomes. These chromosomes can be quite long, anywhere from 30 to 500 (but whatever length they have, they will all be the same size, so if the length is 80, in that GA run all will be 80).
I thought of developing in different ways but they all just seem to me like very inefficient, so I thought I might ask for new, different points of view and suggestions.
For example, one of the ways I thought was of converting the string to an array of characters and iterating from the start point to the end of the crossover locus (ie from s1 & s2[25]
to s1 & s2[40]
) copying into temporal arrays each of the arrays characters between those points and then iterating again and swapping them with the characters from the temporal array of the "partner". But like I said it seems like for a program that will have a population of about 1000 chromosomes and with around 1000 generations will be extremely slow.
Here is an illustration of what two-point crossover looks like:
There is also the easier one point crossover:
As am not very advanced at all in Java could you advice me on what approach to take, maybe a Java function am unaware of, or some algorithm that I could implement?