GList* initializePopulation(individual* seed, gint number){ GList* population=NULL; gint i, j; gint random; individual* ind; ind=copyIndividual(seed); evaluateIndividual(ind, 0); memoryUsage* memoryU=stdMemoryAvg->data; memoryU->timeUsr=ind->time; memoryU->MEMORY_PROFILING_UNIT=ind->memory; population=g_list_append(population, ind); mutType mt; for(i=1; i<number; i++){ ind=copyIndividual(seed); //random=randomIntRange(0, numberOfGenes); for(j=0; j<numberOfGenes; j++){ if(default_mutation_type[j]==mutation_power2){ mt=mutation_power2_random; } else if(default_mutation_type[j]==mutation_power2_allow0){ mt=mutation_power2_allow0_random; } else mt=mutation_random; ind->chrom[j]=mutationGene(mt, ind->chrom[j], default_lower_bound[j], default_upper_bound[j]); } evaluateIndividual(ind, i); population=g_list_append(population, ind); } calculateFrontier(&population); return population; }
gint crossover(GList** population){ gint num, length=g_list_length(*population); individual* parent1, *parent2, *child1, *child2; for(num=0; num<POPULATION_SIZE*CROSSOVER_RATE; num+=2){ g_printf("crossover %d, size=%d\n", num+1, g_list_length(*population)); parent1=tournamentSelect(*population); child1=copyIndividual(parent1); parent2=tournamentSelect(*population); while(parent1==parent2) parent2=tournamentSelect(*population); child2=copyIndividual(parent2); crossoverScattered(child1, child2); child1->fitness=evaluateIndividual(child1, length+num); child2->fitness=evaluateIndividual(child2, length+num+1); *population=g_list_append(*population, child1); *population=g_list_append(*population, child2); } return 0; }
GList* initializeRandPopulation(individual* seed, gint number){ GList* population=NULL; gint i, j; gint random; individual* ind; ind=copyIndividual(seed); evaluateIndividual(ind, 0); memoryUsage* memoryU=stdMemoryAvg->data; memoryU->timeUsr=ind->time; memoryU->MEMORY_PROFILING_UNIT=ind->memory; population=g_list_append(population, ind); //gint printGap=number/100==0?1:number/100; mutType mt; for(i=1; i<number; i++){ ind=copyIndividual(seed); if(i%50==0){ g_printf("\n%d-%d: ", i, i+50); fprintf(logfp, "\n%d-%d: ", i, i+50); } //random=randomIntRange(0, numberOfGenes); for(j=0; j<numberOfGenes; j++){ if(default_mutation_type[j]==mutation_power2){ mt=mutation_power2_random; } else if(default_mutation_type[j]==mutation_power2_allow0){ mt=mutation_power2_allow0_random; } else mt=mutation_random; ind->chrom[j]=mutationGene(mt, ind->chrom[j], default_lower_bound[j], default_upper_bound[j]); } evaluateIndividual(ind, i); population=g_list_append(population, ind); } g_printf("\n"); selection(&population); return population; }
void AtariFTNeatExperiment::processGroup(shared_ptr<NEAT::GeneticGeneration> generation) { shared_ptr<NEAT::GeneticIndividual> individual = group.front(); evaluateIndividual(individual); }