00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef MOEOOBJECTIVEVECTORTRAITS_H_
00014 #define MOEOOBJECTIVEVECTORTRAITS_H_
00015
00016 #include <vector>
00017 #include <iostream>
00018 #include <stdexcept>
00019
00023 class moeoObjectiveVectorTraits
00024 {
00025 public:
00026
00032 static void setup(unsigned _nObjectives, std::vector < bool > & _bObjectives)
00033 {
00034
00035 if ( nObj && (nObj != _nObjectives) ) {
00036 std::cout << "WARNING\n";
00037 std::cout << "WARNING : the number of objectives are changing\n";
00038 std::cout << "WARNING : Make sure all existing objects are destroyed\n";
00039 std::cout << "WARNING\n";
00040 }
00041
00042 nObj = _nObjectives;
00043
00044 bObj = _bObjectives;
00045
00046 if (nObj != bObj.size())
00047 throw std::runtime_error("Number of objectives and min/max size don't match in moeoObjectiveVectorTraits::setup");
00048 }
00049
00053 static unsigned nObjectives()
00054 {
00055
00056 if (! nObj)
00057 throw std::runtime_error("Number of objectives not assigned in moeoObjectiveVectorTraits");
00058 return nObj;
00059 }
00060
00065 static bool minimizing(unsigned _i)
00066 {
00067
00068 if (_i >= bObj.size())
00069 throw std::runtime_error("Wrong index in moeoObjectiveVectorTraits");
00070 return bObj[_i];
00071 }
00072
00077 static bool maximizing(unsigned _i) {
00078 return (! minimizing(_i));
00079 }
00080
00084 static double tolerance()
00085 {
00086 return 1e-6;
00087 }
00088
00089
00090 private:
00091
00093 static unsigned nObj;
00095 static std::vector < bool > bObj;
00096
00097 };
00098
00099 #endif
00100
00101
00102
00103
00104 unsigned moeoObjectiveVectorTraits::nObj;
00105 std::vector < bool > moeoObjectiveVectorTraits::bObj;