当前位置: 首页>>代码示例>>C++>>正文


C++ Chromosome::push_back方法代码示例

本文整理汇总了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;
}
开发者ID:snappas,项目名称:AI_Homework,代码行数:22,代码来源:Population.cpp

示例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;
     
}
开发者ID:trycity,项目名称:gaopenmp,代码行数:50,代码来源:TwoPointCrossing_test.cpp


注:本文中的Chromosome::push_back方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。