Sch1.cpp

00001 /*
00002 * <Sch1.cpp>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
00005 *
00006 * Abdelhakim Deneche, Arnaud Liefooghe
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * data to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
00034 *
00035 */
00036 //-----------------------------------------------------------------------------
00037 
00038 #include <stdio.h>
00039 #include <moeo>
00040 #include <es/eoRealInitBounded.h>
00041 #include <es/eoRealOp.h>
00042 
00043 using namespace std;
00044 
00045 
00046 // the moeoObjectiveVectorTraits : minimizing 2 objectives
00047 class Sch1ObjectiveVectorTraits : public moeoObjectiveVectorTraits
00048 {
00049 public:
00050     static bool minimizing (int i)
00051     {
00052         return true;
00053     }
00054     static bool maximizing (int i)
00055     {
00056         return false;
00057     }
00058     static unsigned int nObjectives ()
00059     {
00060         return 2;
00061     }
00062 };
00063 
00064 
00065 // objective vector of real values
00066 typedef moeoRealObjectiveVector < Sch1ObjectiveVectorTraits > Sch1ObjectiveVector;
00067 
00068 
00069 // multi-objective evolving object for the Sch1 problem
00070 class Sch1 : public moeoRealVector < Sch1ObjectiveVector, double, double >
00071 {
00072 public:
00073     Sch1() : moeoRealVector < Sch1ObjectiveVector, double, double > (1)
00074     {}
00075 };
00076 
00077 
00078 // evaluation of objective functions
00079 class Sch1Eval : public moeoEvalFunc < Sch1 >
00080 {
00081 public:
00082     void operator () (Sch1 & _sch1)
00083     {
00084         if (_sch1.invalidObjectiveVector())
00085         {
00086             Sch1ObjectiveVector objVec;
00087             double x = _sch1[0];
00088             objVec[0] = x * x;
00089             objVec[1] = (x - 2.0) * (x - 2.0);
00090             _sch1.objectiveVector(objVec);
00091         }
00092     }
00093 };
00094 
00095 
00096 // main
00097 int main (int argc, char *argv[])
00098 {
00099     eoParser parser(argc, argv);  // for user-parameter reading
00100     eoState state;                // to keep all things allocated
00101 
00102     // parameters
00103     unsigned int POP_SIZE = parser.createParam((unsigned int)(100), "popSize", "Population size",'P',"Param").value();
00104     unsigned int MAX_GEN = parser.createParam((unsigned int)(100), "maxGen", "Maximum number of generations",'G',"Param").value();
00105     double M_EPSILON = parser.createParam(0.01, "mutEpsilon", "epsilon for mutation",'e',"Param").value();
00106     double P_CROSS = parser.createParam(0.25, "pCross", "Crossover probability",'C',"Param").value();
00107     double P_MUT = parser.createParam(0.35, "pMut", "Mutation probability",'M',"Param").value();
00108 
00109     // objective functions evaluation
00110     Sch1Eval eval;
00111 
00112     // crossover and mutation
00113     eoQuadCloneOp < Sch1 > xover;
00114     eoUniformMutation < Sch1 > mutation (M_EPSILON);
00115 
00116     // generate initial population
00117     eoRealVectorBounds bounds (1, 0.0, 2.0);    // [0, 2]
00118     eoRealInitBounded < Sch1 > init (bounds);
00119     eoPop < Sch1 > pop (POP_SIZE, init);
00120 
00121     // build NSGA-II
00122     moeoNSGAII < Sch1 > nsgaII (MAX_GEN, eval, xover, P_CROSS, mutation, P_MUT);
00123 
00124     // help ?
00125     make_help(parser);
00126 
00127     // run the algo
00128     nsgaII (pop);
00129 
00130     // extract first front of the final population using an moeoArchive (this is the output of nsgaII)
00131     moeoArchive < Sch1 > arch;
00132     arch.update (pop);
00133 
00134     // printing of the final archive
00135     cout << "Final Archive" << endl;
00136     arch.sortedPrintOn (cout);
00137     cout << endl;
00138 
00139     return EXIT_SUCCESS;
00140 }

Generated on Thu Mar 13 15:54:08 2008 for ParadisEO-MOEO-MultiObjectiveEvolvingObjects by  doxygen 1.4.7