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