views:

106

answers:

3

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?

+2  A: 

I rather thought the point of a GA was to find a solution to a problem heuristically, not exhaustively. If you're compelled to try every combination, you can probably solve the problem without GAs.

Tony Ennis
that is probably closer to what is needed as GA is something new to me, thats why I seem to go back to exhaustive search as it is familiar to me.
Woot4Moo
A GA is best suited for problems that can't be solved exhaustively. We used something similar when I worked at an engineering firm to solve complex non-linear equations in *many* variables and constraints.
Tony Ennis
Good to know Tony, if you have any resources I would be all ears
Woot4Moo
Thar be Dragons. http://en.wikipedia.org/wiki/Heuristic_algorithm
Tony Ennis
+1  A: 

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.

AmaDaden
if I were to approach this heuristically as Tony suggested how would this need to be changed?
Woot4Moo
Think of heuristic algorithms as "good but not perfect" algorithms. How you do it depends on the problem.If you would like to continue to use the idea of GA but use a heuristic way of picking one I would use a greedy recursive algorithm. Pick any possible child and then create a another child that only differs from the first child by one gene. Compare the two and what ever child is better is run through this process again. Keep doing this until you find a child that is better then all of it's siblings that differ from it by one gene.
AmaDaden
+1  A: 

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.

Ishtar
so one would assume that we are looking to set a limit of the permutations that can be generated, even though the number of generations can be > limit
Woot4Moo
Not sure what you mean... You don't limit the permutations, you just take as much random children as you need to fill the current-generation-pool (somewhere around 1000). As Tony Ennis pointed out, it's heuristically. You don't limit on the 1000000000000000000000000000000 permutations, you take as much as you can handle.
Ishtar
it was early and I was semi-rambling =p
Woot4Moo