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

@ -26,8 +26,8 @@
#endif
#include <iostream>
#include <gp/eoParseTree.h>
#include <eo>
#include "gp/eoParseTree.h"
#include "eo"
using namespace gp_parse_tree;
using namespace std;
@ -130,7 +130,7 @@ int main(int argc, char *argv[])
checkPoint.add(avg);
checkPoint.add(best);
#if !defined(NO_GNUPLOT)
#ifdef HAVE_GNUPLOT
eoGnuplot1DMonitor gnuplotmonitor("gnuplotBestStats");
gnuplotmonitor.add(generationCounter);
gnuplotmonitor.add(best);

View file

@ -208,7 +208,6 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
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

View file

@ -49,17 +49,25 @@ 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.createParam(unsigned(0),"saveFrequency","Save every F generation (0 = only final state, absent = never)",'\0',"Persistence" );
eoValueParam<unsigned>& saveFrequencyParam
= _parser.getORcreateParam(unsigned(0), "saveFrequency",
"Save every F generation (0 = only final state, absent = never)",
'\0', "Persistence" );
testDirRes(dirName, erase); // TRUE
@ -128,7 +136,6 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
// GNUPLOT
// -------
#if !defined(NO_GNUPLOT)
if (gnuplots ){
std::string stmp;
@ -156,7 +163,6 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
}
}
#endif
// WRITE STUFF TO FILE
// -------------------

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

View file

@ -44,30 +44,34 @@ eoGnuplot::eoGnuplot(std::string _title, std::string _extra)
eoGnuplot::~eoGnuplot()
{
#ifdef HAVE_GNUPLOT
if( gpCom ) {
PipeComSend( gpCom, "quit\n" );
PipeComClose( gpCom );
gpCom =NULL;
}
#endif
}
void eoGnuplot::gnuplotCommand(const char *_command)
{
#ifdef HAVE_GNUPLOT
if(gpCom) {
PipeComSend( gpCom, _command );
PipeComSend( gpCom, "\n" );
}
#endif
}
void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
{
#ifdef HAVE_GNUPLOT
std::ostringstream os;
os << "250x150-0+" << numWindow*170;
numWindow++;
os << "250x150-0+" << 170 * numWindow++;
char *args[6];
args[0] = strdup( GNUPLOT_PROGRAM );
args[1] = strdup( "-geometry" );
@ -83,6 +87,7 @@ void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
PipeComSend( gpCom, _extra.c_str() );
PipeComSend( gpCom, "\n" );
}
#endif
}

View file

@ -29,29 +29,30 @@
#include <sstream>
#include "eoGnuplot1DMonitor.h"
#include "eoParam.h"
#include "utils/eoGnuplot1DMonitor.h"
#include "utils/eoParam.h"
eoMonitor& eoGnuplot1DMonitor::operator() (void)
{
// update file using the eoFileMonitor
eoFileMonitor::operator()();
// sends plot order to gnuplot
// assumes successive plots will have same nb of columns!!!
if (firstTime)
// update file using the eoFileMonitor
eoFileMonitor::operator()();
#ifdef HAVE_GNUPLOT
// sends plot order to gnuplot
// assumes successive plots will have same nb of columns!!!
if (firstTime)
{
FirstPlot();
firstTime = false;
FirstPlot();
firstTime = false;
}
else
else
{
if( gpCom ) {
PipeComSend( gpCom, "replot\n" );
}
if( gpCom ) {
PipeComSend( gpCom, "replot\n" );
}
}
return *this;
#endif
return *this;
}
@ -62,6 +63,7 @@ void eoGnuplot1DMonitor::FirstPlot()
{
throw std::runtime_error("Must have some stats to plot!\n");
}
#ifdef HAVE_GNUPLOT
std::ostringstream os;
os << "plot";
for (unsigned i=1; i<vec.size(); i++) {
@ -72,6 +74,7 @@ void eoGnuplot1DMonitor::FirstPlot()
}
os << '\n';
PipeComSend( gpCom, os.str().c_str());
#endif
}

View file

@ -1,5 +1,3 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// eoGnuplot1DMonitor.h
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
@ -49,6 +47,7 @@ everytime
class eoGnuplot1DMonitor : public eoFileMonitor, public eoGnuplot
{
public:
using eoMonitor::vec;
/** Constructor */
@ -70,4 +69,13 @@ public:
};
#endif
#endif // EO_eoGnuplot1DMonitor_H
// Local Variables:
// c-file-style: "Stroustrup"
// comment-column: 35
// fill-column: 80
// mode: C++
// End:

View file

@ -6,20 +6,22 @@
inline eoMonitor& eoGnuplot1DSnapshot::operator() (void)
eoMonitor& eoGnuplot1DSnapshot::operator()()
{
// update file using the eoFileMonitor method
eoFileSnapshot::operator()();
// update file using the eoFileMonitor method
eoFileSnapshot::operator()();
// sends plot order to gnuplot
//std::string buff; // need local memory
std::ostringstream os;
os << "set title 'Gen. " << getCounter() << "'; plot '"
// mk: had to use getFilename().c_str(), because it seems the string(stream) lib is screwed in gcc3.2
<< getFileName().c_str() << "' notitle with points ps " << pointSize;
os << std::endl;
PipeComSend( gpCom, os.str().c_str());
return (*this);
#ifdef HAVE_GNUPLOT
// sends plot order to gnuplot
std::ostringstream os;
os << "set title 'Gen. " << getCounter() << "'; plot '"
// mk: had to use getFilename().c_str(),
// because it seems the string(stream) lib is screwed in gcc3.2
<< getFileName().c_str() << "' notitle with points ps " << pointSize
<< std::endl;
PipeComSend(gpCom, os.str().c_str());
#endif
return *this;
}

