From 422ddc6f5f2e9858615f35b075af82235220ed48 Mon Sep 17 00:00:00 2001 From: jmerelo Date: Fri, 18 May 2001 07:33:12 +0000 Subject: [PATCH] Added the missing file --- eo/test/t-MGE1bit.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 eo/test/t-MGE1bit.cpp diff --git a/eo/test/t-MGE1bit.cpp b/eo/test/t-MGE1bit.cpp new file mode 100644 index 00000000..8376831a --- /dev/null +++ b/eo/test/t-MGE1bit.cpp @@ -0,0 +1,104 @@ +//----------------------------------------------------------------------------- +// t-eoMGE.cpp +//----------------------------------------------------------------------------- + +#ifndef __GNUG__ +// to avoid long name warnings +#pragma warning(disable:4786) +#endif // __GNUG__ + +#include +#include + +#include "RoyalRoad.h" + +// Viri +#include +#include +#include + +//----------------------------------------------------------------------------- + +typedef eoVirus Chrom; + +//----------------------------------------------------------------------------- + +int main() +{ + const unsigned POP_SIZE = 1000, CHROM_SIZE = 128; + unsigned i; + eoBooleanGenerator gen; + + // the populations: + eoPop pop; + + // Evaluation + RoyalRoad rr( 8 ); + eoEvalFuncCounter eval( rr ); + + eoInitVirus1bit 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 + eoStochTournamentSelect lottery(0.9 ); + + // breeder + VirusShiftMutation vm; + VirusTransmission vt; + VirusBitFlip vf; + eoUBitXover xover; + eoProportionalOp propSel; + eoGeneralBreeder breeder( lottery, propSel ); + propSel.add(vm, 0.8); + propSel.add(vf, 0.05); + propSel.add(vt, 0.05); + propSel.add(xover, 0.1); + + // Replace a single one + eoCommaReplacement replace; + + // Terminators + eoGenContinue continuator1(500); + eoFitContinue continuator2(128); + eoCombinedContinue continuator(continuator1, continuator2); + eoCheckPoint checkpoint(continuator); + eoStdoutMonitor monitor; + checkpoint.add(monitor); + eoSecondMomentStats stats; + eoPopStat dumper( 10 ); + monitor.add(stats); + checkpoint.add(dumper); + 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; + + cout << "\n --> Number of Evaluations = " << eval.getValue() << endl; + return 0; +} + +//-----------------------------------------------------------------------------