Merge branch 'master' of ssh://eodev.git.sourceforge.net/gitroot/eodev/eodev

This commit is contained in:
nojhan 2012-07-06 18:25:15 +02:00
commit 07fede786f
36 changed files with 564 additions and 468 deletions

View file

@ -1,4 +1,24 @@
// (c) Thales group, 2010 /*
The Evolving Distribution Objects framework (EDO) is a template-based,
ANSI-C++ evolutionary computation library which helps you to write your
own estimation of distribution algorithms.
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
version 2.1 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Copyright (C) 2010 Thales group
*/
/* /*
Authors: Authors:
Johann Dreo <johann.dreo@thalesgroup.com> Johann Dreo <johann.dreo@thalesgroup.com>

View file

@ -1,3 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
###################################################################################### ######################################################################################
### 0) If you want to set your variables in eo-conf.cmake and avoid the cmd line ### 0) If you want to set your variables in eo-conf.cmake and avoid the cmd line

View file

@ -5,3 +5,4 @@ SET(PROJECT_VERSION_MINOR 3)
SET(PROJECT_VERSION_PATCH 0) SET(PROJECT_VERSION_PATCH 0)
SET(PROJECT_VERSION_MISC "-edge") SET(PROJECT_VERSION_MISC "-edge")
# ADD_DEFINITIONS(-DDEPRECATED_MESSAGES) # disable warning deprecated function messages

View file

@ -9,8 +9,8 @@ PREFIX = "/usr"
DATA = { DATA = {
'dirs': [ "%s/share/%s" % (PREFIX, NAME) ], 'dirs': [ "%s/share/%s" % (PREFIX, NAME) ],
'links': [ ("%s/src" % SOURCE, "%s/include/%s" % (PREFIX, NAME)), 'links': [ ("%s/src" % SOURCE, "%s/include/%s" % (PREFIX, NAME)),
("%s/doc" % BINARY, "%s/share/%s/doc" % (PREFIX, NAME)), ("%s/doc" % BINARY, "%s/share/%s/doc" % (PREFIX, NAME)),
("%s/%s.pc" % (BINARY, NAME), "%s/lib/pkgconfig/%s.pc" % (PREFIX, NAME)), ("%s/%s.pc" % (BINARY, NAME), "%s/lib/pkgconfig/%s.pc" % (PREFIX, NAME)),
] ]
} }
@ -21,19 +21,19 @@ import os, sys
def isroot(): def isroot():
if os.getuid() != 0: if os.getuid() != 0:
print '[WARNING] you have to be root' print('[WARNING] you have to be root')
return False return False
return True return True
def uninstall(): def uninstall():
for dummy, link in DATA['links']: os.remove(link) for dummy, link in DATA['links']: os.remove(link)
for dirname in DATA['dirs']: os.rmdir(dirname) for dirname in DATA['dirs']: os.rmdir(dirname)
print 'All symlinks have been removed.' print('All symlinks have been removed.')
def install(): def install():
for dirname in DATA['dirs']: os.mkdir(dirname) for dirname in DATA['dirs']: os.mkdir(dirname)
for src, dst in DATA['links']: os.symlink(src, dst) for src, dst in DATA['links']: os.symlink(src, dst)
print 'All symlinks have been installed.' print('All symlinks have been installed.')
def data(): def data():
from pprint import pprint from pprint import pprint
@ -41,11 +41,11 @@ def data():
if __name__ == '__main__': if __name__ == '__main__':
if not isroot(): if not isroot():
sys.exit() sys.exit()
if len(sys.argv) < 2: if len(sys.argv) < 2:
print 'Usage: %s [install|uninstall|data]' % sys.argv[0] print(('Usage: %s [install|uninstall|data]' % sys.argv[0]))
sys.exit() sys.exit()
if sys.argv[1] == 'install': install() if sys.argv[1] == 'install': install()
elif sys.argv[1] == 'uninstall': uninstall() elif sys.argv[1] == 'uninstall': uninstall()

View file

@ -1,45 +1,32 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// 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
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
Marc.Schoenauer@polytechnique.fr
mkeijzer@dhi.dk
*/
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
Marc.Schoenauer@polytechnique.fr
mkeijzer@dhi.dk
*/
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifndef _make_checkpoint_h #ifndef _make_checkpoint_h
#define _make_checkpoint_h #define _make_checkpoint_h
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#endif #endif
@ -52,521 +39,315 @@
#include <eoEvalFuncCounter.h> #include <eoEvalFuncCounter.h>
#include <utils/checkpointing> #include <utils/checkpointing>
// at the moment, in utils/make_help.cpp // at the moment, in utils/make_help.cpp
// this should become some eoUtils.cpp with corresponding eoUtils.h // this should become some eoUtils.cpp with corresponding eoUtils.h
bool testDirRes(std::string _dirName, bool _erase); bool testDirRes(std::string _dirName, bool _erase);
/////////////////// The checkpoint and other I/O ////////////// /////////////////// The checkpoint and other I/O //////////////
/** /**
* *
* CHANGE (March 2008): now receiving an eoValueParam instead of an eoEvalFuncCounter. This function is just interested * CHANGE (March 2008): now receiving an eoValueParam instead of an eoEvalFuncCounter. This function is just interested
* in the value of the parameter calculated on the evaluation function, not in the actual function itself!! * in the value of the parameter calculated on the evaluation function, not in the actual function itself!!
* *
* @ingroup Builders * @ingroup Builders
*/ */
template <class EOT> template <class EOT>
eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValueParam<unsigned long>& _eval, eoContinue<EOT>& _continue) eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValueParam<unsigned long>& _eval, eoContinue<EOT>& _continue)
{ {
// first, create a checkpoint from the eoContinue
eoCheckPoint<EOT> *checkpoint = new eoCheckPoint<EOT>(_continue);
// first, create a checkpoint from the eoContinue _state.storeFunctor(checkpoint);
eoCheckPoint<EOT> *checkpoint = new eoCheckPoint<EOT>(_continue);
_state.storeFunctor(checkpoint); ////////////////////
// Signal monitoring
////////////////////
#ifndef _MSC_VER
// the CtrlC monitoring interception
eoSignal<EOT> *mon_ctrlCCont;
eoValueParam<bool>& mon_ctrlCParam = _parser.createParam(false, "monitor-with-CtrlC", "Monitor current generation upon Ctrl C",0, "Stopping criterion");
if (mon_ctrlCParam.value())
{
mon_ctrlCCont = new eoSignal<EOT>;
// store
_state.storeFunctor(mon_ctrlCCont);
// add to checkpoint
checkpoint->add(*mon_ctrlCCont);
}
#endif
///////////////////
// Counters
//////////////////
/////////////////// // is nb Eval to be used as counter?
eoValueParam<bool>& useEvalParam = _parser.createParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output");
eoValueParam<bool>& useTimeParam = _parser.createParam(true, "useTime", "Display time (s) every generation", '\0', "Output");
// if we want the time, we need an eoTimeCounter
eoTimeCounter * tCounter = NULL;
// Counters // 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.");
// is nb Eval to be used as counter?
eoValueParam<bool>& useEvalParam = _parser.createParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output");
eoValueParam<bool>& useTimeParam = _parser.createParam(true, "useTime", "Display time (s) every generation", '\0', "Output");
// 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
// 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,
checkpoint->add(*generationCounter);
// store it in the state
_state.storeFunctor(generationCounter);
// And add it to the checkpoint,
checkpoint->add(*generationCounter);
// dir for DISK output // dir for DISK output
eoValueParam<std::string>& dirNameParam = _parser.createParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output - Disk"); eoValueParam<std::string>& dirNameParam = _parser.createParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output - Disk");
// 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.createParam(true, "eraseDir", "erase files in dirName if any", '\0', "Output - Disk");
bool dirOK = false; // not tested yet bool dirOK = false; // not tested yet
///////////////////////////////////////// /////////////////////////////////////////
// now some statistics on the population: // now some statistics on the population:
///////////////////////////////////////// /////////////////////////////////////////
/** /**
* existing stats as of today, April 10. 2001 * existing stats as of today, April 10. 2001
* *
* eoBestFitnessStat : best value in pop - type EOT::Fitness * eoBestFitnessStat : best value in pop - type EOT::Fitness
* eoAverageStat : average value in pop - type EOT::Fitness * eoAverageStat : average value in pop - type EOT::Fitness
* eoSecondMomentStat: average + stdev - type std::pair<double, double> * eoSecondMomentStat: average + stdev - type std::pair<double, double>
* eoSortedPopStat : whole population - type std::string (!!) * eoSortedPopStat : whole population - type std::string (!!)
* eoScalarFitnessStat: the fitnesses - type std::vector<double> * eoScalarFitnessStat: the fitnesses - type std::vector<double>
*/ */
// Best fitness in population // Best fitness in population
//--------------------------- //---------------------------
eoValueParam<bool>& printBestParam = _parser.createParam(true, "printBestStat", "Print Best/avg/stdev every gen.", '\0', "Output"); eoValueParam<bool>& printBestParam = _parser.createParam(true, "printBestStat", "Print Best/avg/stdev every gen.", '\0', "Output");
eoValueParam<bool>& plotBestParam = _parser.createParam(false, "plotBestStat", "Plot Best/avg Stat", '\0', "Output - Graphical"); eoValueParam<bool>& plotBestParam = _parser.createParam(false, "plotBestStat", "Plot Best/avg Stat", '\0', "Output - Graphical");
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>;
{ // store it
_state.storeFunctor(bestStat);
bestStat = new eoBestFitnessStat<EOT>; // add it to the checkpoint
checkpoint->add(*bestStat);
// store it // check if monitoring with signal
if ( mon_ctrlCParam.value() )
_state.storeFunctor(bestStat); mon_ctrlCCont->add(*bestStat);
}
// add it to the checkpoint
checkpoint->add(*bestStat);
}
// Average fitness alone // Average fitness alone
//---------------------- //----------------------
eoAverageStat<EOT> *averageStat = NULL; // do we need averageStat? eoAverageStat<EOT> *averageStat = NULL; // do we need averageStat?
if ( printBestParam.value() || plotBestParam.value() || fileBestParam.value() ) // we need it for gnuplot output
if ( plotBestParam.value() ) // we need it for gnuplot output {
averageStat = new eoAverageStat<EOT>;
{ // store it
_state.storeFunctor(averageStat);
averageStat = new eoAverageStat<EOT>; // add it to the checkpoint
checkpoint->add(*averageStat);
// store it // check if monitoring with signal
if ( mon_ctrlCParam.value() )
_state.storeFunctor(averageStat); mon_ctrlCCont->add(*averageStat);
}
// add it to the checkpoint
checkpoint->add(*averageStat);
}
// Second moment stats: average and stdev // Second moment stats: average and stdev
//--------------------------------------- //---------------------------------------
eoSecondMomentStats<EOT> *secondStat = NULL; eoSecondMomentStats<EOT> *secondStat = NULL;
if ( printBestParam.value() || fileBestParam.value() ) // we need it for screen output or file output
if ( printBestParam.value() || fileBestParam.value() ) // we need it for screen output or file output {
secondStat = new eoSecondMomentStats<EOT>;
{ // store it
_state.storeFunctor(secondStat);
secondStat = new eoSecondMomentStats<EOT>; // add it to the checkpoint
checkpoint->add(*secondStat);
// store it // check if monitoring with signal
if ( mon_ctrlCParam.value() )
_state.storeFunctor(secondStat); mon_ctrlCCont->add(*secondStat);
}
// add it to the checkpoint
checkpoint->add(*secondStat);
}
// Dump of the whole population // Dump of the whole population
//----------------------------- //-----------------------------
eoSortedPopStat<EOT> *popStat = NULL; eoSortedPopStat<EOT> *popStat = NULL;
eoValueParam<bool>& printPopParam = _parser.createParam(false, "printPop", "Print sorted pop. every gen.", '\0', "Output"); eoValueParam<bool>& printPopParam = _parser.createParam(false, "printPop", "Print sorted pop. every gen.", '\0', "Output");
if ( printPopParam.value() ) // we do want pop dump if ( printPopParam.value() ) // we do want pop dump
{
{ popStat = new eoSortedPopStat<EOT>;
// store it
popStat = new eoSortedPopStat<EOT>; _state.storeFunctor(popStat);
// add it to the checkpoint
// store it checkpoint->add(*popStat);
// check if monitoring with signal
_state.storeFunctor(popStat); if ( mon_ctrlCParam.value() )
mon_ctrlCCont->add(*popStat);
// add it to the checkpoint }
checkpoint->add(*popStat);
}
// do we wnat some histogram of fitnesses snpashots? // do we wnat some histogram of fitnesses snpashots?
eoValueParam<bool> plotHistogramParam = _parser.createParam(false, "plotHisto", "Plot histogram of fitnesses", '\0', "Output - Graphical"); eoValueParam<bool> plotHistogramParam = _parser.createParam(false, "plotHisto", "Plot histogram of fitnesses", '\0', "Output - Graphical");
/////////////// ///////////////
// 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);
_state.storeFunctor(monitor);
{ // when called by the checkpoint (i.e. at every generation)
// check if monitoring with signal
if ( ! mon_ctrlCParam.value() )
checkpoint->add(*monitor);
else
mon_ctrlCCont->add(*monitor);
eoStdoutMonitor *monitor = new eoStdoutMonitor(false); // the monitor will output a series of parameters: add them
monitor->add(*generationCounter);
_state.storeFunctor(monitor); if (useEvalParam.value()) // we want nb of evaluations
monitor->add(_eval);
if (useTimeParam.value()) // we want time
{
// when called by the checkpoint (i.e. at every generation) tCounter = new eoTimeCounter;
_state.storeFunctor(tCounter);
checkpoint->add(*monitor); // check if monitoring with signal
if ( ! mon_ctrlCParam.value() )
checkpoint->add(*tCounter);
else
// the monitor will output a series of parameters: add them mon_ctrlCCont->add(*tCounter);
monitor->add(*tCounter);
monitor->add(*generationCounter); }
if (useEvalParam.value()) // we want nb of evaluations
monitor->add(_eval);
if (useTimeParam.value()) // we want time
{
tCounter = new eoTimeCounter;
_state.storeFunctor(tCounter);
checkpoint->add(*tCounter);
monitor->add(*tCounter);
}
if (printBestParam.value())
{
monitor->add(*bestStat);
monitor->add(*secondStat);
}
if ( printPopParam.value())
monitor->add(*popStat);
}
if (printBestParam.value())
{
monitor->add(*bestStat);
monitor->add(*secondStat);
}
if ( printPopParam.value())
monitor->add(*popStat);
}
// 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
if (fileBestParam.value()) // A file monitor for best & secondMoment if (fileBestParam.value()) // A file monitor for best & secondMoment
{
{
#ifdef _MSVC #ifdef _MSVC
std::string stmp = dirNameParam.value() + "\best.xg";
std::string stmp = dirNameParam.value() + "\best.xg";
#else #else
std::string stmp = dirNameParam.value() + "/best.xg";
std::string stmp = dirNameParam.value() + "/best.xg";
#endif #endif
eoFileMonitor *fileMonitor = new eoFileMonitor(stmp);
eoFileMonitor *fileMonitor = new eoFileMonitor(stmp); // save and give to checkpoint
_state.storeFunctor(fileMonitor);
// save and give to checkpoint checkpoint->add(*fileMonitor);
// and feed with some statistics
_state.storeFunctor(fileMonitor); fileMonitor->add(*generationCounter);
fileMonitor->add(_eval);
checkpoint->add(*fileMonitor); if (tCounter) // we want the time as well
{
// and feed with some statistics // std::cout << "On met timecounter\n";
fileMonitor->add(*tCounter);
fileMonitor->add(*generationCounter); }
fileMonitor->add(*bestStat);
fileMonitor->add(_eval); fileMonitor->add(*secondStat);
}
if (tCounter) // we want the time as well
{
// std::cout << "On met timecounter\n";
fileMonitor->add(*tCounter);
}
fileMonitor->add(*bestStat);
fileMonitor->add(*secondStat);
}
#if defined(HAVE_GNUPLOT) #if defined(HAVE_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";
eoGnuplot1DMonitor *gnuMonitor = new eoGnuplot1DMonitor(stmp,minimizing_fitness<EOT>());
std::string stmp = dirNameParam.value() + "/gnu_best.xg"; // save and give to checkpoint
_state.storeFunctor(gnuMonitor);
eoGnuplot1DMonitor *gnuMonitor = new eoGnuplot1DMonitor(stmp,minimizing_fitness<EOT>()); checkpoint->add(*gnuMonitor);
// and feed with some statistics
// save and give to checkpoint if (useEvalParam.value()) // do we want eval as X coordinate
gnuMonitor->add(_eval);
_state.storeFunctor(gnuMonitor); else if (tCounter) // or time?
gnuMonitor->add(*tCounter);
checkpoint->add(*gnuMonitor); else // default: generation
gnuMonitor->add(*generationCounter);
// and feed with some statistics gnuMonitor->add(*bestStat);
gnuMonitor->add(*averageStat);
if (useEvalParam.value()) // do we want eval as X coordinate }
gnuMonitor->add(_eval);
else if (tCounter) // or time?
gnuMonitor->add(*tCounter);
else // default: generation
gnuMonitor->add(*generationCounter);
gnuMonitor->add(*bestStat);
gnuMonitor->add(*averageStat);
}
// historgram? // historgram?
if (plotHistogramParam.value()) // want to see how the fitness is spread? if (plotHistogramParam.value()) // want to see how the fitness is spread?
{
{ eoScalarFitnessStat<EOT> *fitStat = new eoScalarFitnessStat<EOT>;
_state.storeFunctor(fitStat);
eoScalarFitnessStat<EOT> *fitStat = new eoScalarFitnessStat<EOT>; checkpoint->add(*fitStat);
// a gnuplot-based monitor for snapshots: needs a dir name
_state.storeFunctor(fitStat); eoGnuplot1DSnapshot *fitSnapshot = new eoGnuplot1DSnapshot(dirNameParam.value());
_state.storeFunctor(fitSnapshot);
checkpoint->add(*fitStat); // add any stat that is a std::vector<double> to it
fitSnapshot->add(*fitStat);
// a gnuplot-based monitor for snapshots: needs a dir name // and of course add it to the checkpoint
checkpoint->add(*fitSnapshot);
eoGnuplot1DSnapshot *fitSnapshot = new eoGnuplot1DSnapshot(dirNameParam.value()); }
_state.storeFunctor(fitSnapshot);
// add any stat that is a std::vector<double> to it
fitSnapshot->add(*fitStat);
// and of course add it to the checkpoint
checkpoint->add(*fitSnapshot);
}
#endif #endif
////////////////////////////////// //////////////////////////////////
// State savers // State savers
////////////////////////////// //////////////////////////////
// feed the state to state savers // feed the state to state savers
// save state every N generation // save state every N generation
eoValueParam<unsigned>& saveFrequencyParam = _parser.createParam(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" );
if (_parser.isItThere(saveFrequencyParam)) if (_parser.isItThere(saveFrequencyParam))
{
// first make sure dirName is OK
if (! dirOK )
dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE
{ unsigned freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX );
// first make sure dirName is OK
if (! dirOK )
dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE
unsigned freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX );
#ifdef _MSVC #ifdef _MSVC
std::string stmp = dirNameParam.value() + "\generations";
std::string stmp = dirNameParam.value() + "\generations";
#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);
checkpoint->add(*stateSaver1);
_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" ); 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)
{
{ // first make sure dirName is OK
if (! dirOK )
// first make sure dirName is OK dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE
if (! dirOK )
dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE
#ifdef _MSVC #ifdef _MSVC
std::string stmp = dirNameParam.value() + "\time";
std::string stmp = dirNameParam.value() + "\time";
#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);
checkpoint->add(*stateSaver2);
_state.storeFunctor(stateSaver2); }
checkpoint->add(*stateSaver2);
}
// and that's it for the (control and) output // and that's it for the (control and) output
return *checkpoint; return *checkpoint;
} }
#endif #endif

