本文整理汇总了C++中StateP::getElapsedTime方法的典型用法代码示例。如果您正苦于以下问题:C++ StateP::getElapsedTime方法的具体用法?C++ StateP::getElapsedTime怎么用?C++ StateP::getElapsedTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateP
的用法示例。
在下文中一共展示了StateP::getElapsedTime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: advanceGeneration
//.........这里部分代码省略.........
}
// calculate particle velocity according to the velocity equation (1)
flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (bestParticle->getGenotype(2));
std::vector< double > &bestParticlesPbestx = flp->realValue;
for( uint j = 0; j < velocities.size(); j++ ) {
double velocity;
velocity = weight_up * velocities[j] +
2 * R1 * (pbestx[j] - positions[j]) +
2 * R2 * (bestParticlesPbestx[j] - positions[j]);
if( velocity > m_maxV ) velocity = m_maxV;
if( velocity < -m_maxV) velocity = -m_maxV;
velocities[j] = velocity;
positions[j] += velocities[j]; //Updated positions with velocitites X(t+1)=X(t)+velocities(t);
// TODO apply position constriction
// check for bounds
if(bounded_) {
if(positions[j] < lbound_)
positions[j] = lbound_;
if(positions[j] > ubound_)
positions[j] = ubound_;
}
//std::cout<<"LA VELOCIDAD ES::::"<<velocity<<std::endl;
}
int proportion=55;
if(rand()%100>=proportion){
//Initial PSO inheritance algorithm -> 100%inheritance no evaluations.
//determine new particle fitness
//Particle best personal fitness
// flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (particle->getGenotype(3));
// double &particlePbestFitness = flp->realValue[0];
//Best particle fitness
// flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (bestParticle->getGenotype(3));
// double &bestparticlePbestFitness = flp->realValue[0];
// vf=(C1*R1*(particlePbestFitness-particle->fitness->getValue())+C2*R2*(bestparticlePbestFitness-particle->fitness->getValue()))
// /(1+C1*R1+C2*R2);
// vf=vf+particle->fitness->getValue();
evaluate( particle );
//std::cout<< " Inherited: " << vf<< " -> Evaluated "<< particle->fitness->getValue() <<std::endl ;
}
else{
//Particle best personal fitness
flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (particle->getGenotype(3));
double &particlePbestFitness = flp->realValue[0];
//Best particle fitness
flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (bestParticle->getGenotype(3));
double &bestparticlePbestFitness = flp->realValue[0];
//std::cout<<std::endl<<"The EverPersonalBEST of this particle is:"<<particlePbestFitness<<std::endl;
//std::cout<<std::endl<<"THE present LEADER(Allbes) of this particle fitness is:"<<bestparticlePbestFitness<<std::endl;
//Inheritance based on flight formula
std::cout<<"Particle Fitness"<<particle->fitness->getValue()<<" "<<std::endl;
//Fitness inheritance
vf=(C1*R1*(particlePbestFitness-particle->fitness->getValue())+C2*R2*(bestparticlePbestFitness-particle->fitness->getValue()))
/(1+C1*R1+C2*R2);
particle->fitness->setValue(vf+particle->fitness->getValue());
std::cout<< " Inherited: " << particle->fitness->getValue()<< " "<< std::endl ;
}
}
//std::cout<<std::endl<<"THE NUMBER OF THIS GENERATION IS:"<<state->getGenerationNo() <<std::endl;
std::cout<<std::endl<<"THE NUMBER OF EVALUATIONS ARE:"<<state->getEvaluations() <<std::endl;
std::cout<<std::endl<<"THE TIME TAKEN TO DO THIS IS:"<<state->getElapsedTime() <<std::endl;
//*******************FILE OUTPUT FOR DEBUGGING***********************************************//
IndividualP bestParticle = selBestOp->select( *deme );
FloatingPointP flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (bestParticle->getGenotype(3));
double &bestparticlePbestFitness = flp->realValue[0];
std::ofstream myfile1;
myfile1.open("FitnessvsEvaluations.txt", std::ios_base::app);
if (myfile1.is_open()){
myfile1<<bestparticlePbestFitness<<" ";
myfile1<<state->getEvaluations()<<std::endl;
}
//*******************************************************************************************//
return true;
}