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
00039
00040 #include <eo>
00041 #include <es/eoRealInitBounded.h>
00042 #include <es/eoRealOp.h>
00043 #include <moeo>
00044
00045
00046
00047 class ObjectiveVectorTraits : 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 typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector;
00065
00066 class Solution : public moeoRealVector < ObjectiveVector, double, double >
00067 {
00068 public:
00069 Solution() : moeoRealVector < ObjectiveVector, double, double > (1) {}
00070 };
00071
00072 class TestEval : public moeoEvalFunc < Solution >
00073 {
00074 public:
00075 void operator () (Solution & _sol)
00076 {
00077 ObjectiveVector objVec;
00078 objVec[0] = _sol[0];
00079 objVec[1] = _sol[0] * _sol[0];
00080 _sol.objectiveVector(objVec);
00081 }
00082 };
00083
00084
00085
00086 int main()
00087 {
00088 std::cout << "[moeoEasyEA]" << std::endl;
00089
00090 TestEval eval;
00091 eoQuadCloneOp < Solution > xover;
00092 eoUniformMutation < Solution > mutation(0.05);
00093 eoSequentialOp < Solution > op;
00094 op.add(xover, 1.0);
00095 op.add(mutation, 1.0);
00096 eoRealVectorBounds bounds(1, 1.0, 2.0);
00097 eoRealInitBounded < Solution > init(bounds);
00098 eoPop < Solution > pop(20, init);
00099 eoGenContinue < Solution > term(20);
00100 moeoFastNonDominatedSortingFitnessAssignment < Solution > fitnessAssignment;
00101 moeoFrontByFrontCrowdingDiversityAssignment < Solution > diversityAssignment;
00102 moeoFitnessThenDiversityComparator < Solution > comparator;
00103 moeoDetTournamentSelect < Solution > select(comparator, 2);
00104 moeoElitistReplacement < Solution > replace(fitnessAssignment, diversityAssignment, comparator);
00105 eoGeneralBreeder < Solution > breed(select, op);
00106
00107
00108 moeoEasyEA < Solution > algo (term, eval, breed, replace, fitnessAssignment, diversityAssignment);
00109
00110
00111 algo(pop);
00112
00113
00114 std::cout << "Final population" << std::endl;
00115 std::cout << pop << std::endl;
00116
00117 std::cout << "[moeoEasyEA] OK" << std::endl;
00118 return EXIT_SUCCESS;
00119 }
00120
00121