14 struct FitnessComparator {
15 bool operator()(
const IndividualType & a,
const IndividualType & b ) {
23 int main(
int argc,
char ** argv ) {
25 const unsigned Mu = 15;
26 const unsigned Lambda = 100;
27 const unsigned Dimension = 30;
28 const double InitialSigma = 3.;
31 Ackley ackley( Dimension );
35 mutationDistribution.
resize(Dimension);
38 prototypeIndividual.
chromosome() = InitialSigma;
44 for(
auto& ind: parents ) {
52 double tau0 = 1. / sqrt(2. * Dimension);
53 double tau1 = 1. / sqrt(2. * sqrt( static_cast<double>( Dimension ) ) );
58 for( std::size_t i = 0; i < offspring.size(); i++ ) {
70 offspring[i].searchPoint() = uniform(
random::globalRng, mom->searchPoint(), dad->searchPoint() );
72 offspring[i].searchPoint() = offspring[i].chromosome() * mutationDistribution(
random::globalRng).first;
75 offspring[i].unpenalizedFitness() = ackley.
eval( offspring[i].
searchPoint() );
79 example::FitnessComparator comp;
80 std::sort( offspring.begin(), offspring.end(), comp );
81 std::copy( offspring.begin(), offspring.begin() + Mu, parents.begin() );
85 << parents.front().unpenalizedFitness() <<
" " 86 << parents.front().chromosome()