2
private static int generation = 0;
private static int numInGeneration = 0;


public static void Calculate()
{
    const double crossoverProbability = 0.65; 
    const double mutationProbability = 0.08; 
    const int elitismPercentage = 5;
    ...
    var population = new Population(100, 40, false, false, ParentSelectionMethod.FitnessProportionateSelection);



private static double EvaluateFitness(Chromosome chromosome)
{
    numInGeneration++; // incrementing evaluation number in the same generation

    // save to DB chromosome, fitness, generation, numInGeneration ...



private static bool TerminateAlgorithm(Population population, int currentGeneration, long currentEvaluation)
{
    numInGeneration = 0; // reseting number in generation

NumInGeneration represents number of entries inside of fitness function. When I grouped results for each generation I've got following results:

Generation  NumInGeneration
    0           289
    1           186
    2           188
    3           182
    4           190
    5           189
    6           184
    7           184
    8           185

Why there are no 100 evaluations, 100 entries to the fitness function. In this case in 0th generation it is 289 times?

I was expecting to see 100 chromosomes generated for each generation, which was implying to have 100 evaluations (100 entries to the fitness function).

When I grouped chromosomes in the 0th generation I've got repeating for evaluations of the same chromosomes:

Chromosome                                  Repeating
0001001110101011101110111011101011101011    12
0010000111110011110100011011101110101100    8
0010111011001000001110011000110001010010    5
0011100011110010100010001100001101111001    5
0000011011001111101000001101011111111111    4
0010011010100110001001110101001101111101    4
0001101110101101110100001000110000001000    3
0100011001110010100001010111000011111011    3
1110100110001010000101010110111100000101    2
0100010110100111010100100100110110111111    2
0100101111011000000000111100100000011100    2
1111001111101100011101100000101101101001    2
1100000100110000001010110110110001010000    2
0110010101110011000101001111011010111011    2
1100101011010001010011100101101110011100    2
0010000110101011110010111010110100000010    2
0100000000000101101011111011111011111100    2
0100110011000001010000011110001110010110    2
0111101101000111111011111011111011100100    2
0111110010011110010010000000100011010010    2
0111111011110101111111000001101011011111    1
0111111100101001110011111110110100010010    1
1000001001101011100010001011011110100110    1

Another question is why is fitness function called more times for the same chromosome. In this example it's possible to see that 12 times the same calculation has been made? Is there some internal caching that has to be setup?

Probably I've got wrong idea how GAF should work. In that case please explain what is connection between population number and number of entries to the fitness function. How to setup and control number of entries to the fitness function. In case when fitness function is to heavy there is waste of resources when evaluation is made for the same chromosome more than once. In that case I don't see a problem to make an "external" caching if needed.

Alen
  • 49
  • 5

1 Answers1

1

The number of evaluations is based on the number of the population in relation to the number of operators. If all chromosomes were evaluated for each generation, then you would see 300 evaluations per generation. However, this number is reduced based on the parameters specified. For example crossover ReEvaluateAll is set to false. This means that the GAF will not re-evaluate anything it already has a fitness for. Elite is set to 5% which means that these will not be evaluated for each operator/generation. Crossover probabilty is set fairly low at 0.65 which means that there is a significant chance that crossover will not occur in many cases thereby reducing the number of evaluations still further.

Parent selection is determined in part by current fitness, therefore, the process of evaluation is to undertake an initial evaluation of the population before starting the first generation and then evaluating as described above for each operator in each generation. Therefore it is quite normal that the first generation will have more evaluations than subsequent ones. The results of the initial evaluation are available by hooking up to the OnInitialEvaluationComplete event. If you have a population of 100, the number of evaluations at this point will be 100.

For the second part of your question ...why is fitness function called more times for the same chromosome? the answer is that it is not. What you have is 12 different chromosomes all with the same value. Checking the Chromosome.Id property (Guid) for each of the 'duplicates' should prove this. It is common to have duplicate values in a GA population due to the parent selection process often using the same or similar parents to create offspring.

Your idea of cacheing fitness values for known chromosome values seems, on the face of it, a reasonable approach for chromosomes other than the object type. The product is open source (LGPL), you could always add this and create a pull request.

John Newcombe
  • 364
  • 2
  • 7