ReturnFlag CPSORSwarm::run_(){ #ifdef OFEC_CONSOLE if(Global::msp_global->m_runId==0){ mSingleObj::getSingleObj()->setProgrOutputFlag(true); if(mMultiModal::getPopInfor()) mMultiModal::getPopInfor()->setOutProgFlag(true); } #endif // OFEC_CONSOLE createSubswarms(); ReturnFlag r_flag=Return_Normal; while(!ifTerminating()){ for(auto &swarm:m_subPop){ if(swarm->m_popsize==0) continue; r_flag=swarm->evolve(); if(r_flag==Return_Terminate) break; handleReturnFlagAll(r_flag); HANDLE_RETURN_FLAG(r_flag) #ifdef OFEC_DEMON vector<Algorithm*> vp; for(auto &it:m_subPop){ vp.push_back(it.get()); } msp_buffer->updateBuffer_(&vp); #endif } if(r_flag==Return_Terminate) break; //cout<<Global::msp_global->mp_problem->getEvaluations()<<" "<<getNumPops()<<" "<<m_subPop[findBestPop(1)]->m_best[0]->obj(0)<<endl; measureMultiPop(); if(m_subPop.size()>1){ while(removeOverlapping()!=-1); for(auto it=m_subPop.begin();it!=m_subPop.end();++it) (*it)->checkOverCrowd(m_subSize); for(decltype(m_subPop.size()) i=0;i<m_subPop.size();i++){ if(m_subPop[i]->isConverged(0.0001)){ deletePopulation(i); i--; } } } if(Global::msp_global->m_totalNumIndis<m_initialSize*m_diversityDegree){ initialize(); if(ifTerminating()) break; createSubswarms(); } } return Return_Terminate; }
bool MuSlashRhoLambdaES::startEvolutionRun( int mu, int rho, int lambda, ESInitialize *init) { deletePopulation(); // set information struct to values mInformation.currentGeneration = 0; mInformation.mu = mu; mInformation.rho = rho; mInformation.lambda = lambda; mInformation.numberOfLastSuccessfulIndividuals = 0; if(mInformation.mu <= 0 || mInformation.rho <= 0 || mInformation.lambda <= 0){ return false; } mPopulation = init->createPopulation(mInformation.mu); if(mPopulation.size() <= 0){ return false; } mInformation.numberOfStrategyParameters = mPopulation.first()->getStrategyParameters().size(); mInformation.numberOfObjectParameters = mPopulation.first()->getObjectParameters().size(); //calculate fitness values of population bool ok = mFitnessEvaluation->doEvaluation(mPopulation, mInformation); if(ok == false){ return false; } qSort(mPopulation.begin(), mPopulation.end(), MuSlashRhoLambdaES::descendingOrder); calculateStatistics(); return true; }
MuSlashRhoLambdaES::~MuSlashRhoLambdaES() { deletePopulation(); }
bool MuSlashRhoLambdaES::doNextGeneration() { /* QFile file ("evolution.log"); file.open(QIODevice::WriteOnly | QIODevice::Append); QTextStream out(&file); out << "\n\n--------------------------\nNew generation:\n"; */ bool ok = true; QList<ESIndividual*> offsprings; QList<double> bestParentsFitness; // generate offsprings for(int i = 0; i < mInformation.lambda; i++) { // select parents which should be used to generate current offspring QList<ESIndividual*> curParents = mMarriage->doMarriage(getPopulation(), mInformation.rho, mInformation); // check if an error occured if(curParents.size() <= 0){ return false; } // get fitness of the best parent qSort(curParents.begin(), curParents.end(), MuSlashRhoLambdaES::descendingOrder); bestParentsFitness.append(curParents.first()->getFitness()); /* out << "\tParents:\n"; for(int parentIndex = 0; parentIndex < curParents.size(); parentIndex++) { out << "\t\t" << curParents.at(parentIndex)->toString() << "\n"; } */ // recombine offspring strategy parameters from parents QList<OptimizationDouble> recombinedStratParas = mStrategyParametersRecombination->doRecombination( curParents, ESRecombination::STRATEGY, mInformation); // check if an error occured if(recombinedStratParas.size() <= 0){ return false; } // recombine offspring object parameters from parents QList<OptimizationDouble> recombinedObjParas = mObjectParametersRecombination->doRecombination( curParents, ESRecombination::OBJECT, mInformation); // check if an error occured if(recombinedObjParas.size() <= 0){ return false; } // mutate the offspring strategy parameters QList<OptimizationDouble> mutatedStratParas = mStrategyParametersMutation->doMutation( recombinedStratParas, mInformation); // check if an error occured if(mutatedStratParas.size() <= 0){ return false; } // mutate the offspring object parameters with help of is mutated strategy parameters QList<OptimizationDouble> mutatedObjParas = mObjectParametersMutation->doMutation( recombinedObjParas, mutatedStratParas, mInformation); // check if an error occured if(mutatedObjParas.size() <= 0){ return false; } // create new Individual and add it to offspring list offsprings.append( new ESIndividual(mutatedObjParas, mutatedStratParas, 0.0) ); /* out << "\t--> Offspring:\n"; out << "\t\t" << offsprings.last()->toString(); out << "\n\n"; */ } //calculate fitness values of offsprings ok &= mFitnessEvaluation->doEvaluation(offsprings, mInformation); if(ok == false){ return false; } // calculate sum of offsprings which have a better fitness then their best parent mInformation.numberOfLastSuccessfulIndividuals = 0; for(int i = 0; i < offsprings.size(); i++) { if(offsprings.at(i)->getFitness() > bestParentsFitness.at(i)){ mInformation.numberOfLastSuccessfulIndividuals++; } } bestParentsFitness.clear(); // sort offspring accordingly their fitness qSort(offsprings.begin(), offsprings.end(), MuSlashRhoLambdaES::descendingOrder); // get list with new population QList<ESIndividual*> selectionList = mSelection->doSelection(mPopulation, offsprings, mInformation.mu, mInformation); // check if an error occured if(selectionList.size() <= 0){ return false; } // delete old parents which are not in the selection deletePopulation(selectionList); // use selection as new population mPopulation = selectionList; // update statisticvalues in mInformation calculateStatistics(); mInformation.currentGeneration++; /* file.flush(); file.close(); */ return ok; }