#ifdef HAVE_CONFIG_H #include #endif #include #ifdef HAVE_SSTREAM #include #else #include #endif #include #include typedef eoBit Indi ; // A bitstring with fitness double #include "binary_value.h" using namespace std; void main_function(int argc, char **argv) { // Some parameters 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 POP_SIZE = 100 ; // Size of population const unsigned int MAX_GEN = 20 ; // Maximum number of generation before STOP const double P_CROSS = 0.8 ; // Crossover probability const double P_MUT = 1.0 ; // Mutation probability const double P_MUT_PER_BIT = 0.01 ; // Internal probability for bit-flip mutation const double onePointRate = 0.5 ; // Rate for 1-pt Xover const double bitFlipRate = 0.5 ; // Rate for bit-flip mutation rng.reseed (SEED) ; eoEvalFuncPtr & > eval (binary_value) ; eoUniformGenerator uGen ; eoInitFixedLength random (VEC_SIZE, uGen) ; eoPop pop (POP_SIZE, random) ; apply (eval, pop) ; eoDetTournamentSelect selectOne (T_SIZE) ; eoSelectPerc select (selectOne) ; eoGenerationalReplacement replace ; eo1PtBitXover xover1 ; eoBitMutation mutationBitFlip(P_MUT_PER_BIT) ; // The operators are encapsulated into an eoTRansform object eoSGATransform transform(xover1, P_CROSS, mutationBitFlip, P_MUT); eoGenContinue genCont (MAX_GEN); eoEasyEA gga (genCont, eval, select, transform, replace); eoListener listen (argc, argv) ; eoDistEvalEasyEA dist_gga (listen, gga, "Mars") ; dist_gga (pop) ; listen.destroy ("Mars") ; // OUTPUT // Print (sorted) intial population pop.sort(); cout << "FINAL Population\n" << pop << endl; // GENERAL } // A main that catches the exceptions int main(int argc, char **argv) { try { main_function(argc, argv); } catch(exception& e) { cout << "Exception: " << e.what() << '\n'; } return 1; }