本文整理汇总了C++中Species::add_Organism方法的典型用法代码示例。如果您正苦于以下问题:C++ Species::add_Organism方法的具体用法?C++ Species::add_Organism怎么用?C++ Species::add_Organism使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Species
的用法示例。
在下文中一共展示了Species::add_Organism方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reproduce
//.........这里部分代码省略.........
//std::cout<<"mutate_add_link: "<<new_genome<<std::endl;
mut_struct_baby=true;
}
else {
//Only do other mutations when not doing sturctural mutations
if (randfloat()<NEAT::mutate_random_trait_prob) {
new_genome->mutate_random_trait();
//std::cout<<"..mutate random trait: "<<new_genome<<std::endl;
}
if (randfloat()<NEAT::mutate_link_trait_prob) {
new_genome->mutate_link_trait(1);
//std::cout<<"..mutate link trait: "<<new_genome<<std::endl;
}
if (randfloat()<NEAT::mutate_node_trait_prob) {
new_genome->mutate_node_trait(1);
//std::cout<<"mutate_node_trait: "<<new_genome<<std::endl;
}
if (randfloat()<NEAT::mutate_link_weights_prob) {
new_genome->mutate_link_weights(mut_power,1.0,GAUSSIAN);
//std::cout<<"mutate_link_weights: "<<new_genome<<std::endl;
}
if (randfloat()<NEAT::mutate_toggle_enable_prob) {
new_genome->mutate_toggle_enable(1);
//std::cout<<"mutate_toggle_enable: "<<new_genome<<std::endl;
}
if (randfloat()<NEAT::mutate_gene_reenable_prob) {
new_genome->mutate_gene_reenable();
//std::cout<<"mutate_gene_reenable: "<<new_genome<<std::endl;
}
}
//Create the baby
baby=new Organism(0.0,new_genome,generation);
}
else {
//Create the baby without mutating first
baby=new Organism(0.0,new_genome,generation);
}
}
//Add the baby to its proper Species
//If it doesn't fit a Species, create a new one
baby->mut_struct_baby=mut_struct_baby;
baby->mate_baby=mate_baby;
curspecies=(pop->species).begin();
if (curspecies==(pop->species).end()){
//Create the first species
newspecies=new Species(++(pop->last_species),true);
(pop->species).push_back(newspecies);
newspecies->add_Organism(baby); //Add the baby
baby->species=newspecies; //Point the baby to its species
}
else {
comporg=(*curspecies)->first();
found=false;
while((curspecies!=(pop->species).end())&&
(!found)) {
if (comporg==0) {
//Keep searching for a matching species
++curspecies;
if (curspecies!=(pop->species).end())
comporg=(*curspecies)->first();
}
else if (((baby->gnome)->compatibility(comporg->gnome))<NEAT::compat_threshold) {
//Found compatible species, so add this organism to it
(*curspecies)->add_Organism(baby);
baby->species=(*curspecies); //Point organism to its species
found=true; //Note the search is over
}
else {
//Keep searching for a matching species
++curspecies;
if (curspecies!=(pop->species).end())
comporg=(*curspecies)->first();
}
}
//If we didn't find a match, create a new species
if (found==false) {
newspecies=new Species(++(pop->last_species),true);
//std::std::cout<<"CREATING NEW SPECIES "<<pop->last_species<<std::std::endl;
(pop->species).push_back(newspecies);
newspecies->add_Organism(baby); //Add the baby
baby->species=newspecies; //Point baby to its species
}
} //end else
}
return true;
}
示例2: if
//.........这里部分代码省略.........
new_genome->mutate_random_trait();
//cout<<"..mutate random trait: "<<new_genome<<endl;
}
if (randfloat()<NEAT::mutate_link_trait_prob) {
new_genome->mutate_link_trait(1);
//cout<<"..mutate link trait: "<<new_genome<<endl;
}
if (randfloat()<NEAT::mutate_node_trait_prob) {
new_genome->mutate_node_parameters(NEAT::time_const_mut_power,NEAT::time_const_mut_prob,
NEAT::bias_mut_power,NEAT::bias_mut_prob,NEAT::afunc_mut_prob);
new_genome->mutate_node_trait(1);
//cout<<"mutate_node_trait: "<<new_genome<<endl;
}
if (randfloat()<NEAT::mutate_link_weights_prob) {
new_genome->mutate_link_weights(mut_power,1.0,GAUSSIAN);
//cout<<"mutate_link_weights: "<<new_genome<<endl;
}
if (randfloat()<NEAT::mutate_toggle_enable_prob) {
new_genome->mutate_toggle_enable(1);
//cout<<"mutate_toggle_enable: "<<new_genome<<endl;
}
if (randfloat()<NEAT::mutate_gene_reenable_prob) {
new_genome->mutate_gene_reenable();
//cout<<"mutate_gene_reenable: "<<new_genome<<endl;
}
}
//Create the baby
baby=new Organism(0.0,new_genome,generation);
}
else {
//Create the baby without mutating first
baby=new Organism(0.0,new_genome,generation);
}
}
//Add the baby to its proper Species
//If it doesn't fit a Species, create a new one
baby->mut_struct_baby=mut_struct_baby;
baby->mate_baby=mate_baby;
curspecies=(pop->species).begin();
if (curspecies==(pop->species).end()){
//Create the first species
newspecies=new Species(++(pop->last_species),true);
(pop->species).push_back(newspecies);
newspecies->add_Organism(baby); //Add the baby
baby->species=newspecies; //Point the baby to its species
}
else {
comporg=(*curspecies)->first();
found=false;
// Testing out what happens when speciation is disabled
//found = true;
//(*curspecies)->add_Organism(baby);
//baby->species = (*curspecies);
while((curspecies!=(pop->species).end()) && (!found))
{
if (comporg==0) {
//Keep searching for a matching species
++curspecies;
if (curspecies!=(pop->species).end())
comporg=(*curspecies)->first();
}
else if (((baby->gnome)->compatibility(comporg->gnome))<NEAT::compat_threshold) {
//Found compatible species, so add this organism to it
(*curspecies)->add_Organism(baby);
baby->species=(*curspecies); //Point organism to its species
found=true; //Note the search is over
}
else {
//Keep searching for a matching species
++curspecies;
if (curspecies!=(pop->species).end())
comporg=(*curspecies)->first();
}
}
//If we didn't find a match, create a new species
if (found==false) {
newspecies=new Species(++(pop->last_species),true);
(pop->species).push_back(newspecies);
newspecies->add_Organism(baby); //Add the baby
baby->species=newspecies; //Point baby to its species
}
} //end else
//Put the baby also in the master organism list
(pop->organisms).push_back(baby);
return baby; //Return a pointer to the baby
}