- Main Page
- Classes
- Files

- File List

# OptFrame/Util/TestSolution.hpp

    00001 #ifndef OPTFRAME_TESTSOLUTION_HPP_
    00002 #define OPTFRAME_TESTSOLUTION_HPP_
    00003
    00004 #include "../Solution.hpp"
    00005
    00006 #include <cstdlib>
    00007 #include <iostream>
    00008
    00009 template<class R>
    00010 class TestSolution : public Solution<R>
    00011 {
    00012 private:
    00013         static const unsigned long long MAX_SOL_IN_MEMORY_ERROR = 1000;
    00014         static unsigned long long MAX_SOL_IN_MEMORY_WARNING;
    00015
    00016         static unsigned long long testsolution_objects;
    00017         static unsigned long long testsolution_objects_nodecrement;
    00018
    00019         unsigned long long testsolution_number;
    00020
    00021 public:
    00022         TestSolution(R& rr):Solution<R>(rr)
    00023         {
    00024                 testsolution_objects++;
    00025                 testsolution_objects_nodecrement++;
    00026                 check();
    00027
    00028                 testsolution_number = testsolution_objects_nodecrement;
    00029         }
    00030
    00031         TestSolution(const TestSolution<R>& s):Solution<R>(s)
    00032         {
    00033                 testsolution_objects++;
    00034                 testsolution_objects_nodecrement++;
    00035                 check();
    00036
    00037                 testsolution_number = testsolution_objects_nodecrement;
    00038         }
    00039
    00040         virtual ~TestSolution() { testsolution_objects--; }
    00041
    00042         void check() // check number of TestSolution objects in memory
    00043         {
    00044                 if(testsolution_objects >= MAX_SOL_IN_MEMORY_WARNING)
    00045                 {
    00046                         cout << "WARNING: " << TestSolution<R>::testsolution_objects << " TestSolution objects in memory!" << endl;
    00047                         TestSolution<R>::MAX_SOL_IN_MEMORY_WARNING++;
    00048                 }
    00049
    00050                 if(testsolution_objects >= MAX_SOL_IN_MEMORY_ERROR)
    00051                 {
    00052                         cout << "ERROR: " << TestSolution<R>::testsolution_objects << " TestSolution objects in memory!" << endl;
    00053                         cout << "MAX_SOL_IN_MEMORY_ERROR = "<< MAX_SOL_IN_MEMORY_ERROR << endl;
    00054                         cout << "aborting...";
    00055                         exit(1);
    00056                 }
    00057         }
    00058
    00059         void print() const
    00060         {
    00061                 cout << "TestSolution #"<<testsolution_number<<" ("<<testsolution_objects<<" in memory now): ";
    00062                 cout << Solution<R>::r << endl;
    00063         }
    00064
    00065         TestSolution<R>& operator= (const TestSolution<R>& s)
    00066         {
    00067                 if(&s == this) // auto ref check
    00068                         return *this;
    00069
    00070                 *this = Solution<R>::operator=(s);
    00071
    00072                 // do not copy the 'testsolution_number'
    00073
    00074                 return *this;
    00075         }
    00076
    00077         Solution<R>& operator=(const Solution<R>& s)
    00078         {
    00079                 return operator=((const TestSolution<R>&)s);
    00080         }
    00081
    00082         Solution<R>& clone() const
    00083         {
    00084                 Solution<R>* s = new TestSolution<R>(*this);
    00085                 return (*s);
    00086         }
    00087 };
    00088
    00089 template<class R>
    00090 unsigned long long TestSolution<R>::MAX_SOL_IN_MEMORY_WARNING = 0.7*MAX_SOL_IN_MEMORY_ERROR;
    00091
    00092 template<class R>
    00093 unsigned long long TestSolution<R>::testsolution_objects = 0;
    00094
    00095 template<class R>
    00096 unsigned long long TestSolution<R>::testsolution_objects_nodecrement = 0;
    00097
    00098 #endif /* OPTFRAME_TESTSOLUTION_HPP_ */

All Classes Functions