本文整理汇总了C++中StateP::getGenerationNo方法的典型用法代码示例。如果您正苦于以下问题:C++ StateP::getGenerationNo方法的具体用法?C++ StateP::getGenerationNo怎么用?C++ StateP::getGenerationNo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateP
的用法示例。
在下文中一共展示了StateP::getGenerationNo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operate
bool TermStagnationOp::operate(StateP state)
{
uint currentGen = state->getGenerationNo();
if(currentGen - state->getPopulation()->getHof()->getLastChange() > termStagnation_) {
state->setTerminateCond();
ECF_LOG(state, 1, "Termination: maximum number of generations without improvement ("
+ uint2str(termStagnation_) + ") reached");
}
return true;
}
示例2: advanceGeneration
bool PSOInheritance::advanceGeneration(StateP state, DemeP deme)
{
// a) For each particle:
// 1) If the fitness value is better than the best fitness value (pBest) in history
// 2) Set current value as the new pBest
// 3) Put particle in the ranking array using the fitness value
// End
// b) For the p best particles in the ranking arrayºº
// 1) Find, in the particle neighborhood, the particle with the best fitness
// 2) Calculate particle velocity according to the velocity equation (1)
// 3) Apply the velocity constriction
// 4) Update particle position according to the position equation (2)
// 5) Apply the position constriction
// c) Inherit // Evaluate
// 1) Get the fitness value via evaluation or inheritance.
// End
for( uint i = 0; i < deme->getSize(); i++ ) { // for each particle
IndividualP particle = deme->at(i); //Read "i" particle
// the whole point of this section is to compare fitness and pbest
FloatingPointP flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (particle->getGenotype(3));
double &particlePbestFitness = flp->realValue[0];
double fitness = particle->fitness->getValue();
//There is a problem with the particlePbestFitness initialization in this algorithm. The following lines take care of this.
//TODO: Find a way to do this in the ¿initialize fuction?.
if(state->getGenerationNo()==1){
//std::cout<<"INCIALIZADOOOOOOOOOOOOO!!!!!!!!!!!!!!!!!"<<std::endl;
particlePbestFitness=fitness;
}
else{
//std::cout<<"FITNESS"<<fitness<<std::endl;
flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (particle->getGenotype(0));
std::vector< double > &positions = flp->realValue;
flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (particle->getGenotype(2));
std::vector< double > &pbestx = flp->realValue;
// set particle pbestx-es
if( /*iter == 0 ||*/ fitness < particlePbestFitness ) { // minimize error
particlePbestFitness = fitness; //Update particle personal fitness
// set pbestx-es
for( uint j = 0;j<pbestx.size();j++ ) {
pbestx[j] = positions[j];
}
}
}
// NOTE store best particle index?
//std::cout<<"THE PBEST OF THIS PARTICLE IS!!!!!!!!!!!!:"<<particlePbestFitness<<std::endl;
}
// b)
for( uint i = 0; i < deme->getSize(); i++ ) { // for each particle
IndividualP particle = deme->at(i);
IndividualP bestParticle = selBestOp->select( *deme );
FloatingPointP flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (particle->getGenotype(0));
std::vector< double > &positions = flp->realValue;
flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (particle->getGenotype(1));
std::vector< double > &velocities = flp->realValue;
flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (particle->getGenotype(2));
std::vector< double > &pbestx = flp->realValue;
double R1=rand()/(float)RAND_MAX, R2=rand()/(float)RAND_MAX, vf;
int C1=2, C2=2;
double weight_up;
switch( m_weightType )
{
//time variant weight, linear from weight to 0.4
case TIME_VARIANT:
weight_up = ( m_weight - 0.4 ) * ( m_maxIter - state->getGenerationNo() ) / m_maxIter + 0.4;
break;
// constant inertia weight
case CONSTANT:
default:
weight_up = m_weight;
break;
}
// 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]);
//.........这里部分代码省略.........