View file

@ -61,7 +61,9 @@ public:
eoCombinedContinue( eoContinue<EOT>& _cont1, eoContinue<EOT>& _cont2) eoCombinedContinue( eoContinue<EOT>& _cont1, eoContinue<EOT>& _cont2)
: eoContinue<EOT>(), std::vector<eoContinue<EOT>* >() : eoContinue<EOT>(), std::vector<eoContinue<EOT>* >()
{ {
#ifndef DEPRECATED_MESSAGES
#pragma message "The double continuators constructor of eocombinedContinue is deprecated and will be removed in the next release." #pragma message "The double continuators constructor of eocombinedContinue is deprecated and will be removed in the next release."
#endif // !DEPRECATED_MESSAGES
this->push_back(&_cont1); this->push_back(&_cont1);
this->push_back(&_cont2); this->push_back(&_cont2);
@ -74,7 +76,10 @@ public:
void removeLast(void) void removeLast(void)
{ {
#ifndef DEPRECATED_MESSAGES
#pragma message "The removeLast method of eocombinedContinue is deprecated and will be removed in the next release, use pop_back instead." #pragma message "The removeLast method of eocombinedContinue is deprecated and will be removed in the next release, use pop_back instead."
#endif // !DEPRECATED_MESSAGES
this->pop_back(); this->pop_back();
} }

View file

@ -30,7 +30,7 @@
#ifndef eoCtrlCContinue_h #ifndef eoCtrlCContinue_h
#define eoCtrlCContinue_h #define eoCtrlCContinue_h
#include <signal.h> #include <csignal>
#include <eoContinue.h> #include <eoContinue.h>
/** /**

View file

@ -46,7 +46,7 @@ public:
{ {
for (unsigned i = 0; i < _pop.size (); i++) for (unsigned i = 0; i < _pop.size (); i++)
{ {
operator ()(_pop[i]); this->operator ()(_pop[i]);
} }
} }

View file

@ -129,7 +129,7 @@ private :
class eoDummyEval : public eoPopEvalFunc<POT> class eoDummyEval : public eoPopEvalFunc<POT>
{ {
public: public:
void operator()(eoPop<POT> &,eoPop<POT> &_pop) void operator()(eoPop<POT> &,eoPop<POT> &/*_pop*/)
{} {}
} }
dummyEval; dummyEval;

