本文整理汇总了C++中ThreadData::SetSimulating方法的典型用法代码示例。如果您正苦于以下问题:C++ ThreadData::SetSimulating方法的具体用法?C++ ThreadData::SetSimulating怎么用?C++ ThreadData::SetSimulating使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThreadData
的用法示例。
在下文中一共展示了ThreadData::SetSimulating方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void* GeneticAlgorithmProfile1::Algorithm( void* arg )
{
srand (static_cast <unsigned> (time(0)));
ThreadData* td = (ThreadData*)arg;
if( td->first && td->generation.size() == 0 ) {
td->generation = GeneticAlgorithmProfile1::GeneratePopulation(MaxChromosomesPopulationSize, 0, 0);
}
td->SetSimulating(false);
td->SetGaInitialized(true);
td->SetGaEnabled(true);
if( td->first && td->generation.size() > 0 ) {
for(int i = 0; i < td->generation.size(); i++) {
GeneticAlgorithmProfile1::CalculateFitness(td, td->generation.at(i));
}
std::sort (td->generation.begin(), td->generation.end(), [](Chromosome * a, Chromosome * b) {
if (b->fitnessScore == a->fitnessScore) { return b->fitnessHPPercentage < a->fitnessHPPercentage; }
return b->fitnessScore < a->fitnessScore; });
td->first = false;
}
//DBG - LOG
std::cout << "\n\n LOG - Generation : INITIAL POP " << " START ";
for(int k = 0; k < td->generation.size(); k++) {
std::cout << "\n Chromosome : " << k << " fitness score : " << td->generation.at(k)->fitnessScore;
}
std::cout << "\n ---END--- ";
for(int i = 0; i < MaxGenerations; i++) {
std::cout << "\n START OF NEW GENERATION\n";
td->previouslyPlayedFitness = td->generation.at(0)->fitnessScore;
Chromosome* elite =(Chromosome*) malloc(sizeof(Chromosome));
for ( int j = 0; j < CreepsPerRound; j ++) {
elite->healthPoints[j] = td->generation.at(0)->healthPoints[j];
elite->movementSpeed[j] = td->generation.at(0)->movementSpeed[j];
elite->elementalAffinity[j] = td->generation.at(0)->elementalAffinity[j];
elite->fitnessScore = td->generation.at(0)->fitnessScore;
}
Chromosome* parent1;
Chromosome* parent2;
if(td->crossoverRate == 100) {
int totalFitness = 0;
std::vector<double> result(td->generation.size());
for(int x = 0; x < td->generation.size(); x++) {
totalFitness = totalFitness + td->generation.at(x)->fitnessScore;
}
for(int p = 0; p < td->generation.size(); p++) {
result[p] = (((double)td->generation.at(p)->fitnessScore) / ((double)totalFitness)) * 100;
}
bool firstSelected = false;
bool secondSelected = false;
for(int l = 0 ; l < result.size() ; l++) {
float roll = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/100.0f));
if( roll <= result.at(l) ) {
if(!firstSelected) {
parent1 = td->generation.at(l);
firstSelected = true;
}
else if(!secondSelected) {
parent2 = td->generation.at(l);
secondSelected = true;
}
}
if(firstSelected && secondSelected) {
break;
}
else {
if( l == result.size()-1 ) {
l = 0;
}
}
}
GeneticAlgorithmProfile1::Crossover(td, parent1, parent2);
}
td->generation.pop_back();
GeneticAlgorithmProfile1::Mutate(td, &td->generation);
td->generation.push_back(elite);
for(int k = 0; k < td->generation.size(); k++) {
Chromosome* c = td->generation.at(k);
GeneticAlgorithmProfile1::CalculateFitness(td, c);
}
std::sort (td->generation.begin(), td->generation.end(), [](Chromosome * a, Chromosome * b) {
if (b->fitnessScore == a->fitnessScore) { return b->fitnessHPPercentage < a->fitnessHPPercentage; }
return b->fitnessScore < a->fitnessScore; });
//DBG - LOG
std::cout << "\n\n LOG - Generation : " << i << " START ";
for(int k = 0; k < td->generation.size(); k++) {
std::cout << "\n Chromosome : " << k << " fitness score : " << td->generation.at(k)->fitnessScore;
}
std::cout << "\n ---END--- ";
std::cout << "\n\n GENS PAST " << i;
if ( td->generation.at(0)->fitnessScore == MinAcceptableFitness ) { break; }
}
std::cout << " \n DEPLOYMENT SETTING --- FITNESS : " << td->generation.at(0)->fitnessScore;
//.........这里部分代码省略.........