diff --git a/eo/src/do/make_algo_scalar.h b/eo/src/do/make_algo_scalar.h index fed479b7..98e769f3 100644 --- a/eo/src/do/make_algo_scalar.h +++ b/eo/src/do/make_algo_scalar.h @@ -73,7 +73,7 @@ template eoAlgo & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc& _eval, eoContinue& _continue, eoGenOp& _op) { // the selection - eoValueParam& selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", "Selection: Roulette, DetTour(T), StochTour(t) or Sequential(ordered/unordered)", 'S', "Evolution Engine"); + eoValueParam& selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", "Selection: Roulette, Ranking(p,e), DetTour(T), StochTour(t) or Sequential(ordered/unordered)", 'S', "Evolution Engine"); eoParamParamType & ppSelect = selectionParam.value(); // pair > @@ -108,6 +108,50 @@ eoAlgo & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc select = new eoStochTournamentSelect(p); } + else if (ppSelect.first == string("Ranking")) + { + double p,e; + if (ppSelect.second.size()==2) // 2 parameters: pressure and exponent + { + p = atof(ppSelect.second[0].c_str()); + e = atof(ppSelect.second[1].c_str()); + } + else if (ppSelect.second.size()==1) // 1 parameter: pressure + { + cerr << "WARNING, no exponent to Ranking, using 1" << endl; + e = 1; + ppSelect.second.push_back(string("1")); + p = atof(ppSelect.second[0].c_str()); + } + else // no parameters ... or garbage + { + cerr << "WARNING, no parameter to Ranking, using (2,1)" << endl; + p=2; + e=1; + // put back in parameter for consistency (and status file) + ppSelect.second.resize(2); // just in case + ppSelect.second[0] = (string("2")); + ppSelect.second[1] = (string("1")); + } + // check for authorized values + // pressure in (0,1] + if ( (p<=1) || (p>2) ) + { + cerr << "WARNING, selective pressure must be in (0,1] in Ranking, using 2\n"; + p=2; + ppSelect.second[0] = (string("2")); + } + // exponent >0 + if (e<=0) + { + cerr << "WARNING, exponent must be positive in Ranking, using 1\n"; + e=1; + ppSelect.second[1] = (string("1")); + } + // now we're OK + eoPerf2Worth & p2w = _state.storeFunctor( new eoRanking(p,e) ); + select = new eoRouletteWorthSelect(p2w); + } else if (ppSelect.first == string("Sequential")) // one after the other { bool b;