Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Genetic Algorithm - help please

codenewbiecodenewbie Member Posts: 22
I'm a student and have taken Goldbergs Simple Genetic algorithm code and have made alot of changes to it, i.e. changing the selection mode to tournament vice roulette wheel, etc. I want to change this one point cross over code to a two point cross over, but not sure how to implement it..

void crossover (int parent1, int parent2, int child1, int child2)
{
int i, site;
if (flip(PCROSS)==1) site = (int) randomain(0,CHROM_LENGTH);
else site = CHROM_LENGTH-1;
for (i=0; i<CHROM_LENGTH; i++)
{
if ((i<=site) || (site==0))
{
new_pool[child1].string[i] = pool[parent1].string[i];
new_pool[child2].string[i] = pool[parent2].string[i];
}
else
{
new_pool[child1].string[i] = pool[parent2].string[i];
new_pool[child2].string[i] = pool[parent1].string[i];
}
}
}

Sign In or Register to comment.