Esempio n. 1
0
stResult<TCity> * main_genetic(mySlimTree* SlimTree, TCity * queryObject, stDistance range)
{
	time_t begin, end;

	begin = time(NULL);
	
	srand(time(NULL));
	
	Population * pop = new_population();
	Population * aux_pop = new_empty_population();
	
	infeasible(SlimTree, pop);
	
	set_genotype(pop);
	
	evaluate_fitness(pop, SlimTree, queryObject, range);

	#if DEBUG
	print_population(pop ,"Pop", number_of_gerations);
	#endif

	while( (number_of_gerations < MAX_NUMBER_OF_GERATIONS) && (delta_fitness > 0.0001) )
	{
		number_of_gerations++;
		#if DEBUG
		cout << "Number of Gerations: "<< number_of_gerations << endl;
		#endif
		selection_by_tournament(pop, aux_pop);
		#if DEBUG
		cout << "Torneio" << endl;
		#endif
		crossover_uniform(aux_pop);
		#if DEBUG
		cout << "Crossover Uniforme" << endl;
		#endif
		mutation(aux_pop);
		#if DEBUG
		cout << "Mutação" << endl;
		#endif
		set_phenotype(aux_pop);
		#if DEBUG
		cout << "Fenotipo" << endl;
		#endif
		infeasible(SlimTree, aux_pop);
		#if DEBUG
		cout << "Infactibilidade" << endl;
		#endif
		set_genotype(aux_pop);
		#if DEBUG
		cout << "Fenotipo" << endl;
		#endif
		copy_population(aux_pop, pop);
		#if DEBUG
		cout << "Copiar aux pop" << endl;
		#endif
		evaluate_fitness(pop, SlimTree, queryObject, range);
		#if DEBUG
		cout << "Fitness" << endl;
		#endif
		
		old_media_of_fitness = media_of_fitness;
		media_of_fitness = get_media_of_population(pop);
		delta_fitness = fabs(media_of_fitness - old_media_of_fitness);
	}

	end = time(NULL);
	
	#if DEBUG
	print_population(pop, "PopulatioN", number_of_gerations);
	
	print_statistic(pop, begin, end);
	#endif
}
void ClonalParasitePopulation::mutate_to(Genotype* genotype) {
    //TODO:: do other statistic things
    set_genotype(genotype);
}