00001
00002
00003
00004
00005
00006
00007
00008
00009
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
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
00040 typedef moeoRealObjectiveVector < Sch1ObjectiveVectorTraits > Sch1ObjectiveVector;
00041
00042
00043
00044 class Sch1 : public moeoRealVector < Sch1ObjectiveVector, double, double >
00045 {
00046 public:
00047 Sch1() : moeoRealVector < Sch1ObjectiveVector, double, double > (1) {}
00048 };
00049
00050
00051
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
00070 int main (int argc, char *argv[])
00071 {
00072
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
00080 Sch1Eval eval;
00081
00082
00083 eoQuadCloneOp < Sch1 > xover;
00084 eoUniformMutation < Sch1 > mutation (M_EPSILON);
00085
00086
00087 eoRealVectorBounds bounds (1, 0.0, 2.0);
00088 eoRealInitBounded < Sch1 > init (bounds);
00089 eoPop < Sch1 > pop (POP_SIZE, init);
00090
00091
00092 moeoNSGAII < Sch1 > nsgaII (MAX_GEN, eval, xover, P_CROSS, mutation, P_MUT);
00093
00094
00095 nsgaII (pop);
00096
00097
00098 moeoArchive < Sch1 > arch;
00099 arch.update (pop);
00100
00101
00102 cout << "Final Archive" << endl;
00103 arch.sortedPrintOn (cout);
00104 cout << endl;
00105
00106 return EXIT_SUCCESS;
00107 }