本文整理汇总了C++中Population::genesis方法的典型用法代码示例。如果您正苦于以下问题:C++ Population::genesis方法的具体用法?C++ Population::genesis怎么用?C++ Population::genesis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population
的用法示例。
在下文中一共展示了Population::genesis方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
//1. load the example file
NEATsettings * s = new NEATsettings();
ifstream ifs(args[2],ios::in);
ifs>>s;
ifs.close();
//2. generate the pop
TransferFunctions * tfs = new TransferFunctions(s);
Population * pop = makePopulation(args[3],s,tfs);
//3. then the selector
Selector * sel = makeSelector(args[4]);
int g = atoi(args[5]);
int iter = atoi(args[6]);
string dfile = args[7];
DataSet * set = new DataSet(false,dfile,0.0);
FitnessEvaluator * de = new DatasetHyperNEAT(s,tfs,set);
Evaluator * ev = new Evaluator(de);
LocalReproducer * rp = new LocalReproducer();
int gc = 0; double sum=0; double sum2=0; double sum3=0;
Phenotype * cbest = NULL;
Phenotype * sbest = NULL;
Phenotype * best = NULL;
int osize=pop->getMembers()->size();
int ss=0;
double ocomp=0;
time_t startt;
double timesum = 0;
for(int i2=0;i2<iter;i2++){
gc = 0;
best = NULL;
startt = time(0);
for(int i=0;i<g;i++){
gc++;
// cout << "before eval.." << endl;
ev->evaluate(pop->getMembers(),pop->getMembers()->size());
// cout << "after eval.." << endl;
if((unsigned int)pop->getOriginalSize()!=pop->getMembers()->size())
cout << "size not right after eval.." << endl;
ss=pop->getSpecies()->size();
// cout << "before pop juggling.." << endl;
pop->updateSpeciesStats();
pop->sortmembers();
pop->sortspecies();
cbest = pop->getCopyOfCurrentBest();
de->f(cbest);
// cout << "before best juggling.." << endl;
if(best==NULL){
best = cbest;
}else if(cbest->getFitness()>best->getFitness()){
delete best;
best = cbest;
}else{
delete cbest;
}
// cout << "after best juggling.." << endl;
cout << "gen: "<<i<<" best: " << best->getFitness() << "worst: " << pop->getMembers()->at(pop->getMembers()->size()-1)->getFitness() << endl;
if(((DatasetHyperNEAT*)de)->done(best)){
i = g;
// cout << best;
((DatasetHyperNEAT*)de)->runTest(best);
}
// cout << "after xor testing.." << endl;
sel->select(pop,0);
rp->reproduce(pop);
// cout << "after select and reproduce.." << endl;
}
if(sbest==NULL)
sbest = best;
else if(best->getFitness()>sbest->getFitness())
sbest = best;
time_t ft = time(0)-startt;
timesum += ft;
cout << "run: "<<i2+1<<" gc: "<<gc<<" maxfitness: " << pop->getHighestFitness()
<< " sbest fitness: " << sbest->getFitness() << " species: " << ss
<< " time: " << ft << " time/gen: " << (double)ft/(double)gc << endl;
sum += gc;
sum2 += best->getGenome()->extrons();
sum3 += best->getGenome()->countHidden();
if(i2!=iter){
if(pop->getOriginalSeed()!=NULL){
Genome * oseed = pop->getOriginalSeed();
int oelitism = pop->getOriginalInitialElitism();
ocomp = pop->getOcomp();
delete pop;
pop = new Population(s,ocomp,tfs);
// oseed->setTfs(pop->getTfs());
pop->genesis(oseed,osize,oelitism);
}else{
pop->resetSpawn();
}
}
}
((DatasetHyperNEAT*)de)->runTest(sbest);
cout << ((DatasetHyperNEAT*)de)->output(sbest);
}