예제 #1
0
파일: GABaseGA.C 프로젝트: dbremner/galib
// 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;
}
예제 #2
0
파일: GABaseGA.C 프로젝트: dbremner/galib
// If we are maximizing, then terminate when the convergence has exceeded the
// specified convergence.  If we are minimizing, then terminate when the 
// convergence has dropped below the specified convergence.
GABoolean 
GAGeneticAlgorithm::TerminateUponConvergence(GAGeneticAlgorithm & ga){
  GABoolean val = gaFalse;
  if(ga.minimaxi() == GAGeneticAlgorithm::MINIMIZE) {
    if(ga.convergence() == 0 || ga.convergence() > ga.pConvergence())
      val = gaFalse;
    else 
      val = gaTrue;
  }
  else {
    if(ga.convergence() < ga.pConvergence())
      val = gaFalse;
    else 
      val = gaTrue;
  }
  return val;
}