- 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 <iostream>
    00017 #include <stdexcept>
    00018 #include <vector>
    00019
    00023 class moeoObjectiveVectorTraits
    00024 {
    00025 public:
    00026
    00032     static void setup(unsigned int _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
    00050
    00054     static unsigned int nObjectives()
    00055     {
    00056         // in case the number of objectives would not be assigned yet
    00057         if (! nObj)
    00058             throw std::runtime_error("Number of objectives not assigned in moeoObjectiveVectorTraits");
    00059         return nObj;
    00060     }
    00061
    00062
    00067     static bool minimizing(unsigned int _i)
    00068     {
    00069         // in case there would be a wrong index
    00070         if (_i >= bObj.size())
    00071             throw std::runtime_error("Wrong index in moeoObjectiveVectorTraits");
    00072         return bObj[_i];
    00073     }
    00074
    00075
    00080     static bool maximizing(unsigned int _i) {
    00081         return (! minimizing(_i));
    00082     }
    00083
    00084
    00088     static double tolerance()
    00089     {
    00090         return 1e-6;
    00091     }
    00092
    00093
    00094 private:
    00095
    00097     static unsigned int nObj;
    00099     static std::vector < bool > bObj;
    00100
    00101 };
    00102
    00103 #endif /*MOEOOBJECTIVEVECTORTRAITS_H_*/