// Use the ratio between the minimum and maximum to determine whether the // population has converged. This method will not work if the values cross // zero! // Note that this is significantly different than the definition (and the // bug-laden implementation) that was in version of GAlib prior to 2.4.5. // // For historical purposes, here is the old definition of this method: // // Use the ratio of the population mean divided by the population maximum to // determine whether the population has converged. If we are maximizing, then // check to see if the ratio exceeds the convergence. If we are minimizing, // then check to see if the ratio has dropped below the convergence. GABoolean GAGeneticAlgorithm::TerminateUponPopConvergence(GAGeneticAlgorithm & ga){ GABoolean val = gaFalse; if(ga.statistics().current(GAStatistics::Maximum) == 0) { return val; } float ratio = ga.statistics().current(GAStatistics::Minimum) / ga.statistics().current(GAStatistics::Maximum); if(ga.minimaxi() == GAGeneticAlgorithm::MINIMIZE) { if(ratio <= ga.pConvergence()) val = gaTrue; else val = gaFalse; } else { if(ratio >= ga.pConvergence()) val = gaTrue; else val = gaFalse; } return val; }
GABoolean GAGeneticAlgorithm::TerminateUponPopConvergence(GAGeneticAlgorithm & ga){ if(ga.statistics().current(GAStatistics::Mean) / ga.statistics().current(GAStatistics::Maximum) < ga.pConvergence()) return gaTrue; else return gaFalse; }