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.