Update after the change in replacements
This commit is contained in:
parent
ca586fc799
commit
ed0e76350a
5 changed files with 18 additions and 21 deletions
|
|
@ -79,7 +79,7 @@ void main_function(int argc, char **argv)
|
|||
// Initialization of the population
|
||||
eoPop<Indi> pop(POP_SIZE, random);
|
||||
|
||||
// and evaluate it in one line
|
||||
// and evaluate it in one loop
|
||||
apply<Indi>(eval, pop); // STL syntax
|
||||
|
||||
// OUTPUT
|
||||
|
|
@ -102,7 +102,7 @@ void main_function(int argc, char **argv)
|
|||
// REPLACE
|
||||
// And we now have the full slection/replacement - though with
|
||||
// no replacement (== generational replacement) at the moment :-)
|
||||
eoNoReplacement<Indi> replace;
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -45,13 +45,11 @@ void main_function(int argc, char **argv)
|
|||
const float P_MUT = 0.5; // mutation probability
|
||||
|
||||
const double EPSILON = 0.01; // range for real uniform mutation
|
||||
const double SIGMA = 0.01; // std. dev. of normal mutation
|
||||
// some parameters for chosing among different operators
|
||||
const double segmentRate = 0.5; // rate for 1-pt Xover
|
||||
const double arithmeticRate = 0.5; // rate for 2-pt Xover
|
||||
const double uniformMutRate = 0.5; // rate for bit-flip mutation
|
||||
const double detMutRate = 0.5; // rate for one-bit mutation
|
||||
const double normMutRate = 0.5; // rate for normal mutation
|
||||
|
||||
// GENERAL
|
||||
//////////////////////////
|
||||
|
|
@ -79,7 +77,7 @@ void main_function(int argc, char **argv)
|
|||
// Initialization of the population
|
||||
eoPop<Indi> pop(POP_SIZE, random);
|
||||
|
||||
// and evaluate it in one line
|
||||
// and evaluate it in one loop
|
||||
apply<Indi>(eval, pop); // STL syntax
|
||||
|
||||
// OUTPUT
|
||||
|
|
@ -102,7 +100,7 @@ void main_function(int argc, char **argv)
|
|||
// REPLACE
|
||||
// And we now have the full slection/replacement - though with
|
||||
// no replacement (== generational replacement) at the moment :-)
|
||||
eoNoReplacement<Indi> replace;
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
|
|
@ -115,19 +113,16 @@ void main_function(int argc, char **argv)
|
|||
eoArithmeticCrossover<Indi> xoverA;
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedQuadOp<Indi> xover(xoverS, segmentRate);
|
||||
xover.add(xoverA, arithmeticRate, eo_verbose);
|
||||
xover.add(xoverA, arithmeticRate, true);
|
||||
|
||||
// MUTATION
|
||||
// Gaussian mutation - std dev as argument
|
||||
eoNormalMutation<Indi> mutationN(SIGMA);
|
||||
// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]
|
||||
eoUniformMutation<Indi> mutationU(EPSILON);
|
||||
// k (=1) coordinates of parents are uniformly modified
|
||||
eoDetUniformMutation<Indi> mutationD(EPSILON);
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedMonOp<Indi> mutation(mutationU, uniformMutRate);
|
||||
mutation.add(mutationD, detMutRate);
|
||||
mutation.add(mutationN, normMutRate, eo_verbose);
|
||||
mutation.add(mutationD, detMutRate, true);
|
||||
|
||||
// STOP
|
||||
// CHECKPOINT
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ void main_function(int argc, char **argv)
|
|||
// PARAMETRES
|
||||
const unsigned int SEED = 42; // seed for random number generator
|
||||
const unsigned int T_SIZE = 3; // size for tournament selection
|
||||
const unsigned int VEC_SIZE = 8; // Number of bits in genotypes
|
||||
const unsigned int VEC_SIZE = 20; // Number of bits in genotypes
|
||||
const unsigned int POP_SIZE = 20; // Size of population
|
||||
|
||||
const unsigned int MAX_GEN = 500; // Maximum number of generation before STOP
|
||||
|
|
@ -98,7 +98,7 @@ void main_function(int argc, char **argv)
|
|||
eoDetTournament<Indi> selectOne(T_SIZE); // T_SIZE in [2,POP_SIZE]
|
||||
// solution solution solution solution solution solution solution
|
||||
// modify the rate in the constructor
|
||||
eoSelectPerc<Indi> select(selectOne,2.0);// rate is second arg.
|
||||
eoSelectMany<Indi> select(selectOne,2, eo_is_an_integer);// rate is second arg.
|
||||
|
||||
// REPLACE
|
||||
// solution solution solution solution solution solution solution
|
||||
|
|
|
|||
|
|
@ -218,8 +218,8 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// REPLACE
|
||||
// And we now have the full slection/replacement - though with
|
||||
// no replacement (== generational replacement) at the moment :-)
|
||||
eoNoReplacement<Indi> replace;
|
||||
// the same generational replacement at the moment :-)
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
|
|
@ -235,7 +235,7 @@ void main_function(int argc, char **argv)
|
|||
// Combine them with relative rates
|
||||
eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);
|
||||
xover.add(xoverU, URate);
|
||||
xover.add(xover2, twoPointsRate, eo_verbose);
|
||||
xover.add(xover2, twoPointsRate, true);
|
||||
|
||||
// MUTATION
|
||||
// standard bit-flip mutation for bitstring
|
||||
|
|
@ -244,7 +244,7 @@ void main_function(int argc, char **argv)
|
|||
eoDetBitFlip<Indi> mutationOneBit;
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedMonOp<Indi> mutation(mutationBitFlip, bitFlipRate);
|
||||
mutation.add(mutationOneBit, oneBitRate, eo_verbose);
|
||||
mutation.add(mutationOneBit, oneBitRate, true);
|
||||
|
||||
// The operators are encapsulated into an eoTRansform object
|
||||
eoSGATransform<Indi> transform(xover, pCross, mutation, pMut);
|
||||
|
|
@ -294,7 +294,7 @@ void main_function(int argc, char **argv)
|
|||
checkpoint.add(SecondStat);
|
||||
|
||||
// The Stdout monitor will print parameters to the screen ...
|
||||
eoStdoutMonitor monitor(eo_no_verbose);
|
||||
eoStdoutMonitor monitor(false);
|
||||
|
||||
// when called by the checkpoint (i.e. at every generation)
|
||||
checkpoint.add(monitor);
|
||||
|
|
|
|||
|
|
@ -203,10 +203,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// OUTPUT
|
||||
// sort pop for pretty printout
|
||||
pop.sort();
|
||||
// pop.sort();
|
||||
// Print (sorted) intial population (raw printout)
|
||||
cout << "Initial Population" << endl << pop << endl;
|
||||
|
||||
cout << "Initial Population" << endl << pop ;
|
||||
cout << "and best is " << pop.best_element() << "\n\n";
|
||||
cout << "and worse is " << pop.worse_element() << "\n\n";
|
||||
// ENGINE
|
||||
/////////////////////////////////////
|
||||
// selection and replacement
|
||||
|
|
@ -221,6 +222,7 @@ void main_function(int argc, char **argv)
|
|||
// And we now have the full slection/replacement - though with
|
||||
// no replacement (== generational replacement) at the moment :-)
|
||||
eoNoReplacement<Indi> replace;
|
||||
// eoWeakElitistReplacement<Indi> replace(replace_main);
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue