finish the handling of gnuplot completely at build-time.

No gnuplot-ifs in headers anymore.
This commit is contained in:
kuepper 2005-10-05 21:34:19 +00:00
commit afc0659e35
12 changed files with 219 additions and 192 deletions

View file

@ -3,7 +3,7 @@
//-----------------------------------------------------------------------------
// make_checkpoint.h
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000
/*
/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
@ -45,7 +45,7 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
// first, create a checkpoint from the eoContinue
eoCheckPoint<EOT> *checkpoint = new eoCheckPoint<EOT>(_continue);
_state.storeFunctor(checkpoint);
///////////////////
// Counters
//////////////////
@ -55,14 +55,14 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
// if we want the time, we need an eoTimeCounter
eoTimeCounter * tCounter = NULL;
// Create anyway a generation-counter
// Recent change (03/2002): it is now an eoIncrementorParam, both
// Create anyway a generation-counter
// Recent change (03/2002): it is now an eoIncrementorParam, both
// a parameter AND updater so you can store it into the eoState
eoIncrementorParam<unsigned> *generationCounter = new eoIncrementorParam<unsigned>("Gen.");
// store it in the state
_state.storeFunctor(generationCounter);
// And add it to the checkpoint,
// And add it to the checkpoint,
checkpoint->add(*generationCounter);
// dir for DISK output
@ -91,7 +91,7 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
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.value() )
if ( printBestParam.value() || plotBestParam.value() || fileBestParam.value() )
// we need the bestStat for at least one of the 3 above
{
bestStat = new eoBestFitnessStat<EOT>;
@ -147,11 +147,11 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
// The monitors
///////////////
// do we want an eoStdoutMonitor?
bool needStdoutMonitor = printBestParam.value()
bool needStdoutMonitor = printBestParam.value()
|| printPopParam.value() ;
// The Stdout monitor will print parameters to the screen ...
if ( needStdoutMonitor )
// The Stdout monitor will print parameters to the screen ...
if ( needStdoutMonitor )
{
eoStdoutMonitor *monitor = new eoStdoutMonitor(false);
_state.storeFunctor(monitor);
@ -180,7 +180,7 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
}
// first handle the dir test - if we need at least one file
if ( ( fileBestParam.value() || plotBestParam.value() ||
if ( ( fileBestParam.value() || plotBestParam.value() ||
plotHistogramParam.value() )
&& !dirOK ) // just in case we add something before
dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE
@ -204,11 +204,10 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
// std::cout << "On met timecounter\n";
fileMonitor->add(*tCounter);
}
fileMonitor->add(*bestStat);
fileMonitor->add(*bestStat);
fileMonitor->add(*secondStat);
}
#if !defined(NO_GNUPLOT)
if (plotBestParam.value()) // an eoGnuplot1DMonitor for best & average
{
std::string stmp = dirNameParam.value() + "/gnu_best.xg";
@ -241,7 +240,6 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
// and of course add it to the checkpoint
checkpoint->add(*fitSnapshot);
}
#endif
//////////////////////////////////
// State savers
@ -263,12 +261,12 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
#else
std::string stmp = dirNameParam.value() + "/generations";
#endif
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
_state.storeFunctor(stateSaver1);
checkpoint->add(*stateSaver1);
}
// save state every T seconds
// save state every T seconds
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)
{
@ -281,7 +279,7 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
#else
std::string stmp = dirNameParam.value() + "/time";
#endif
eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp);
eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp);
_state.storeFunctor(stateSaver2);
checkpoint->add(*stateSaver2);
}

View file

@ -11,16 +11,16 @@
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
Marc.Schoenauer@inria.fr
mak@dhi.dk
@ -49,18 +49,26 @@ template <class EOT>
eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _state, eoEvalFuncCounter<EOT>& _eval, eoContinue<EOT>& _continue)
{
// SOME PARSER PARAMETERS
// ----------------------
std::string dirName = _parser.createParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output").value();
bool erase = _parser.createParam(true, "eraseDir", "Erase files in dirName if any", '\0', "Output").value();
#if !defined(NO_GNUPLOT)
bool gnuplots = _parser.createParam(true,"plots","Plot stuff using GnuPlot",'\0',"Output").value();
#endif
bool printFile = _parser.createParam(true,"printFile","Print statistics file",'\0',"Output").value();
// SOME PARSER PARAMETERS
// ----------------------
std::string dirName = _parser.getORcreateParam(std::string("Res"), "resDir",
"Directory to store DISK outputs",
'\0', "Output").value();
bool erase = _parser.getORcreateParam(true, "eraseDir",
"Erase files in dirName if any",
'\0', "Output").value();
bool gnuplots = _parser.getORcreateParam(true, "plots",
"Plot stuff using GnuPlot",
'\0', "Output").value();
bool printFile = _parser.getORcreateParam(true, "printFile",
"Print statistics file",
'\0', "Output").value();
eoValueParam<unsigned>& saveFrequencyParam
= _parser.getORcreateParam(unsigned(0), "saveFrequency",
"Save every F generation (0 = only final state, absent = never)",
'\0', "Persistence" );
eoValueParam<unsigned>& saveFrequencyParam =
_parser.createParam(unsigned(0),"saveFrequency","Save every F generation (0 = only final state, absent = never)",'\0',"Persistence" );
testDirRes(dirName, erase); // TRUE
// CREATE CHECKPOINT FROM eoContinue
@ -88,7 +96,7 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
Fit fit;
std::vector<std::string> fitness_descriptions = fit.getDescriptionVector();
unsigned nTerms = fitness_descriptions.size();
// STAT VALUES OF A POPULATION
// ---------------------------
@ -109,7 +117,7 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
_state.storeFunctor( bestvals[j] );
checkpoint->add( *bestvals[j] );
}
// STDOUT
// ------
eoStdoutMonitor *monitor = new eoStdoutMonitor(false);
@ -125,10 +133,9 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
// Add all average vals
for (unsigned l=0; l < nTerms; ++l)
monitor->add( *avgvals[l] );
// GNUPLOT
// -------
#if !defined(NO_GNUPLOT)
if (gnuplots ){
std::string stmp;
@ -144,7 +151,7 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
// and of course add it to the checkpoint
checkpoint->add(*fitSnapshot);
std::vector<eoGnuplot1DMonitor*> gnumonitors(nTerms, NULL );
std::vector<eoGnuplot1DMonitor*> gnumonitors(nTerms, NULL );
for (unsigned k=0; k < nTerms; ++k){
stmp = dirName + "/gnuplot_" + fitness_descriptions[k] + ".xg";
gnumonitors[k] = new eoGnuplot1DMonitor(stmp,true);
@ -156,7 +163,6 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
}
}
#endif
// WRITE STUFF TO FILE
// -------------------
@ -181,10 +187,10 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
// feed the state to state savers
if (_parser.isItThere(saveFrequencyParam)) {
unsigned freq = (saveFrequencyParam.value() > 0 ? saveFrequencyParam.value() : UINT_MAX );
std::string stmp = dirName + "/generations";
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
_state.storeFunctor(stateSaver1);
checkpoint->add(*stateSaver1);
}

View file

@ -44,22 +44,24 @@ bool testDirRes(std::string _dirName, bool _erase);
/** Of course, Fitness needs to be an eoParetoFitness!!!
*/
template <class EOT>
eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state, eoEvalFuncCounter<EOT>& _eval, eoContinue<EOT>& _continue)
eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
eoEvalFuncCounter<EOT>& _eval, eoContinue<EOT>& _continue)
{
// first, create a checkpoint from the eoContinue - and store in _state
eoCheckPoint<EOT> & checkpoint =
_state.storeFunctor(new eoCheckPoint<EOT>(_continue));
// first, create a checkpoint from the eoContinue - and store in _state
eoCheckPoint<EOT> & checkpoint = _state.storeFunctor(new eoCheckPoint<EOT>(_continue));
/////// get number of obectives from Fitness - not very elegant
typedef typename EOT::Fitness Fit;
Fit fit;
unsigned nObj = fit.size();
/////// get number of obectives from Fitness - not very elegant
typedef typename EOT::Fitness Fit;
Fit fit;
unsigned nObj = fit.size();
///////////////////
// Counters
//////////////////
// is nb Eval to be used as counter?
bool useEval = _parser.createParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output").value();
///////////////////
// Counters
//////////////////
// is nb Eval to be used as counter?
bool useEval = _parser.getORcreateParam(true, "useEval",
"Use nb of eval. as counter (vs nb of gen.)",
'\0', "Output").value();
// Create anyway a generation-counter parameter WARNING: not stored anywhere!!!
eoValueParam<unsigned> *generationCounter = new eoValueParam<unsigned>(0, "Gen.");
@ -70,9 +72,13 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
checkpoint.add(increment);
// dir for DISK output
std::string & dirName = _parser.getORcreateParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output - Disk").value();
std::string & dirName = _parser.getORcreateParam(std::string("Res"), "resDir",
"Directory to store DISK outputs",
'\0', "Output - Disk").value();
// shoudl we empty it if exists
eoValueParam<bool>& eraseParam = _parser.createParam(true, "eraseDir", "erase files in dirName if any", '\0', "Output - Disk");
eoValueParam<bool>& eraseParam = _parser.getORcreateParam(true, "eraseDir",
"erase files in dirName if any",
'\0', "Output - Disk");
bool dirOK = false; // not tested yet
/////////////////////////////////////////
@ -84,22 +90,20 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
* eoSortedPopStat : whole population - type std::string (!!)
*/
eoValueParam<eoParamParamType>& fPlotParam = _parser.createParam(
eoParamParamType("1(0,1)"), "frontFileFrequency",
eoValueParam<eoParamParamType>& fPlotParam
= _parser.getORcreateParam(eoParamParamType("1(0,1)"), "frontFileFrequency",
"File save frequency in objective spaces (std::pairs of comma-separated objectives " \
"in 1 single parentheses std::pair)",
'\0', "Output - Disk");
'\0', "Output - Disk");
#if !defined(NO_GNUPLOT)
bool boolGnuplot = _parser.createParam(false, "plotFront",
"Objective plots (requires corresponding files " \
"- see frontFileFrequency",
'\0', "Output - Graphical").value();
#endif
bool boolGnuplot = _parser.getORcreateParam(false, "plotFront",
"Objective plots (requires corresponding files " \
"- see frontFileFrequency",
'\0', "Output - Graphical").value();
eoParamParamType & fPlot = fPlotParam.value(); // std::pair<std::string,std::vector<std::string> >
unsigned frequency = atoi(fPlot.first.c_str());
if (frequency) // something to plot
eoParamParamType & fPlot = fPlotParam.value(); // std::pair<std::string,std::vector<std::string> >
unsigned frequency = atoi(fPlot.first.c_str());
if (frequency) // something to plot
{
unsigned nbPlot = fPlot.second.size();
if ( nbPlot % 2 ) // odd!
@ -145,20 +149,20 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
snapshot.add(*theStats[obj2]);
// and create the gnuplotter from the fileSnapshot
#if !defined(NO_GNUPLOT)
if (boolGnuplot)
if(boolGnuplot)
{
eoGnuplot1DSnapshot & plotSnapshot = _state.storeFunctor(new
eoGnuplot1DSnapshot(snapshot));
plotSnapshot.pointSize =3;
checkpoint.add(plotSnapshot);
}
#endif
}
}
// Dump of the whole population
//-----------------------------
bool printPop = _parser.createParam(false, "printPop", "Print sorted pop. every gen.", '\0', "Output").value();
bool printPop = _parser.getORcreateParam(false, "printPop",
"Print sorted pop. every gen.",
'\0', "Output").value();
eoSortedPopStat<EOT> * popStat;
if ( printPop ) // we do want pop dump
{
@ -217,7 +221,9 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
}
// save state every T seconds
eoValueParam<unsigned>& saveTimeIntervalParam = _parser.createParam(unsigned(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" );
eoValueParam<unsigned>& saveTimeIntervalParam
= _parser.getORcreateParam(unsigned(0), "saveTimeInterval",
"Save every T seconds (0 or absent = never)", '\0',"Persistence" );
if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0)
{
// first make sure dirName is OK