Reputation: 24336
I started to delve into GA a bit here for study and I cannot seem to find an answer to crossover generation break points. For instance if I start with the parents:
Father = [A,B,B,A,C]
Mother = [D,D,B,A,A]
At what point can I legitmately stop producing children to prove that all possible combinations have been exhausted? Code as follows:
void reproduce(String[] father, String[] mother) {
double choice = Math.random() * 100;
if((int) choice % 10 < 2){
//start at father[1] and swap.
//Continue for other choices
This is a small piece as to the logic I am utilizing. So my question comes back to, how can I legitimately determine when to stop creating children? Or is this just a mathematical problem where I should just look at a straight permutation generator and ignore GA for the moment?
Upvotes: 4
Views: 7073
Reputation: 11662
For a start this should be a not too bad way to make a child out of the parents. It's a single point crossover.
public String[] reproduce(String[] father, String[] mother) {
int[] child=new String[father.length];
int crossPoint = Math.random()*father.length;//make a crossover point
for (int i=0;i<father.length;++i)
{
if (i<crossPoint)
child[i]=father[i];
else
child[i]=mother[i];
}
return child;
}
No coffee, so no guarantee. You may want to check for off-by-one mistakes.
Upvotes: 2
Reputation: 1204
Since you are using random numbers to make the changes you have no guarantee that after X children you will have tried everything. If you want to try every option you should not be using random numbers. So yes, go with a straight permutation generator and ignore GA.
Upvotes: 1