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
00051
00052 std::vector<const std::vector<double>* > mu(parents.size());
00053
00054 parents.sort(sorted);
00055 for (unsigned i = 0; i < sorted.size(); ++i) {
00056 mu[i] = static_cast< const std::vector<double>* >( sorted[i] );
00057 }
00058
00059
00060 state.reestimate(mu, sorted[0]->fitness(), sorted.back()->fitness());
00061
00062 if (!state.updateEigenSystem(10)) {
00063 std::cerr << "No good eigensystem found" << std::endl;
00064 }
00065
00066
00067 offspring.resize(lambda);
00068
00069 for (unsigned i = 0; i < lambda; ++i) {
00070 state.sample( static_cast< std::vector<double>& >( offspring[i] ));
00071 offspring[i].invalidate();
00072 }
00073
00074 }
00075 };
00076
00077
00078 #endif