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,16 +3,16 @@
it under the terms of the GNU 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 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
jeggermo@liacs.nl
*/
@ -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;
@ -43,7 +43,7 @@ using namespace std;
typedef eoParseTree<FitnessType, Node > EoType;
typedef eoPop<EoType> Pop;
typedef eoPop<EoType> Pop;
//-----------------------------------------------------------------------------
@ -52,23 +52,23 @@ int main(int argc, char *argv[])
// the vector containing the possible nodes
vector<Node> initSequence;
// initialise parameters
Parameters parameter(argc, argv);
// initialise parameters
Parameters parameter(argc, argv);
// set the randomseed
rng.reseed(parameter.randomseed);
// Create a generation counter
eoValueParam<unsigned> generationCounter(0, "Gen.");
// Create an incrementor (sub-class of eoUpdater). Note that the
// parameter's value is passed by reference,
// Create an incrementor (sub-class of eoUpdater). Note that the
// parameter's value is passed by reference,
// so every time the incrementer is updated (every generation),
// the data in generationCounter will change.
eoIncrementor<unsigned> increment(generationCounter.value());
// create an instantiation of the fitness/evaluation function
// it initializes the initSequence vector
// the parameters are passed on as well
@ -76,44 +76,44 @@ int main(int argc, char *argv[])
// Depth Initializor, set for Ramped Half and Half Initialization
eoParseTreeDepthInit<FitnessType, Node> initializer(parameter.InitMaxDepth, initSequence, true, true);
// create the initial population
Pop pop(parameter.population_size, initializer);
// and evaluate the individuals
// and evaluate the individuals
apply<EoType>(eval, pop);
generationCounter.value()++; // set the generationCounter to 1
// define X-OVER
eoSubtreeXOver<FitnessType, Node> xover(parameter.MaxSize);
// define MUTATION
eoBranchMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
// eoExpansionMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
// eoCollapseSubtreeMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
// eoPointMutation<FitnessType, Node> mutation(initSequence);
// eoHoistMutation<FitnessType, Node> mutation;
// The operators are encapsulated into an eoTRansform object,
// The operators are encapsulated into an eoTRansform object,
// that performs sequentially crossover and mutation
eoSGATransform<EoType> transform(xover, parameter.xover_rate, mutation, parameter.mutation_rate);
// The robust tournament selection
// in our case 5-tournament selection
eoDetTournamentSelect<EoType> selectOne(parameter.tournamentsize);
// is now encapsulated in a eoSelectMany
eoSelectMany<EoType> select(selectOne, parameter.offspring_size, eo_is_an_integer);
// and the generational replacement
//eoGenerationalReplacement<EoType> replace;
// or the SteadtState replacment
//eoSSGAWorseReplacement<EoType> replace;
// or comma selection
eoCommaReplacement<EoType> replace;
// Terminators
eoGenContinue<EoType> term(parameter.nGenerations);
@ -124,13 +124,13 @@ int main(int argc, char *argv[])
eoBestFitnessStat<EoType> best;
// Add it to the checkpoint,
// Add it to the checkpoint,
// so the counter is updated (here, incremented) every generation
checkPoint.add(increment);
checkPoint.add(avg);
checkPoint.add(best);
#if !defined(NO_GNUPLOT)
#ifdef HAVE_GNUPLOT
eoGnuplot1DMonitor gnuplotmonitor("gnuplotBestStats");
gnuplotmonitor.add(generationCounter);
gnuplotmonitor.add(best);
@ -147,7 +147,7 @@ int main(int argc, char *argv[])
checkPoint.add(gnuplotmonitor);
checkPoint.add(gnuplotAvgmonitor);
#endif
#endif
// GP Generation
eoEasyEA<EoType> gp(checkPoint, eval, select, transform, replace);

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

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

