finish the handling of gnuplot completely at build-time.
No gnuplot-ifs in headers anymore.
This commit is contained in:
parent
4eb298ac73
commit
afc0659e35
12 changed files with 219 additions and 192 deletions
|
|
@ -3,16 +3,16 @@
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Lesser General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this library; if not, write to the Free Software
|
along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
jeggermo@liacs.nl
|
jeggermo@liacs.nl
|
||||||
*/
|
*/
|
||||||
|
|
@ -26,8 +26,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <gp/eoParseTree.h>
|
#include "gp/eoParseTree.h"
|
||||||
#include <eo>
|
#include "eo"
|
||||||
|
|
||||||
using namespace gp_parse_tree;
|
using namespace gp_parse_tree;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
@ -43,7 +43,7 @@ using namespace std;
|
||||||
|
|
||||||
|
|
||||||
typedef eoParseTree<FitnessType, Node > EoType;
|
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
|
// the vector containing the possible nodes
|
||||||
vector<Node> initSequence;
|
vector<Node> initSequence;
|
||||||
|
|
||||||
// initialise parameters
|
// initialise parameters
|
||||||
Parameters parameter(argc, argv);
|
Parameters parameter(argc, argv);
|
||||||
|
|
||||||
// set the randomseed
|
// set the randomseed
|
||||||
rng.reseed(parameter.randomseed);
|
rng.reseed(parameter.randomseed);
|
||||||
|
|
||||||
// Create a generation counter
|
// Create a generation counter
|
||||||
eoValueParam<unsigned> generationCounter(0, "Gen.");
|
eoValueParam<unsigned> generationCounter(0, "Gen.");
|
||||||
|
|
||||||
// Create an incrementor (sub-class of eoUpdater). Note that the
|
// Create an incrementor (sub-class of eoUpdater). Note that the
|
||||||
// parameter's value is passed by reference,
|
// parameter's value is passed by reference,
|
||||||
// so every time the incrementer is updated (every generation),
|
// so every time the incrementer is updated (every generation),
|
||||||
// the data in generationCounter will change.
|
// the data in generationCounter will change.
|
||||||
eoIncrementor<unsigned> increment(generationCounter.value());
|
eoIncrementor<unsigned> increment(generationCounter.value());
|
||||||
|
|
||||||
|
|
||||||
// create an instantiation of the fitness/evaluation function
|
// create an instantiation of the fitness/evaluation function
|
||||||
// it initializes the initSequence vector
|
// it initializes the initSequence vector
|
||||||
// the parameters are passed on as well
|
// 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
|
// Depth Initializor, set for Ramped Half and Half Initialization
|
||||||
eoParseTreeDepthInit<FitnessType, Node> initializer(parameter.InitMaxDepth, initSequence, true, true);
|
eoParseTreeDepthInit<FitnessType, Node> initializer(parameter.InitMaxDepth, initSequence, true, true);
|
||||||
|
|
||||||
// create the initial population
|
// create the initial population
|
||||||
Pop pop(parameter.population_size, initializer);
|
Pop pop(parameter.population_size, initializer);
|
||||||
|
|
||||||
// and evaluate the individuals
|
// and evaluate the individuals
|
||||||
apply<EoType>(eval, pop);
|
apply<EoType>(eval, pop);
|
||||||
|
|
||||||
generationCounter.value()++; // set the generationCounter to 1
|
generationCounter.value()++; // set the generationCounter to 1
|
||||||
|
|
||||||
|
|
||||||
// define X-OVER
|
// define X-OVER
|
||||||
|
|
||||||
eoSubtreeXOver<FitnessType, Node> xover(parameter.MaxSize);
|
eoSubtreeXOver<FitnessType, Node> xover(parameter.MaxSize);
|
||||||
|
|
||||||
// define MUTATION
|
// define MUTATION
|
||||||
eoBranchMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
|
eoBranchMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
|
||||||
// eoExpansionMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
|
// eoExpansionMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
|
||||||
// eoCollapseSubtreeMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
|
// eoCollapseSubtreeMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
|
||||||
// eoPointMutation<FitnessType, Node> mutation(initSequence);
|
// eoPointMutation<FitnessType, Node> mutation(initSequence);
|
||||||
// eoHoistMutation<FitnessType, Node> mutation;
|
// 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
|
// that performs sequentially crossover and mutation
|
||||||
eoSGATransform<EoType> transform(xover, parameter.xover_rate, mutation, parameter.mutation_rate);
|
eoSGATransform<EoType> transform(xover, parameter.xover_rate, mutation, parameter.mutation_rate);
|
||||||
|
|
||||||
// The robust tournament selection
|
// The robust tournament selection
|
||||||
// in our case 5-tournament selection
|
// in our case 5-tournament selection
|
||||||
eoDetTournamentSelect<EoType> selectOne(parameter.tournamentsize);
|
eoDetTournamentSelect<EoType> selectOne(parameter.tournamentsize);
|
||||||
// is now encapsulated in a eoSelectMany
|
// is now encapsulated in a eoSelectMany
|
||||||
eoSelectMany<EoType> select(selectOne, parameter.offspring_size, eo_is_an_integer);
|
eoSelectMany<EoType> select(selectOne, parameter.offspring_size, eo_is_an_integer);
|
||||||
|
|
||||||
// and the generational replacement
|
// and the generational replacement
|
||||||
//eoGenerationalReplacement<EoType> replace;
|
//eoGenerationalReplacement<EoType> replace;
|
||||||
// or the SteadtState replacment
|
// or the SteadtState replacment
|
||||||
//eoSSGAWorseReplacement<EoType> replace;
|
//eoSSGAWorseReplacement<EoType> replace;
|
||||||
// or comma selection
|
// or comma selection
|
||||||
eoCommaReplacement<EoType> replace;
|
eoCommaReplacement<EoType> replace;
|
||||||
|
|
||||||
// Terminators
|
// Terminators
|
||||||
eoGenContinue<EoType> term(parameter.nGenerations);
|
eoGenContinue<EoType> term(parameter.nGenerations);
|
||||||
|
|
||||||
|
|
@ -124,13 +124,13 @@ int main(int argc, char *argv[])
|
||||||
eoBestFitnessStat<EoType> best;
|
eoBestFitnessStat<EoType> best;
|
||||||
|
|
||||||
|
|
||||||
// Add it to the checkpoint,
|
// Add it to the checkpoint,
|
||||||
// so the counter is updated (here, incremented) every generation
|
// so the counter is updated (here, incremented) every generation
|
||||||
checkPoint.add(increment);
|
checkPoint.add(increment);
|
||||||
checkPoint.add(avg);
|
checkPoint.add(avg);
|
||||||
checkPoint.add(best);
|
checkPoint.add(best);
|
||||||
|
|
||||||
#if !defined(NO_GNUPLOT)
|
#ifdef HAVE_GNUPLOT
|
||||||
eoGnuplot1DMonitor gnuplotmonitor("gnuplotBestStats");
|
eoGnuplot1DMonitor gnuplotmonitor("gnuplotBestStats");
|
||||||
gnuplotmonitor.add(generationCounter);
|
gnuplotmonitor.add(generationCounter);
|
||||||
gnuplotmonitor.add(best);
|
gnuplotmonitor.add(best);
|
||||||
|
|
@ -147,7 +147,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
checkPoint.add(gnuplotmonitor);
|
checkPoint.add(gnuplotmonitor);
|
||||||
checkPoint.add(gnuplotAvgmonitor);
|
checkPoint.add(gnuplotAvgmonitor);
|
||||||
#endif
|
#endif
|
||||||
// GP Generation
|
// GP Generation
|
||||||
eoEasyEA<EoType> gp(checkPoint, eval, select, transform, replace);
|
eoEasyEA<EoType> gp(checkPoint, eval, select, transform, replace);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// make_checkpoint.h
|
// make_checkpoint.h
|
||||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000
|
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000
|
||||||
/*
|
/*
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
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
|
// first, create a checkpoint from the eoContinue
|
||||||
eoCheckPoint<EOT> *checkpoint = new eoCheckPoint<EOT>(_continue);
|
eoCheckPoint<EOT> *checkpoint = new eoCheckPoint<EOT>(_continue);
|
||||||
_state.storeFunctor(checkpoint);
|
_state.storeFunctor(checkpoint);
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// Counters
|
// Counters
|
||||||
//////////////////
|
//////////////////
|
||||||
|
|
@ -55,14 +55,14 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
|
||||||
|
|
||||||
// if we want the time, we need an eoTimeCounter
|
// if we want the time, we need an eoTimeCounter
|
||||||
eoTimeCounter * tCounter = NULL;
|
eoTimeCounter * tCounter = NULL;
|
||||||
|
|
||||||
// Create anyway a generation-counter
|
// Create anyway a generation-counter
|
||||||
// Recent change (03/2002): it is now an eoIncrementorParam, both
|
// Recent change (03/2002): it is now an eoIncrementorParam, both
|
||||||
// a parameter AND updater so you can store it into the eoState
|
// a parameter AND updater so you can store it into the eoState
|
||||||
eoIncrementorParam<unsigned> *generationCounter = new eoIncrementorParam<unsigned>("Gen.");
|
eoIncrementorParam<unsigned> *generationCounter = new eoIncrementorParam<unsigned>("Gen.");
|
||||||
// store it in the state
|
// store it in the state
|
||||||
_state.storeFunctor(generationCounter);
|
_state.storeFunctor(generationCounter);
|
||||||
// And add it to the checkpoint,
|
// And add it to the checkpoint,
|
||||||
checkpoint->add(*generationCounter);
|
checkpoint->add(*generationCounter);
|
||||||
|
|
||||||
// dir for DISK output
|
// 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");
|
eoValueParam<bool>& fileBestParam = _parser.createParam(false, "fileBestStat", "Output bes/avg/std to file", '\0', "Output - Disk");
|
||||||
|
|
||||||
eoBestFitnessStat<EOT> *bestStat = NULL;
|
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
|
// we need the bestStat for at least one of the 3 above
|
||||||
{
|
{
|
||||||
bestStat = new eoBestFitnessStat<EOT>;
|
bestStat = new eoBestFitnessStat<EOT>;
|
||||||
|
|
@ -147,11 +147,11 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
|
||||||
// The monitors
|
// The monitors
|
||||||
///////////////
|
///////////////
|
||||||
// do we want an eoStdoutMonitor?
|
// do we want an eoStdoutMonitor?
|
||||||
bool needStdoutMonitor = printBestParam.value()
|
bool needStdoutMonitor = printBestParam.value()
|
||||||
|| printPopParam.value() ;
|
|| printPopParam.value() ;
|
||||||
|
|
||||||
// The Stdout monitor will print parameters to the screen ...
|
// The Stdout monitor will print parameters to the screen ...
|
||||||
if ( needStdoutMonitor )
|
if ( needStdoutMonitor )
|
||||||
{
|
{
|
||||||
eoStdoutMonitor *monitor = new eoStdoutMonitor(false);
|
eoStdoutMonitor *monitor = new eoStdoutMonitor(false);
|
||||||
_state.storeFunctor(monitor);
|
_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
|
// first handle the dir test - if we need at least one file
|
||||||
if ( ( fileBestParam.value() || plotBestParam.value() ||
|
if ( ( fileBestParam.value() || plotBestParam.value() ||
|
||||||
plotHistogramParam.value() )
|
plotHistogramParam.value() )
|
||||||
&& !dirOK ) // just in case we add something before
|
&& !dirOK ) // just in case we add something before
|
||||||
dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE
|
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";
|
// std::cout << "On met timecounter\n";
|
||||||
fileMonitor->add(*tCounter);
|
fileMonitor->add(*tCounter);
|
||||||
}
|
}
|
||||||
fileMonitor->add(*bestStat);
|
fileMonitor->add(*bestStat);
|
||||||
fileMonitor->add(*secondStat);
|
fileMonitor->add(*secondStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(NO_GNUPLOT)
|
|
||||||
if (plotBestParam.value()) // an eoGnuplot1DMonitor for best & average
|
if (plotBestParam.value()) // an eoGnuplot1DMonitor for best & average
|
||||||
{
|
{
|
||||||
std::string stmp = dirNameParam.value() + "/gnu_best.xg";
|
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
|
// and of course add it to the checkpoint
|
||||||
checkpoint->add(*fitSnapshot);
|
checkpoint->add(*fitSnapshot);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
// State savers
|
// State savers
|
||||||
|
|
@ -263,12 +261,12 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
|
||||||
#else
|
#else
|
||||||
std::string stmp = dirNameParam.value() + "/generations";
|
std::string stmp = dirNameParam.value() + "/generations";
|
||||||
#endif
|
#endif
|
||||||
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
|
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
|
||||||
_state.storeFunctor(stateSaver1);
|
_state.storeFunctor(stateSaver1);
|
||||||
checkpoint->add(*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" );
|
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)
|
if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0)
|
||||||
{
|
{
|
||||||
|
|
@ -281,7 +279,7 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
|
||||||
#else
|
#else
|
||||||
std::string stmp = dirNameParam.value() + "/time";
|
std::string stmp = dirNameParam.value() + "/time";
|
||||||
#endif
|
#endif
|
||||||
eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp);
|
eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp);
|
||||||
_state.storeFunctor(stateSaver2);
|
_state.storeFunctor(stateSaver2);
|
||||||
checkpoint->add(*stateSaver2);
|
checkpoint->add(*stateSaver2);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,16 +11,16 @@
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
version 2 of the License, or (at your option) any later version.
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Lesser General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
Marc.Schoenauer@inria.fr
|
Marc.Schoenauer@inria.fr
|
||||||
mak@dhi.dk
|
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)
|
eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _state, eoEvalFuncCounter<EOT>& _eval, eoContinue<EOT>& _continue)
|
||||||
{
|
{
|
||||||
|
|
||||||
// SOME PARSER PARAMETERS
|
// SOME PARSER PARAMETERS
|
||||||
// ----------------------
|
// ----------------------
|
||||||
std::string dirName = _parser.createParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output").value();
|
std::string dirName = _parser.getORcreateParam(std::string("Res"), "resDir",
|
||||||
bool erase = _parser.createParam(true, "eraseDir", "Erase files in dirName if any", '\0', "Output").value();
|
"Directory to store DISK outputs",
|
||||||
#if !defined(NO_GNUPLOT)
|
'\0', "Output").value();
|
||||||
bool gnuplots = _parser.createParam(true,"plots","Plot stuff using GnuPlot",'\0',"Output").value();
|
bool erase = _parser.getORcreateParam(true, "eraseDir",
|
||||||
#endif
|
"Erase files in dirName if any",
|
||||||
bool printFile = _parser.createParam(true,"printFile","Print statistics file",'\0',"Output").value();
|
'\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
|
testDirRes(dirName, erase); // TRUE
|
||||||
|
|
||||||
// CREATE CHECKPOINT FROM eoContinue
|
// CREATE CHECKPOINT FROM eoContinue
|
||||||
|
|
@ -88,7 +96,7 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
|
||||||
Fit fit;
|
Fit fit;
|
||||||
std::vector<std::string> fitness_descriptions = fit.getDescriptionVector();
|
std::vector<std::string> fitness_descriptions = fit.getDescriptionVector();
|
||||||
unsigned nTerms = fitness_descriptions.size();
|
unsigned nTerms = fitness_descriptions.size();
|
||||||
|
|
||||||
// STAT VALUES OF A POPULATION
|
// STAT VALUES OF A POPULATION
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
||||||
|
|
@ -109,7 +117,7 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
|
||||||
_state.storeFunctor( bestvals[j] );
|
_state.storeFunctor( bestvals[j] );
|
||||||
checkpoint->add( *bestvals[j] );
|
checkpoint->add( *bestvals[j] );
|
||||||
}
|
}
|
||||||
|
|
||||||
// STDOUT
|
// STDOUT
|
||||||
// ------
|
// ------
|
||||||
eoStdoutMonitor *monitor = new eoStdoutMonitor(false);
|
eoStdoutMonitor *monitor = new eoStdoutMonitor(false);
|
||||||
|
|
@ -125,10 +133,9 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
|
||||||
// Add all average vals
|
// Add all average vals
|
||||||
for (unsigned l=0; l < nTerms; ++l)
|
for (unsigned l=0; l < nTerms; ++l)
|
||||||
monitor->add( *avgvals[l] );
|
monitor->add( *avgvals[l] );
|
||||||
|
|
||||||
// GNUPLOT
|
// GNUPLOT
|
||||||
// -------
|
// -------
|
||||||
#if !defined(NO_GNUPLOT)
|
|
||||||
if (gnuplots ){
|
if (gnuplots ){
|
||||||
std::string stmp;
|
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
|
// and of course add it to the checkpoint
|
||||||
checkpoint->add(*fitSnapshot);
|
checkpoint->add(*fitSnapshot);
|
||||||
|
|
||||||
std::vector<eoGnuplot1DMonitor*> gnumonitors(nTerms, NULL );
|
std::vector<eoGnuplot1DMonitor*> gnumonitors(nTerms, NULL );
|
||||||
for (unsigned k=0; k < nTerms; ++k){
|
for (unsigned k=0; k < nTerms; ++k){
|
||||||
stmp = dirName + "/gnuplot_" + fitness_descriptions[k] + ".xg";
|
stmp = dirName + "/gnuplot_" + fitness_descriptions[k] + ".xg";
|
||||||
gnumonitors[k] = new eoGnuplot1DMonitor(stmp,true);
|
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
|
// WRITE STUFF TO FILE
|
||||||
// -------------------
|
// -------------------
|
||||||
|
|
@ -181,10 +187,10 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
|
||||||
// feed the state to state savers
|
// feed the state to state savers
|
||||||
|
|
||||||
if (_parser.isItThere(saveFrequencyParam)) {
|
if (_parser.isItThere(saveFrequencyParam)) {
|
||||||
|
|
||||||
unsigned freq = (saveFrequencyParam.value() > 0 ? saveFrequencyParam.value() : UINT_MAX );
|
unsigned freq = (saveFrequencyParam.value() > 0 ? saveFrequencyParam.value() : UINT_MAX );
|
||||||
std::string stmp = dirName + "/generations";
|
std::string stmp = dirName + "/generations";
|
||||||
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
|
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
|
||||||
_state.storeFunctor(stateSaver1);
|
_state.storeFunctor(stateSaver1);
|
||||||
checkpoint->add(*stateSaver1);
|
checkpoint->add(*stateSaver1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,22 +44,24 @@ bool testDirRes(std::string _dirName, bool _erase);
|
||||||
/** Of course, Fitness needs to be an eoParetoFitness!!!
|
/** Of course, Fitness needs to be an eoParetoFitness!!!
|
||||||
*/
|
*/
|
||||||
template <class EOT>
|
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
|
// first, create a checkpoint from the eoContinue - and store in _state
|
||||||
eoCheckPoint<EOT> & checkpoint =
|
eoCheckPoint<EOT> & checkpoint = _state.storeFunctor(new eoCheckPoint<EOT>(_continue));
|
||||||
_state.storeFunctor(new eoCheckPoint<EOT>(_continue));
|
|
||||||
|
|
||||||
/////// get number of obectives from Fitness - not very elegant
|
/////// get number of obectives from Fitness - not very elegant
|
||||||
typedef typename EOT::Fitness Fit;
|
typedef typename EOT::Fitness Fit;
|
||||||
Fit fit;
|
Fit fit;
|
||||||
unsigned nObj = fit.size();
|
unsigned nObj = fit.size();
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// Counters
|
// Counters
|
||||||
//////////////////
|
//////////////////
|
||||||
// is nb Eval to be used as counter?
|
// 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();
|
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!!!
|
// Create anyway a generation-counter parameter WARNING: not stored anywhere!!!
|
||||||
eoValueParam<unsigned> *generationCounter = new eoValueParam<unsigned>(0, "Gen.");
|
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);
|
checkpoint.add(increment);
|
||||||
|
|
||||||
// dir for DISK output
|
// 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
|
// 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
|
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 (!!)
|
* eoSortedPopStat : whole population - type std::string (!!)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
eoValueParam<eoParamParamType>& fPlotParam = _parser.createParam(
|
eoValueParam<eoParamParamType>& fPlotParam
|
||||||
eoParamParamType("1(0,1)"), "frontFileFrequency",
|
= _parser.getORcreateParam(eoParamParamType("1(0,1)"), "frontFileFrequency",
|
||||||
"File save frequency in objective spaces (std::pairs of comma-separated objectives " \
|
"File save frequency in objective spaces (std::pairs of comma-separated objectives " \
|
||||||
"in 1 single parentheses std::pair)",
|
"in 1 single parentheses std::pair)",
|
||||||
'\0', "Output - Disk");
|
'\0', "Output - Disk");
|
||||||
|
|
||||||
#if !defined(NO_GNUPLOT)
|
bool boolGnuplot = _parser.getORcreateParam(false, "plotFront",
|
||||||
bool boolGnuplot = _parser.createParam(false, "plotFront",
|
"Objective plots (requires corresponding files " \
|
||||||
"Objective plots (requires corresponding files " \
|
"- see frontFileFrequency",
|
||||||
"- see frontFileFrequency",
|
'\0', "Output - Graphical").value();
|
||||||
'\0', "Output - Graphical").value();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
eoParamParamType & fPlot = fPlotParam.value(); // std::pair<std::string,std::vector<std::string> >
|
eoParamParamType & fPlot = fPlotParam.value(); // std::pair<std::string,std::vector<std::string> >
|
||||||
unsigned frequency = atoi(fPlot.first.c_str());
|
unsigned frequency = atoi(fPlot.first.c_str());
|
||||||
if (frequency) // something to plot
|
if (frequency) // something to plot
|
||||||
{
|
{
|
||||||
unsigned nbPlot = fPlot.second.size();
|
unsigned nbPlot = fPlot.second.size();
|
||||||
if ( nbPlot % 2 ) // odd!
|
if ( nbPlot % 2 ) // odd!
|
||||||
|
|
@ -145,20 +149,20 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
|
||||||
snapshot.add(*theStats[obj2]);
|
snapshot.add(*theStats[obj2]);
|
||||||
|
|
||||||
// and create the gnuplotter from the fileSnapshot
|
// and create the gnuplotter from the fileSnapshot
|
||||||
#if !defined(NO_GNUPLOT)
|
if(boolGnuplot)
|
||||||
if (boolGnuplot)
|
|
||||||
{
|
{
|
||||||
eoGnuplot1DSnapshot & plotSnapshot = _state.storeFunctor(new
|
eoGnuplot1DSnapshot & plotSnapshot = _state.storeFunctor(new
|
||||||
eoGnuplot1DSnapshot(snapshot));
|
eoGnuplot1DSnapshot(snapshot));
|
||||||
plotSnapshot.pointSize =3;
|
plotSnapshot.pointSize =3;
|
||||||
checkpoint.add(plotSnapshot);
|
checkpoint.add(plotSnapshot);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Dump of the whole population
|
// 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;
|
eoSortedPopStat<EOT> * popStat;
|
||||||
if ( printPop ) // we do want pop dump
|
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
|
// 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)
|
if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0)
|
||||||
{
|
{
|
||||||
// first make sure dirName is OK
|
// first make sure dirName is OK
|
||||||
|
|
|
||||||
|
|
@ -44,30 +44,34 @@ eoGnuplot::eoGnuplot(std::string _title, std::string _extra)
|
||||||
|
|
||||||
eoGnuplot::~eoGnuplot()
|
eoGnuplot::~eoGnuplot()
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_GNUPLOT
|
||||||
if( gpCom ) {
|
if( gpCom ) {
|
||||||
PipeComSend( gpCom, "quit\n" );
|
PipeComSend( gpCom, "quit\n" );
|
||||||
PipeComClose( gpCom );
|
PipeComClose( gpCom );
|
||||||
gpCom =NULL;
|
gpCom =NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void eoGnuplot::gnuplotCommand(const char *_command)
|
void eoGnuplot::gnuplotCommand(const char *_command)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_GNUPLOT
|
||||||
if(gpCom) {
|
if(gpCom) {
|
||||||
PipeComSend( gpCom, _command );
|
PipeComSend( gpCom, _command );
|
||||||
PipeComSend( gpCom, "\n" );
|
PipeComSend( gpCom, "\n" );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
|
void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_GNUPLOT
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "250x150-0+" << numWindow*170;
|
os << "250x150-0+" << 170 * numWindow++;
|
||||||
numWindow++;
|
|
||||||
char *args[6];
|
char *args[6];
|
||||||
args[0] = strdup( GNUPLOT_PROGRAM );
|
args[0] = strdup( GNUPLOT_PROGRAM );
|
||||||
args[1] = strdup( "-geometry" );
|
args[1] = strdup( "-geometry" );
|
||||||
|
|
@ -83,6 +87,7 @@ void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
|
||||||
PipeComSend( gpCom, _extra.c_str() );
|
PipeComSend( gpCom, _extra.c_str() );
|
||||||
PipeComSend( gpCom, "\n" );
|
PipeComSend( gpCom, "\n" );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,29 +29,30 @@
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "eoGnuplot1DMonitor.h"
|
#include "utils/eoGnuplot1DMonitor.h"
|
||||||
#include "eoParam.h"
|
#include "utils/eoParam.h"
|
||||||
|
|
||||||
|
|
||||||
eoMonitor& eoGnuplot1DMonitor::operator() (void)
|
eoMonitor& eoGnuplot1DMonitor::operator() (void)
|
||||||
{
|
{
|
||||||
// update file using the eoFileMonitor
|
// update file using the eoFileMonitor
|
||||||
eoFileMonitor::operator()();
|
eoFileMonitor::operator()();
|
||||||
|
#ifdef HAVE_GNUPLOT
|
||||||
// sends plot order to gnuplot
|
// sends plot order to gnuplot
|
||||||
// assumes successive plots will have same nb of columns!!!
|
// assumes successive plots will have same nb of columns!!!
|
||||||
if (firstTime)
|
if (firstTime)
|
||||||
{
|
{
|
||||||
FirstPlot();
|
FirstPlot();
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( gpCom ) {
|
if( gpCom ) {
|
||||||
PipeComSend( gpCom, "replot\n" );
|
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");
|
throw std::runtime_error("Must have some stats to plot!\n");
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_GNUPLOT
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "plot";
|
os << "plot";
|
||||||
for (unsigned i=1; i<vec.size(); i++) {
|
for (unsigned i=1; i<vec.size(); i++) {
|
||||||
|
|
@ -72,6 +74,7 @@ void eoGnuplot1DMonitor::FirstPlot()
|
||||||
}
|
}
|
||||||
os << '\n';
|
os << '\n';
|
||||||
PipeComSend( gpCom, os.str().c_str());
|
PipeComSend( gpCom, os.str().c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eoGnuplot1DMonitor.h
|
// eoGnuplot1DMonitor.h
|
||||||
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
|
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
|
||||||
|
|
@ -49,6 +47,7 @@ everytime
|
||||||
class eoGnuplot1DMonitor : public eoFileMonitor, public eoGnuplot
|
class eoGnuplot1DMonitor : public eoFileMonitor, public eoGnuplot
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using eoMonitor::vec;
|
using eoMonitor::vec;
|
||||||
|
|
||||||
/** Constructor */
|
/** 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:
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,22 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline eoMonitor& eoGnuplot1DSnapshot::operator() (void)
|
eoMonitor& eoGnuplot1DSnapshot::operator()()
|
||||||
{
|
{
|
||||||
// update file using the eoFileMonitor method
|
// update file using the eoFileMonitor method
|
||||||
eoFileSnapshot::operator()();
|
eoFileSnapshot::operator()();
|
||||||
|
|
||||||
// sends plot order to gnuplot
|
#ifdef HAVE_GNUPLOT
|
||||||
//std::string buff; // need local memory
|
// sends plot order to gnuplot
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "set title 'Gen. " << getCounter() << "'; plot '"
|
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
|
// mk: had to use getFilename().c_str(),
|
||||||
<< getFileName().c_str() << "' notitle with points ps " << pointSize;
|
// because it seems the string(stream) lib is screwed in gcc3.2
|
||||||
os << std::endl;
|
<< getFileName().c_str() << "' notitle with points ps " << pointSize
|
||||||
PipeComSend( gpCom, os.str().c_str());
|
<< std::endl;
|
||||||
return (*this);
|
PipeComSend(gpCom, os.str().c_str());
|
||||||
|
#endif
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,8 @@ class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
|
||||||
public:
|
public:
|
||||||
// Ctor
|
// Ctor
|
||||||
eoGnuplot1DSnapshot(std::string _dirname, unsigned _frequency = 1,
|
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),
|
eoFileSnapshot(_dirname, _frequency, _filename, _delim, _counter, _rmFiles),
|
||||||
eoGnuplot(_filename,"set data style points"),
|
eoGnuplot(_filename,"set data style points"),
|
||||||
pointSize(5)
|
pointSize(5)
|
||||||
|
|
@ -88,7 +89,7 @@ class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
|
||||||
// Dtor
|
// Dtor
|
||||||
virtual ~eoGnuplot1DSnapshot(){}
|
virtual ~eoGnuplot1DSnapshot(){}
|
||||||
|
|
||||||
virtual eoMonitor& operator() (void) ;
|
virtual eoMonitor& operator()();
|
||||||
|
|
||||||
/// Class name.
|
/// Class name.
|
||||||
virtual std::string className() const { return "eoGnuplot1DSnapshot"; }
|
virtual std::string className() const { return "eoGnuplot1DSnapshot"; }
|
||||||
|
|
@ -96,20 +97,20 @@ class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
|
||||||
virtual void handleBounds(eoRealVectorBounds & _bounds)
|
virtual void handleBounds(eoRealVectorBounds & _bounds)
|
||||||
{
|
{
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
// std::ostrstream os;
|
os << "set autoscale\nset yrange [" ;
|
||||||
os << "set autoscale\nset yrange [" ;
|
if (_bounds.isMinBounded(0))
|
||||||
if (_bounds.isMinBounded(0))
|
os << _bounds.minimum(0);
|
||||||
os << _bounds.minimum(0);
|
os << ":" ;
|
||||||
os << ":" ;
|
if (_bounds.isMaxBounded(0))
|
||||||
if (_bounds.isMaxBounded(0))
|
os << _bounds.maximum(0);
|
||||||
os << _bounds.maximum(0);
|
os << "]\n";
|
||||||
os << "]\n";
|
gnuplotCommand(os.str());
|
||||||
gnuplotCommand(os.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned pointSize;
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
unsigned pointSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ int main(int argc, char* argv[])
|
||||||
///// FIRST, problem or representation dependent stuff
|
///// 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>);
|
eoEvalFuncPtr<Indi, double> mainEval( binary_value<Indi>);
|
||||||
eoEvalFuncCounter<Indi> eval(mainEval);
|
eoEvalFuncCounter<Indi> eval(mainEval);
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ int main(int argc, char* argv[])
|
||||||
eoCheckPoint<Indi> & checkpoint = make_checkpoint(parser, state, eval, term);
|
eoCheckPoint<Indi> & checkpoint = make_checkpoint(parser, state, eval, term);
|
||||||
|
|
||||||
// add a graphical output for the distribution
|
// 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
|
// it has been enetered in make_checkoint
|
||||||
|
|
||||||
eoParam* ptParam = parser.getParamWithLongName(string("resDir"));
|
eoParam* ptParam = parser.getParamWithLongName(string("resDir"));
|
||||||
|
|
@ -91,24 +91,26 @@ int main(int argc, char* argv[])
|
||||||
if (!ptDirNameParam) // not found
|
if (!ptDirNameParam) // not found
|
||||||
throw runtime_error("Parameter resDir not found where it was supposed to be");
|
throw runtime_error("Parameter resDir not found where it was supposed to be");
|
||||||
|
|
||||||
#if !defined(NO_GNUPLOT)
|
|
||||||
// now create the snapshot monitor
|
// 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())
|
if (plotDistribParam.value())
|
||||||
{
|
{
|
||||||
unsigned frequency=1; // frequency of plots updates
|
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);
|
state.storeFunctor(distribSnapshot);
|
||||||
// add the distribution (it is an eoValueParam<vector<double> >)
|
// add the distribution (it is an eoValueParam<vector<double> >)
|
||||||
distribSnapshot->add(distrib);
|
distribSnapshot->add(distrib);
|
||||||
// and of course add it to the checkpoint
|
// and of course add it to the checkpoint
|
||||||
checkpoint.add(*distribSnapshot);
|
checkpoint.add(*distribSnapshot);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// the algorithm: EDA
|
// the algorithm: EDA
|
||||||
// don't know where else to put the population size!
|
// 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);
|
eoSimpleEDA<Indi> eda(update, eval, popSize, checkpoint);
|
||||||
|
|
||||||
///// End of construction of the algorith
|
///// End of construction of the algorith
|
||||||
|
|
@ -125,14 +127,12 @@ int main(int argc, char* argv[])
|
||||||
distrib.printOn(std::cout);
|
distrib.printOn(std::cout);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
#if !defined(NO_GNUPLOT)
|
|
||||||
// wait - for graphical output
|
// wait - for graphical output
|
||||||
if (plotDistribParam.value())
|
if (plotDistribParam.value())
|
||||||
{
|
{
|
||||||
string foo;
|
string foo;
|
||||||
cin >> foo;
|
cin >> foo;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
catch(std::exception& e)
|
catch(std::exception& e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -205,7 +205,6 @@ void the_main(int argc, char* argv[])
|
||||||
cp.add(fitness0);
|
cp.add(fitness0);
|
||||||
cp.add(fitness1);
|
cp.add(fitness1);
|
||||||
|
|
||||||
#if !defined(NO_GNUPLOT)
|
|
||||||
eoGnuplot1DSnapshot snapshot("pareto");
|
eoGnuplot1DSnapshot snapshot("pareto");
|
||||||
//snapshot.with(eoGnuplot::Points(3));
|
//snapshot.with(eoGnuplot::Points(3));
|
||||||
|
|
||||||
|
|
@ -213,7 +212,6 @@ void the_main(int argc, char* argv[])
|
||||||
|
|
||||||
snapshot.add(fitness0);
|
snapshot.add(fitness0);
|
||||||
snapshot.add(fitness1);
|
snapshot.add(fitness1);
|
||||||
#endif
|
|
||||||
|
|
||||||
// the algo
|
// the algo
|
||||||
eoEasyEA<eoDouble> ea(cp, eval, breeder, replace);
|
eoEasyEA<eoDouble> ea(cp, eval, breeder, replace);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ main file BitEA in tutorial/Lesson4 dir.
|
||||||
Or you can wait until we do it :-)
|
Or you can wait until we do it :-)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Miscilaneous include and declaration
|
// Miscilaneous include and declaration
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
@ -29,17 +29,17 @@ using namespace std;
|
||||||
// include here whatever specific files for your representation
|
// include here whatever specific files for your representation
|
||||||
// Basically, this should include at least the following
|
// Basically, this should include at least the following
|
||||||
|
|
||||||
/** definition of representation:
|
/** definition of representation:
|
||||||
* class eoMyStruct MUST derive from EO<FitT> for some fitness
|
* class eoMyStruct MUST derive from EO<FitT> for some fitness
|
||||||
*/
|
*/
|
||||||
#include "eoMyStruct.h"
|
#include "eoMyStruct.h"
|
||||||
|
|
||||||
/** definition of initilizqtion:
|
/** definition of initilizqtion:
|
||||||
* class eoMyStructInit MUST derive from eoInit<eoMyStruct>
|
* class eoMyStructInit MUST derive from eoInit<eoMyStruct>
|
||||||
*/
|
*/
|
||||||
#include "eoMyStructInit.h"
|
#include "eoMyStructInit.h"
|
||||||
|
|
||||||
/** definition of evaluation:
|
/** definition of evaluation:
|
||||||
* class eoMyStructEvalFunc MUST derive from eoEvalFunc<eoMyStruct>
|
* class eoMyStructEvalFunc MUST derive from eoEvalFunc<eoMyStruct>
|
||||||
* and should test for validity before doing any computation
|
* and should test for validity before doing any computation
|
||||||
* see tutorial/Templates/evalFunc.tmpl
|
* see tutorial/Templates/evalFunc.tmpl
|
||||||
|
|
@ -47,7 +47,7 @@ using namespace std;
|
||||||
#include "eoMyStructEvalFunc.h"
|
#include "eoMyStructEvalFunc.h"
|
||||||
|
|
||||||
/** definitions of operators: write as many classes as types of operators
|
/** 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
|
* one crossover (2->2) and one mutation (1->1) operators are used
|
||||||
*/
|
*/
|
||||||
#include "eoMyStructQuadCrossover.h"
|
#include "eoMyStructQuadCrossover.h"
|
||||||
|
|
@ -61,17 +61,17 @@ using namespace std;
|
||||||
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||||
// START fitness type: double or eoMaximizingFitness if you are maximizing
|
// START fitness type: double or eoMaximizingFitness if you are maximizing
|
||||||
// eoMinimizingFitness if you are minimizing
|
// eoMinimizingFitness if you are minimizing
|
||||||
typedef eoMinimizingFitness MyFitT ; // type of fitness
|
typedef eoMinimizingFitness MyFitT ; // type of fitness
|
||||||
// END fitness type
|
// END fitness type
|
||||||
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||||
|
|
||||||
// Then define your EO objects using that 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
|
// 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
|
// it IS representation independent if an eoInit is given
|
||||||
#include <do/make_pop.h>
|
#include <do/make_pop.h>
|
||||||
eoPop<Indi >& make_pop(eoParser& _parser, eoState& _state, eoInit<Indi> & _init)
|
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, ...)
|
// outputs (stats, population dumps, ...)
|
||||||
#include <do/make_checkpoint.h>
|
#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);
|
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);
|
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
|
// no template for that one
|
||||||
#include <do/make_run.h>
|
#include <do/make_run.h>
|
||||||
// the instanciating fitnesses
|
// the instanciating fitnesses
|
||||||
|
|
@ -120,40 +120,40 @@ int main(int argc, char* argv[])
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
eoParser parser(argc, argv); // for user-parameter reading
|
eoParser parser(argc, argv); // for user-parameter reading
|
||||||
|
|
||||||
eoState state; // keeps all things allocated
|
eoState state; // keeps all things allocated
|
||||||
|
|
||||||
// The fitness
|
// The fitness
|
||||||
//////////////
|
//////////////
|
||||||
eoMyStructEvalFunc<Indi> plainEval/* (varType _anyVariable) */;
|
eoMyStructEvalFunc<Indi> plainEval/* (varType _anyVariable) */;
|
||||||
// turn that object into an evaluation counter
|
// turn that object into an evaluation counter
|
||||||
eoEvalFuncCounter<Indi> eval(plainEval);
|
eoEvalFuncCounter<Indi> eval(plainEval);
|
||||||
|
|
||||||
// a genotype initializer
|
// a genotype initializer
|
||||||
eoMyStructInit<Indi> init;
|
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
|
// - write a constructor of the eoMyStructInit that uses a parser
|
||||||
// - call it from here:
|
// - call it from here:
|
||||||
// eoMyStructInit<Indi> init(parser);
|
// eoMyStructInit<Indi> init(parser);
|
||||||
|
|
||||||
// if you want to do sharing, you'll need a distance.
|
// if you want to do sharing, you'll need a distance.
|
||||||
// see file utils/eoDistance.h
|
// 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)
|
// then you can use for instance the quadratic distance (L2 norm)
|
||||||
// eoQuadDistance<Indi> dist;
|
// eoQuadDistance<Indi> dist;
|
||||||
// or the Hamming distance (L1 norm)
|
// or the Hamming distance (L1 norm)
|
||||||
// eoHammingDistance<Indi> dist;
|
// eoHammingDistance<Indi> dist;
|
||||||
|
|
||||||
|
|
||||||
// Build the variation operator (any seq/prop construct)
|
// Build the variation operator (any seq/prop construct)
|
||||||
// here, a simple example with only 1 crossover (2->2, a QuadOp) and
|
// here, a simple example with only 1 crossover (2->2, a QuadOp) and
|
||||||
// one mutation, is given.
|
// one mutation, is given.
|
||||||
// Hints to have choice among multiple crossovers and mutations are given
|
// Hints to have choice among multiple crossovers and mutations are given
|
||||||
|
|
||||||
// A (first) crossover (possibly use the parser in its Ctor)
|
// A (first) crossover (possibly use the parser in its Ctor)
|
||||||
eoMyStructQuadCrossover<Indi> cross /* (eoParser parser) */;
|
eoMyStructQuadCrossover<Indi> cross /* (eoParser parser) */;
|
||||||
|
|
||||||
// IF MORE THAN ONE:
|
// IF MORE THAN ONE:
|
||||||
|
|
||||||
// read its relative rate in the combination
|
// read its relative rate in the combination
|
||||||
|
|
@ -167,9 +167,9 @@ try
|
||||||
// 2- include that file here together with eoMyStructQuadCrossover above
|
// 2- include that file here together with eoMyStructQuadCrossover above
|
||||||
// 3- uncomment and duplicate the following lines:
|
// 3- uncomment and duplicate the following lines:
|
||||||
//
|
//
|
||||||
// eoMyStructSecondCrossover<Indi> cross2(eoParser parser);
|
// eoMyStructSecondCrossover<Indi> cross2(eoParser parser);
|
||||||
// double cross2Rate = parser.createParam(1.0, "cross2Rate", "Relative rate for crossover 2", '2', "Variation Operators").value();
|
// double cross2Rate = parser.createParam(1.0, "cross2Rate", "Relative rate for crossover 2", '2', "Variation Operators").value();
|
||||||
// cross.add(cross2, cross2Rate);
|
// cross.add(cross2, cross2Rate);
|
||||||
|
|
||||||
// NOTE: if you want some gentle output, the last one shoudl be like
|
// NOTE: if you want some gentle output, the last one shoudl be like
|
||||||
// cross.add(cross, crossXXXRate, true);
|
// cross.add(cross, crossXXXRate, true);
|
||||||
|
|
@ -192,9 +192,9 @@ try
|
||||||
// 2- include that file here together with eoMyStructMutation above
|
// 2- include that file here together with eoMyStructMutation above
|
||||||
// 3- uncomment and duplicate the following lines:
|
// 3- uncomment and duplicate the following lines:
|
||||||
//
|
//
|
||||||
// eoMyStructSecondMutation<Indi> mut2(eoParser parser);
|
// eoMyStructSecondMutation<Indi> mut2(eoParser parser);
|
||||||
// double mut2Rate = parser.createParam(1.0, "mut2Rate", "Relative rate for mutation 2", '2', "Variation Operators").value();
|
// double mut2Rate = parser.createParam(1.0, "mut2Rate", "Relative rate for mutation 2", '2', "Variation Operators").value();
|
||||||
// mut.add(mut2, mut2Rate);
|
// mut.add(mut2, mut2Rate);
|
||||||
|
|
||||||
// NOTE: if you want some gentle output, the last one shoudl be like
|
// NOTE: if you want some gentle output, the last one shoudl be like
|
||||||
// mut.add(mut, mutXXXRate, true);
|
// mut.add(mut, mutXXXRate, true);
|
||||||
|
|
@ -217,7 +217,7 @@ try
|
||||||
eoSGAGenOp<Indi> op(cross, pCross, mut, pMut);
|
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
|
// You do not need to modify anything beyond this point
|
||||||
// unless you want to add specific statistics to the checkpoint
|
// 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 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!
|
// 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);
|
checkpoint.add(myStat);
|
||||||
// This one is probably redundant with the one in make_checkpoint, but w.t.h.
|
// This one is probably redundant with the one in make_checkpoint, but w.t.h.
|
||||||
eoIncrementorParam<unsigned> generationCounter("Gen.");
|
eoIncrementorParam<unsigned> generationCounter("Gen.");
|
||||||
|
|
@ -252,7 +252,7 @@ try
|
||||||
// those need to be pointers because of the if's
|
// those need to be pointers because of the if's
|
||||||
eoStdoutMonitor *myStdOutMonitor;
|
eoStdoutMonitor *myStdOutMonitor;
|
||||||
eoFileMonitor *myFileMonitor;
|
eoFileMonitor *myFileMonitor;
|
||||||
#if !defined(NO_GNUPLOT)
|
#ifdef HAVE_GNUPLOT
|
||||||
eoGnuplot1DMonitor *myGnuMonitor;
|
eoGnuplot1DMonitor *myGnuMonitor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -283,7 +283,7 @@ try
|
||||||
// should we write it to a file ?
|
// should we write it to a file ?
|
||||||
if (fileMyStructStat)
|
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
|
// a string parameter in the parser if you prefer
|
||||||
myFileMonitor = new eoFileMonitor(dirName + "myStat.xg");
|
myFileMonitor = new eoFileMonitor(dirName + "myStat.xg");
|
||||||
// don't forget to store the memory in the state
|
// don't forget to store the memory in the state
|
||||||
|
|
@ -296,14 +296,14 @@ try
|
||||||
myFileMonitor->add(myStat);
|
myFileMonitor->add(myStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(NO_GNUPLOT)
|
#ifdef HAVE_GNUPLOT
|
||||||
// should we PLOT it on StdOut ? (one dot per generation, incremental plot)
|
// should we PLOT it on StdOut ? (one dot per generation, incremental plot)
|
||||||
if (plotMyStructStat)
|
if (plotMyStructStat)
|
||||||
{
|
{
|
||||||
myGnuMonitor = new eoGnuplot1DMonitor(dirName+"plot_myStat.xg",minimizing_fitness<Indi>());
|
myGnuMonitor = new eoGnuplot1DMonitor(dirName+"plot_myStat.xg",minimizing_fitness<Indi>());
|
||||||
// NOTE: you cand send commands to gnuplot at any time with the method
|
// NOTE: you cand send commands to gnuplot at any time with the method
|
||||||
// myGnuMonitor->gnuplotCommand(string)
|
// 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
|
// don't forget to store the memory in the state
|
||||||
state.storeFunctor(myGnuMonitor);
|
state.storeFunctor(myGnuMonitor);
|
||||||
|
|
|
||||||
Reference in a new issue