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


C++ Genome::mutate方法代码示例

本文整理汇总了C++中Genome::mutate方法的典型用法代码示例。如果您正苦于以下问题:C++ Genome::mutate方法的具体用法?C++ Genome::mutate怎么用?C++ Genome::mutate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Genome的用法示例。


在下文中一共展示了Genome::mutate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: nextGeneration

void SteadyStateGA::nextGeneration()
{
	double cross_random;
	double mutate_random;

	// sort the population bases on the parameters
	pop->sortPopulation();

	vector<Genome *> *new_genomes = new vector<Genome *>;

	// we only replace replace_percentage of the population.
	// decide which percentage to replace...the lowest scores... (-1) fitnesses
	// reverse interate through and delete the genomes.

	// copy the top (pop_size * replacement_percentage) genomes into the new genome vector
	for(int i = 0; i < (int)(pop->getPopSize() * replace_percentage); ++i)
	{
		new_genomes->push_back(pop->getGenome(i)->clone());
	}


	// now i need to add 1 - pop->getPopSize() * replace_percentage more genomes
	for(int i = 0; i < (int)(pop->getPopSize() - (pop->getPopSize() * replace_percentage)); ++i)
	{
		// need to select a dad and mom .. select...
		Genome *dad = pop->select();
		Genome *mom = pop->select();	
	

		// then create child for crossover.
		Genome *child;

		cross_random = objRand->randomPercentage();
		// if crossover does not happen make the children = to the parents
		if(cross_random <= crossover_percentage)
		{
			// perform crossover
			child = dad->crossover(*mom);
		}
		else
		{
			// make child and dad equal to each other
			child = dad->clone();

		}

		mutate_random = objRand->randomPercentage();
		// chance of mutation to each of the children
		if(mutate_random <= mutation_percentage)
		{
			// perform crossover
			child->mutate();
		}

		if((int)new_genomes->size() < pop->getPopSize())
			new_genomes->push_back(child);

	}

	
	++current_generation;

	pop->setPopGenomes(new_genomes);
	init(); // init the new population
}
开发者ID:gprimeca,项目名称:GenALib,代码行数:65,代码来源:SteadyStateGA.cpp


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