本文整理汇总了C++中Genome::clone方法的典型用法代码示例。如果您正苦于以下问题:C++ Genome::clone方法的具体用法?C++ Genome::clone怎么用?C++ Genome::clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Genome
的用法示例。
在下文中一共展示了Genome::clone方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
const unsigned mutations=2;
Genome::set_mutations_at_cloning(mutations);
std::cout<<"[Cloning with "<<mutations<<" mutations.]"<<std::endl;
Genome A;
std::cout<<"HEALTHY GENOME: "<<std::endl<<" "<<A<<std::endl;
std::cout<<" Bad mutations within first 10 years = "<<A.bad_mutations(10)<<std::endl;
Genome B=A.clone();
std::cout<<"AFTER 1st CLONING: "<<std::endl<<" "<<B<<std::endl;
std::cout<<" Bad mutations within the whole Genome = "<<B.bad_mutations(Genome::max_age-1)<<std::endl;
for (unsigned i=0; i<5; ++i) {
A=B.clone();
B=A.clone();
}
std::cout<<"AFTER 10 MORE CLONINGS: "<<std::endl<<" "<<A<<std::endl;
std::cout<<" Bad mutations within first 5 years = "<<A.bad_mutations(5)<<std::endl;
std::cout<<"AFTER 1 MORE CLONING: "<<std::endl<<" "<<B<<std::endl;
std::cout<<" Bad mutations within first 10 years = "<<A.bad_mutations(10)<<std::endl;
for (unsigned i=0; i<50; ++i) {
A=B.clone();
B=A.clone();
}
std::cout<<"AFTER 100 MORE CLONINGS: "<<std::endl<<" "<<A<<std::endl;
std::cout<<" Bad mutations within first 2 years = "<<A.bad_mutations(2)<<std::endl;
std::cout<<"AFTER 1 MORE CLONING: "<<std::endl<<" "<<B<<std::endl;
std::cout<<" Bad mutations within first 2 years = "<<A.bad_mutations(2)<<std::endl;
return 0;
}
示例2: main
int main()
{
Genome::set_mutations_at_cloning(Genome::max_age-Genome::max_age/4);
Genome gene;
Genome gene2=gene.clone();
cout<<gene;
cout<<gene2;
}
示例3: crossoverSexually
void CalculatorGenome::crossoverSexually(const Genome& father, const Genome& mother,
shared_ptr<Genome>& brother, shared_ptr<Genome>& sister)
{
shared_ptr<CalculatorGenome> bro = dynamic_pointer_cast<CalculatorGenome>(father.clone());
shared_ptr<CalculatorGenome> sis = dynamic_pointer_cast<CalculatorGenome>(mother.clone());
// find the cut points
shared_ptr<CalculatorGenomeNode> broSubtree = bro->_chooseRandomNode();
shared_ptr<CalculatorGenomeNode> sisSubtree = sis->_chooseRandomNode();
shared_ptr<CalculatorGenomeNode> broSubtreeParent = bro->_findParent(broSubtree);
shared_ptr<CalculatorGenomeNode> sisSubtreeParent = sis->_findParent(sisSubtree);
// move the sister subtree over to the bro
if (broSubtreeParent == NULL)
{
bro->_root = sisSubtree;
}
else
{
std::string broLabel = broSubtreeParent->findInput(broSubtree);
broSubtreeParent->setInput(broLabel, sisSubtree);
}
// move the brother subtree over to the bro
if (sisSubtreeParent == NULL)
{
sis->_root = broSubtree;
}
else
{
std::string sisLabel = sisSubtreeParent->findInput(sisSubtree);
sisSubtreeParent->setInput(sisLabel, broSubtree);
}
brother = bro;
brother->setScore(-1);
sister = sis;
sister->setScore(-1);
}
示例4: 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
}