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
Printable View
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
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
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.Quote:
I can't understand the algorithm clearly
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 :-)
Please edit your post and wrap your code with code tags:
[code=java]
YOUR CODE HERE
[/code]
to get highlighting and preserve formatting.