- Main Page
- Classes
- Files

- Search for |

# Sch1.cpp

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // Sch1.cpp
    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 #include <stdio.h>
    00014 #include <moeo>
    00015 #include <es/eoRealInitBounded.h>
    00016 #include <es/eoRealOp.h>
    00017
    00018 using namespace std;
    00019
    00020 // the moeoObjectiveVectorTraits : minimizing 2 objectives
    00021 class Sch1ObjectiveVectorTraits : public moeoObjectiveVectorTraits
    00022 {
    00023 public:
    00024     static bool minimizing (int i)
    00025     {
    00026         return true;
    00027     }
    00028     static bool maximizing (int i)
    00029     {
    00030         return false;
    00031     }
    00032     static unsigned int nObjectives ()
    00033     {
    00034         return 2;
    00035     }
    00036 };
    00037
    00038
    00039 // objective vector of real values
    00040 typedef moeoRealObjectiveVector < Sch1ObjectiveVectorTraits > Sch1ObjectiveVector;
    00041
    00042
    00043 // multi-objective evolving object for the Sch1 problem
    00044 class Sch1 : public moeoRealVector < Sch1ObjectiveVector, double, double >
    00045 {
    00046 public:
    00047     Sch1() : moeoRealVector < Sch1ObjectiveVector, double, double > (1) {}
    00048 };
    00049
    00050
    00051 // evaluation of objective functions
    00052 class Sch1Eval : public moeoEvalFunc < Sch1 >
    00053 {
    00054 public:
    00055     void operator () (Sch1 & _sch1)
    00056     {
    00057         if (_sch1.invalidObjectiveVector())
    00058         {
    00059             Sch1ObjectiveVector objVec;
    00060             double x = _sch1[0];
    00061             objVec[0] = x * x;
    00062             objVec[1] = (x - 2.0) * (x - 2.0);
    00063             _sch1.objectiveVector(objVec);
    00064         }
    00065     }
    00066 };
    00067
    00068
    00069 // main
    00070 int main (int argc, char *argv[])
    00071 {
    00072     // parameters
    00073     unsigned int POP_SIZE = 20;
    00074     unsigned int MAX_GEN = 100;
    00075     double M_EPSILON = 0.01;
    00076     double P_CROSS = 0.25;
    00077     double P_MUT = 0.35;
    00078
    00079     // objective functions evaluation
    00080     Sch1Eval eval;
    00081
    00082     // crossover and mutation
    00083     eoQuadCloneOp < Sch1 > xover;
    00084     eoUniformMutation < Sch1 > mutation (M_EPSILON);
    00085
    00086     // generate initial population
    00087     eoRealVectorBounds bounds (1, 0.0, 2.0);    // [0, 2]
    00088     eoRealInitBounded < Sch1 > init (bounds);
    00089     eoPop < Sch1 > pop (POP_SIZE, init);
    00090
    00091     // build NSGA-II
    00092     moeoNSGAII < Sch1 > nsgaII (MAX_GEN, eval, xover, P_CROSS, mutation, P_MUT);
    00093
    00094     // run the algo
    00095     nsgaII (pop);
    00096
    00097     // extract first front of the final population using an moeoArchive (this is the output of nsgaII)
    00098     moeoArchive < Sch1 > arch;
    00099     arch.update (pop);
    00100
    00101     // printing of the final archive
    00102     cout << "Final Archive" << endl;
    00103     arch.sortedPrintOn (cout);
    00104     cout << endl;
    00105
    00106     return EXIT_SUCCESS;
    00107 }