//----------------------------------------------------------------------------- // t-eoMGE.cpp //----------------------------------------------------------------------------- #ifndef __GNUG__ // to avoid long name warnings #pragma warning(disable:4786) #endif // __GNUG__ #include #include #include "binary_value.h" // Viri #include #include #include //----------------------------------------------------------------------------- typedef eoVirus Chrom; //----------------------------------------------------------------------------- int main() { const unsigned POP_SIZE = 100, CHROM_SIZE = 16; unsigned i; eoBooleanGenerator gen; // the populations: eoPop pop; // Evaluation eoEvalFuncPtr eval( binary_value ); eoInitVirus random(CHROM_SIZE, gen); for (i = 0; i < POP_SIZE; ++i) { Chrom chrom; random(chrom); eval(chrom); pop.push_back(chrom); } cout << "population:" << endl; for (i = 0; i < pop.size(); ++i) cout << "\t" << pop[i] << " " << pop[i].fitness() << endl; // selection eoDetTournamentSelect lottery( 3) ; // breeder VirusMutation vm; VirusTransmission vt; VirusBitFlip vf; eoUBitXover xover; eoProportionalOp propSel; eoGeneralBreeder breeder( lottery, propSel ); propSel.add(vm, 0.25); propSel.add(vf, 0.25); propSel.add(vt, 0.25); propSel.add(xover, 0.25); // Replace a single one eoPlusReplacement replace; // Terminators eoGenContinue continuator1(50); eoFitContinue continuator2(65535.f); eoCombinedContinue continuator(continuator1, continuator2); eoCheckPoint checkpoint(continuator); eoStdoutMonitor monitor; checkpoint.add(monitor); eoSecondMomentStats stats; monitor.add(stats); checkpoint.add(stats); // GA generation eoEasyEA ea(checkpoint, eval, breeder, replace ); // evolution try { ea(pop); } catch (exception& e) { cout << "exception: " << e.what() << endl;; exit(EXIT_FAILURE); } cout << "pop" << endl; for (i = 0; i < pop.size(); ++i) cout << "\t" << pop[i] << " " << pop[i].fitness() << endl; return 0; } //-----------------------------------------------------------------------------