From a764bb57828198e5d6463d6589fe856d90ff0a3a Mon Sep 17 00:00:00 2001 From: evomarc Date: Mon, 17 Jun 2002 04:51:34 +0000 Subject: [PATCH] Reshaped the whole code Added the SequentialSelect selectors THe generated files are now "hidden" in ResSelect dir (hardcoded!) --- eo/test/t-eoSelect.cpp | 128 +++++++++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 48 deletions(-) diff --git a/eo/test/t-eoSelect.cpp b/eo/test/t-eoSelect.cpp index 771368085..3fde7f5ca 100644 --- a/eo/test/t-eoSelect.cpp +++ b/eo/test/t-eoSelect.cpp @@ -7,17 +7,9 @@ #include // runtime_error -//----------------------------------------------------------------------------- -// tt.cpp: -// -//----------------------------------------------------------------------------- - - // general #include -#include -#include -#include + //----------------------------------------------------------------------------- struct Dummy : public EO @@ -52,22 +44,18 @@ unsigned isInPop(EOT & _indi, eoPop & _pop) } unsigned int pSize; // global variable, bouh! +string fitnessType; // yes, a global variable :-) +eoDummyPop parentsOrg; template void testSelectMany(eoSelect & _select, string _name) { - cout << "\n\n" << _name << endl; + unsigned i; + cout << "\n\n" << fitnessType + _name << endl; cout << "===============\n"; - eoDummyPop parents(pSize); + eoDummyPop parents(parentsOrg); eoDummyPop offspring(0); - unsigned i; - // initialize parents - for (i=0; i & _select, string _name) throw runtime_error("Pas trouve ds parents"); nb[trouve]++; } - // dump to file so you can plot using gnuplot - string fName = _name + ".prop"; + // dump to file so you can plot using gnuplot - dir name is hardcoded! + string fName = "ResSelect/" + fitnessType + _name + ".select"; ofstream os(fName.c_str()); for (i=0; i & _select, string _name) } template -void testSelectOne(eoSelectOne & _select, eoHowMany & _hm, string _name) +void testSelectOne(eoSelectOne & _select, eoHowMany & _offspringRate, + eoHowMany & _fertileRate, string _name) { - eoSelectMany percSelect(_select, _hm); + eoTruncatedSelectOne truncSelect(_select, _fertileRate); + eoSelectMany percSelect(truncSelect, _offspringRate); testSelectMany(percSelect, _name); } @@ -113,26 +103,65 @@ int the_main(int argc, char **argv) eoValueParam offsrpringRateParam = parser.createParam(eoHowMany(1.0), "offsrpringRate", "Offsrpring rate (% or absolute)",'O'); eoHowMany oRate = offsrpringRateParam.value(); + eoValueParam fertileRateParam = parser.createParam(eoHowMany(1.0), "fertileRate", "Fertility rate (% or absolute)",'F'); + eoHowMany fRate = fertileRateParam.value(); + eoValueParam tournamentSizeParam = parser.createParam(unsigned(2), "tournamentSize", "Deterministic tournament size",'T'); unsigned int tSize = tournamentSizeParam.value(); - eoValueParam tournamentRateParam = parser.createParam(0.75, "tournamentRate", "Stochastic tournament rate",'R'); + eoValueParam tournamentRateParam = parser.createParam(1.0, "tournamentRate", "Stochastic tournament rate",'t'); double tRate = tournamentRateParam.value(); - eoValueParam rankingPressureParam = parser.createParam(1.75, "rankingPressure", "Selective pressure for the ranking selection",'p'); + eoValueParam rankingPressureParam = parser.createParam(2.0, "rankingPressure", "Selective pressure for the ranking selection",'p'); double rankingPressure = rankingPressureParam.value(); + eoValueParam rankingExponentParam = parser.createParam(1.0, "rankingExponent", "Exponent for the ranking selection",'e'); + double rankingExponent = rankingExponentParam.value(); + + eoValueParam fitTypeParam = parser.createParam(string("linear"), "fitType", "Type of fitness (linear, exp, log, super",'f'); + fitnessType = fitTypeParam.value(); + if (parser.userNeedsHelp()) { parser.printHelp(cout); exit(0); } + // hard-coded directory name ... + system("mkdir ResSelect"); cout << "Testing the Selections\nParents size = " << pSize - << ", offspring rate = " << oRate << endl; + << ", offspring rate = " << oRate; + cout << " and putting rsulting files in dir ResSelect" << endl; - rng.reseed(42); + // initialize parent population + parentsOrg.resize(pSize); + if (fitnessType == string("linear")) + for (unsigned i=0; i& seedParam = parser.createParam(uint32(0), "seed", "Random number seed", 'S'); + if (seedParam.value() == 0) + seedParam.value() = time(0); + rng.reseed(seedParam.value()); + + char fileName[1024]; // the selection procedures under test // eoDetSelect detSelect(oRate); @@ -140,39 +169,42 @@ eoValueParam tournamentSizeParam = parser.createParam(unsigned(2), "to // Roulette eoProportionalSelect propSelect; - testSelectOne(propSelect, oRate, "propSelect"); + testSelectOne(propSelect, oRate, fRate, "PropSelect"); - // Ranking - eoRankingSelect rankSelect(rankingPressure); - testSelectOne(rankSelect, oRate, "rankSelect"); + // Linear ranking using the perf2Worth construct + eoRankingSelect newRankingSelect(rankingPressure); + sprintf(fileName,"LinRank_%g",rankingPressure); + testSelectOne(newRankingSelect, oRate, fRate, fileName); - // New ranking using the perf2Worth construct - cout << "Avant appel a LinearRanking()" << endl; - eoRankingSelect newRankingSelect(rankingPressure); // pressure 2 by default - testSelectOne(newRankingSelect, oRate, "newRankSelect"); - - // New ranking using the perf2Worth construct - cout << "Avant appel a exponentialRanking()" << endl; - eoRankingSelect expRankingSelect(rankingPressure,2); - testSelectOne(expRankingSelect, oRate, "expRankingSelect"); + // Exponential ranking using the perf2Worth construct + cout << "rankingExponent " << rankingExponent << endl; + eoRankingSelect expRankingSelect(rankingPressure,rankingExponent); + sprintf(fileName,"ExpRank_%g_%g",rankingPressure, rankingExponent); + testSelectOne(expRankingSelect, oRate, fRate, fileName); // Det tournament eoDetTournamentSelect detTourSelect(tSize); - testSelectOne(detTourSelect, oRate, "detTourSelect"); + sprintf(fileName,"DetTour_%d",tSize); + testSelectOne(detTourSelect, oRate, fRate, fileName); // Stoch tournament eoStochTournamentSelect stochTourSelect(tRate); - testSelectOne(stochTourSelect, oRate, "stochTourSelect"); - - exit(0); + sprintf(fileName,"StochTour_%g",tRate); + testSelectOne(stochTourSelect, oRate, fRate, fileName); // Fitness scaling -// eoFitnessScalingSelect fitScaleSelect(rankingPressure); -// testSelectOne(fitScaleSelect, oRate, "fitScaleSelect"); - - // NEW Fitness scaling eoFitnessScalingSelect newFitScaleSelect(rankingPressure); - testSelectOne(newFitScaleSelect, oRate, "NewFitScaleSelect"); + sprintf(fileName,"LinFitScale_%g",rankingPressure); + testSelectOne(newFitScaleSelect, oRate, fRate, fileName); + + // Sequential selections + eoSequentialSelect seqSel(false); + strcpy(fileName,"Sequential"); + testSelectOne(seqSel, oRate, fRate, fileName); + + eoEliteSequentialSelect eliteSeqSel; + strcpy(fileName,"EliteSequential"); + testSelectOne(eliteSeqSel, oRate, fRate, fileName); return 1; }