Example #1
0
void over_production::operator()(const individual_vector& young_adults, 
        individual_vector& population) const
{
    individual_vector elites;
    if(population.size() >= count_ && elitism_)
    {
        std::sort(population.begin(), population.end(), &reverse_compare_individuals);
        for(std::size_t i = 0; i < count_; ++i)
        {
            elites.push_back(population[i]);
        }
        for(std::size_t i = count_; i < population.size(); ++i)
        {
            free_individual(population[i]);
        }
    }
    else free_individuals(population);
    population.clear();
    individual_vector copy = young_adults;
    for(std::size_t i = 0; i < elites.size(); ++i)
    {
        population.push_back(elites[i]);
    }
    std::sort(copy.begin(), copy.end(), &reverse_compare_individuals);
    for(std::size_t i = 0; i < pop_size_ - elites.size(); ++i)
    {
        population.push_back(copy[i]);
    }
    for(std::size_t i = pop_size_ - elites.size(); i < copy.size(); ++i)
    {
        free_individual(copy[i]);
    }
}
Example #2
0
int remove_individual(int identity)
/* Removes the individual with ID 'identity' from the global population. */
{
     individual *temp;
     int result;
     if((identity > global_population.last_identity) || (identity < 0))
          return (1);
     temp = get_individual(identity);
     if(temp == NULL)
          return (1);

     global_population.individual_array[identity] = NULL;

     if(identity == global_population.last_identity)
     {
          global_population.last_identity--;
     }
     else
     {
          result = push(&global_population.free_ids_stack, identity);
          if (result == 1)
          {
               log_to_file(log_file, __FILE__, __LINE__, 
                           "Pushing a free identity to stack failed.");
               return (1);
          }
     }

     global_population.size--;

     free_individual(temp);
     
     return (0);
}
Example #3
0
individual* getOriginal(){
	if(ori) free_individual(ori);
	ori=g_malloc0(sizeof(individual));
	ori->dominateSet=(individual**)g_malloc0(COMBINED_POPULATION_SIZE*sizeof(individual*));
	gint i;
	for(i=0; i<numberOfGenes; i++){
		ori->chrom[i]=default_individual[i];
	}
	ori->evaluateTimes=0;
	return ori;
}