Making the probability of a fitter number getting picked higher.

So I have to make a mating pool and with it a sort of raffle for the fittest strings. The problem I'm facing is that I am stuck how to go about making a raffle and choosing the fittest of the strings. The ultimate goal of the function is to build an array with the indices of the strings that are the best match based on the fitness score. The fitness score is inside of the populationFitness array.Each fitness score is multiplied by a mating factor and that gives it a certain amount of tickets. Then based on how many tickets each index has, the "fitter" ticket indexes get put into the mating pool array.I just don't know how to go about programming a raffle. Any help would be much appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void buildMatingPool(int matingFactor, double populationFitness[],int matingPool[]){
    int i;
    int j = -1;
    int num1 = 0;
    double tickets;
    double ticketI[200] = {};
    int population[200] = {};

    for(i = 0; i < 200; i++){
        population[i] = i;
    }
    for (i = 0; i < 200; i++){
        tickets = 0;
        tickets = populationFitness[i] * matingFactor;
        ticketI[i] = tickets;
        if(ticketI[i] > 0){
            matingPool[j] = population[i];
            j = j + 1;
        }
        cout << ticketI[i] << endl;
    }
}
Topic archived. No new replies allowed.