- Main Page
- Classes
- Files

- Search for |

# moeoObjectiveVectorTraits.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // moeoObjectiveVectorTraits.h
    00005 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
    00006 /*
    00007     This library...
    00008
    00009     Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
    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         // in case the number of objectives was already set to a different value
    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         // number of objectives
    00042         nObj = _nObjectives;
    00043         // min/max vector
    00044         bObj = _bObjectives;
    00045         // in case the number of objectives and the min/max vector size don't match
    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         // in case the number of objectives would not be assigned yet
    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         // in case there would be a wrong index
    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 /*MOEOOBJECTIVEVECTORTRAITS_H_*/
    00100
    00101
    00102 // The static variables of the moeoObjectiveVectorTraits class need to be allocated
    00103 // (maybe it would have been better to put this on a moeoObjectiveVectorTraits.cpp file)
    00104 unsigned moeoObjectiveVectorTraits::nObj;
    00105 std::vector < bool > moeoObjectiveVectorTraits::bObj;