00001 00021 #include <realea/common/distance.h> 00022 #include "replace.h" 00023 #include <cassert> 00024 #include <cstdio> 00025 00026 using namespace realea; 00027 00028 IReplace::IReplace(void) : m_total(0), m_success(0) { 00029 00030 } 00031 00032 void IReplace::reset(void) { 00033 double ratio; 00034 00035 if (m_total != 0) { 00036 ratio = ((double)m_success)/m_total; 00037 printf("Replacement Ratio: %.0lf%%\n", 100*ratio); 00038 } 00039 00040 m_total = m_success = 0; 00041 printf("IReplace: Se reinicia\n"); 00042 } 00043 00044 bool IReplace::mustBeReplace(tIndividualRealPtr old, tIndividualRealPtr newind) { 00045 bool changed = newind->isBetter(old); 00046 00047 if (changed) { 00048 m_success += 1; 00049 } 00050 00051 m_total += 1; 00052 return changed; 00053 } 00054 00055 unsigned ReplaceWorst::getCandidate(PopulationRealPtr pop, tIndividualRealPtr newind) { 00056 return pop->getWorst(); 00057 } 00058 00059 unsigned ReplaceDC::getCandidate(PopulationRealPtr pop, tIndividualRealPtr newind) { 00060 unsigned posind; 00061 distanceMin(newind->sol(), pop, &posind); 00062 assert(posind < pop->size()); 00063 return posind; 00064 }