本文整理汇总了C++中Chromosome::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ Chromosome::push_back方法的具体用法?C++ Chromosome::push_back怎么用?C++ Chromosome::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chromosome
的用法示例。
在下文中一共展示了Chromosome::push_back方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generate
/*
* Generate a population of random bits using a specific seed
* Parameters: populationSize, chromosomeLength, seed value
* Return: boolean
*/
bool Population::generate(size_t populationSize, size_t chromosomeLength, string seedValue) {
seed_seq seed(seedValue.begin(), seedValue.end()); //Use the seed value instead of random_device
mt19937 gen(seed);
bernoulli_distribution dist; //Bernoulli distribution of type bool
for(size_t i = 0; i < populationSize; i++){
Chromosome chromosome;
chromosome.reserve(chromosomeLength);
for(size_t j = 0; j<chromosomeLength; j++){
chromosome.push_back(dist(gen)); ///generate a random bool
}
population.push_back(chromosome);
}
return true;
}
示例2: testcrossingtwo
void TwoPointCrossing_test::testcrossingtwo()
{
Chromosome achromosome;
achromosome.push_back(true);
achromosome.push_back(true);
achromosome.push_back(true);
achromosome.push_back(true);
achromosome.push_back(true);
achromosome.push_back(false);
achromosome.push_back(false);
achromosome.push_back(false);
achromosome.push_back(false);
achromosome.push_back(false);
Chromosome trueChromosome(10, true);
POPULATION fpop;//(5, trueChromosome);
/*fpop.push_back(achromosome);
fpop.push_back(achromosome);
fpop.push_back(achromosome);
fpop.push_back(achromosome);
fpop.push_back(achromosome);*/
for(int i=0; i<100; ++i)
{
fpop.push_back(trueChromosome);
fpop.push_back(trueChromosome);
fpop.push_back(achromosome);
}
printFarm(fpop);
high_resolution_clock::time_point t1 = high_resolution_clock::now();
TwoPointCrossing onepoint(fpop);
for(int i=0; i<10; ++i)
{
onepoint.crossovertwo();
}
high_resolution_clock::time_point t2 = high_resolution_clock::now();
std::cout<<"Final population"<<std::endl;
printFarm(fpop);
duration<double> time_span = duration_cast<duration<double>>(t2 - t1);
std::cout << "It took me " << time_span.count() << " seconds."<<std::endl;
}