View file

@ -46,7 +46,7 @@ public:
{ {
for (unsigned i = 0; i < _pop.size (); i++) for (unsigned i = 0; i < _pop.size (); i++)
{ {
operator ()(_pop[i]); this->operator ()(_pop[i]);
} }
} }

View file

@ -39,7 +39,7 @@ public:
/** It returns 'true' only if the current number of generations modulo /** It returns 'true' only if the current number of generations modulo
the period doen't equal to zero. */ the period doen't equal to zero. */
bool operator () (const eoPop <EOT> & pop) bool operator () (const eoPop <EOT> & /*pop*/)
{ {
return ((++ counter) % period) != 0 ; return ((++ counter) % period) != 0 ;
} }

View file

@ -188,8 +188,11 @@ public:
virtual void add(eoQuadOp<EOT> & _op, const double _rate, bool _verbose) virtual void add(eoQuadOp<EOT> & _op, const double _rate, bool _verbose)
{ {
#ifndef DEPRECATED_MESSAGES
#pragma message "The use of the verbose parameter in eoPropCombinedQuadOp::add is deprecated and will be removed in the next release." #pragma message "The use of the verbose parameter in eoPropCombinedQuadOp::add is deprecated and will be removed in the next release."
eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoPropCombinedQuadOp::add is deprecated and will be removed in the next release." << std::endl; eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoPropCombinedQuadOp::add is deprecated and will be removed in the next release." << std::endl;
#endif // !DEPRECATED_MESSAGES
add(_op,_rate); add(_op,_rate);
} }

