Merge branch 'master' of /tools/eo
This commit is contained in:
commit
11f01d5a53
108 changed files with 8642 additions and 1297 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
In order to create a new release from the current repository, perform the
|
||||
following steps:
|
||||
|
||||
- If necessary, create a branch named "eo_x.y.z"
|
||||
- Set version number in eo-conf.cmake
|
||||
- Check/update NEWS file, set release date and version in NEWS.
|
||||
- use the "archive_current.sh" script to create the source archive
|
||||
- Build the packages
|
||||
- Put source archive and packages files at SourceForge
|
||||
- Post news on SourceForge project-page
|
||||
- Send announcement to mailing lists
|
||||
- Bump version number to next "x.y.z-edge" in eo-conf.cmake
|
||||
|
||||
|
||||
When reaching stable versions:
|
||||
- prepare a message with the following template:
|
||||
-----8<-----
|
||||
A new version of the "Evolving Objects" framework is available.
|
||||
|
||||
EO is a template-based, C++ evolutionary computation library which
|
||||
helps you to write your own stochastic optimization algorithms
|
||||
insanely fast.
|
||||
|
||||
Learn more about EO on the official website:
|
||||
http://eodev.sourceforge.net/
|
||||
|
||||
You will find the release x.y.z at the following address:
|
||||
https://sourceforge.net/projects/eodev/files/eo/
|
||||
|
||||
Here is a summary of the change log:
|
||||
- XXXXX
|
||||
- and more…
|
||||
|
||||
Do not hesitate to submit the bugs you will face:
|
||||
https://sourceforge.net/apps/trac/eodev/wiki/WikiStart
|
||||
|
||||
Happy evolutionary hacking.
|
||||
-----8<-----
|
||||
- Post the message to:
|
||||
- EO news https://sourceforge.net/news/?group_id=9775
|
||||
- EO mailing list: eodev-main@lists.sourceforge.net
|
||||
- ParadisEO mailing list: paradiseo-users@lists.gforge.inria.fr
|
||||
- EC-digest maling list: ec-digest-l@listserv.gmu.edu
|
||||
- JET mailing list: jet@inria.fr
|
||||
|
||||
37
eo/NEWS
37
eo/NEWS
|
|
@ -1,4 +1,29 @@
|
|||
* current version
|
||||
* current release:
|
||||
|
||||
* release 1.3.1 (2012-07-27)
|
||||
- the eo::mpi modules is no longer dependent from boost::mpi
|
||||
- parallel multi-start example
|
||||
- bugfix: an error is now thrown when accessing best_element of an empty population
|
||||
|
||||
* release 1.3.0 (2012-07-24)
|
||||
- features:
|
||||
- delete the deprecated code parts (was marked as deprecated in the release 1.1)
|
||||
- eoSignal: a class to handle signal with eoCheckpoint instances
|
||||
- eoDetSingleBitFlip: bit flip mutation that changes exactly k bits while checking for duplicate
|
||||
- eoFunctorStat: a wrapper to turn any stand-alone function and into an eoStat
|
||||
- generilazed the output of an eoState: now you can change the format, comes with defaults formatting (latex and json)
|
||||
- eoWrongParamTypeException: a new exception to handle cases where a wrong template is given to eoParser::valueOf
|
||||
- added a getParam method to the eoParser, that raise an exception if the parameter has not been declared
|
||||
- eoParserLogger features are now included in the default eoParser
|
||||
- build system:
|
||||
- improvements of the build architecture
|
||||
- create PKGBUILD file for archlinux package manager
|
||||
- a FindEO module for CMake
|
||||
- bugfixes:
|
||||
- fixed regression with gcc 4.7
|
||||
- fixed compilation issues in Microsoft Visual C++, related to time measurement
|
||||
- added several asserts accross the framework (note: asserts are included only in debug mode)
|
||||
- lot of small bugfixes :-)
|
||||
|
||||
* release 1.2 (16. May. 2011)
|
||||
- fixed the incremental allocation issue in variation operators which were
|
||||
|
|
@ -20,11 +45,11 @@
|
|||
- GCC 4.3 compatibility
|
||||
- new versatile log system with several nested verbose levels
|
||||
- classes using intern verbose parameters marked as deprecated, please update your code accordingly if you use one of the following files:
|
||||
eo/src/eoCombinedInit.h
|
||||
eo/src/eoGenContinue.h
|
||||
eo/src/eoProportionalCombinedOp.h
|
||||
eo/src/utils/eoData.h
|
||||
eo/src/utils/eoStdoutMonitor.h
|
||||
eo/src/eoCombinedInit.h
|
||||
eo/src/eoGenContinue.h
|
||||
eo/src/eoProportionalCombinedOp.h
|
||||
eo/src/utils/eoData.h
|
||||
eo/src/utils/eoStdoutMonitor.h
|
||||
- an evaluator that throw an exception if a maximum eval numbers has been reached, independently of the number of generations
|
||||
- new monitor that can write on any ostream
|
||||
- new continuator that can catch POSIX system user signals
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
The best place to learn about the features and approaches of %EO with the help of examples is to look at
|
||||
the <a href="../../tutorial/html/eoTutorial.html">tutorial</a>.
|
||||
|
||||
Once you have understand the @ref design of %EO, you could search for advanced features by browsing the <a
|
||||
Once you have understand the @ref design of %EO, you can search for advanced features by browsing the <a
|
||||
href="modules.html">modules</a> page.
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@
|
|||
# Current version
|
||||
SET(PROJECT_VERSION_MAJOR 1)
|
||||
SET(PROJECT_VERSION_MINOR 3)
|
||||
SET(PROJECT_VERSION_PATCH 0)
|
||||
SET(PROJECT_VERSION_PATCH 2)
|
||||
SET(PROJECT_VERSION_MISC "-edge")
|
||||
|
||||
# ADD_DEFINITIONS(-DDEPRECATED_MESSAGES) # disable warning deprecated function messages
|
||||
# If you plan to use OpenMP, put the following boolean to true :
|
||||
SET(WITH_OMP FALSE CACHE BOOL "Use OpenMP ?" FORCE)
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ PREFIX = "/usr"
|
|||
DATA = {
|
||||
'dirs': [ "%s/share/%s" % (PREFIX, NAME) ],
|
||||
'links': [ ("%s/src" % SOURCE, "%s/include/%s" % (PREFIX, NAME)),
|
||||
("%s/doc" % BINARY, "%s/share/%s/doc" % (PREFIX, NAME)),
|
||||
("%s/%s.pc" % (BINARY, NAME), "%s/lib/pkgconfig/%s.pc" % (PREFIX, NAME)),
|
||||
("%s/doc" % BINARY, "%s/share/%s/doc" % (PREFIX, NAME)),
|
||||
("%s/%s.pc" % (BINARY, NAME), "%s/lib/pkgconfig/%s.pc" % (PREFIX, NAME)),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -21,19 +21,27 @@ import os, sys
|
|||
|
||||
def isroot():
|
||||
if os.getuid() != 0:
|
||||
print '[WARNING] you have to be root'
|
||||
return False
|
||||
print('[WARNING] you have to be root')
|
||||
return False
|
||||
return True
|
||||
|
||||
def uninstall():
|
||||
for dummy, link in DATA['links']: os.remove(link)
|
||||
for dirname in DATA['dirs']: os.rmdir(dirname)
|
||||
print 'All symlinks have been removed.'
|
||||
print('All symlinks have been removed.')
|
||||
|
||||
def install():
|
||||
for dirname in DATA['dirs']: os.mkdir(dirname)
|
||||
for src, dst in DATA['links']: os.symlink(src, dst)
|
||||
print 'All symlinks have been installed.'
|
||||
for dirname in DATA['dirs']:
|
||||
try:
|
||||
os.makedirs(dirname)
|
||||
except(os.error):
|
||||
pass
|
||||
for src, dst in DATA['links']:
|
||||
try:
|
||||
os.symlink(src, dst)
|
||||
except:
|
||||
pass
|
||||
print('All symlinks have been installed.')
|
||||
|
||||
def data():
|
||||
from pprint import pprint
|
||||
|
|
@ -41,11 +49,11 @@ def data():
|
|||
|
||||
if __name__ == '__main__':
|
||||
if not isroot():
|
||||
sys.exit()
|
||||
sys.exit()
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print 'Usage: %s [install|uninstall|data]' % sys.argv[0]
|
||||
sys.exit()
|
||||
print(('Usage: %s [install|uninstall|data]' % sys.argv[0]))
|
||||
sys.exit()
|
||||
|
||||
if sys.argv[1] == 'install': install()
|
||||
elif sys.argv[1] == 'uninstall': uninstall()
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
|||
IF(WITH_MPI)
|
||||
MESSAGE("[EO] Compilation with MPI.")
|
||||
|
||||
SET(CMAKE_CXX_COMPILER "${MPI_DIR}/bin/mpicxx")
|
||||
#SET(CMAKE_CXX_COMPILER "${MPI_DIR}/bin/mpicxx")
|
||||
SET(CMAKE_CXX_COMPILER mpicxx)
|
||||
|
||||
# headers location
|
||||
INCLUDE_DIRECTORIES(${MPI_DIR}/include)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
mak@dhi.dk
|
||||
mak@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -31,7 +31,10 @@
|
|||
#include <utils/eoLogger.h>
|
||||
#include <eoFunctor.h>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
Applies a unary function to a std::vector of things.
|
||||
|
|
@ -55,14 +58,26 @@ void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
|
|||
if (!eo::parallel.isDynamic())
|
||||
{
|
||||
#pragma omp parallel for if(eo::parallel.isEnabled()) //default(none) shared(_proc, _pop, size)
|
||||
#ifdef _MSC_VER
|
||||
//Visual Studio supports only OpenMP version 2.0 in which
|
||||
//an index variable must be of a signed integral type
|
||||
for (long long i = 0; i < size; ++i) { _proc(_pop[i]); }
|
||||
#else // _MSC_VER
|
||||
for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); }
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma omp parallel for schedule(dynamic) if(eo::parallel.isEnabled())
|
||||
#ifdef _MSC_VER
|
||||
//Visual Studio supports only OpenMP version 2.0 in which
|
||||
//an index variable must be of a signed integral type
|
||||
for (long long i = 0; i < size; ++i) { _proc(_pop[i]); }
|
||||
#else // _MSC_VER
|
||||
//doesnot work with gcc 4.1.2
|
||||
//default(none) shared(_proc, _pop, size)
|
||||
for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); }
|
||||
#endif
|
||||
}
|
||||
|
||||
if ( eo::parallel.enableResults() )
|
||||
|
|
@ -94,7 +109,7 @@ void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
|
|||
// //default(none) shared(_proc, _pop, size)
|
||||
// for (size_t i = 0; i < size; ++i)
|
||||
// {
|
||||
// _proc(_pop[i]);
|
||||
// _proc(_pop[i]);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
|
@ -112,7 +127,7 @@ void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
|
|||
// //default(none) shared(_proc, _pop, size)
|
||||
// for (size_t i = 0; i < size; ++i)
|
||||
// {
|
||||
// _proc(_pop[i]);
|
||||
// _proc(_pop[i]);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +1,32 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// make_checkpoint.h
|
||||
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000
|
||||
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
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.
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
|
||||
mkeijzer@dhi.dk
|
||||
|
||||
*/
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mkeijzer@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#ifndef _make_checkpoint_h
|
||||
|
||||
#define _make_checkpoint_h
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
|
@ -52,521 +39,315 @@
|
|||
#include <eoEvalFuncCounter.h>
|
||||
#include <utils/checkpointing>
|
||||
|
||||
|
||||
|
||||
// at the moment, in utils/make_help.cpp
|
||||
|
||||
// this should become some eoUtils.cpp with corresponding eoUtils.h
|
||||
|
||||
bool testDirRes(std::string _dirName, bool _erase);
|
||||
|
||||
/////////////////// The checkpoint and other I/O //////////////
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 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!!
|
||||
*
|
||||
* @ingroup Builders
|
||||
*/
|
||||
*/
|
||||
template <class EOT>
|
||||
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
|
||||
eoCheckPoint<EOT> *checkpoint = new eoCheckPoint<EOT>(_continue);
|
||||
_state.storeFunctor(checkpoint);
|
||||
|
||||
_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
|
||||
|
||||
//////////////////
|
||||
|
||||
// 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);
|
||||
// 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);
|
||||
|
||||
// dir for DISK output
|
||||
|
||||
eoValueParam<std::string>& dirNameParam = _parser.createParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output - Disk");
|
||||
|
||||
// shoudl we empty it if exists
|
||||
|
||||
eoValueParam<bool>& eraseParam = _parser.createParam(true, "eraseDir", "erase files in dirName if any", '\0', "Output - Disk");
|
||||
|
||||
bool dirOK = false; // not tested yet
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////
|
||||
|
||||
// now some statistics on the population:
|
||||
|
||||
/////////////////////////////////////////
|
||||
|
||||
/**
|
||||
|
||||
* existing stats as of today, April 10. 2001
|
||||
|
||||
*
|
||||
|
||||
* eoBestFitnessStat : best value in pop - type EOT::Fitness
|
||||
|
||||
* eoAverageStat : average value in pop - type EOT::Fitness
|
||||
|
||||
* eoSecondMomentStat: average + stdev - type std::pair<double, double>
|
||||
|
||||
* eoSortedPopStat : whole population - type std::string (!!)
|
||||
|
||||
* eoScalarFitnessStat: the fitnesses - type std::vector<double>
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// Best fitness in population
|
||||
|
||||
//---------------------------
|
||||
|
||||
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>& fileBestParam = _parser.createParam(false, "fileBestStat", "Output bes/avg/std to file", '\0', "Output - Disk");
|
||||
|
||||
|
||||
|
||||
eoBestFitnessStat<EOT> *bestStat = NULL;
|
||||
|
||||
if ( printBestParam.value() || plotBestParam.value() || fileBestParam.value() )
|
||||
|
||||
// we need the bestStat for at least one of the 3 above
|
||||
|
||||
{
|
||||
|
||||
bestStat = new eoBestFitnessStat<EOT>;
|
||||
|
||||
// store it
|
||||
|
||||
_state.storeFunctor(bestStat);
|
||||
|
||||
// add it to the checkpoint
|
||||
|
||||
checkpoint->add(*bestStat);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// we need the bestStat for at least one of the 3 above
|
||||
{
|
||||
bestStat = new eoBestFitnessStat<EOT>;
|
||||
// store it
|
||||
_state.storeFunctor(bestStat);
|
||||
// add it to the checkpoint
|
||||
checkpoint->add(*bestStat);
|
||||
// check if monitoring with signal
|
||||
if ( mon_ctrlCParam.value() )
|
||||
mon_ctrlCCont->add(*bestStat);
|
||||
}
|
||||
|
||||
// Average fitness alone
|
||||
|
||||
//----------------------
|
||||
|
||||
eoAverageStat<EOT> *averageStat = NULL; // do we need averageStat?
|
||||
|
||||
if ( plotBestParam.value() ) // we need it for gnuplot output
|
||||
|
||||
{
|
||||
|
||||
averageStat = new eoAverageStat<EOT>;
|
||||
|
||||
// store it
|
||||
|
||||
_state.storeFunctor(averageStat);
|
||||
|
||||
// add it to the checkpoint
|
||||
|
||||
checkpoint->add(*averageStat);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ( printBestParam.value() || plotBestParam.value() || fileBestParam.value() ) // we need it for gnuplot output
|
||||
{
|
||||
averageStat = new eoAverageStat<EOT>;
|
||||
// store it
|
||||
_state.storeFunctor(averageStat);
|
||||
// add it to the checkpoint
|
||||
checkpoint->add(*averageStat);
|
||||
// check if monitoring with signal
|
||||
if ( mon_ctrlCParam.value() )
|
||||
mon_ctrlCCont->add(*averageStat);
|
||||
}
|
||||
|
||||
// Second moment stats: average and stdev
|
||||
|
||||
//---------------------------------------
|
||||
|
||||
eoSecondMomentStats<EOT> *secondStat = NULL;
|
||||
|
||||
if ( printBestParam.value() || fileBestParam.value() ) // we need it for screen output or file output
|
||||
|
||||
{
|
||||
|
||||
secondStat = new eoSecondMomentStats<EOT>;
|
||||
|
||||
// store it
|
||||
|
||||
_state.storeFunctor(secondStat);
|
||||
|
||||
// add it to the checkpoint
|
||||
|
||||
checkpoint->add(*secondStat);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if ( printBestParam.value() || fileBestParam.value() ) // we need it for screen output or file output
|
||||
{
|
||||
secondStat = new eoSecondMomentStats<EOT>;
|
||||
// store it
|
||||
_state.storeFunctor(secondStat);
|
||||
// add it to the checkpoint
|
||||
checkpoint->add(*secondStat);
|
||||
// check if monitoring with signal
|
||||
if ( mon_ctrlCParam.value() )
|
||||
mon_ctrlCCont->add(*secondStat);
|
||||
}
|
||||
|
||||
// Dump of the whole population
|
||||
|
||||
//-----------------------------
|
||||
|
||||
eoSortedPopStat<EOT> *popStat = NULL;
|
||||
|
||||
eoValueParam<bool>& printPopParam = _parser.createParam(false, "printPop", "Print sorted pop. every gen.", '\0', "Output");
|
||||
|
||||
if ( printPopParam.value() ) // we do want pop dump
|
||||
|
||||
{
|
||||
|
||||
popStat = new eoSortedPopStat<EOT>;
|
||||
|
||||
// store it
|
||||
|
||||
_state.storeFunctor(popStat);
|
||||
|
||||
// add it to the checkpoint
|
||||
|
||||
checkpoint->add(*popStat);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
popStat = new eoSortedPopStat<EOT>;
|
||||
// store it
|
||||
_state.storeFunctor(popStat);
|
||||
// add it to the checkpoint
|
||||
checkpoint->add(*popStat);
|
||||
// check if monitoring with signal
|
||||
if ( mon_ctrlCParam.value() )
|
||||
mon_ctrlCCont->add(*popStat);
|
||||
}
|
||||
|
||||
// do we wnat some histogram of fitnesses snpashots?
|
||||
|
||||
eoValueParam<bool> plotHistogramParam = _parser.createParam(false, "plotHisto", "Plot histogram of fitnesses", '\0', "Output - Graphical");
|
||||
|
||||
|
||||
|
||||
///////////////
|
||||
|
||||
// The monitors
|
||||
|
||||
///////////////
|
||||
|
||||
// do we want an eoStdoutMonitor?
|
||||
|
||||
bool needStdoutMonitor = printBestParam.value()
|
||||
|
||||
|| printPopParam.value() ;
|
||||
|
||||
|
||||
|
||||
// The Stdout monitor will print parameters to the screen ...
|
||||
|
||||
if ( needStdoutMonitor )
|
||||
{
|
||||
eoStdoutMonitor *monitor = new eoStdoutMonitor(/*false FIXME remove this deprecated prototype*/);
|
||||
_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);
|
||||
|
||||
|
||||
|
||||
// when called by the checkpoint (i.e. at every generation)
|
||||
|
||||
checkpoint->add(*monitor);
|
||||
|
||||
|
||||
|
||||
// the monitor will output a series of parameters: add them
|
||||
|
||||
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 (useEvalParam.value()) // we want nb of evaluations
|
||||
monitor->add(_eval);
|
||||
if (useTimeParam.value()) // we want time
|
||||
{
|
||||
tCounter = new eoTimeCounter;
|
||||
_state.storeFunctor(tCounter);
|
||||
// check if monitoring with signal
|
||||
if ( ! mon_ctrlCParam.value() )
|
||||
checkpoint->add(*tCounter);
|
||||
else
|
||||
mon_ctrlCCont->add(*tCounter);
|
||||
monitor->add(*tCounter);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
if ( ( fileBestParam.value() || plotBestParam.value() ||
|
||||
|
||||
plotHistogramParam.value() )
|
||||
|
||||
&& !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
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
#ifdef _MSVC
|
||||
|
||||
std::string stmp = dirNameParam.value() + "\best.xg";
|
||||
|
||||
std::string stmp = dirNameParam.value() + "\best.xg";
|
||||
#else
|
||||
|
||||
std::string stmp = dirNameParam.value() + "/best.xg";
|
||||
|
||||
std::string stmp = dirNameParam.value() + "/best.xg";
|
||||
#endif
|
||||
|
||||
eoFileMonitor *fileMonitor = new eoFileMonitor(stmp);
|
||||
|
||||
// save and give to checkpoint
|
||||
|
||||
_state.storeFunctor(fileMonitor);
|
||||
|
||||
checkpoint->add(*fileMonitor);
|
||||
|
||||
// and feed with some statistics
|
||||
|
||||
fileMonitor->add(*generationCounter);
|
||||
|
||||
fileMonitor->add(_eval);
|
||||
|
||||
if (tCounter) // we want the time as well
|
||||
|
||||
{
|
||||
|
||||
// std::cout << "On met timecounter\n";
|
||||
|
||||
fileMonitor->add(*tCounter);
|
||||
|
||||
}
|
||||
|
||||
fileMonitor->add(*bestStat);
|
||||
|
||||
fileMonitor->add(*secondStat);
|
||||
|
||||
}
|
||||
|
||||
|
||||
eoFileMonitor *fileMonitor = new eoFileMonitor(stmp);
|
||||
// save and give to checkpoint
|
||||
_state.storeFunctor(fileMonitor);
|
||||
checkpoint->add(*fileMonitor);
|
||||
// and feed with some statistics
|
||||
fileMonitor->add(*generationCounter);
|
||||
fileMonitor->add(_eval);
|
||||
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 (plotBestParam.value()) // an eoGnuplot1DMonitor for best & average
|
||||
|
||||
{
|
||||
|
||||
std::string stmp = dirNameParam.value() + "/gnu_best.xg";
|
||||
|
||||
eoGnuplot1DMonitor *gnuMonitor = new eoGnuplot1DMonitor(stmp,minimizing_fitness<EOT>());
|
||||
|
||||
// save and give to checkpoint
|
||||
|
||||
_state.storeFunctor(gnuMonitor);
|
||||
|
||||
checkpoint->add(*gnuMonitor);
|
||||
|
||||
// and feed with some statistics
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
std::string stmp = dirNameParam.value() + "/gnu_best.xg";
|
||||
eoGnuplot1DMonitor *gnuMonitor = new eoGnuplot1DMonitor(stmp,minimizing_fitness<EOT>());
|
||||
// save and give to checkpoint
|
||||
_state.storeFunctor(gnuMonitor);
|
||||
checkpoint->add(*gnuMonitor);
|
||||
// and feed with some statistics
|
||||
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?
|
||||
|
||||
if (plotHistogramParam.value()) // want to see how the fitness is spread?
|
||||
|
||||
{
|
||||
|
||||
eoScalarFitnessStat<EOT> *fitStat = new eoScalarFitnessStat<EOT>;
|
||||
|
||||
_state.storeFunctor(fitStat);
|
||||
|
||||
checkpoint->add(*fitStat);
|
||||
|
||||
// a gnuplot-based monitor for snapshots: needs a dir name
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
{
|
||||
eoScalarFitnessStat<EOT> *fitStat = new eoScalarFitnessStat<EOT>;
|
||||
_state.storeFunctor(fitStat);
|
||||
checkpoint->add(*fitStat);
|
||||
// a gnuplot-based monitor for snapshots: needs a dir name
|
||||
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
|
||||
|
||||
//////////////////////////////////
|
||||
|
||||
// State savers
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
|
||||
|
||||
// feed the state to state savers
|
||||
|
||||
// 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" );
|
||||
|
||||
|
||||
|
||||
if (_parser.isItThere(saveFrequencyParam))
|
||||
{
|
||||
// first make sure dirName is OK
|
||||
if (! dirOK )
|
||||
dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE
|
||||
|
||||
{
|
||||
|
||||
// first make sure dirName is OK
|
||||
|
||||
if (! dirOK )
|
||||
|
||||
dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE
|
||||
|
||||
|
||||
|
||||
unsigned freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX );
|
||||
|
||||
unsigned freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX );
|
||||
#ifdef _MSVC
|
||||
|
||||
std::string stmp = dirNameParam.value() + "\generations";
|
||||
|
||||
std::string stmp = dirNameParam.value() + "\generations";
|
||||
#else
|
||||
|
||||
std::string stmp = dirNameParam.value() + "/generations";
|
||||
|
||||
std::string stmp = dirNameParam.value() + "/generations";
|
||||
#endif
|
||||
|
||||
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
|
||||
|
||||
_state.storeFunctor(stateSaver1);
|
||||
|
||||
checkpoint->add(*stateSaver1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
|
||||
_state.storeFunctor(stateSaver1);
|
||||
checkpoint->add(*stateSaver1);
|
||||
}
|
||||
|
||||
// save state every T seconds
|
||||
|
||||
eoValueParam<unsigned>& saveTimeIntervalParam = _parser.createParam(unsigned(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" );
|
||||
|
||||
if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0)
|
||||
|
||||
{
|
||||
|
||||
// first make sure dirName is OK
|
||||
|
||||
if (! dirOK )
|
||||
|
||||
dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE
|
||||
|
||||
|
||||
{
|
||||
// first make sure dirName is OK
|
||||
if (! dirOK )
|
||||
dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE
|
||||
|
||||
#ifdef _MSVC
|
||||
|
||||
std::string stmp = dirNameParam.value() + "\time";
|
||||
|
||||
std::string stmp = dirNameParam.value() + "\time";
|
||||
#else
|
||||
|
||||
std::string stmp = dirNameParam.value() + "/time";
|
||||
|
||||
std::string stmp = dirNameParam.value() + "/time";
|
||||
#endif
|
||||
|
||||
eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp);
|
||||
|
||||
_state.storeFunctor(stateSaver2);
|
||||
|
||||
checkpoint->add(*stateSaver2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp);
|
||||
_state.storeFunctor(stateSaver2);
|
||||
checkpoint->add(*stateSaver2);
|
||||
}
|
||||
|
||||
// and that's it for the (control and) output
|
||||
|
||||
return *checkpoint;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ eoCheckPoint<EOT>& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval
|
|||
// The Stdout monitor will print parameters to the screen ...
|
||||
if ( needStdoutMonitor )
|
||||
{
|
||||
eoStdoutMonitor *monitor = new eoStdoutMonitor(false);
|
||||
eoStdoutMonitor *monitor = new eoStdoutMonitor(/*false FIXME remove this deprecated prototype*/);
|
||||
_state.storeFunctor(monitor);
|
||||
|
||||
// when called by the checkpoint (i.e. at every generation)
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ eoCheckPoint<EOT>& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta
|
|||
|
||||
// STDOUT
|
||||
// ------
|
||||
eoStdoutMonitor *monitor = new eoStdoutMonitor(false);
|
||||
eoStdoutMonitor *monitor = new eoStdoutMonitor(/*false FIXME remove this deprecated prototype*/);
|
||||
_state.storeFunctor(monitor);
|
||||
checkpoint->add(*monitor);
|
||||
monitor->add(*generationCounter);
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@
|
|||
#include <eoSharingSelect.h>
|
||||
// Embedding truncation selection
|
||||
#include <eoTruncatedSelectOne.h>
|
||||
#include <eoRankMuSelect.h>
|
||||
|
||||
// the batch selection - from an eoSelectOne
|
||||
#include <eoSelectPerc.h>
|
||||
|
|
|
|||
|
|
@ -57,26 +57,35 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
/* FIXME remove in next release
|
||||
/// Ctor - for historical reasons ... should disspear some day
|
||||
eoCombinedContinue( eoContinue<EOT>& _cont1, eoContinue<EOT>& _cont2)
|
||||
: 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."
|
||||
#endif // !DEPRECATED_MESSAGES
|
||||
|
||||
this->push_back(&_cont1);
|
||||
this->push_back(&_cont2);
|
||||
}
|
||||
*/
|
||||
|
||||
void add(eoContinue<EOT> & _cont)
|
||||
{
|
||||
this->push_back(&_cont);
|
||||
}
|
||||
|
||||
/* FIXME remove in next release
|
||||
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."
|
||||
#endif // !DEPRECATED_MESSAGES
|
||||
|
||||
this->pop_back();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/** Returns false when one of the embedded continuators say so (logical and)
|
||||
|
|
|
|||
|
|
@ -44,11 +44,13 @@ public:
|
|||
rates.push_back(_rate);
|
||||
}
|
||||
|
||||
/* FIXME remove in next release
|
||||
void add(eoInit<EOT> & _init, double _rate, bool _verbose)
|
||||
{
|
||||
eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoCombinedInit::add is deprecated and will be removed in the next release." << std::endl;
|
||||
add( _init, _rate );
|
||||
}
|
||||
*/
|
||||
|
||||
/** The usual method to add objects to the combination
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
#ifndef eoCtrlCContinue_h
|
||||
#define eoCtrlCContinue_h
|
||||
|
||||
#include <signal.h>
|
||||
#include <csignal>
|
||||
#include <eoContinue.h>
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
#include <math.h>
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** eoDetSelect selects many individuals determinisctically
|
||||
/** eoDetSelect selects many individuals deterministically
|
||||
*
|
||||
* @ingroup Selectors
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -21,27 +21,30 @@ Authors:
|
|||
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||
*/
|
||||
|
||||
#ifndef __unix__
|
||||
#warning "Warning: class 'eoEvalUserTimeThrowException' is only available under UNIX systems (defining 'rusage' in 'sys/resource.h'), contributions for other systems are welcomed."
|
||||
#else
|
||||
#if !defined(__unix__) && !defined(_WINDOWS)
|
||||
#warning "Warning: class 'eoEvalUserTimeThrowException' is only available under UNIX (defining 'rusage' in 'sys/resource.h') or Win32 (defining 'GetProcessTimes' in 'WinBase.h') systems, contributions for other systems are welcomed."
|
||||
#else //!defined(__unix__) && !defined(_WINDOWS)
|
||||
|
||||
#ifndef __EOEVALUSERTIMETHROWEXCEPTION_H__
|
||||
#define __EOEVALUSERTIMETHROWEXCEPTION_H__
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include <eoExceptions.h>
|
||||
|
||||
/** Check at each evaluation if a given CPU user time contract has been reached.
|
||||
*
|
||||
* Throw an eoMaxTimeException if the given max time has been reached.
|
||||
* Usefull if you want to end the search independently of generations.
|
||||
* This class uses (almost-)POSIX headers.
|
||||
* This class uses (almost-)POSIX or Win32 headers, depending on the platform.
|
||||
* It uses a computation of the user time used on the CPU. For a wallclock time measure, see eoEvalTimeThrowException
|
||||
*
|
||||
* @ingroup Evaluation
|
||||
*/
|
||||
|
||||
#include <eoExceptions.h>
|
||||
|
||||
#ifdef __unix__
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
template< class EOT >
|
||||
class eoEvalUserTimeThrowException : public eoEvalFuncCounter< EOT >
|
||||
{
|
||||
|
|
@ -58,7 +61,7 @@ public:
|
|||
if( current >= _max ) {
|
||||
throw eoMaxTimeException( current );
|
||||
} else {
|
||||
func(eo);
|
||||
this->func(eo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -68,5 +71,41 @@ protected:
|
|||
struct rusage _usage;
|
||||
};
|
||||
|
||||
#else
|
||||
#ifdef _WINDOWS
|
||||
//here _WINDOWS is defined
|
||||
|
||||
#include <WinBase.h>
|
||||
|
||||
template< class EOT >
|
||||
class eoEvalUserTimeThrowException : public eoEvalFuncCounter< EOT >
|
||||
{
|
||||
public:
|
||||
eoEvalUserTimeThrowException( eoEvalFunc<EOT> & func, const long max ) : eoEvalFuncCounter<EOT>( func, "CPU-user"), _max(max) {}
|
||||
|
||||
virtual void operator() ( EOT & eo )
|
||||
{
|
||||
if( eo.invalid() ) {
|
||||
FILETIME dummy;
|
||||
GetProcessTimes(GetCurrentProcess(), &dummy, &dummy, &dummy, &_usage);
|
||||
|
||||
ULARGE_INTEGER current;
|
||||
current.LowPart = _usage.dwLowDateTime;
|
||||
current.HighPart = _usage.dwHighDateTime;
|
||||
if( current.QuadPart >= _max ) {
|
||||
throw eoMaxTimeException( current.QuadPart );
|
||||
} else {
|
||||
func(eo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
const long _max;
|
||||
FILETIME _usage;
|
||||
};
|
||||
|
||||
#endif // _WINDOWS
|
||||
#endif //__unix__
|
||||
#endif // __EOEVALUSERTIMETHROWEXCEPTION_H__
|
||||
#endif // __UNIX__
|
||||
#endif //!defined(__unix__) && !defined(_WINDOWS)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@
|
|||
#define _eoFunctorStore_h
|
||||
|
||||
#include <vector>
|
||||
#include<algorithm>
|
||||
|
||||
#include "utils/eoLogger.h"
|
||||
|
||||
class eoFunctorBase;
|
||||
|
||||
|
|
@ -52,6 +55,13 @@ public:
|
|||
template <class Functor>
|
||||
Functor& storeFunctor(Functor* r)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
unsigned int existing = std::count( vec.begin(), vec.end(), r );
|
||||
if( existing > 0 ) {
|
||||
eo::log << eo::warnings << "WARNING: you asked eoFunctorStore to store the functor " << r << " "
|
||||
<< existing + 1 << " times, a segmentation fault may occur in the destructor." << std::endl;
|
||||
}
|
||||
#endif
|
||||
// If the compiler complains about the following line,
|
||||
// check if you really are giving it a pointer to an
|
||||
// eoFunctorBase derived object
|
||||
|
|
@ -67,6 +77,7 @@ private :
|
|||
/** no assignment allowed */
|
||||
eoFunctorStore operator=(const eoFunctorStore&);
|
||||
|
||||
protected:
|
||||
std::vector<eoFunctorBase*> vec;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class eoMergeReduce : public eoReplacement<EOT>
|
|||
merge(_merge), reduce(_reduce)
|
||||
{}
|
||||
|
||||
void operator()(eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
|
||||
virtual void operator()(eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
|
||||
{
|
||||
merge(_parents, _offspring); // parents untouched, result in offspring
|
||||
reduce(_offspring, _parents.size());
|
||||
|
|
@ -92,6 +92,14 @@ class eoCommaReplacement : public eoMergeReduce<EOT>
|
|||
public :
|
||||
eoCommaReplacement() : eoMergeReduce<EOT>(no_elite, truncate) {}
|
||||
|
||||
virtual void operator()(eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
|
||||
{
|
||||
// There must be more offsprings than parents, or else an exception will be raised
|
||||
assert( _offspring.size() >= _parents.size() );
|
||||
|
||||
eoMergeReduce<EOT>::operator()( _parents, _offspring );
|
||||
}
|
||||
|
||||
private :
|
||||
eoNoElitism<EOT> no_elite;
|
||||
eoTruncate<EOT> truncate;
|
||||
|
|
|
|||
485
eo/src/eoPop.h
485
eo/src/eoPop.h
|
|
@ -4,31 +4,41 @@
|
|||
// eoPop.h
|
||||
// (c) GeNeura Team, 1998
|
||||
/*
|
||||
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 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.
|
||||
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
|
||||
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
|
||||
*/
|
||||
Authors:
|
||||
todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
jmerelo
|
||||
gustavoromero
|
||||
mac
|
||||
maartenkeijzer
|
||||
kuepper
|
||||
okoenig
|
||||
evomarc
|
||||
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _EOPOP_H
|
||||
#define _EOPOP_H
|
||||
#ifndef _EOPOP_H_
|
||||
#define _EOPOP_H_
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iterator> // needed for GCC 3.2
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
|
||||
// EO includes
|
||||
#include <eoOp.h> // for eoInit
|
||||
|
|
@ -54,18 +64,18 @@
|
|||
template<class EOT>
|
||||
class eoPop: public std::vector<EOT>, public eoObject, public eoPersistent
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
using std::vector<EOT>::size;
|
||||
using std::vector<EOT>::resize;
|
||||
using std::vector<EOT>::operator[];
|
||||
using std::vector<EOT>::begin;
|
||||
using std::vector<EOT>::end;
|
||||
using std::vector<EOT>::size;
|
||||
using std::vector<EOT>::resize;
|
||||
using std::vector<EOT>::operator[];
|
||||
using std::vector<EOT>::begin;
|
||||
using std::vector<EOT>::end;
|
||||
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
#if defined(__CUDACC__)
|
||||
typedef typename std::vector<EOT>::iterator iterator;
|
||||
typedef typename std::vector<EOT>::const_iterator const_iterator;
|
||||
typedef typename std::vector<EOT>::iterator iterator;
|
||||
typedef typename std::vector<EOT>::const_iterator const_iterator;
|
||||
#endif
|
||||
|
||||
/** Default ctor. Creates empty pop
|
||||
|
|
@ -74,268 +84,297 @@ public:
|
|||
|
||||
/** Ctor for the initialization of chromosomes
|
||||
|
||||
@param _popSize total population size
|
||||
@param _chromInit Initialization routine, produces EO's, needs to be an eoInit
|
||||
@param _popSize total population size
|
||||
@param _chromInit Initialization routine, produces EO's, needs to be an eoInit
|
||||
*/
|
||||
eoPop( unsigned _popSize, eoInit<EOT>& _chromInit )
|
||||
:std::vector<EOT>()
|
||||
{
|
||||
resize(_popSize);
|
||||
for ( unsigned i = 0; i < _popSize; i++ )
|
||||
{
|
||||
eoPop( unsigned _popSize, eoInit<EOT>& _chromInit )
|
||||
: std::vector<EOT>()
|
||||
{
|
||||
resize(_popSize);
|
||||
for ( unsigned i = 0; i < _popSize; i++ )
|
||||
{
|
||||
_chromInit(operator[](i));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/** appends random guys at end of pop.
|
||||
Can be used to initialize it pop is empty
|
||||
Can be used to initialize it pop is empty
|
||||
|
||||
@param _newPopSize total population size
|
||||
@param _chromInit Initialization routine, produces EO's, needs to be an eoInit
|
||||
@param _newPopSize total population size
|
||||
@param _chromInit Initialization routine, produces EO's, needs to be an eoInit
|
||||
*/
|
||||
void append( unsigned _newPopSize, eoInit<EOT>& _chromInit )
|
||||
{
|
||||
unsigned oldSize = size();
|
||||
if (_newPopSize < oldSize)
|
||||
void append( unsigned _newPopSize, eoInit<EOT>& _chromInit )
|
||||
{
|
||||
throw std::runtime_error("New size smaller than old size in pop.append");
|
||||
return;
|
||||
unsigned oldSize = size();
|
||||
if (_newPopSize < oldSize)
|
||||
{
|
||||
throw std::runtime_error("New size smaller than old size in pop.append");
|
||||
return;
|
||||
}
|
||||
if (_newPopSize == oldSize)
|
||||
return;
|
||||
resize(_newPopSize); // adjust the size
|
||||
for ( unsigned i = oldSize; i < _newPopSize; i++ )
|
||||
{
|
||||
_chromInit(operator[](i));
|
||||
}
|
||||
}
|
||||
if (_newPopSize == oldSize)
|
||||
return;
|
||||
resize(_newPopSize); // adjust the size
|
||||
for ( unsigned i = oldSize; i < _newPopSize; i++ )
|
||||
|
||||
|
||||
/** Ctor from an std::istream; reads the population from a stream,
|
||||
each element should be in different lines
|
||||
@param _is the stream
|
||||
*/
|
||||
eoPop( std::istream& _is ) :std::vector<EOT>()
|
||||
{
|
||||
_chromInit(operator[](i));
|
||||
readFrom( _is );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Ctor from an std::istream; reads the population from a stream,
|
||||
each element should be in different lines
|
||||
@param _is the stream
|
||||
*/
|
||||
eoPop( std::istream& _is ) :std::vector<EOT>() {
|
||||
readFrom( _is );
|
||||
}
|
||||
|
||||
/** Empty Dtor */
|
||||
/** Empty Dtor */
|
||||
virtual ~eoPop() {}
|
||||
|
||||
|
||||
/// helper struct for getting a pointer
|
||||
struct Ref { const EOT* operator()(const EOT& eot) { return &eot;}};
|
||||
/// helper struct for comparing on pointers
|
||||
struct Cmp {
|
||||
bool operator()(const EOT* a, const EOT* b) const
|
||||
/// helper struct for getting a pointer
|
||||
struct Ref { const EOT* operator()(const EOT& eot) { return &eot;}};
|
||||
|
||||
/// helper struct for comparing on pointers
|
||||
struct Cmp {
|
||||
bool operator()(const EOT* a, const EOT* b) const
|
||||
{ return b->operator<(*a); }
|
||||
};
|
||||
/// helper struct for comparing (EA or PSO)
|
||||
struct Cmp2
|
||||
{
|
||||
bool operator()(const EOT & a,const EOT & b) const
|
||||
};
|
||||
|
||||
/// helper struct for comparing (EA or PSO)
|
||||
struct Cmp2
|
||||
{
|
||||
bool operator()(const EOT & a,const EOT & b) const
|
||||
{
|
||||
return b.operator<(a);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
sort the population. Use this member to sort in order
|
||||
of descending Fitness, so the first individual is the best!
|
||||
*/
|
||||
void sort(void)
|
||||
{
|
||||
std::sort(begin(), end(), Cmp2());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** creates a std::vector<EOT*> pointing to the individuals in descending order */
|
||||
void sort(std::vector<const EOT*>& result) const
|
||||
{
|
||||
result.resize(size());
|
||||
|
||||
/**
|
||||
sort the population. Use this member to sort in order
|
||||
of descending Fitness, so the first individual is the best!
|
||||
*/
|
||||
void sort(void)
|
||||
{
|
||||
std::sort(begin(), end(), Cmp2());
|
||||
}
|
||||
std::transform(begin(), end(), result.begin(), Ref());
|
||||
|
||||
/** creates a std::vector<EOT*> pointing to the individuals in descending order */
|
||||
void sort(std::vector<const EOT*>& result) const
|
||||
{
|
||||
result.resize(size());
|
||||
std::sort(result.begin(), result.end(), Cmp());
|
||||
}
|
||||
|
||||
std::transform(begin(), end(), result.begin(), Ref());
|
||||
|
||||
std::sort(result.begin(), result.end(), Cmp());
|
||||
}
|
||||
/**
|
||||
shuffle the population. Use this member to put the population
|
||||
in random order
|
||||
*/
|
||||
void shuffle(void)
|
||||
{
|
||||
UF_random_generator<unsigned int> gen;
|
||||
std::random_shuffle(begin(), end(), gen);
|
||||
}
|
||||
|
||||
/**
|
||||
shuffle the population. Use this member to put the population
|
||||
in random order
|
||||
*/
|
||||
void shuffle(void)
|
||||
{
|
||||
UF_random_generator<unsigned int> gen;
|
||||
std::random_shuffle(begin(), end(), gen);
|
||||
}
|
||||
|
||||
/** creates a std::vector<EOT*> pointing to the individuals in random order */
|
||||
void shuffle(std::vector<const EOT*>& result) const
|
||||
{
|
||||
result.resize(size());
|
||||
/** creates a std::vector<EOT*> pointing to the individuals in random order */
|
||||
void shuffle(std::vector<const EOT*>& result) const
|
||||
{
|
||||
result.resize(size());
|
||||
|
||||
std::transform(begin(), end(), result.begin(), Ref());
|
||||
std::transform(begin(), end(), result.begin(), Ref());
|
||||
|
||||
UF_random_generator<unsigned int> gen;
|
||||
std::random_shuffle(result.begin(), result.end(), gen);
|
||||
}
|
||||
UF_random_generator<unsigned int> gen;
|
||||
std::random_shuffle(result.begin(), result.end(), gen);
|
||||
}
|
||||
|
||||
/** returns an iterator to the best individual DOES NOT MOVE ANYBODY */
|
||||
|
||||
/** returns an iterator to the best individual DOES NOT MOVE ANYBODY */
|
||||
#if defined(__CUDACC__)
|
||||
eoPop<EOT>::iterator it_best_element()
|
||||
{
|
||||
eoPop<EOT>:: iterator it = std::max_element(begin(), end());
|
||||
eoPop<EOT>::iterator it_best_element()
|
||||
{
|
||||
eoPop<EOT>:: iterator it = std::max_element(begin(), end());
|
||||
#else
|
||||
typename eoPop<EOT>::iterator it_best_element() {
|
||||
typename eoPop<EOT>::iterator it = std::max_element(begin(), end());
|
||||
typename eoPop<EOT>::iterator it_best_element()
|
||||
{
|
||||
assert( this->size() > 0 );
|
||||
typename eoPop<EOT>::iterator it = std::max_element(begin(), end());
|
||||
#endif
|
||||
return it;
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
/** returns an iterator to the best individual DOES NOT MOVE ANYBODY */
|
||||
const EOT & best_element() const
|
||||
{
|
||||
|
||||
/** returns an iterator to the best individual DOES NOT MOVE ANYBODY */
|
||||
const EOT & best_element() const
|
||||
{
|
||||
#if defined(__CUDACC__)
|
||||
eoPop<EOT>::const_iterator it = std::max_element(begin(), end());
|
||||
eoPop<EOT>::const_iterator it = std::max_element(begin(), end());
|
||||
#else
|
||||
typename eoPop<EOT>::const_iterator it = std::max_element(begin(), end());
|
||||
typename eoPop<EOT>::const_iterator it = std::max_element(begin(), end());
|
||||
#endif
|
||||
if( it == end() )
|
||||
throw std::runtime_error("eoPop<EOT>: Empty population, when calling best_element().");
|
||||
return (*it);
|
||||
}
|
||||
if( it == end() )
|
||||
throw std::runtime_error("eoPop<EOT>: Empty population, when calling best_element().");
|
||||
return (*it);
|
||||
}
|
||||
|
||||
/** returns a const reference to the worse individual DOES NOT MOVE ANYBODY */
|
||||
const EOT & worse_element() const
|
||||
{
|
||||
/** returns a const reference to the worse individual DOES NOT MOVE ANYBODY */
|
||||
const EOT & worse_element() const
|
||||
{
|
||||
#if defined(__CUDACC__)
|
||||
eoPop<EOT>::const_iterator it = std::min_element(begin(), end());
|
||||
eoPop<EOT>::const_iterator it = std::min_element(begin(), end());
|
||||
#else
|
||||
typename eoPop<EOT>::const_iterator it = std::min_element(begin(), end());
|
||||
assert( this->size() > 0 );
|
||||
typename eoPop<EOT>::const_iterator it = std::min_element(begin(), end());
|
||||
#endif
|
||||
return (*it);
|
||||
}
|
||||
return (*it);
|
||||
}
|
||||
|
||||
/** returns an iterator to the worse individual DOES NOT MOVE ANYBODY */
|
||||
|
||||
/** returns an iterator to the worse individual DOES NOT MOVE ANYBODY */
|
||||
#if defined(__CUDACC__)
|
||||
eoPop<EOT>::iterator it_worse_element()
|
||||
{
|
||||
eoPop<EOT>::iterator it = std::min_element(begin(), end());
|
||||
eoPop<EOT>::iterator it_worse_element()
|
||||
{
|
||||
eoPop<EOT>::iterator it = std::min_element(begin(), end());
|
||||
#else
|
||||
typename eoPop<EOT>::iterator it_worse_element()
|
||||
{
|
||||
typename eoPop<EOT>::iterator it = std::min_element(begin(), end());
|
||||
typename eoPop<EOT>::iterator it_worse_element()
|
||||
{
|
||||
assert( this->size() > 0 );
|
||||
typename eoPop<EOT>::iterator it = std::min_element(begin(), end());
|
||||
#endif
|
||||
return it;
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
/**
|
||||
slightly faster algorithm than sort to find all individuals that are better
|
||||
than the nth individual. INDIVIDUALS ARE MOVED AROUND in the pop.
|
||||
*/
|
||||
|
||||
/**
|
||||
slightly faster algorithm than sort to find all individuals that are better
|
||||
than the nth individual. INDIVIDUALS ARE MOVED AROUND in the pop.
|
||||
*/
|
||||
#if defined(__CUDACC__)
|
||||
eoPop<EOT>::iterator nth_element(int nth)
|
||||
{
|
||||
eoPop<EOT>::iterator it = begin() + nth;
|
||||
eoPop<EOT>::iterator nth_element(int nth)
|
||||
{
|
||||
eoPop<EOT>::iterator it = begin() + nth;
|
||||
#else
|
||||
typename eoPop<EOT>::iterator nth_element(int nth)
|
||||
{
|
||||
typename eoPop<EOT>::iterator it = begin() + nth;
|
||||
typename eoPop<EOT>::iterator nth_element(int nth)
|
||||
{
|
||||
assert( this->size() > 0 );
|
||||
typename eoPop<EOT>::iterator it = begin() + nth;
|
||||
#endif
|
||||
std::nth_element(begin(), it, end(), std::greater<EOT>());
|
||||
return it;
|
||||
}
|
||||
std::nth_element(begin(), it, end(), std::greater<EOT>());
|
||||
return it;
|
||||
}
|
||||
|
||||
struct GetFitness { Fitness operator()(const EOT& _eo) const { return _eo.fitness(); } };
|
||||
|
||||
/** returns the fitness of the nth element */
|
||||
Fitness nth_element_fitness(int which) const
|
||||
{ // probably not the fastest way to do this, but what the heck
|
||||
struct GetFitness { Fitness operator()(const EOT& _eo) const { return _eo.fitness(); } };
|
||||
|
||||
std::vector<Fitness> fitness(size());
|
||||
std::transform(begin(), end(), fitness.begin(), GetFitness());
|
||||
|
||||
typename std::vector<Fitness>::iterator it = fitness.begin() + which;
|
||||
std::nth_element(fitness.begin(), it, fitness.end(), std::greater<Fitness>());
|
||||
return *it;
|
||||
}
|
||||
/** returns the fitness of the nth element */
|
||||
Fitness nth_element_fitness(int which) const
|
||||
{ // probably not the fastest way to do this, but what the heck
|
||||
|
||||
/** const nth_element function, returns pointers to sorted individuals
|
||||
* up the the nth
|
||||
*/
|
||||
void nth_element(int which, std::vector<const EOT*>& result) const
|
||||
{
|
||||
std::vector<Fitness> fitness(size());
|
||||
std::transform(begin(), end(), fitness.begin(), GetFitness());
|
||||
|
||||
result.resize(size());
|
||||
std::transform(begin(), end(), result.begin(), Ref());
|
||||
typename std::vector<Fitness>::iterator it = fitness.begin() + which;
|
||||
std::nth_element(fitness.begin(), it, fitness.end(), std::greater<Fitness>());
|
||||
return *it;
|
||||
}
|
||||
|
||||
typename std::vector<const EOT*>::iterator it = result.begin() + which;
|
||||
|
||||
std::nth_element(result.begin(), it, result.end(), Cmp());
|
||||
}
|
||||
/** const nth_element function, returns pointers to sorted individuals
|
||||
* up the the nth
|
||||
*/
|
||||
void nth_element(int which, std::vector<const EOT*>& result) const
|
||||
{
|
||||
|
||||
/** does STL swap with other pop */
|
||||
void swap(eoPop<EOT>& other)
|
||||
{
|
||||
std::swap(static_cast<std::vector<EOT>& >(*this), static_cast<std::vector<EOT>& >(other));
|
||||
}
|
||||
assert( this->size() > 0 );
|
||||
result.resize(size());
|
||||
std::transform(begin(), end(), result.begin(), Ref());
|
||||
|
||||
/**
|
||||
* Prints sorted pop but does NOT modify it!
|
||||
*
|
||||
* @param _os A std::ostream.
|
||||
*/
|
||||
virtual void sortedPrintOn(std::ostream& _os) const
|
||||
{
|
||||
std::vector<const EOT*> result;
|
||||
sort(result);
|
||||
_os << size() << '\n';
|
||||
for (unsigned i = 0; i < size(); ++i)
|
||||
{
|
||||
_os << *result[i] << std::endl;
|
||||
}
|
||||
}
|
||||
typename std::vector<const EOT*>::iterator it = result.begin() + which;
|
||||
|
||||
/**
|
||||
* Write object. It's called printOn since it prints the object _on_ a stream.
|
||||
* @param _os A std::ostream.
|
||||
*/
|
||||
virtual void printOn(std::ostream& _os) const
|
||||
{
|
||||
_os << size() << '\n';
|
||||
std::copy( begin(), end(), std::ostream_iterator<EOT>( _os, "\n") );
|
||||
}
|
||||
std::nth_element(result.begin(), it, result.end(), Cmp());
|
||||
}
|
||||
|
||||
/** @name Methods from eoObject */
|
||||
//@{
|
||||
/**
|
||||
* Read object. The EOT class must have a ctor from a stream;
|
||||
* @param _is A std::istream.
|
||||
*/
|
||||
virtual void readFrom(std::istream& _is)
|
||||
{
|
||||
size_t sz;
|
||||
_is >> sz;
|
||||
|
||||
resize(sz);
|
||||
/** does STL swap with other pop */
|
||||
void swap(eoPop<EOT>& other)
|
||||
{
|
||||
std::swap(static_cast<std::vector<EOT>& >(*this), static_cast<std::vector<EOT>& >(other));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sz; ++i) {
|
||||
operator[](i).readFrom( _is );
|
||||
}
|
||||
}
|
||||
|
||||
/** Inherited from eoObject. Returns the class name.
|
||||
@see eoObject
|
||||
*/
|
||||
virtual std::string className() const {return "eoPop";};
|
||||
//@}
|
||||
/**
|
||||
* Prints sorted pop but does NOT modify it!
|
||||
*
|
||||
* @param _os A std::ostream.
|
||||
*/
|
||||
virtual void sortedPrintOn(std::ostream& _os) const
|
||||
{
|
||||
std::vector<const EOT*> result;
|
||||
sort(result);
|
||||
_os << size() << '\n';
|
||||
for (unsigned i = 0; i < size(); ++i)
|
||||
{
|
||||
_os << *result[i] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void invalidate()
|
||||
{
|
||||
for (unsigned i=0; i<size(); i++)
|
||||
this->operator[](i).invalidate();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Write object. It's called printOn since it prints the object _on_ a stream.
|
||||
* @param _os A std::ostream.
|
||||
*/
|
||||
virtual void printOn(std::ostream& _os) const
|
||||
{
|
||||
_os << size() << '\n';
|
||||
std::copy( begin(), end(), std::ostream_iterator<EOT>( _os, "\n") );
|
||||
}
|
||||
|
||||
|
||||
/** @name Methods from eoObject */
|
||||
//@{
|
||||
/**
|
||||
* Read object. The EOT class must have a ctor from a stream;
|
||||
* @param _is A std::istream.
|
||||
*/
|
||||
virtual void readFrom(std::istream& _is)
|
||||
{
|
||||
size_t sz;
|
||||
_is >> sz;
|
||||
|
||||
resize(sz);
|
||||
|
||||
for (size_t i = 0; i < sz; ++i) {
|
||||
operator[](i).readFrom( _is );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Inherited from eoObject. Returns the class name.
|
||||
@see eoObject
|
||||
*/
|
||||
virtual std::string className() const {return "eoPop";};
|
||||
//@}
|
||||
|
||||
|
||||
/** Invalidate the whole population
|
||||
*/
|
||||
virtual void invalidate()
|
||||
{
|
||||
for (unsigned i=0; i<size(); i++)
|
||||
this->operator[](i).invalidate();
|
||||
}
|
||||
|
||||
}; // class eoPop
|
||||
|
||||
#endif // _EOPOP_H_
|
||||
|
||||
|
|
|
|||
|
|
@ -186,12 +186,17 @@ public:
|
|||
|
||||
virtual std::string className() const { return "eoPropCombinedQuadOp"; }
|
||||
|
||||
/* FIXME remove in next release
|
||||
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."
|
||||
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);
|
||||
}
|
||||
*/
|
||||
|
||||
// addition of a true operator
|
||||
virtual void add(eoQuadOp<EOT> & _op, const double _rate)
|
||||
|
|
@ -199,7 +204,7 @@ public:
|
|||
ops.push_back(&_op);
|
||||
rates.push_back(_rate);
|
||||
// compute the relative rates in percent - to warn the user!
|
||||
printOn( eo::log << eo::logging );
|
||||
printOn( eo::log << eo::logging );
|
||||
}
|
||||
|
||||
// outputs the operators and percentages
|
||||
|
|
|
|||
54
eo/src/eoRankMuSelect.h
Normal file
54
eo/src/eoRankMuSelect.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
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) 2012 Thales group
|
||||
*/
|
||||
/*
|
||||
Authors:
|
||||
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _eoRankMuSelect_h
|
||||
#define _eoRankMuSelect_h
|
||||
|
||||
#include "eoDetSelect.h"
|
||||
|
||||
/** Selects the "Mu" bests individuals.
|
||||
*
|
||||
* Note: sorts the population before trucating it.
|
||||
*
|
||||
* @ingroup Selectors
|
||||
*/
|
||||
template<typename EOT>
|
||||
class eoRankMuSelect : public eoDetSelect<EOT>
|
||||
{
|
||||
public :
|
||||
// false, because mu is not a rate
|
||||
eoRankMuSelect( unsigned int mu ) : eoDetSelect<EOT>( mu, false ) {}
|
||||
|
||||
void operator()(const eoPop<EOT>& source, eoPop<EOT>& dest)
|
||||
{
|
||||
eoPop<EOT> tmp( source );
|
||||
tmp.sort();
|
||||
eoDetSelect<EOT>::operator()( tmp, dest );
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !_eoRankMuselect_h
|
||||
|
|
@ -104,7 +104,7 @@ public:
|
|||
unsigned eliminated = howMany(popSize);
|
||||
if (!eliminated) // nothing to do
|
||||
return ;
|
||||
unsigned newsize = popSize - eliminated;
|
||||
long newsize = static_cast<long>(popSize) - static_cast<long>(eliminated);
|
||||
if (newsize < 0)
|
||||
throw std::logic_error("eoLinearTruncateSplit: Cannot truncate to a larger size!\n");
|
||||
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ public:
|
|||
//! Print term values and descriptions
|
||||
void printAll(std::ostream& os) const {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ template<class Chrom> class eoOneBitFlip: public eoMonOp<Chrom>
|
|||
bool operator()(Chrom& chrom)
|
||||
{
|
||||
unsigned i = eo::rng.random(chrom.size());
|
||||
chrom[i] = (chrom[i]) ? false : true;
|
||||
chrom[i] = !chrom[i];
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
@ -85,11 +85,11 @@ template<class Chrom> class eoDetBitFlip: public eoMonOp<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++)
|
||||
{
|
||||
unsigned i = eo::rng.random(chrom.size());
|
||||
chrom[i] = (chrom[i]) ? false : true;
|
||||
chrom[i] = !chrom[i];
|
||||
}
|
||||
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
|
||||
\class eoBitMutation eoBitOp.h ga/eoBitOp.h
|
||||
\ingroup bitstring
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* 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,
|
||||
* just declarations
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@
|
|||
*/
|
||||
|
||||
// the genotypes
|
||||
eoInit<eoBit<double> > & make_genotype(eoParser& _parser, eoState& _state, eoBit<double> _eo);
|
||||
eoInit<eoBit<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoBit<eoMinimizingFitness> _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, float _bias=0.5);
|
||||
|
||||
// the operators
|
||||
eoGenOp<eoBit<double> >& make_op(eoParser& _parser, eoState& _state, eoInit<eoBit<double> >& _init);
|
||||
|
|
|
|||
|
|
@ -45,11 +45,11 @@
|
|||
|
||||
/// 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
* @ingroup Builders
|
||||
*/
|
||||
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
|
||||
// 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
|
||||
// based on boolean_generator class (see utils/rnd_generator.h)
|
||||
eoBooleanGenerator * gen = new eoBooleanGenerator;
|
||||
eoBooleanGenerator * gen = new eoBooleanGenerator(_bias);
|
||||
_state.storeFunctor(gen);
|
||||
eoInitFixedLength<EOT>* init = new eoInitFixedLength<EOT>(theSize, *gen);
|
||||
// store in state
|
||||
|
|
|
|||
|
|
@ -115,11 +115,11 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
|
|||
throw std::runtime_error("Invalid uRate");
|
||||
|
||||
// minimum check
|
||||
bool bCross = true;
|
||||
// bool bCross = true; // not used ?
|
||||
if (onePointRateParam.value()+twoPointsRateParam.value()+uRateParam.value()==0)
|
||||
{
|
||||
std::cerr << "Warning: no crossover" << std::endl;
|
||||
bCross = false;
|
||||
// bCross = false;
|
||||
}
|
||||
|
||||
// Create the CombinedQuadOp
|
||||
|
|
@ -156,17 +156,29 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
|
|||
if ( (bitFlipRateParam.value() < 0) )
|
||||
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" );
|
||||
// minimum check
|
||||
if ( (oneBitRateParam.value() < 0) )
|
||||
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
|
||||
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)
|
||||
{
|
||||
std::cerr << "Warning: no mutation" << std::endl;
|
||||
bMut = false;
|
||||
// bMut = false;
|
||||
}
|
||||
|
||||
// Create the CombinedMonOp
|
||||
|
|
@ -184,6 +196,11 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
|
|||
_state.storeFunctor(ptMon);
|
||||
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);
|
||||
|
||||
// now build the eoGenOp:
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public:
|
|||
|
||||
while (size() > _size)
|
||||
{
|
||||
back() = operator[](size()-2);
|
||||
back() = this->operator[](size()-2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ public:
|
|||
v[i] = node;
|
||||
}
|
||||
parse_tree<Node> tmp(v.begin(), v.end());
|
||||
swap(tmp);
|
||||
this->swap(tmp);
|
||||
|
||||
/*
|
||||
* old code which caused problems for paradisEO
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
for i in *.py
|
||||
do
|
||||
python $i > /dev/null
|
||||
python2 $i > /dev/null
|
||||
|
||||
done
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ SET(EOUTILS_SOURCES
|
|||
pipecom.cpp
|
||||
eoLogger.cpp
|
||||
eoParallel.cpp
|
||||
eoSignal.cpp
|
||||
)
|
||||
|
||||
ADD_LIBRARY(eoutils STATIC ${EOUTILS_SOURCES})
|
||||
|
|
|
|||
|
|
@ -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/eoState.h>
|
||||
#include <utils/eoUpdater.h>
|
||||
|
|
@ -10,6 +36,7 @@
|
|||
#include <utils/eoGnuplot1DSnapshot.h>
|
||||
#endif
|
||||
#include <utils/eoCheckPoint.h>
|
||||
#include <utils/eoSignal.h>
|
||||
#include <utils/eoStat.h>
|
||||
#include <utils/eoScalarFitnessStat.h>
|
||||
#include <utils/eoAssembledFitnessStat.h>
|
||||
|
|
@ -21,3 +48,9 @@
|
|||
|
||||
// and make_help - any better suggestion to include it?
|
||||
void make_help(eoParser & _parser);
|
||||
|
||||
#endif // !_CHECKPOINTING_
|
||||
|
||||
// Local Variables:
|
||||
// mode: C++
|
||||
// End:
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include <eoFunctorStore.h>
|
||||
#include <utils/eoStat.h>
|
||||
|
||||
|
||||
|
||||
/** Wrapper to turn any stand-alone function and into an eoStat.
|
||||
*
|
||||
* 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
|
||||
|
|
|
|||
|
|
@ -194,8 +194,7 @@ int eoLogger::outbuf::overflow(int_type c)
|
|||
{
|
||||
if (_fd >= 0 && c != EOF)
|
||||
{
|
||||
size_t num;
|
||||
num = ::write(_fd, &c, 1);
|
||||
::write(_fd, &c, 1);
|
||||
}
|
||||
}
|
||||
return c;
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ eoMonitor& eoOStreamMonitor::operator()(void)
|
|||
} // if firstime
|
||||
|
||||
// ok, now the real saving. write out
|
||||
// FIXME deprecated, remove in next release
|
||||
//! @todo old verbose formatting, do we still need it?
|
||||
/*
|
||||
for (iterator it = vec.begin (); it != vec.end (); ++it) {
|
||||
|
|
|
|||
|
|
@ -44,13 +44,17 @@ Authors:
|
|||
class eoOStreamMonitor : public eoMonitor
|
||||
{
|
||||
public :
|
||||
/* FIXME remove in next release
|
||||
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)
|
||||
{
|
||||
(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;
|
||||
#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=' ' ) :
|
||||
out(_out), delim(_delim), width(_width), fill(_fill), firsttime(true)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@ Authors:
|
|||
|
||||
*/
|
||||
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
#include "eoParallel.h"
|
||||
#include "eoLogger.h"
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
/*
|
||||
(c) Thales group, 2010
|
||||
|
||||
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;
|
||||
version 2 of the License.
|
||||
|
||||
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:
|
||||
Caner Candan <caner.candan@thalesgroup.com>
|
||||
|
||||
*/
|
||||
|
||||
#ifndef EO_PARSER_LOGGER_H
|
||||
#define EO_PARSER_LOGGER_H
|
||||
|
||||
#include "eoParser.h"
|
||||
|
||||
#warning "[eoParserLogger] is deprecated"
|
||||
|
||||
typedef eoParser eoParserLogger;
|
||||
|
||||
#endif // !EO_PARSER_LOGGER_H
|
||||
|
|
@ -150,7 +150,8 @@ public :
|
|||
initialize(2*s);
|
||||
}
|
||||
|
||||
/** Re-initializes the Random Number Generator
|
||||
/* FIXME remove in next release
|
||||
** Re-initializes the Random Number Generator
|
||||
|
||||
This is the traditional seeding procedure. This version is deprecated and
|
||||
only provided for compatibility with old code. In new projects you should
|
||||
|
|
@ -159,11 +160,12 @@ public :
|
|||
@see reseed for details on usage of the seeding value.
|
||||
|
||||
@version old version (deprecated)
|
||||
*/
|
||||
*
|
||||
void oldReseed(uint32_t s)
|
||||
{
|
||||
initialize(s);
|
||||
}
|
||||
*/
|
||||
|
||||
/** Random number from unifom distribution
|
||||
|
||||
|
|
|
|||
36
eo/src/utils/eoSignal.cpp
Normal file
36
eo/src/utils/eoSignal.cpp
Normal 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
106
eo/src/utils/eoSignal.h
Normal 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
|
||||
|
|
@ -18,7 +18,7 @@ using namespace std;
|
|||
|
||||
|
||||
|
||||
void removeComment(string& str, string comment)
|
||||
void eoState::removeComment(string& str, string comment)
|
||||
{
|
||||
string::size_type pos = str.find(comment);
|
||||
|
||||
|
|
@ -28,21 +28,23 @@ void removeComment(string& str, string comment)
|
|||
}
|
||||
}
|
||||
|
||||
bool is_section(const string& str, string& name)
|
||||
bool eoState::is_section(const string& str, string& name)
|
||||
{
|
||||
string::size_type pos = str.find("\\section{");
|
||||
string::size_type pos = str.find(_tag_section_so);
|
||||
|
||||
if (pos == string::npos)
|
||||
return false;
|
||||
//else
|
||||
|
||||
string::size_type end = str.find("}");
|
||||
string::size_type end = str.find(_tag_section_sc);
|
||||
|
||||
if (end == string::npos)
|
||||
return false;
|
||||
// else
|
||||
|
||||
name = str.substr(pos + 9, end-9);
|
||||
// affect name, passed by reference
|
||||
// Note: substr( start, count )
|
||||
name = str.substr( pos + _tag_section_so.size(), end - _tag_section_so.size() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -84,6 +86,7 @@ void eoState::load(const string& _filename)
|
|||
load(is);
|
||||
}
|
||||
|
||||
// FIXME implement parsing and loading of other formats
|
||||
void eoState::load(std::istream& is)
|
||||
{
|
||||
string str;
|
||||
|
|
@ -158,16 +161,49 @@ void eoState::save(const string& filename) const
|
|||
save(os);
|
||||
}
|
||||
|
||||
void eoState::save(std::ostream& os) const
|
||||
{ // saves in order of insertion
|
||||
for (vector<ObjectMap::iterator>::const_iterator it = creationOrder.begin(); it != creationOrder.end(); ++it)
|
||||
{
|
||||
os << "\\section{" << (*it)->first << "}\n";
|
||||
(*it)->second->printOn(os);
|
||||
os << '\n';
|
||||
}
|
||||
//void eoState::save(std::ostream& os) const
|
||||
//{ // saves in order of insertion
|
||||
// for (vector<ObjectMap::iterator>::const_iterator it = creationOrder.begin(); it != creationOrder.end(); ++it)
|
||||
// {
|
||||
// os << "\\section{" << (*it)->first << "}\n";
|
||||
// (*it)->second->printOn(os);
|
||||
// os << '\n';
|
||||
// }
|
||||
//}
|
||||
|
||||
void eoState::saveSection( std::ostream& os, vector<ObjectMap::iterator>::const_iterator it) const
|
||||
{
|
||||
os << _tag_section_so << (*it)->first << _tag_section_sc;
|
||||
|
||||
os << _tag_content_s;
|
||||
(*it)->second->printOn(os);
|
||||
os << _tag_content_e;
|
||||
|
||||
os << _tag_section_e;
|
||||
}
|
||||
|
||||
|
||||
void eoState::save(std::ostream& os) const
|
||||
{
|
||||
os << _tag_state_so << _tag_state_name << _tag_state_sc;
|
||||
|
||||
// save the first section
|
||||
assert( creationOrder.size() > 0 );
|
||||
// saves in order of insertion
|
||||
vector<ObjectMap::iterator>::const_iterator it = creationOrder.begin();
|
||||
saveSection(os,it);
|
||||
it++;
|
||||
|
||||
while( it != creationOrder.end() ) {
|
||||
// add a separator only before [1,n] elements
|
||||
os << _tag_section_sep;
|
||||
saveSection(os, it);
|
||||
it++;
|
||||
}
|
||||
os << _tag_state_e;
|
||||
}
|
||||
|
||||
|
||||
string eoState::createObjectName(eoObject* obj)
|
||||
{
|
||||
if (obj == 0)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
|
||||
#include <eoFunctorStore.h>
|
||||
|
||||
|
|
@ -56,10 +57,50 @@ class eoState : public eoFunctorStore
|
|||
{
|
||||
public :
|
||||
|
||||
eoState(void) {}
|
||||
eoState(std::string name="") :
|
||||
_tag_state_so(""),
|
||||
_tag_state_name(name),
|
||||
_tag_state_sc(""),
|
||||
_tag_section_so("\\section{"),
|
||||
_tag_section_sc("}\n"),
|
||||
_tag_content_s(""),
|
||||
_tag_content_e(""),
|
||||
_tag_section_sep(""),
|
||||
_tag_section_e("\n"),
|
||||
_tag_state_e("")
|
||||
{}
|
||||
|
||||
~eoState(void);
|
||||
|
||||
void formatLatex(std::string name)
|
||||
{
|
||||
_tag_state_so = "";
|
||||
_tag_state_name = name;
|
||||
_tag_state_sc = "";
|
||||
_tag_section_so = "\\section{";
|
||||
_tag_section_sc = "}\n";
|
||||
_tag_content_s = "";
|
||||
_tag_content_e = "";
|
||||
_tag_section_sep = "";
|
||||
_tag_section_e = "\n";
|
||||
_tag_state_e = "";
|
||||
}
|
||||
|
||||
void formatJSON(std::string name)
|
||||
{
|
||||
_tag_state_so = "{ \"";
|
||||
_tag_state_name = name;
|
||||
_tag_state_sc = "\":\n";
|
||||
_tag_section_so = "\t{ \"";
|
||||
_tag_section_sc = "\":\n";
|
||||
_tag_content_s = "\"";
|
||||
_tag_content_e = "\"";
|
||||
_tag_section_sep = ",\n";
|
||||
_tag_section_e = "\t}\n";
|
||||
_tag_state_e = "}\n";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Object registration function, note that it does not take ownership!
|
||||
*/
|
||||
|
|
@ -131,6 +172,43 @@ private :
|
|||
eoState(const eoState&);
|
||||
eoState& operator=(const eoState&);
|
||||
|
||||
/* \@{
|
||||
* s=start, e=end
|
||||
* o=open, c=close
|
||||
*
|
||||
* { "my_state":
|
||||
* {
|
||||
* "section_pop":"…",
|
||||
* "section_rng":"…"
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // JSON LATEX (default)
|
||||
*/
|
||||
std::string _tag_state_so; // { "
|
||||
std::string _tag_state_name; // my_state
|
||||
std::string _tag_state_sc; // ":
|
||||
|
||||
std::string _tag_section_so; // { " \\section{
|
||||
std::string _tag_section_sc; // ": }\n
|
||||
|
||||
std::string _tag_content_s; // "
|
||||
std::string _tag_content_e; // "
|
||||
|
||||
std::string _tag_section_sep;// ,
|
||||
|
||||
std::string _tag_section_e; // } \n
|
||||
|
||||
std::string _tag_state_e; // }
|
||||
/** \@} */
|
||||
|
||||
void removeComment( std::string& str, std::string comment);
|
||||
|
||||
bool is_section(const std::string& str, std::string& name);
|
||||
|
||||
protected:
|
||||
void saveSection( std::ostream& os, std::vector<ObjectMap::iterator>::const_iterator it) const;
|
||||
|
||||
};
|
||||
/** @example t-eoStateAndParser.cpp
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -43,11 +43,15 @@ Authors:
|
|||
class eoStdoutMonitor : public eoOStreamMonitor
|
||||
{
|
||||
public :
|
||||
/* FIXME remove in next release
|
||||
eoStdoutMonitor(bool _verbose, std::string _delim = "\t", unsigned int _width=20, char _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=' ' ) :
|
||||
eoOStreamMonitor( std::cout, _delim, _width, _fill)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ LINK_DIRECTORIES(${EO_BINARY_DIR}/lib)
|
|||
|
||||
IF(WITH_MPI)
|
||||
LINK_DIRECTORIES(${MPI_DIR}/lib)
|
||||
SET(CMAKE_CXX_COMPILER "${MPI_DIR}/bin/mpicxx")
|
||||
SET(CMAKE_CXX_COMPILER "mpicxx")
|
||||
ENDIF()
|
||||
|
||||
######################################################################################
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ FOREACH (test ${TEST_LIST})
|
|||
SET ("T_${test}_SOURCES" "${test}.cpp")
|
||||
ENDFOREACH (test)
|
||||
|
||||
SET(CMAKE_CXX_COMPILER "${MPI_DIR}/bin/mpicxx")
|
||||
SET(CMAKE_CXX_COMPILER "mpicxx")
|
||||
ADD_DEFINITIONS(-DWITH_MPI)
|
||||
|
||||
IF(ENABLE_CMAKE_TESTING)
|
||||
|
|
|
|||
|
|
@ -69,7 +69,8 @@ int main()
|
|||
// Terminators
|
||||
eoGenContinue<Chrom> continuator1(10);
|
||||
eoFitContinue<Chrom> continuator2(CHROM_SIZE);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1);
|
||||
continuator.add( continuator2 );
|
||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||
eoStdoutMonitor monitor;
|
||||
checkpoint.add(monitor);
|
||||
|
|
|
|||
|
|
@ -73,7 +73,8 @@ int main()
|
|||
// Terminators
|
||||
eoGenContinue<Chrom> continuator1(10);
|
||||
eoFitContinue<Chrom> continuator2(CHROM_SIZE);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1);
|
||||
continuator.add( continuator2);
|
||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||
eoStdoutMonitor monitor;
|
||||
checkpoint.add(monitor);
|
||||
|
|
|
|||
|
|
@ -72,7 +72,8 @@ int main()
|
|||
// Terminators
|
||||
eoGenContinue<Chrom> continuator1(10);
|
||||
eoFitContinue<Chrom> continuator2(CHROM_SIZE);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1);
|
||||
continuator.add(continuator2);
|
||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||
eoStdoutMonitor monitor;
|
||||
checkpoint.add(monitor);
|
||||
|
|
|
|||
|
|
@ -139,7 +139,8 @@ void main_function()
|
|||
eoGenContinue<Chrom> continuator1(50);
|
||||
eoFitContinue<Chrom> continuator2(65535.f);
|
||||
|
||||
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1);
|
||||
continuator.add( continuator2);
|
||||
|
||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ Caner Candan <caner.candan@thalesgroup.com>
|
|||
|
||||
#include <omp.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "real_value.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
Reference in a new issue