#include "types.h" #include "options.h" INT length; OPTION app_options[] = { { "length", "l", INT_OPT, TRUE, LLIMIT(1.0), VADDR(length), "The length of the genome." }, { (STRING) 0, "", 0, FALSE, NO_LIMITS(), (VOID *) 0, "" } }; INT app_individual_size() { return length; } VOID app_evaluate_population(context) CONTEXT *context; { register INT i; register INT population_size = context->population_size; register FITNESS this_fitness; context->total_fitness = (FITNESS)0; context->best_fitness_of_generation = ((INT) -1); for (i = 0; i < population_size; i++){ register FITNESS this_fitness; if (context->population[i].evaluated == FALSE){ register INT j; register FITNESS fitness = (FITNESS) 0; register INDIVIDUAL_TYPE genome = context->population[i].genome; for (j = 0; j < length; j++){ if (genome[j] == '1'){ fitness ++; } } this_fitness = context->population[i].unscaled_fitness = fitness; context->population[i].evaluated = TRUE; } else { this_fitness = context->population[i].unscaled_fitness; } context->total_fitness += this_fitness; if (this_fitness > context->best_fitness_of_generation){ context->best_individual_of_generation = i; context->best_fitness_of_generation = this_fitness; } } return; }