- Main Page
- Classes
- Files

- File List

# OptFrame/Util/TestEvaluation.hpp

    00001 #ifndef OPTFRAME_TESTEVALUATION_HPP_
    00002 #define OPTFRAME_TESTEVALUATION_HPP_
    00003
    00004 #include "../Evaluation.hpp"
    00005
    00006 #include <cstdlib>
    00007 #include <iostream>
    00008
    00009 using namespace std;
    00010
    00011 template<class M = OPTFRAME_DEFAULT_MEMORY>
    00012 class TestEvaluation: public Evaluation<M>
    00013 {
    00014 private:
    00015         static const unsigned long long MAX_EV_IN_MEMORY_ERROR = 1000;
    00016         static unsigned long long MAX_EV_IN_MEMORY_WARNING;
    00017
    00018         static unsigned long long ev_objects;
    00019         static unsigned long long ev_objects_nodecrement;
    00020
    00021         unsigned long long ev_number;
    00022
    00023 public:
    00024
    00025         TestEvaluation(double obj, double inf, M& mm) :
    00026                 Evaluation<M> (obj, inf, mm)
    00027         {
    00028                 ev_objects++;
    00029                 ev_objects_nodecrement++;
    00030                 check();
    00031
    00032                 ev_number = ev_objects_nodecrement;
    00033         }
    00034
    00035         TestEvaluation(double obj, M& mm) :
    00036                 Evaluation<M> (obj, mm)
    00037         {
    00038                 ev_objects++;
    00039                 ev_objects_nodecrement++;
    00040                 check();
    00041
    00042                 ev_number = ev_objects_nodecrement;
    00043         }
    00044
    00045         TestEvaluation(const TestEvaluation<M>& e) :
    00046                 Evaluation<M> (e)
    00047         {
    00048                 ev_objects++;
    00049                 ev_objects_nodecrement++;
    00050                 check();
    00051
    00052                 ev_number = ev_objects_nodecrement;
    00053         }
    00054
    00055         virtual ~TestEvaluation()
    00056         {
    00057                 ev_objects--;
    00058         }
    00059
    00060         void check() // check number of TestSolution objects in memory
    00061         {
    00062
    00063                 if (ev_objects >= MAX_EV_IN_MEMORY_WARNING)
    00064                 {
    00065                         cout << "WARNING: " << TestEvaluation<M>::ev_objects
    00066                                         << " Evaluation objects in memory!" << endl;
    00067                         TestEvaluation<M>::MAX_EV_IN_MEMORY_WARNING++;
    00068                 }
    00069
    00070                 if (ev_objects >= MAX_EV_IN_MEMORY_ERROR)
    00071                 {
    00072                         cout << "ERROR: " << TestEvaluation<M>::ev_objects
    00073                                         << " Evaluation objects in memory!" << endl;
    00074                         cout << "MAX_EV_IN_MEMORY_ERROR = " << MAX_EV_IN_MEMORY_ERROR
    00075                                         << endl;
    00076                         cout << "aborting...";
    00077                         exit(1);
    00078                 }
    00079         }
    00080
    00081         void print() const
    00082         {
    00083                 cout << "TestEvaluation #" << ev_number << " (" << ev_objects
    00084                                 << " in memory now) - ";
    00085
    00086                 cout << "Evaluation function value = " << Evaluation<M>::evaluation();
    00087                 cout << (Evaluation<M>::isFeasible() ? " " : " (not feasible) ")
    00088                                 << endl;
    00089
    00090                 // default - not printing memory
    00091                 //cout << Evaluation<M>::m << endl;
    00092         }
    00093
    00094         TestEvaluation<M>& operator=(const TestEvaluation<M>& e)
    00095         {
    00096                 if (&e == this) // auto ref check
    00097                         return *this;
    00098
    00099                 *this = Evaluation<M>::operator=(e);
    00100
    00101                 // do not copy the 'ev_number'
    00102
    00103                 return *this;
    00104         }
    00105
    00106         Evaluation<M>& operator=(const Evaluation<M>& e)
    00107         {
    00108                 return operator=((const TestEvaluation<M>&) e);
    00109         }
    00110
    00111         Evaluation<M>& clone() const
    00112         {
    00113                 Evaluation<M>* e = new TestEvaluation<M> (*this);
    00114                 return (*e);
    00115         }
    00116 };
    00117
    00118 template<class M>
    00119 unsigned long long TestEvaluation<M>::MAX_EV_IN_MEMORY_WARNING = 0.7
    00120                 * MAX_EV_IN_MEMORY_ERROR;
    00121
    00122 template<class M>
    00123 unsigned long long TestEvaluation<M>::ev_objects = 0;
    00124
    00125 template<class M>
    00126 unsigned long long TestEvaluation<M>::ev_objects_nodecrement = 0;
    00127
    00128 #endif /*OPTFRAME_TESTEVALUATION_HPP_*/

All Classes Functions