00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
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
00066 typedef moeoRealObjectiveVector < Sch1ObjectiveVectorTraits > Sch1ObjectiveVector;
00067
00068
00069
00070 class Sch1 : public moeoRealVector < Sch1ObjectiveVector, double, double >
00071 {
00072 public:
00073 Sch1() : moeoRealVector < Sch1ObjectiveVector, double, double > (1)
00074 {}
00075 };
00076
00077
00078
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
00097 int main (int argc, char *argv[])
00098 {
00099 eoParser parser(argc, argv);
00100 eoState state;
00101
00102
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
00110 Sch1Eval eval;
00111
00112
00113 eoQuadCloneOp < Sch1 > xover;
00114 eoUniformMutation < Sch1 > mutation (M_EPSILON);
00115
00116
00117 eoRealVectorBounds bounds (1, 0.0, 2.0);
00118 eoRealInitBounded < Sch1 > init (bounds);
00119 eoPop < Sch1 > pop (POP_SIZE, init);
00120
00121
00122 moeoNSGAII < Sch1 > nsgaII (MAX_GEN, eval, xover, P_CROSS, mutation, P_MUT);
00123
00124
00125 make_help(parser);
00126
00127
00128 nsgaII (pop);
00129
00130
00131 moeoArchive < Sch1 > arch;
00132 arch.update (pop);
00133
00134
00135 cout << "Final Archive" << endl;
00136 arch.sortedPrintOn (cout);
00137 cout << endl;
00138
00139 return EXIT_SUCCESS;
00140 }