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 #ifndef _EOCMABREED_H
00026 #define _EOCMABREED_H
00027
00028 #include <eoBreed.h>
00029 #include <eoVector.h>
00030 #include <es/CMAState.h>
00031
00032 #include <algorithm>
00033
00035 template <class FitT>
00036 class eoCMABreed : public eoBreed< eoVector<FitT, double> > {
00037
00038 eo::CMAState& state;
00039 unsigned lambda;
00040
00041 typedef eoVector<FitT, double> EOT;
00042
00043 public:
00044 eoCMABreed(eo::CMAState& state_, unsigned lambda_) : state(state_), lambda(lambda_) {}
00045
00046 void operator()(const eoPop<EOT>& parents, eoPop<EOT>& offspring) {
00047
00048
00049 std::vector<const EOT*> sorted(parents.size());
00050 std::vector<const std::vector<double>* > mu(parents.size());
00051
00052 parents.sort(sorted);
00053 for (unsigned i = 0; i < sorted.size(); ++i) {
00054 mu[i] = static_cast< const std::vector<double>* >( sorted[i] );
00055 }
00056
00057
00058
00059 state.reestimate(mu, sorted[0]->fitness(), sorted.back()->fitness());
00060
00061 if (!state.updateEigenSystem(10)) {
00062 std::cerr << "No good eigensystem found" << std::endl;
00063 }
00064
00065
00066 offspring.resize(lambda);
00067
00068 for (unsigned i = 0; i < lambda; ++i) {
00069 state.sample( static_cast< std::vector<double>& >( offspring[i] ));
00070 offspring[i].invalidate();
00071 }
00072
00073 }
00074 };
00075
00076
00077 #endif