View file

@ -46,7 +46,7 @@ template <class EOT> class eoProportionalSelect: public eoSelectOne<EOT>
{ {
public: public:
/// Sanity check /// Sanity check
eoProportionalSelect(const eoPop<EOT>& pop = eoPop<EOT>()) eoProportionalSelect(const eoPop<EOT>& /*pop*/ = eoPop<EOT>())
{ {
if (minimizing_fitness<EOT>()) if (minimizing_fitness<EOT>())
throw std::logic_error("eoProportionalSelect: minimizing fitness"); throw std::logic_error("eoProportionalSelect: minimizing fitness");

View file

@ -104,7 +104,7 @@ public:
unsigned eliminated = howMany(popSize); unsigned eliminated = howMany(popSize);
if (!eliminated) // nothing to do if (!eliminated) // nothing to do
return ; return ;
unsigned newsize = popSize - eliminated; long newsize = static_cast<long>(popSize) - static_cast<long>(eliminated);
if (newsize < 0) if (newsize < 0)
throw std::logic_error("eoLinearTruncateSplit: Cannot truncate to a larger size!\n"); throw std::logic_error("eoLinearTruncateSplit: Cannot truncate to a larger size!\n");

View file

@ -212,7 +212,7 @@ public:
//! Print term values and descriptions //! Print term values and descriptions
void printAll(std::ostream& os) const { void printAll(std::ostream& os) const {
for (size_type i=0; i < size(); ++i ) for (size_type i=0; i < size(); ++i )
os << FitnessTraits::getDescription(i) << " = " << operator[](i) << " "; os << FitnessTraits::getDescription(i) << " = " << this->operator[](i) << " ";
} }
//! Comparison, using less by default //! Comparison, using less by default

View file

@ -217,7 +217,7 @@ public:
#ifndef NDEBUG #ifndef NDEBUG
// check whether the stuff is still in sync // check whether the stuff is still in sync
check_sync(index, _pop[index]); this->check_sync(index, _pop[index]);
#endif #endif
return _pop[index]; return _pop[index];

View file

@ -241,7 +241,7 @@ private:
{ {
public: public:
eoDummyFlight () {} eoDummyFlight () {}
void operator () (POT & _po) {} void operator () (POT & /*_po*/) {}
}dummyFlight; }dummyFlight;
// if the initializer does not need to be used, use the dummy one instead // if the initializer does not need to be used, use the dummy one instead

View file

@ -49,7 +49,7 @@ public:
{ {
for (unsigned i = 0; i < _pop.size (); i++) for (unsigned i = 0; i < _pop.size (); i++)
{ {
operator ()(_pop[i],i); this->operator ()(_pop[i],i);
} }
} }
@ -57,7 +57,7 @@ public:
/** /**
* Update the neighborhood of the given particle. * Update the neighborhood of the given particle.
*/ */
virtual void updateNeighborhood(POT & ,unsigned _indice){} virtual void updateNeighborhood(POT & ,unsigned /*_indice*/){}
/** /**

View file

@ -56,7 +56,7 @@ template<class Chrom> class eoOneBitFlip: public eoMonOp<Chrom>
bool operator()(Chrom& chrom) bool operator()(Chrom& chrom)
{ {
unsigned i = eo::rng.random(chrom.size()); unsigned i = eo::rng.random(chrom.size());
chrom[i] = (chrom[i]) ? false : true; chrom[i] = !chrom[i];
return true; return true;
} }
}; };
@ -85,11 +85,11 @@ template<class Chrom> class eoDetBitFlip: public eoMonOp<Chrom>
*/ */
bool operator()(Chrom& chrom) bool operator()(Chrom& chrom)
{ {
// does not check for duplicate: if someone volunteers .... // for duplicate checking see eoDetSingleBitFlip
for (unsigned k=0; k<num_bit; k++) for (unsigned k=0; k<num_bit; k++)
{ {
unsigned i = eo::rng.random(chrom.size()); unsigned i = eo::rng.random(chrom.size());
chrom[i] = (chrom[i]) ? false : true; chrom[i] = !chrom[i];
} }
return true; return true;
} }
@ -98,6 +98,58 @@ template<class Chrom> class eoDetBitFlip: public eoMonOp<Chrom>
}; };
/** eoDetSingleBitFlip --> changes exactly k bits with checking for duplicate
\class eoDetSingleBitFlip eoBitOp.h ga/eoBitOp.h
\ingroup bitstring
*/
template<class Chrom> class eoDetSingleBitFlip: public eoMonOp<Chrom>
{
public:
/**
* (Default) Constructor.
* @param _num_bit The number of bits to change
* default is one - equivalent to eoOneBitFlip then
*/
eoDetSingleBitFlip(const unsigned& _num_bit = 1): num_bit(_num_bit) {}
/// The class name.
virtual std::string className() const { return "eoDetSingleBitFlip"; }
/**
* Change num_bit bits.
* @param chrom The cromosome which one bit is going to be changed.
*/
bool operator()(Chrom& chrom)
{
std::vector< unsigned > selected;
// check for duplicate
for (unsigned k=0; k<num_bit; k++)
{
unsigned temp;
do
{
temp = eo::rng.random( chrom.size() );
}
while ( find( selected.begin(), selected.end(), temp ) != selected.end() );
selected.push_back(temp);
}
for ( size_t i = 0; i < selected.size(); ++i )
{
chrom[i] = !chrom[i];
}
return true;
}
private:
unsigned num_bit;
};
/** eoBitMutation --> classical mutation /** eoBitMutation --> classical mutation
\class eoBitMutation eoBitOp.h ga/eoBitOp.h \class eoBitMutation eoBitOp.h ga/eoBitOp.h
\ingroup bitstring \ingroup bitstring

View file

@ -37,7 +37,7 @@
* *
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained * The corresponding ***INSTANCIATED DECLARATIONS*** are contained
* in ga.h * in ga.h
* while the TEMPLATIZED code is define in make_contninue.h in the src/do dir * while the TEMPLATIZED code is define in make_continue.h in the src/do dir
* *
* Unlike most EO .h files, it does not (and should not) contain any code, * Unlike most EO .h files, it does not (and should not) contain any code,
* just declarations * just declarations

View file

@ -57,8 +57,8 @@
*/ */
// the genotypes // the genotypes
eoInit<eoBit<double> > & make_genotype(eoParser& _parser, eoState& _state, eoBit<double> _eo); eoInit<eoBit<double> > & make_genotype(eoParser& _parser, eoState& _state, eoBit<double> _eo, float _bias=0.5);
eoInit<eoBit<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoBit<eoMinimizingFitness> _eo); eoInit<eoBit<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoBit<eoMinimizingFitness> _eo, float _bias=0.5);
// the operators // the operators
eoGenOp<eoBit<double> >& make_op(eoParser& _parser, eoState& _state, eoInit<eoBit<double> >& _init); eoGenOp<eoBit<double> >& make_op(eoParser& _parser, eoState& _state, eoInit<eoBit<double> >& _init);