@ -65,7 +65,7 @@ int main(int argc, char* argv[])
///// FIRST, problem or representation dependent stuff
//////////////////////////////////////////////////////
// The evaluation fn - encapsulated into an eval counter for output
// The evaluation fn - encapsulated into an eval counter for output
eoEvalFuncPtr<Indi, double> mainEval( binary_value<Indi>);
eoEvalFuncCounter<Indi> eval(mainEval);
@ -83,7 +83,7 @@ int main(int argc, char* argv[])
eoCheckPoint<Indi> & checkpoint = make_checkpoint(parser, state, eval, term);
// add a graphical output for the distribution
// first, get the direname from the parser
// first, get the direname from the parser
// it has been enetered in make_checkoint
eoParam* ptParam = parser.getParamWithLongName(string("resDir"));
@ -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

@ -17,7 +17,7 @@ main file BitEA in tutorial/Lesson4 dir.
Or you can wait until we do it :-)
*/
// Miscilaneous include and declaration
// Miscilaneous include and declaration
#include <iostream>
using namespace std;
@ -29,17 +29,17 @@ using namespace std;
// include here whatever specific files for your representation
// Basically, this should include at least the following
/** definition of representation:
/** definition of representation:
* class eoMyStruct MUST derive from EO<FitT> for some fitness
*/
#include "eoMyStruct.h"
/** definition of initilizqtion:
/** definition of initilizqtion:
* class eoMyStructInit MUST derive from eoInit<eoMyStruct>
*/
#include "eoMyStructInit.h"
/** definition of evaluation:
/** definition of evaluation:
* class eoMyStructEvalFunc MUST derive from eoEvalFunc<eoMyStruct>
* and should test for validity before doing any computation
* see tutorial/Templates/evalFunc.tmpl
@ -47,7 +47,7 @@ using namespace std;
#include "eoMyStructEvalFunc.h"
/** definitions of operators: write as many classes as types of operators
* and include them here. In this simple example,
* and include them here. In this simple example,
* one crossover (2->2) and one mutation (1->1) operators are used
*/
#include "eoMyStructQuadCrossover.h"
@ -61,17 +61,17 @@ using namespace std;
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
// START fitness type: double or eoMaximizingFitness if you are maximizing
// eoMinimizingFitness if you are minimizing
typedef eoMinimizingFitness MyFitT ; // type of fitness
typedef eoMinimizingFitness MyFitT ; // type of fitness
// END fitness type
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
// Then define your EO objects using that fitness type
typedef eoMyStruct<MyFitT> Indi; // ***MUST*** derive from EO
typedef eoMyStruct<MyFitT> Indi; // ***MUST*** derive from EO
// Use existing modules to define representation independent routines
// how to initialize the population
// how to initialize the population
// it IS representation independent if an eoInit is given
#include <do/make_pop.h>
eoPop<Indi >& make_pop(eoParser& _parser, eoState& _state, eoInit<Indi> & _init)
@ -88,7 +88,7 @@ eoContinue<Indi>& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCo
// outputs (stats, population dumps, ...)
#include <do/make_checkpoint.h>
eoCheckPoint<Indi>& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi>& _eval, eoContinue<Indi>& _continue)
eoCheckPoint<Indi>& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi>& _eval, eoContinue<Indi>& _continue)
{
return do_make_checkpoint(_parser, _state, _eval, _continue);
}
@ -100,7 +100,7 @@ eoAlgo<Indi>& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<I
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op, _dist);
}
// simple call to the algo. stays there for consistency reasons
// simple call to the algo. stays there for consistency reasons
// no template for that one
#include <do/make_run.h>
// the instanciating fitnesses
@ -120,40 +120,40 @@ int main(int argc, char* argv[])
try
{
eoParser parser(argc, argv); // for user-parameter reading
eoState state; // keeps all things allocated
// The fitness
//////////////
eoMyStructEvalFunc<Indi> plainEval/* (varType _anyVariable) */;
// turn that object into an evaluation counter
eoEvalFuncCounter<Indi> eval(plainEval);
// a genotype initializer
eoMyStructInit<Indi> init;
// or, if you need some parameters, you might as well
// or, if you need some parameters, you might as well
// - write a constructor of the eoMyStructInit that uses a parser
// - call it from here:
// eoMyStructInit<Indi> init(parser);
// if you want to do sharing, you'll need a distance.
// see file utils/eoDistance.h
//
// IF you representation has an operator[]() double-castable,
// IF you representation has an operator[]() double-castable,
// then you can use for instance the quadratic distance (L2 norm)
// eoQuadDistance<Indi> dist;
// or the Hamming distance (L1 norm)
// eoHammingDistance<Indi> dist;
// Build the variation operator (any seq/prop construct)
// here, a simple example with only 1 crossover (2->2, a QuadOp) and
// one mutation, is given.
// Hints to have choice among multiple crossovers and mutations are given
// A (first) crossover (possibly use the parser in its Ctor)
eoMyStructQuadCrossover<Indi> cross /* (eoParser parser) */;
// IF MORE THAN ONE:
// read its relative rate in the combination
@ -167,9 +167,9 @@ try
// 2- include that file here together with eoMyStructQuadCrossover above
// 3- uncomment and duplicate the following lines:
//
// eoMyStructSecondCrossover<Indi> cross2(eoParser parser);
// double cross2Rate = parser.createParam(1.0, "cross2Rate", "Relative rate for crossover 2", '2', "Variation Operators").value();
// cross.add(cross2, cross2Rate);
// eoMyStructSecondCrossover<Indi> cross2(eoParser parser);
// double cross2Rate = parser.createParam(1.0, "cross2Rate", "Relative rate for crossover 2", '2', "Variation Operators").value();
// cross.add(cross2, cross2Rate);
// NOTE: if you want some gentle output, the last one shoudl be like
// cross.add(cross, crossXXXRate, true);
@ -192,9 +192,9 @@ try
// 2- include that file here together with eoMyStructMutation above
// 3- uncomment and duplicate the following lines:
//
// eoMyStructSecondMutation<Indi> mut2(eoParser parser);
// double mut2Rate = parser.createParam(1.0, "mut2Rate", "Relative rate for mutation 2", '2', "Variation Operators").value();
// mut.add(mut2, mut2Rate);
// eoMyStructSecondMutation<Indi> mut2(eoParser parser);
// double mut2Rate = parser.createParam(1.0, "mut2Rate", "Relative rate for mutation 2", '2', "Variation Operators").value();
// mut.add(mut2, mut2Rate);
// NOTE: if you want some gentle output, the last one shoudl be like
// mut.add(mut, mutXXXRate, true);
@ -217,7 +217,7 @@ try
eoSGAGenOp<Indi> op(cross, pCross, mut, pMut);
//// Now some representation-independent things
//// Now some representation-independent things
//
// You do not need to modify anything beyond this point
// unless you want to add specific statistics to the checkpoint
@ -240,7 +240,7 @@ try
// if uncommented, it is assumed that you will want to print some stat.
// if not, then the following objects will be created uselessly - but what the heck!
eoMyStructStat<Indi> myStat; // or maybe myStat(parser);
eoMyStructStat<Indi> myStat; // or maybe myStat(parser);
checkpoint.add(myStat);
// This one is probably redundant with the one in make_checkpoint, but w.t.h.
eoIncrementorParam<unsigned> generationCounter("Gen.");
@ -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
@ -283,7 +283,7 @@ try
// should we write it to a file ?
if (fileMyStructStat)
{
// the file name is hard-coded - of course you can read
// the file name is hard-coded - of course you can read
// a string parameter in the parser if you prefer
myFileMonitor = new eoFileMonitor(dirName + "myStat.xg");
// don't forget to store the memory in the state
@ -296,14 +296,14 @@ 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)
{
myGnuMonitor = new eoGnuplot1DMonitor(dirName+"plot_myStat.xg",minimizing_fitness<Indi>());
// NOTE: you cand send commands to gnuplot at any time with the method
// myGnuMonitor->gnuplotCommand(string)
// par exemple, gnuplotCommand("set logscale y")
// par exemple, gnuplotCommand("set logscale y")
// don't forget to store the memory in the state
state.storeFunctor(myGnuMonitor);