I need code for the ranking selection method on a genetic algorithm. I have create roulette and tournament selections method but now I need ranking and I am stuck.
My roulette code is here (I am using atom struct for genetic atoms) :
const int roulette (const atom *f)
{
int i;
double sum, sumrnd;
sum = 0;
for (i = 0; i < N; i++)
sum += f[i].fitness + OFFSET;
sumrnd = rnd () * sum;
sum = 0;
for (i = 0; i < N; i++) {
sum += f[i].fitness + OFFSET;
if (sum > sumrnd)
break;
}
return i;
}
Where atom :
typedef struct atom
{
int geno[VARS];
double pheno[VARS];
double fitness;
} atom;