View file

@ -45,11 +45,11 @@
/// The following function merely call the templatized do_* functions above /// The following function merely call the templatized do_* functions above
eoInit<eoBit<double> > & make_genotype(eoParser& _parser, eoState& _state, eoBit<double> _eo) eoInit<eoBit<double> > & make_genotype(eoParser& _parser, eoState& _state, eoBit<double> _eo, float _bias)
{ {
return do_make_genotype(_parser, _state, _eo); return do_make_genotype(_parser, _state, _eo, _bias);
} }
eoInit<eoBit<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoBit<eoMinimizingFitness> _eo) eoInit<eoBit<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoBit<eoMinimizingFitness> _eo, float _bias)
{ {
return do_make_genotype(_parser, _state, _eo); return do_make_genotype(_parser, _state, _eo, _bias);
} }

View file

@ -60,7 +60,7 @@
* @ingroup Builders * @ingroup Builders
*/ */
template <class EOT> template <class EOT>
eoInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT) eoInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT, float _bias=0.5)
{ {
// for bitstring, only thing needed is the size // for bitstring, only thing needed is the size
// but it might have been already read in the definition fo the performance // but it might have been already read in the definition fo the performance
@ -68,7 +68,7 @@ eoInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
// Then we can built a bitstring random initializer // Then we can built a bitstring random initializer
// based on boolean_generator class (see utils/rnd_generator.h) // based on boolean_generator class (see utils/rnd_generator.h)
eoBooleanGenerator * gen = new eoBooleanGenerator; eoBooleanGenerator * gen = new eoBooleanGenerator(_bias);
_state.storeFunctor(gen); _state.storeFunctor(gen);
eoInitFixedLength<EOT>* init = new eoInitFixedLength<EOT>(theSize, *gen); eoInitFixedLength<EOT>* init = new eoInitFixedLength<EOT>(theSize, *gen);
// store in state // store in state

View file

@ -115,11 +115,11 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
throw std::runtime_error("Invalid uRate"); throw std::runtime_error("Invalid uRate");
// minimum check // minimum check
bool bCross = true; // bool bCross = true; // not used ?
if (onePointRateParam.value()+twoPointsRateParam.value()+uRateParam.value()==0) if (onePointRateParam.value()+twoPointsRateParam.value()+uRateParam.value()==0)
{ {
std::cerr << "Warning: no crossover" << std::endl; std::cerr << "Warning: no crossover" << std::endl;
bCross = false; // bCross = false;
} }
// Create the CombinedQuadOp // Create the CombinedQuadOp
@ -156,17 +156,29 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
if ( (bitFlipRateParam.value() < 0) ) if ( (bitFlipRateParam.value() < 0) )
throw std::runtime_error("Invalid bitFlipRate"); throw std::runtime_error("Invalid bitFlipRate");
// oneBitFlip
eoValueParam<double> & oneBitRateParam = _parser.createParam(0.01, "oneBitRate", "Relative rate for deterministic bit-flip mutation", 'd', "Variation Operators" ); eoValueParam<double> & oneBitRateParam = _parser.createParam(0.01, "oneBitRate", "Relative rate for deterministic bit-flip mutation", 'd', "Variation Operators" );
// minimum check // minimum check
if ( (oneBitRateParam.value() < 0) ) if ( (oneBitRateParam.value() < 0) )
throw std::runtime_error("Invalid oneBitRate"); throw std::runtime_error("Invalid oneBitRate");
// kBitFlip
eoValueParam<unsigned> & kBitParam = _parser.createParam((unsigned)1, "kBit", "Number of bit for deterministic k bit-flip mutation", 0, "Variation Operators" );
// minimum check // minimum check
bool bMut = true; if ( ! kBitParam.value() )
throw std::runtime_error("Invalid kBit");
eoValueParam<double> & kBitRateParam = _parser.createParam(0.0, "kBitRate", "Relative rate for deterministic k bit-flip mutation", 0, "Variation Operators" );
// minimum check
if ( (kBitRateParam.value() < 0) )
throw std::runtime_error("Invalid kBitRate");
// minimum check
// bool bMut = true; // not used ?
if (bitFlipRateParam.value()+oneBitRateParam.value()==0) if (bitFlipRateParam.value()+oneBitRateParam.value()==0)
{ {
std::cerr << "Warning: no mutation" << std::endl; std::cerr << "Warning: no mutation" << std::endl;
bMut = false; // bMut = false;
} }
// Create the CombinedMonOp // Create the CombinedMonOp
@ -184,6 +196,11 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
_state.storeFunctor(ptMon); _state.storeFunctor(ptMon);
ptCombinedMonOp->add(*ptMon, oneBitRateParam.value()); ptCombinedMonOp->add(*ptMon, oneBitRateParam.value());
// mutate exactly k bit per individual
ptMon = new eoDetBitFlip<EOT>(kBitParam.value());
_state.storeFunctor(ptMon);
ptCombinedMonOp->add(*ptMon, kBitRateParam.value());
_state.storeFunctor(ptCombinedMonOp); _state.storeFunctor(ptCombinedMonOp);
// now build the eoGenOp: // now build the eoGenOp:

View file

@ -94,7 +94,7 @@ public:
while (size() > _size) while (size() > _size)
{ {
back() = operator[](size()-2); back() = this->operator[](size()-2);
} }
} }
@ -150,7 +150,7 @@ public:
v[i] = node; v[i] = node;
} }
parse_tree<Node> tmp(v.begin(), v.end()); parse_tree<Node> tmp(v.begin(), v.end());
swap(tmp); this->swap(tmp);
/* /*
* old code which caused problems for paradisEO * old code which caused problems for paradisEO

View file

@ -2,6 +2,6 @@
for i in *.py for i in *.py
do do
python $i > /dev/null python2 $i > /dev/null
done done

View file

@ -29,6 +29,7 @@ SET(EOUTILS_SOURCES
pipecom.cpp pipecom.cpp
eoLogger.cpp eoLogger.cpp
eoParallel.cpp eoParallel.cpp
eoSignal.cpp
) )
ADD_LIBRARY(eoutils STATIC ${EOUTILS_SOURCES}) ADD_LIBRARY(eoutils STATIC ${EOUTILS_SOURCES})

View file

@ -1,3 +1,29 @@
/*
-----------------------------------------------------------------------------
checkpointing
(c) Maarten Keijzer (mak@dhi.dk) and GeNeura Team, 1999, 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
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
*/
#ifndef _CHECKPOINTING_
#define _CHECKPOINTING_
#include <utils/eoParser.h> #include <utils/eoParser.h>
#include <utils/eoState.h> #include <utils/eoState.h>
#include <utils/eoUpdater.h> #include <utils/eoUpdater.h>
@ -10,6 +36,7 @@
#include <utils/eoGnuplot1DSnapshot.h> #include <utils/eoGnuplot1DSnapshot.h>
#endif #endif
#include <utils/eoCheckPoint.h> #include <utils/eoCheckPoint.h>
#include <utils/eoSignal.h>
#include <utils/eoStat.h> #include <utils/eoStat.h>
#include <utils/eoScalarFitnessStat.h> #include <utils/eoScalarFitnessStat.h>
#include <utils/eoAssembledFitnessStat.h> #include <utils/eoAssembledFitnessStat.h>
@ -21,3 +48,9 @@
// and make_help - any better suggestion to include it? // and make_help - any better suggestion to include it?
void make_help(eoParser & _parser); void make_help(eoParser & _parser);
#endif // !_CHECKPOINTING_
// Local Variables:
// mode: C++
// End:

