Corrected a problem in eoEsChromInit (it refused plain eoReal) + some

other minor modications (e.g. a dir in make_checkpoint where ALL file
will go).
This commit is contained in:
evomarc 2001-05-03 17:20:27 +00:00
commit f4d2630516
9 changed files with 98 additions and 64 deletions

View file

@ -73,7 +73,7 @@ template <class EOT>
eoAlgo<EOT> & do_make_algo_scalar(eoParameterLoader& _parser, eoState& _state, eoEvalFunc<EOT>& _eval, eoContinue<EOT>& _ccontinue, eoGenOp<EOT>& _op)
{
// the selection
eoValueParam<eoParamParamType>& selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", "Selection: Roulette, DetTour(T), StochTour(t) or Sequential(ordered/unordered)", 'S', "engine");
eoValueParam<eoParamParamType>& selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", "Selection: Roulette, DetTour(T), StochTour(t) or Sequential(ordered/unordered)", 'S', "Evolution Engine");
eoParamParamType & ppSelect = selectionParam.value(); // pair<string,vector<string> >
@ -109,18 +109,21 @@ eoAlgo<EOT> & do_make_algo_scalar(eoParameterLoader& _parser, eoState& _state, e
select = new eoProportionalSelect<EOT>;
}
else
throw runtime_error("Invalid selection");
{
string stmp = string("Invalid selection: ") + ppSelect.first;
throw runtime_error(stmp.c_str());
}
_state.storeFunctor(select);
// the number of offspring
eoValueParam<eoRateParamType>& offspringRateParam = _parser.createParam(eoRateParamType("100%"), "nbOffspring", "Nb of offspring (percentage or absolute)", 'O', "engine");
eoValueParam<eoRateParamType>& offspringRateParam = _parser.createParam(eoRateParamType("100%"), "nbOffspring", "Nb of offspring (percentage or absolute)", 'O', "Evolution Engine");
// an eoRateParamType is simply a pair<double,bool>
double offRate=offspringRateParam.value().first;
bool offInterpret_as_rate = offspringRateParam.value().second;
// the replacement
eoValueParam<eoParamParamType>& replacementParam = _parser.createParam(eoParamParamType("Comma"), "replacement", "Replacement: Comma, Plus or EPTour(T), SSGAWorst, SSGADet(T), SSGAStoch(t)", 'R', "engine");
eoValueParam<eoParamParamType>& replacementParam = _parser.createParam(eoParamParamType("Comma"), "replacement", "Replacement: Comma, Plus or EPTour(T), SSGAWorst, SSGADet(T), SSGAStoch(t)", 'R', "Evolution Engine");
eoParamParamType & ppReplace = replacementParam.value(); // pair<string,vector<string> >
@ -159,12 +162,15 @@ eoAlgo<EOT> & do_make_algo_scalar(eoParameterLoader& _parser, eoState& _state, e
replace = new eoSSGAStochTournamentReplacement<EOT>(p);
}
else
throw runtime_error("Invalid replacement");
{
string stmp = string("Invalid replacement: ") + ppReplace.first;
throw runtime_error(stmp.c_str());
}
_state.storeFunctor(replace);
// adding weak elitism
eoValueParam<bool>& weakElitismParam = _parser.createParam(false, "weakElitism", "Old best parent replaces new worst offspring *if necessary*", 'w', "engine");
eoValueParam<bool>& weakElitismParam = _parser.createParam(false, "weakElitism", "Old best parent replaces new worst offspring *if necessary*", 'w', "Evolution Engine");
if (weakElitismParam.value())
{
eoReplacement<EOT> *replaceTmp = replace;

View file

@ -77,12 +77,15 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParameterLoader& _parser, eoState& _stat
// Best fitness in population
//---------------------------
eoValueParam<bool>& printBestParam = _parser.createParam(true, "printBestStat", "Print Best/avg/stdev every gen.", '\0', "Output");
eoValueParam<bool>& plotBestParam = _parser.createParam(false, "plotBestStat", "Plot Best/avg Stat", '\0', "Output");
eoValueParam<string>& bestFileNameParam = _parser.createParam(string("best.xg"), "BestFileName", "Name of file for Best/avg/stdev", '\0', "Output");
bool fileBestParam = _parser.isItThere(bestFileNameParam);
eoValueParam<bool>& plotBestParam = _parser.createParam(false, "plotBestStat", "Plot Best/avg Stat", '\0', "Output - Graphical");
// dir for DISK output
eoValueParam<string>& dirNameParam = _parser.createParam(string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output - Disk");
eoValueParam<bool>& fileBestParam = _parser.createParam(false, "fileBestStat", "Output bes/avg/std to file", '\0', "Output - Disk");
eoBestFitnessStat<EOT> *bestStat = NULL;
if ( printBestParam.value() || plotBestParam.value() || fileBestParam )
if ( printBestParam.value() || plotBestParam.value() || fileBestParam.value() )
// we need the bestStat for at least one of the 3 above
{
bestStat = new eoBestFitnessStat<EOT>;
@ -134,7 +137,7 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParameterLoader& _parser, eoState& _stat
// the Fitness Distance Correlation
//---------------------------------
eoValueParam<bool>& printFDCParam = _parser.createParam(true, "printFDC", "Print FDC coeff. every gen.", '\0', "Output");
eoValueParam<bool>& plotFDCParam = _parser.createParam(false, "plotFDCStat", "Plot FDC scatter plot", '\0', "Output");
eoValueParam<bool>& plotFDCParam = _parser.createParam(false, "plotFDCStat", "Plot FDC scatter plot", '\0', "Output - Graphical");
eoFDCStat<EOT> *fdcStat = NULL;
if ( printFDCParam.value() || plotFDCParam.value() ) // we need FDCStat
@ -180,9 +183,10 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParameterLoader& _parser, eoState& _stat
monitor->add(*popStat);
}
if (fileBestParam) // A file monitor for best & secondMoment
if (fileBestParam.value()) // A file monitor for best & secondMoment
{
eoFileMonitor *fileMonitor = new eoFileMonitor(bestFileNameParam.value());
string stmp = dirNameParam.value() + "/best.xg";
eoFileMonitor *fileMonitor = new eoFileMonitor(stmp);
// save and give to checkpoint
_state.storeFunctor(fileMonitor);
checkpoint->add(*fileMonitor);
@ -195,7 +199,8 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParameterLoader& _parser, eoState& _stat
if (plotBestParam.value()) // an eoGnuplot1DMonitor for best & average
{
eoGnuplot1DMonitor *gnuMonitor = new eoGnuplot1DMonitor("_gnu_best.xg",minimizing_fitness<EOT>());
string stmp = dirNameParam.value() + "_gnu_best.xg";
eoGnuplot1DMonitor *gnuMonitor = new eoGnuplot1DMonitor(stmp,minimizing_fitness<EOT>());
// save and give to checkpoint
_state.storeFunctor(gnuMonitor);
checkpoint->add(*gnuMonitor);
@ -211,7 +216,7 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParameterLoader& _parser, eoState& _stat
if (plotFDCParam.value()) // a specific plot monitor for FDC
{
// first into a file (it adds everything ti itself
eoFDCFileSnapshot<EOT> *fdcFileSnapshot = new eoFDCFileSnapshot<EOT>(*fdcStat);
eoFDCFileSnapshot<EOT> *fdcFileSnapshot = new eoFDCFileSnapshot<EOT>(*fdcStat, dirNameParam.value());
_state.storeFunctor(fdcFileSnapshot);
// then to a Gnuplot monitor
eoGnuplot1DSnapshot *fdcGnuplot = new eoGnuplot1DSnapshot(*fdcFileSnapshot);
@ -222,14 +227,14 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParameterLoader& _parser, eoState& _stat
checkpoint->add(*fdcGnuplot);
}
eoValueParam<bool> plotHistogramParam = _parser.createParam(false, "plotHisto", "Plot histogram of fitnesses", '\0', "Output");
eoValueParam<bool> plotHistogramParam = _parser.createParam(false, "plotHisto", "Plot histogram of fitnesses", '\0', "Output - Graphical");
if (plotHistogramParam.value()) // want to see how the fitness is spread?
{
eoScalarFitnessStat<EOT> *fitStat = new eoScalarFitnessStat<EOT>;
_state.storeFunctor(fitStat);
checkpoint->add(*fitStat);
// a gnuplot-based monitor for snapshots: needs a dir name
eoGnuplot1DSnapshot *fitSnapshot = new eoGnuplot1DSnapshot("Fitnesses");
eoGnuplot1DSnapshot *fitSnapshot = new eoGnuplot1DSnapshot(dirNameParam.value());
_state.storeFunctor(fitSnapshot);
// add any stat that is a vector<double> to it
fitSnapshot->add(*fitStat);
@ -248,7 +253,8 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParameterLoader& _parser, eoState& _stat
if (_parser.isItThere(saveFrequencyParam))
{
unsigned freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX );
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, "generation");
string stmp = dirNameParam.value() + "/generations";
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
_state.storeFunctor(stateSaver1);
checkpoint->add(*stateSaver1);
}
@ -257,7 +263,8 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParameterLoader& _parser, eoState& _stat
eoValueParam<unsigned>& saveTimeIntervalParam = _parser.createParam(unsigned(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" );
if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0)
{
eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, "time");
string stmp = dirNameParam.value() + "/time";
eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp);
_state.storeFunctor(stateSaver2);
checkpoint->add(*stateSaver2);
}

View file

@ -47,8 +47,11 @@
template <class EOT>
eoPop<EOT>& do_make_pop(eoParser & _parser, eoState& _state, eoInit<EOT> & _init)
{
eoValueParam<uint32>& seedParam = _parser.createParam(uint32(time(0)), "seed", "Random number seed", 'S');
eoValueParam<unsigned>& popSize = _parser.createParam(unsigned(20), "popSize", "Population Size", 'P', "initialization");
// random seed
eoValueParam<uint32>& seedParam = _parser.createParam(uint32(0), "seed", "Random number seed", 'S');
if (seedParam.value() == 0)
seedParam.value() = random_seed();
eoValueParam<unsigned>& popSize = _parser.createParam(unsigned(20), "popSize", "Population Size", 'P', "Evolution Engine");
// Either load or initialize
// create an empty pop and let the state handle the memory