示例#1
0
Population * new_empty_population()
{
	Population * population;
	long features[PHENOTYPE_SIZE];
	if((population = (Population*)malloc(sizeof(Population))) != NULL)
	{
		for(int i = 0; i < POPULATION_SIZE; ++i)
		{
			for(int j = 0; j < PHENOTYPE_SIZE; ++j)
			{
				features[j] = 0;
			}
			population->individuals[i] = (*new_individual(features));
		}
	}
	else
	{
		exit(1);
	}
	return population;
}
示例#2
0
int state0() 
/* Do what needs to be done in state 0.

   pre: The global variable 'paramfile' contains the name of the
        parameter file specified on the commandline.
        The global variable 'alpha' contains the number of indiviuals
        you need to generate for the initial population.
                
   post: Optionally read parameter specific for the module.
         Optionally do some initialization.
         Initial population created.
         Information about initial population written to the ini file
         using write_ini().
         Return value == 0 if successful,
                      == 1 if unspecified errors happened,
                      == 2 if file reading failed.
*/
{
     /**********| added for DTLZ |**************/
     int i;
     /**********| addition for DTLZ end |*******/

     
     int result; /* stores return values of called functions */
     int *initial_population; /* storing the IDs of the individuals */
     initial_population = (int *) malloc(alpha * sizeof(int)); 
     if (initial_population == NULL)
     {
          log_to_file(log_file, __FILE__, __LINE__, "variator out of memory");
          return (1);
     }

     /**********| added for DTLZ |**************/
     result = read_local_parameters();
     
     if (result != 0)
     { 
          log_to_file(log_file, __FILE__, __LINE__,
                      "couldn't read local parameters");
          return (1);
     }

     /* initializing the first alpha individuals */
     for(i = 0; i < alpha; i++)
     {
 	 individual *ind = new_individual();
	 eval(ind);
	 initial_population[i] = add_individual(ind);
         if(initial_population[i] == -1)
            return(1);
     } 

     gen = 1;
     
     /**********| addition for DTLZ end |*******/

     result = write_ini(initial_population);
     if (result != 0)
     { 
          log_to_file(log_file, __FILE__, __LINE__,
                      "couldn't write ini");
          free(initial_population);
          return (1);
     }

     free(initial_population);
     return (0);
}