diff --git a/eo/test/Makefile.am b/eo/test/Makefile.am index 3efec4a1..d69a6082 100644 --- a/eo/test/Makefile.am +++ b/eo/test/Makefile.am @@ -13,7 +13,7 @@ LDADDS = $(top_builddir)/src/libeo.a $(top_builddir)/src/utils/libeoutils.a ############################################################################### -noinst_PROGRAMS = t-eofitness t-eobin t-eoStateAndParser t-eoCheckpointing t-eoExternalEO t-eoESFull t-eoSymreg t-eo t-eoReplacement +noinst_PROGRAMS = t-eofitness t-eobin t-eoStateAndParser t-eoCheckpointing t-eoExternalEO t-eoESFull t-eoSymreg t-eo t-eoReplacement t-eoSelect ############################################################################### @@ -57,6 +57,13 @@ t_eoReplacement_LDADD = $(LDADDS) ############################################################################### +t_eoSelect_SOURCES = t-eoSelect.cpp +t_eoSelect_DEPENDENCIES = $(DEPS) +t_eoSelect_LDFLAGS = -lm +t_eoSelect_LDADD = $(LDADDS) + +############################################################################### + t_eoExternalEO_SOURCES = t-eoExternalEO.cpp t_eoExternalEO_DEPENDENCIES = $(DEPS) t_eoExternalEO_LDFLAGS = -lm diff --git a/eo/test/t-eoSelect.cpp b/eo/test/t-eoSelect.cpp new file mode 100644 index 00000000..b0bdcbbe --- /dev/null +++ b/eo/test/t-eoSelect.cpp @@ -0,0 +1,107 @@ +//----------------------------------------------------------------------------- + +// to avoid long name warnings +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif + +#include // runtime_error + +//----------------------------------------------------------------------------- +// tt.cpp: +// +//----------------------------------------------------------------------------- + + +// general +#include +#include +//----------------------------------------------------------------------------- + +struct Dummy : public EO +{ + typedef double Type; + void printOn(ostream & _os) const + { + _os << " - "; + EO::printOn(_os); + } +}; + + +struct eoDummyPop : public eoPop +{ +public : + eoDummyPop(int s=0) { resize(s); } +}; + +//----------------------------------------------------------------------------- + +int the_main(int argc, char **argv) +{ + eoParser parser(argc, argv); + eoValueParam parentSizeParam = parser.createParam(10, "parentSize", "Parent size",'P'); + unsigned int pSize = parentSizeParam.value(); + + eoValueParam offsrpringRateParam = parser.createParam(1.0, "offsrpringRate", "Offsrpring rate",'O'); + double oRate = offsrpringRateParam.value(); + + eoValueParam interpretAsRateParam = parser.createParam(true, "interpretAsRate", "interpret rate as Rate (False = as Number)",'b'); + bool interpretAsRate = interpretAsRateParam.value(); + +eoValueParam tournamentSizeParam = parser.createParam(2, "tournamentSize", "Deterministic tournament size",'T'); + unsigned int tSize = tournamentSizeParam.value(); + + eoValueParam tournamentRateParam = parser.createParam(0.75, "tournamentRate", "Stochastic tournament rate",'R'); + double tRate = tournamentRateParam.value(); + + if (parser.userNeedsHelp()) + { + parser.printHelp(cout); + exit(1); + } + + unsigned i; + + cout << "Testing the Selections\nParents size = " << pSize + << ", offspring rate = " << oRate << + "interpreted as " << (interpretAsRate ? "Rate" : "Number") << endl; + + rng.reseed(42); + + + eoDummyPop parents(pSize); + eoDummyPop offspring(0); + + // initialize so we can recognize them later! + for (i=0; i detSelect(oRate, interpretAsRate); + + // here we go + // Deterministic + cout << "eoDetSelect\n"; + cout << "===========\n"; + detSelect(parents, offspring); +cout << "Selected offsprings (origonally all even\n" << offspring << endl; + + return 1; +} + +int main(int argc, char **argv) +{ + try + { + the_main(argc, argv); + } + catch(exception& e) + { + cout << "Exception: " << e.what() << endl; + } + + return 1; +}