# Need help in roulette wheel Selection in genetic algorithm

Printable View

• February 7th, 2014, 07:55 AM
Infanta
Need help in roulette wheel Selection in genetic algorithm
I want java coding for roulette wheel selection in genetic algorithm with some explanation. I can't understand the algorithm clearly to implement in my project .... Can anyone explain in detail
• February 7th, 2014, 07:58 AM
Sambit
Re: Need help in roulette wheel Selection in genetic algorithm
Sorry we cant provide the code in this forum. If you can come up with a code or algorithm then we can help in your project
• February 7th, 2014, 07:58 AM
GregBrannon
Re: Need help in roulette wheel Selection in genetic algorithm
Quote:

I can't understand the algorithm clearly
What algorithm? Show us what you don't understand, and ask questions about it. If you don't have an algorithm and haven't been able to come up with one, then describe what the algorithm should do. Write pseudo code or real code from that if you can. Recommend you check out the API page for Random to get some ideas.
• February 7th, 2014, 09:59 AM
Infanta
Re: Need help in roulette wheel Selection in genetic algorithm
here is the part i got from other website. I don't understand the proper algorithm ... Proper reason for those variables and loop.... I have calculated the fitness for all the population. Now i want to do selection process using "roulette wheel selection algorithm" ...... What should i do...

public double[] roulettewheel(){

double min=0,max;
Random r = new Random();int popSize=30;
double[] populationNew = new double[popSize];
//sum the total fitness of the population
for (int i = 0; i < popSize; i++) {
totalfitness =+ fitness[i];
}
/* sum the fitness of each individual in the population again
* until the running sum is >= to the randomly chosen number.
*/
max = totalfitness + 1;
for (int i = 0; i < popSize; i++) {
//pick a random number between 0 and that sum.
double randomNumber;
//randomNumber = r.nextDouble(totalfitness + 1);
randomNumber = r.nextDouble() * 3.67;
int runningSum = 0;
int index = 0;
int lastAddedIndex = 0;
while (runningSum < randomNumber) {
runningSum += aPopulation[index].fitnessVal;
lastAddedIndex = index;
index++;
}
populationNew[i] = aPopulation[lastAddedIndex];
runningSum = 0;
index = 0;
lastAddedIndex = 0;
}
return populationNew;
}

Thanks in advance :-)
• February 7th, 2014, 10:28 AM
Norm
Re: Need help in roulette wheel Selection in genetic algorithm
Please edit your post and wrap your code with code tags:
[code=java]
YOUR CODE HERE
[/code]
to get highlighting and preserve formatting.