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 #ifdef HAVE_CONFIG_H
00030 #include <config.h>
00031 #endif
00032
00033 #include <iostream>
00034 #include <cmath>
00035
00036
00037 #include <eo>
00038 #include <utils/eoRealVectorBounds.h>
00039
00040
00041 #include <es/eoReal.h>
00042 #include <es/eoRealInitBounded.h>
00043 #include <es/make_genotype_real.h>
00044 #include <eoEvalFunc.h>
00045 #include <es/make_op_real.h>
00046 #include <eoScalarFitnessAssembled.h>
00047 typedef eoReal<eoAssembledMinimizingFitness> Indi;
00048
00049
00050 #include <do/make_pop.h>
00051 #include <do/make_continue.h>
00052 #include <do/make_checkpoint_assembled.h>
00053 #include <do/make_algo_scalar.h>
00054 #include <do/make_run.h>
00055
00056
00057 template <class EOT>
00058 class eoAssembledEvalFunc : public eoEvalFunc<EOT>{
00059 public:
00060
00061 eoAssembledEvalFunc() {
00062
00063
00064 typename EOT::Fitness tmpfit(3, 0.0);
00065 tmpfit.setDescription(0,"Fitness");
00066 tmpfit.setDescription(1,"Some Value");
00067 tmpfit.setDescription(2,"Other Value");
00068
00069 }
00070
00071 void operator()(EOT& _eo){
00072
00073
00074
00075 typename EOT::Fitness tmpfit;
00076
00077
00078 double sum1=0.0, sum2=0.0;
00079 for (unsigned i=0; i < _eo.size(); ++i){
00080 sum1 += _eo[i]*_eo[i];
00081 sum2 += fabs(_eo[i]) + fabs(_eo[i]);
00082 }
00083
00084
00085 tmpfit[1]= sum1;
00086 tmpfit[2]= sum2;
00087
00088
00089 tmpfit = (sum1 + sum2)/_eo.size();
00090
00091
00092 _eo.fitness( tmpfit );
00093
00094 }
00095 };
00096
00097
00098 void make_help(eoParser & _parser);
00099
00100
00101 int main(int argc, char* argv[]){
00102
00103 std::cout << "-----------------------------------" << std::endl;
00104 std::cout << "START t-eoFitnessAssembledEA" << std::endl;
00105
00106 try{
00107
00108
00109 eoParser parser(argc, argv);
00110 eoState state;
00111
00113
00115
00116
00117 eoAssembledEvalFunc<Indi> plainEval;
00118
00119 eoEvalFuncCounter<Indi> eval(plainEval);
00120
00121
00122 eoRealInitBounded<Indi>& init = do_make_genotype(parser, state, Indi() );
00123
00124
00125 eoGenOp<Indi>& op = do_make_op(parser, state, init);
00126
00128
00130
00131
00132
00133 eoPop<Indi>& pop = do_make_pop(parser, state, init);
00134
00135
00136 eoContinue<Indi> & term = do_make_continue(parser, state, eval);
00137
00138 eoCheckPoint<Indi> & checkpoint = do_make_checkpoint_assembled(parser, state, eval, term);
00139
00140 eoAlgo<Indi>& ga = do_make_algo_scalar(parser, state, eval, checkpoint, op);
00141
00142
00143 make_help(parser);
00144
00146
00148
00149
00150 apply<Indi>(eval, pop);
00151
00152 std::cout << "Initial Population\n";
00153 pop.sortedPrintOn(std::cout);
00154 std::cout << std::endl;
00155
00156 do_run(ga, pop);
00157
00158 std::cout << "Final Population\n";
00159 pop.sortedPrintOn(std::cout);
00160 std::cout << std::endl;
00161
00162 }
00163 catch(std::exception& e)
00164 {
00165 std::cout << e.what() << std::endl;
00166 return 1;
00167 }
00168
00169 std::cout << "-----------------------------------" << std::endl;
00170 std::cout << "END t-eoFitnessAssembledEA" << std::endl;
00171
00172 return 0;
00173
00174 }