View file

@ -4,6 +4,8 @@
#include <eoFunctorStore.h> #include <eoFunctorStore.h>
#include <utils/eoStat.h> #include <utils/eoStat.h>
/** Wrapper to turn any stand-alone function and into an eoStat. /** Wrapper to turn any stand-alone function and into an eoStat.
* *
* The function should take an eoPop as argument. * The function should take an eoPop as argument.
@ -41,4 +43,38 @@ eoFuncPtrStat<EOT, T>& makeFuncPtrStat( T (*func)(const eoPop<EOT>&), eoFunctorS
); );
} }
/** Wrapper to turn any stand-alone function and into an eoStat.
*
* The function should take an eoPop as argument.
*
* @ingroup Stats
*/
template <class EOT, class T>
class eoFunctorStat : public eoStat<EOT, T>
{
public :
eoFunctorStat(eoUF< const eoPop<EOT>&, T >& f, std::string _description = "functor")
: eoStat<EOT, T>(T(), _description), func(f)
{}
using eoStat<EOT, T>::value;
void operator()(const eoPop<EOT>& pop) {
value() = func(pop);
}
private:
eoUF< const eoPop<EOT>&, T >& func;
};
/**
* @ingroup Stats
*/
template <class EOT, class T>
eoFunctorStat<EOT, T>& makeFunctorStat( eoUF< const eoPop<EOT>&, T >& func, eoFunctorStore& store, std::string description = "func") {
return store.storeFunctor(
new eoFunctorStat<EOT, T>( func, description)
);
}
#endif #endif