View file

@ -53,7 +53,8 @@ class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
public:
// Ctor
eoGnuplot1DSnapshot(std::string _dirname, unsigned _frequency = 1,
std::string _filename = "gen", std::string _delim = " ", unsigned _counter = 0, bool _rmFiles = true) :
std::string _filename = "gen", std::string _delim = " ",
unsigned _counter = 0, bool _rmFiles = true) :
eoFileSnapshot(_dirname, _frequency, _filename, _delim, _counter, _rmFiles),
eoGnuplot(_filename,"set data style points"),
pointSize(5)
@ -88,7 +89,7 @@ class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
// Dtor
virtual ~eoGnuplot1DSnapshot(){}
virtual eoMonitor& operator() (void) ;
virtual eoMonitor& operator()();
/// Class name.
virtual std::string className() const { return "eoGnuplot1DSnapshot"; }
@ -96,20 +97,20 @@ class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
virtual void handleBounds(eoRealVectorBounds & _bounds)
{
std::ostringstream os;
// std::ostrstream os;
os << "set autoscale\nset yrange [" ;
if (_bounds.isMinBounded(0))
os << _bounds.minimum(0);
os << ":" ;
if (_bounds.isMaxBounded(0))
os << _bounds.maximum(0);
os << "]\n";
gnuplotCommand(os.str());
os << "set autoscale\nset yrange [" ;
if (_bounds.isMinBounded(0))
os << _bounds.minimum(0);
os << ":" ;
if (_bounds.isMaxBounded(0))
os << _bounds.maximum(0);
os << "]\n";
gnuplotCommand(os.str());
}
unsigned pointSize;
private:
protected:
unsigned pointSize;
};

View file

@ -91,24 +91,26 @@ int main(int argc, char* argv[])
if (!ptDirNameParam) // not found
throw runtime_error("Parameter resDir not found where it was supposed to be");
#if !defined(NO_GNUPLOT)
// now create the snapshot monitor
eoValueParam<bool>& plotDistribParam = parser.createParam(false, "plotDistrib", "Plot Distribution", '\0', "Output - Graphical");
eoValueParam<bool>& plotDistribParam = parser.getORcreateParam(false, "plotDistrib",
"Plot Distribution", '\0',
"Output - Graphical");
if (plotDistribParam.value())
{
unsigned frequency=1; // frequency of plots updates
eoGnuplot1DSnapshot *distribSnapshot = new eoGnuplot1DSnapshot(ptDirNameParam->value(), frequency, "distrib");
eoGnuplot1DSnapshot *distribSnapshot = new eoGnuplot1DSnapshot(ptDirNameParam->value(),
frequency, "distrib");
state.storeFunctor(distribSnapshot);
// add the distribution (it is an eoValueParam<vector<double> >)
distribSnapshot->add(distrib);
// and of course add it to the checkpoint
checkpoint.add(*distribSnapshot);
}
#endif
// the algorithm: EDA
// don't know where else to put the population size!
unsigned popSize = parser.createParam(unsigned(100), "popSize", "Population Size", 'P', "Algorithm").value();
unsigned popSize = parser.getORcreateParam(unsigned(100), "popSize",
"Population Size", 'P', "Algorithm").value();
eoSimpleEDA<Indi> eda(update, eval, popSize, checkpoint);
///// End of construction of the algorith
@ -125,14 +127,12 @@ int main(int argc, char* argv[])
distrib.printOn(std::cout);
std::cout << std::endl;
#if !defined(NO_GNUPLOT)
// wait - for graphical output
if (plotDistribParam.value())
{
string foo;
cin >> foo;
}
#endif
}
catch(std::exception& e)
{

View file

@ -205,7 +205,6 @@ void the_main(int argc, char* argv[])
cp.add(fitness0);
cp.add(fitness1);
#if !defined(NO_GNUPLOT)
eoGnuplot1DSnapshot snapshot("pareto");
//snapshot.with(eoGnuplot::Points(3));
@ -213,7 +212,6 @@ void the_main(int argc, char* argv[])
snapshot.add(fitness0);
snapshot.add(fitness1);
#endif
// the algo
eoEasyEA<eoDouble> ea(cp, eval, breeder, replace);

View file

@ -252,7 +252,7 @@ try
// those need to be pointers because of the if's
eoStdoutMonitor *myStdOutMonitor;
eoFileMonitor *myFileMonitor;
#if !defined(NO_GNUPLOT)
#ifdef HAVE_GNUPLOT
eoGnuplot1DMonitor *myGnuMonitor;
#endif
@ -296,7 +296,7 @@ try
myFileMonitor->add(myStat);
}
#if !defined(NO_GNUPLOT)
#ifdef HAVE_GNUPLOT
// should we PLOT it on StdOut ? (one dot per generation, incremental plot)
if (plotMyStructStat)
{