本文整理汇总了C++中Population::evaluate方法的典型用法代码示例。如果您正苦于以下问题:C++ Population::evaluate方法的具体用法?C++ Population::evaluate怎么用?C++ Population::evaluate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population
的用法示例。
在下文中一共展示了Population::evaluate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: single_run
/*
* single_run.cpp
* it is basically the independet thread that can be launched
* independently
* Created on: Mar 2, 2011
* Author: cnua
*/
int single_run (int run_id, int cur_run, int* SEED, string OUTPUT_STRING, \
RunParameters* p_parameters,\
ProblemDefinition* p_problem, \
Reporter pop_reporter,\
time_t start, time_t finish, double delta_t)
{
// create directory run_k
char num_field[10];
sprintf(num_field, "%d", cur_run+1);
string num_field_s = num_field;
string DIR_RUN_K = OUTPUT_STRING + "/run_" + num_field;
mkdir(DIR_RUN_K.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH );
// seed the random generator
srand(SEED[cur_run]);
// start time
time(&start);
int elapsed_time;
//---------------------------------------------------------------------
// CREATE THE POPULATION (constructor called)
//---------------------------------------------------------------------
Variable* Z; //to be included in ProblemDefinition...
p_problem->initialise_variables(&Z, p_parameters->max_n_periods);
// do you really need new? no, but don't touch it for now
Population* P = new Population(p_parameters, p_problem);
if (!P) {
cerr << "\nmain : Error creating population!!!\n";
exit(-1);
}
//as it's hard to pass Pop as a parameter to fdf_c__ through fortran functions, treat it as a global variable
Pop = P;
cout << "\nP = " << P;
cout << "\nPop = " << Pop;
///// INITIAL GENERATION (0) ///////////////////////////////////////
// trees before parameters insertion
cout << "\nInitialization of the population (generation 0)\n";
P->print_population_without_parameters(0);
/// split the data set in tuning set (data_tuning) and validation set (data_validation). See SPLIT and VALIDATING_LINES in input file
//this function will also allow to increase the number of fitness cases during the run...
P->split_data(p_parameters, p_problem, 0,1);
// here or before parallel section begins?
// Depends if you want to change fitness cases during the evolution...
/////////// OTHER GENERATIONS ///////////////////////////////////////
int check_end = 0;
int last_gen=0;
for (int i=0; i<p_parameters->G+1; i++) { // generations
if (i) { //skip generation 0
// split the data for the current generation (this function will also allow to increase the number of fitness cases during the run...)
//P->split_data(i,G,split); // not used...
/*
if ((i%6)==0) { //6
// KILLING and FILLING
P->kill_and_fill(&problem);
//cin.get();
}
else
//*/
// GENETIC OPERATORS: sorting, reproduction, crossover, mutation, pruning
P->new_spawn(*p_parameters, *p_problem, p_parameters->nfitcases,i);
// print population WITHOUT parameters after genetic operations
//if (COMMENT) {
// printf("\n\n***********Generation %d after genetic operations (not sorted, new trees marked with f9.999999E+99)************\n", i-1);
// P->print_population_without_parameters(i-1);
// printf("\n***********************************************************************\n");
//}
}
// evaluate fitness function (in structural GP parameters are added and tuned first, then the evaluation is performed)
P->evaluate(i,p_parameters->G);
//----------------------------------------------------------------------------------
// extfitness - keeping the individual with least fitness value -------
// sort according to fitness (error)
//P->sort(i,tree_comp_fitness);
///printf("\n\n***********Generation %d after genetic operations (not sorted, new trees marked with f9.999999E+99)************\n", i-1);
//P->print_population_without_parameters(i-1);
//printf("\n***********************************************************************\n");
// update the best individual - structure and complete tree (for PARAMETER INHERITANCE)
//P->update_ext_archive();
//.........这里部分代码省略.........