View file

@ -194,8 +194,7 @@ int eoLogger::outbuf::overflow(int_type c)
{ {
if (_fd >= 0 && c != EOF) if (_fd >= 0 && c != EOF)
{ {
size_t num; ::write(_fd, &c, 1);
num = ::write(_fd, &c, 1);
} }
} }
return c; return c;

View file

@ -44,12 +44,13 @@ Authors:
class eoOStreamMonitor : public eoMonitor class eoOStreamMonitor : public eoMonitor
{ {
public : public :
eoOStreamMonitor( std::ostream & _out, bool _verbose=true, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) : eoOStreamMonitor( std::ostream & _out, bool /*_verbose*/=true, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) :
out(_out), delim(_delim), width(_width), fill(_fill), firsttime(true) out(_out), delim(_delim), width(_width), fill(_fill), firsttime(true)
{ {
(void)_verbose; #ifndef DEPRECATED_MESSAGES
eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoOStreamMonitor constructor is deprecated and will be removed in the next release" << std::endl; eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoOStreamMonitor constructor is deprecated and will be removed in the next release" << std::endl;
#pragma message "WARNING: the use of the verbose parameter in eoOStreamMonitor constructor is deprecated and will be removed in the next release" #pragma message "WARNING: the use of the verbose parameter in eoOStreamMonitor constructor is deprecated and will be removed in the next release"
#endif // !DEPRECATED_MESSAGES
} }
eoOStreamMonitor( std::ostream & _out, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) : eoOStreamMonitor( std::ostream & _out, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) :

36
eo/src/utils/eoSignal.cpp Normal file
View file

@ -0,0 +1,36 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
/**
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
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: http://eodev.sourceforge.net
Autors: todos@geneura.ugr.es, http://geneura.ugr.es
Marc.Schoenauer@polytechnique.fr
mak@dhi.dk
Caner.Candan@univ-angers.fr
*/
#include <utils/eoSignal.h>
/**
* @addtogroup Continuators
* @{
*/
// --- Global variables - but don't know what else to do - MS ---
std::map< int, bool > signals_called;
/** @} */

106
eo/src/utils/eoSignal.h Normal file
View file

@ -0,0 +1,106 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
/**
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
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: http://eodev.sourceforge.net
Authors: todos@geneura.ugr.es, http://geneura.ugr.es
Marc.Schoenauer@polytechnique.fr
mak@dhi.dk
Caner.Candan@univ-angers.fr
*/
#ifndef _eoSignal_h
#define _eoSignal_h
#include <csignal>
#include <utils/eoCheckPoint.h>
#include <utils/eoLogger.h>
#include <map>
#include <vector>
/**
* @addtogroup Continuators
* @{
*/
extern std::map< int, bool > signals_called;
/** eoSignal inherits from eoCheckPoint including signals handling (see signal(7))
*
* @ingroup Utilities
*/
template <class EOT>
class eoSignal : public eoCheckPoint<EOT>
{
public :
eoSignal( int sig = SIGINT ) : eoCheckPoint<EOT>( _dummyContinue ), _sig( sig )
{
::signals_called[_sig] = false;
#ifndef _WINDOWS
#ifdef SIGQUIT
::signal( _sig, handler );
#endif // !SIGQUIT
#endif // !_WINDOWS
}
eoSignal( eoContinue<EOT>& _cont, int sig = SIGINT ) : eoCheckPoint<EOT>( _cont ), _sig( sig )
{
::signals_called[_sig] = false;
#ifndef _WINDOWS
#ifdef SIGQUIT
::signal( _sig, handler );
#endif // !SIGQUIT
#endif // !_WINDOWS
}
bool operator()( const eoPop<EOT>& _pop )
{
bool& called = ::signals_called[_sig];
if ( called )
{
eo::log << eo::logging << "Signal granted…" << std::endl ;
called = false;
return this->eoCheckPoint<EOT>::operator()( _pop );
}
return true;
}
virtual std::string className(void) const { return "eoSignal"; }
static void handler( int sig )
{
::signals_called[sig] = true;
eo::log << eo::logging << "Signal wished…" << std::endl ;
}
private:
class DummyContinue : public eoContinue<EOT>
{
public:
bool operator() ( const eoPop<EOT>& ) { return true; }
} _dummyContinue;
int _sig;
};
/** @} */
#endif // !_eoSignal_h

View file

@ -46,7 +46,9 @@ public :
eoStdoutMonitor(bool _verbose, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) : eoStdoutMonitor(bool _verbose, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) :
eoOStreamMonitor( std::cout, _verbose, _delim, _width, _fill) eoOStreamMonitor( std::cout, _verbose, _delim, _width, _fill)
{ {
eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoStdutMonitor constructor is deprecated and will be removed in the next release" << std::endl; #ifndef DEPRECATED_MESSAGES
eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoStdoutMonitor constructor is deprecated and will be removed in the next release" << std::endl;
#endif // !DEPRECATED_MESSAGES
} }
eoStdoutMonitor(std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) : eoStdoutMonitor(std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) :

View file

@ -66,7 +66,7 @@ SET (TEST_LIST
t-eoLogger t-eoLogger
t-eoIQRStat t-eoIQRStat
t-eoParallel t-eoParallel
t-openmp #t-openmp # does not work anymore since functions used in this test were removed from EO
#t-eoDualFitness #t-eoDualFitness
t-eoParser t-eoParser
) )

View file

@ -39,6 +39,8 @@ Caner Candan <caner.candan@thalesgroup.com>
#include <omp.h> #include <omp.h>
#include <unistd.h>
#include "real_value.h" #include "real_value.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------