本文整理汇总了C++中GAPopulation::max方法的典型用法代码示例。如果您正苦于以下问题:C++ GAPopulation::max方法的具体用法?C++ GAPopulation::max怎么用?C++ GAPopulation::max使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GAPopulation
的用法示例。
在下文中一共展示了GAPopulation::max方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setConvergence
// Use this method to update the statistics to account for the current
// population. This routine increments the generation counter and assumes that
// the population that gets passed is the current population.
// If we are supposed to flush the scores, then we dump them to the specified
// file. If no flushing frequency has been specified then we don't record.
void
GAStatistics::update(const GAPopulation & pop){
++curgen; // must do this first so no divide-by-zero
if(scoreFreq > 0 && (curgen % scoreFreq == 0)) setScore(pop);
if(Nscrs > 0 && nscrs >= Nscrs) flushScores();
maxever = (pop.max() > maxever) ? pop.max() : maxever;
minever = (pop.min() < minever) ? pop.min() : minever;
float tmpval;
tmpval = (on*(curgen-1) + pop.ave()) / curgen;
on = tmpval;
tmpval = (offmax*(curgen-1) + pop.max()) / curgen;
offmax = tmpval;
tmpval = (offmin*(curgen-1) + pop.min()) / curgen;
offmin = tmpval;
setConvergence((pop.order() == GAPopulation::HIGH_IS_BEST) ?
pop.max() : pop.min());
updateBestIndividual(pop);
numpeval = pop.nevals();
}
示例2: memset
// Reset the GA's statistics based on the population. To do this right you
// should initialize the population before you pass it to this routine. If you
// don't, the stats will be based on a non-initialized population.
void
GAStatistics::reset(const GAPopulation & pop){
curgen = 0;
numsel = numcro = nummut = numrep = numeval = numpeval = 0;
memset(gen, 0, Nscrs*sizeof(int));
memset(aveScore, 0, Nscrs*sizeof(float));
memset(maxScore, 0, Nscrs*sizeof(float));
memset(minScore, 0, Nscrs*sizeof(float));
memset(devScore, 0, Nscrs*sizeof(float));
memset(divScore, 0, Nscrs*sizeof(float));
nscrs = 0;
setScore(pop);
if(Nscrs > 0) flushScores();
memset(cscore, 0, Nconv*sizeof(float));
nconv = 0; // should set to -1 then call setConv
cscore[0] =
((pop.order() == GAPopulation::HIGH_IS_BEST) ? pop.max() : pop.min());
// cscore[0] = pop.max();
// setConvergence(maxScore[0]);
updateBestIndividual(pop, gaTrue);
aveCur = aveInit = pop.ave();
maxCur = maxInit = maxever = pop.max();
minCur = minInit = minever = pop.min();
devCur = devInit = pop.dev();
divCur = divInit = ((dodiv == gaTrue) ? pop.div() : (float)-1.0);
on = pop.ave();
offmax = pop.max();
offmin = pop.min();
numpeval = pop.nevals();
for(int i=0; i<pop.size(); i++)
numeval += pop.individual(i).nevals();
}
示例3:
// Set the score info to the appropriate values. Update the score count.
void
GAStatistics::setScore(const GAPopulation& pop){
aveCur = pop.ave();
maxCur = pop.max();
minCur = pop.min();
devCur = pop.dev();
divCur = ((dodiv == gaTrue) ? pop.div() : (float)-1.0);
if(Nscrs == 0) return;
gen[nscrs] = curgen;
aveScore[nscrs] = aveCur;
maxScore[nscrs] = maxCur;
minScore[nscrs] = minCur;
devScore[nscrs] = devCur;
divScore[nscrs] = divCur;
nscrs++;
}
示例4: if
void
GALinearScaling::evaluate(const GAPopulation & p) {
// Here we calculate the slope and intercept using the multiplier and objective
// score ranges...
double pmin = p.min();
double pmax = p.max();
double pave = p.ave();
double delta, a, b;
if(pave == pmax){ // no scaling - population is all the same
a = 1.0;
b = 0.0;
}
else if(pmin > ((double)c * pave - pmax)/((double)c - 1.0)){
delta = pmax - pave;
a = ((double)c - 1.0) * pave / delta;
b = pave * (pmax - (double)c * pave) / delta;
}
else{ // stretch to make min be 0
delta = pave - pmin;
a = pave / delta;
b = -pmin * pave / delta;
}
// and now we calculate the scaled scaled values. Negative scores are not
// allowed with this kind of scaling, so check for negative values. If we get
// a negative value, dump an error message then set all of the scores to 0.
for(int i=0; i<p.size(); i++){
double f = p.individual(i).score();
if(f < 0.0){
GAErr(GA_LOC, className(), "evaluate", gaErrNegFitness);
for(int ii=0; ii<p.size(); ii++)
p.individual(ii).fitness(0.0);
return;
}
f = f * a + b;
if(f < 0) f = 0.0; // truncate if necessary (only due to roundoff error)
p.individual(i).fitness((float)f); // might lose information here!
}
}