00001 00020 #include "problem.h" 00021 #include <cassert> 00022 #include "running.h" 00023 00024 using namespace realea; 00025 00026 Problem::Problem(void) : m_checkOptime(NULL), m_domain(NULL) { 00027 } 00028 00029 bool Problem::isBetter(tFitness value1, tFitness value2) { 00030 return m_checkOptime->isBetter(value1, value2); 00031 } 00032 00033 bool Problem::minimize(void) { 00034 if (m_domain == NULL) { 00035 throw new ConfigException("domain"); 00036 } 00037 00038 return m_checkOptime->minimize(); 00039 } 00040 00041 bool Problem::maximize(void) { 00042 return !minimize(); 00043 } 00044 00045 void Problem::setMaximize(void) { 00046 m_checkOptime->setMaximize(); 00047 } 00048 00049 void Problem::setMinimize(void) { 00050 m_checkOptime->setMinimize(); 00051 } 00052 00053 00054 void Problem::setDimension(unsigned int dim) { 00055 m_domain = new DomainReal(dim); 00056 } 00057 00058 void Problem::setDomainValues(unsigned int gen, tGen min, tGen max, bool check) { 00059 if (m_domain == NULL) { 00060 throw new ConfigException("domain"); 00061 } 00062 00063 m_domain->setValues(gen, min, max, check); 00064 } 00065 00066 00067 Problem::~Problem(void) { 00068 if (m_checkOptime) { 00069 delete m_checkOptime; 00070 } 00071 00072 if (m_domain) { 00073 delete m_domain; 00074 } 00075 00076 } 00077 00078 void Problem::setOptimize(tFitness optime, double threshold) { 00079 m_checkOptime = new OptimeCriterion(optime,threshold); 00080 } 00081 00082 DomainRealPtr Problem::getDomain(void) { 00083 if (m_domain == NULL) { 00084 throw new ConfigException("domain"); 00085 } 00086 return m_domain; 00087 } 00088 00089 void Problem::setThreshold(double dif) { 00090 if (m_checkOptime == NULL) { 00091 throw new ConfigException("optime"); 00092 } 00093 00094 m_checkOptime->setThreshold(dif); 00095 } 00096 00097 tFitness Problem::getOptime(void) { 00098 if (m_checkOptime == NULL) { 00099 throw new ConfigException("optime"); 00100 } 00101 return m_checkOptime->getOptime(); 00102 } 00103 00104 void Problem::setEval(tEval eval) { 00105 m_eval = eval; 00106 } 00107 00108 void Problem::setMaxEval(unsigned eval) { 00109 m_maxeval = eval; 00110 } 00111 00112 unsigned Problem::getMaxEval(void) { 00113 return m_maxeval; 00114 } 00115 00116 00117 00118 00119 tFitness Problem::eval(const tChromosomeReal &sol) { 00120 tFitness fit = (*m_eval)(&sol[0], sol.size()); 00121 return fit; 00122 } 00123 00124 unsigned Problem::getDimension(void) { 00125 return m_domain->getDimension(); 00126 } 00127 00128 void Problem::copy(Problem *problem) { 00129 assert(problem->m_checkOptime == NULL && 00130 problem->m_domain == NULL); 00131 00132 problem->m_checkOptime = this->m_checkOptime; 00133 problem->m_domain = this->m_domain; 00134 problem->m_eval = this->m_eval; 00135 problem->m_maxeval = this->m_maxeval; 00136 }