Merge branch 'master' of /tools/eo
This commit is contained in:
commit
11f01d5a53
53 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_
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue