本文整理汇总了C++中Chromosome::Fitness方法的典型用法代码示例。如果您正苦于以下问题:C++ Chromosome::Fitness方法的具体用法?C++ Chromosome::Fitness怎么用?C++ Chromosome::Fitness使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chromosome
的用法示例。
在下文中一共展示了Chromosome::Fitness方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RunGA
void RunGA(){
int generations = 0;
while(max_generation >= 0 && generations <= max_generation){
GAStep();
if(generations % 100 == 0){
std::cout << "Generacion: " << generations << "\n";
}
if(generations % 1000 == 0){
Chromosome *best = SelectBest();
QImage image = DrawImage(best);
image.save(QString("out/out_") + QString::number(generations) + ".png");
qDebug() << "Fitness: " << best->Fitness();
}
generations++;
}
DrawSVG(SelectBest(), "Final.svg");
}
示例2: GAStep
void GAStep(){
Chromosome *elite = SelectBest();
Chromosome clonA;
Chromosome clonB;
Chromosome *ap = NULL;
// Elitism
elite->Clone(&clonA);
InsertPobB(&clonA);
// harem
int fraction = int(HAREM * sizePopulationA);
for(int i = 0; i < fraction; i += 2){
elite->Clone(&clonA);
SelectTournament()->Clone(&clonB);
Crossover(&clonA, &clonB);
clonA.Mutate();
clonB.Mutate();
clonA.Fitness() = Distance(&clonA);
clonB.Fitness() = Distance(&clonB);
InsertPobB(&clonA);
InsertPobB(&clonB);
}
// Fill
while((sizePopulationA - sizePopulationB) > 0){
ap = SelectTournament();
ap->Clone(&clonA);
ap = SelectTournament();
ap->Clone(&clonB);
Crossover(&clonA, &clonB);
clonA.Mutate();
clonB.Mutate();
clonA.Fitness() = Distance(&clonA);
clonB.Fitness() = Distance(&clonB);
if(clonA.Fitness() < clonB.Fitness())
InsertPobB(&clonA);
else
InsertPobB(&clonB);
}
UpdatePopulation();
}