Paradiseo-eo sources added

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
legrand 2006-12-12 14:49:08 +00:00
commit c3aec878e5
438 changed files with 342772 additions and 0 deletions

View file

@ -0,0 +1,6 @@
*.lo
*.la
.deps
.libs
Makefile
Makefile.in

View file

@ -0,0 +1,108 @@
/.cvsignore/1.1.1.1/Fri Jan 29 12:23:53 1999//
/EO.h/1.26/Thu Feb 27 19:26:10 2003//
/Makefile.am/1.59/Thu Mar 23 10:15:17 2006//
/apply.h/1.4/Thu Feb 27 19:26:11 2003//
/eo/1.57/Tue Feb 28 14:40:37 2006//
/eoAlgo.h/1.5/Thu Dec 23 17:26:38 2004//
/eoBreed.h/1.4/Wed Oct 5 22:08:29 2005//
/eoCellularEasyEA.h/1.1/Thu Apr 25 14:06:43 2002//
/eoCloneOps.h/1.2/Thu Feb 27 19:26:09 2003//
/eoCombinedContinue.h/1.6/Tue Jun 15 07:28:54 2004//
/eoCombinedInit.h/1.2/Sat Aug 28 14:03:34 2004//
/eoContinue.h/1.4/Fri Dec 9 17:45:56 2005//
/eoCounter.h/1.4/Wed Feb 14 10:35:25 2001//
/eoCtrlCContinue.cpp/1.4/Fri Feb 28 16:49:13 2003//
/eoCtrlCContinue.h/1.6/Tue Jun 15 07:28:54 2004//
/eoDetSelect.h/1.5/Sun Mar 2 11:29:01 2003//
/eoDetTournamentSelect.h/1.7/Thu Feb 27 19:26:01 2003//
/eoDistribUpdater.h/1.2/Sat Nov 10 09:02:17 2001//
/eoDistribution.h/1.1/Thu Nov 8 07:40:27 2001//
/eoDominanceMap.h/1.10/Thu Dec 23 15:40:44 2004//
/eoEDA.h/1.1/Mon Jun 9 06:17:26 2003//
/eoEasyEA.h/1.23/Wed Oct 5 22:08:29 2005//
/eoEvalContinue.h/1.3/Tue Jun 15 07:28:54 2004//
/eoEvalFunc.h/1.16/Mon Jul 12 09:16:41 2004//
/eoEvalFuncCounter.h/1.1/Tue Apr 24 04:56:12 2001//
/eoEvalFuncPtr.h/1.7/Sat Nov 17 07:22:31 2001//
/eoFactory.h/1.4/Thu Feb 27 19:25:59 2003//
/eoFitContinue.h/1.4/Tue Jun 15 07:28:54 2004//
/eoFitnessScalingSelect.h/1.2/Fri Feb 16 08:21:25 2001//
/eoFlOrBinOp.h/1.1/Sat Aug 2 06:42:33 2003//
/eoFlOrMonOp.h/1.2/Mon Mar 14 21:00:00 2005//
/eoFlOrQuadOp.h/1.1/Sat Aug 2 06:42:33 2003//
/eoFunctor.h/1.7/Wed Dec 1 09:22:48 2004//
/eoFunctorStore.cpp/1.5/Wed Dec 7 15:51:32 2005//
/eoFunctorStore.h/1.7/Wed Dec 7 15:40:23 2005//
/eoG3Replacement.h/1.2/Thu Feb 27 19:25:59 2003//
/eoGenContinue.h/1.10/Fri Dec 9 17:49:43 2005//
/eoGenOp.h/1.11/Tue Aug 10 17:19:46 2004//
/eoGeneralBreeder.h/1.7/Thu Feb 27 19:25:59 2003//
/eoInit.h/1.16/Wed Dec 1 09:19:47 2004//
/eoInvalidateOps.h/1.3/Thu Feb 15 04:47:18 2001//
/eoLinearFitScaling.h/1.7/Mon Mar 27 18:55:19 2006//
/eoMGGReplacement.h/1.4/Sun Mar 2 11:26:45 2003//
/eoMerge.h/1.12/Thu Feb 27 19:25:58 2003//
/eoMergeReduce.h/1.2/Fri Jan 5 05:42:08 2001//
/eoNDSorting.h/1.20/Mon Mar 27 18:55:19 2006//
/eoObject.h/1.15/Thu Feb 27 19:25:58 2003//
/eoOneToOneBreeder.h/1.3/Thu Feb 27 19:25:57 2003//
/eoOp.h/1.29/Tue Aug 10 17:19:46 2004//
/eoOpContainer.h/1.10/Mon Mar 27 18:55:19 2006//
/eoOpSelMason.h/1.5/Thu Feb 27 19:25:55 2003//
/eoParetoConstraintFitness.h/1.3/Fri Apr 18 13:32:39 2003//
/eoParetoFitness.cpp/1.2/Mon Feb 4 13:16:50 2002//
/eoParetoFitness.h/1.10/Thu Feb 27 19:25:54 2003//
/eoParetoRanking.h/1.5/Mon Mar 27 18:55:19 2006//
/eoPerf2Worth.h/1.10/Mon Mar 27 18:55:19 2006//
/eoPeriodicContinue.h/1.1/Tue Feb 28 14:39:45 2006//
/eoPersistent.cpp/1.9/Thu Feb 27 19:25:53 2003//
/eoPersistent.h/1.8/Thu Feb 27 19:25:53 2003//
/eoPop.h/1.40/Thu Dec 23 10:14:42 2004//
/eoPopAlgo.h/1.1/Wed Mar 27 17:28:04 2002//
/eoPopEvalFunc.h/1.2/Tue Sep 4 06:50:42 2001//
/eoPopulator.h/1.9/Mon Sep 5 16:47:53 2005//
/eoPrintable.cpp/1.3/Thu Feb 27 19:25:52 2003//
/eoPrintable.h/1.6/Thu Feb 27 19:25:52 2003//
/eoPropGAGenOp.h/1.1/Sat May 7 15:43:29 2005//
/eoProportionalCombinedOp.h/1.8/Tue Aug 10 17:19:46 2004//
/eoProportionalSelect.h/1.4/Wed Jun 4 09:33:27 2003//
/eoRandomSelect.h/1.12/Mon Jun 17 09:18:37 2002//
/eoRanking.h/1.9/Mon Mar 27 18:55:19 2006//
/eoRankingSelect.h/1.4/Thu Feb 27 19:25:52 2003//
/eoReduce.h/1.11/Thu Feb 27 19:25:52 2003//
/eoReduceMerge.h/1.1/Tue Dec 19 18:41:19 2000//
/eoReduceMergeReduce.h/1.3/Thu Feb 27 19:25:52 2003//
/eoReduceSplit.h/1.4/Mon Jan 2 14:09:22 2006//
/eoReplacement.h/1.5/Tue Aug 10 17:19:46 2004//
/eoSGA.h/1.11/Thu Dec 23 17:26:38 2004//
/eoSGAGenOp.h/1.3/Thu Feb 27 19:25:51 2003//
/eoSGATransform.h/1.8/Tue Aug 10 17:19:46 2004//
/eoSTLFunctor.h/1.2/Wed Mar 21 12:10:13 2001//
/eoScalarFitness.h/1.7/Sat Feb 17 10:51:31 2001//
/eoScalarFitnessAssembled.cpp/1.1/Wed Apr 2 21:08:13 2003//
/eoScalarFitnessAssembled.h/1.11/Thu Dec 23 15:29:06 2004//
/eoSelect.h/1.2/Mon Oct 9 16:13:19 2000//
/eoSelectFactory.h/1.4/Thu Feb 27 19:25:52 2003//
/eoSelectFromWorth.h/1.9/Thu Dec 23 15:29:06 2004//
/eoSelectMany.h/1.2/Mon May 7 07:13:36 2001//
/eoSelectNumber.h/1.1/Tue Dec 19 18:41:19 2000//
/eoSelectOne.h/1.4/Sat Nov 10 09:02:17 2001//
/eoSelectPerc.h/1.3/Fri Dec 1 15:46:07 2000//
/eoSequentialSelect.h/1.4/Mon Oct 3 12:54:45 2005//
/eoSharing.h/1.6/Mon Mar 27 18:55:19 2006//
/eoSharingSelect.h/1.2/Sat Aug 28 16:26:03 2004//
/eoSimpleEDA.h/1.1/Mon Jun 9 06:17:26 2003//
/eoSteadyFitContinue.h/1.5/Tue Aug 10 17:19:46 2004//
/eoStochTournamentSelect.h/1.5/Thu Feb 27 19:25:48 2003//
/eoStochasticUniversalSelect.h/1.3/Thu Dec 23 17:22:52 2004//
/eoSurviveAndDie.h/1.3/Thu Dec 23 15:29:06 2004//
/eoTransform.h/1.2/Mon Oct 9 16:13:19 2000//
/eoTruncSelect.h/1.2/Sun Jan 5 16:31:47 2003//
/eoTruncatedSelectMany.h/1.2/Thu Feb 27 19:25:48 2003//
/eoTruncatedSelectOne.h/1.2/Mon Jun 17 09:19:17 2002//
/eoVariableLengthCrossover.h/1.14/Fri Oct 7 08:27:59 2005//
/eoVariableLengthMutation.h/1.10/Wed Sep 28 21:49:26 2005//
/eoVector.h/1.17/Thu Oct 6 17:22:40 2005//
/es.h/1.8/Tue Jul 29 05:33:58 2003//
/ga.h/1.3/Sat Sep 8 05:58:13 2001//
D

View file

@ -0,0 +1,10 @@
A D/MGE////
A D/do////
A D/es////
A D/ga////
A D/gp////
A D/obsolete////
A D/other////
A D/paradisEO////
A D/pyeo////
A D/utils////

View file

@ -0,0 +1 @@
eo/src

View file

@ -0,0 +1 @@
:ext:evomarc@eodev.cvs.sourceforge.net:/cvsroot/eodev

152
trunk/paradiseo-eo/src/EO.h Normal file
View file

@ -0,0 +1,152 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// EO.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 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 EO_H
#define EO_H
//-----------------------------------------------------------------------------
#include <stdexcept> // std::runtime_error
#include <eoObject.h> // eoObject
#include <eoPersistent.h> // eoPersistent
//-----------------------------------------------------------------------------
/** EO is a base class for evolvable objects, that is, the subjects of
evolution. EOs have only got a fitness, which at the same time needs to be
only an object with the operation less than (<) defined. Fitness says how
good is the object; evolution or change of these objects is left to the
genetic operators. A fitness less than another means a worse fitness, in
whatever the context; thus, fitness is always maximized; although it can
be minimized with a proper definition of the < operator. The fitness
object must have, besides an void ctor, a copy ctor.
*/
template<class F> class EO: public eoObject, public eoPersistent
{
public:
typedef F Fitness;
/** Default constructor.
Fitness must have a ctor which takes 0 as a value; we can not use void
ctors here since default types like float have no void initializer.
VC++ allows it, but gcc does not
*/
EO(): repFitness(Fitness()), invalidFitness(true) {}
/// Virtual dtor
virtual ~EO() {};
/// Return fitness value.
Fitness fitness() const {
if (invalid())
throw std::runtime_error("invalid fitness");
return repFitness;
}
// Set fitness as invalid.
void invalidate() { invalidFitness = true; }
/** Set fitness. At the same time, validates it.
* @param _fitness New fitness value.
*/
void fitness(const Fitness& _fitness)
{
repFitness = _fitness;
invalidFitness = false;
}
/** Return true If fitness value is invalid, false otherwise.
* @return true If fitness is invalid.
*/
bool invalid() const { return invalidFitness; }
/** Returns true if
@return true if the fitness is higher
*/
bool operator<(const EO& _eo2) const { return fitness() < _eo2.fitness(); }
bool operator>(const EO& _eo2) const { return !(fitness() <= _eo2.fitness()); }
/// Methods inherited from eoObject
//@{
/** Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const { return "EO"; }
/**
* Read object.\\
* Calls base class, just in case that one had something to do.
* The read and print methods should be compatible and have the same format.
* In principle, format is "plain": they just print a number
* @param _is a std::istream.
* @throw runtime_std::exception If a valid object can't be read.
*/
virtual void readFrom(std::istream& _is) {
// the new version of the reafFrom function.
// It can distinguish between valid and invalid fitness values.
std::string fitness_str;
int pos = _is.tellg();
_is >> fitness_str;
if (fitness_str == "INVALID")
{
invalidFitness = true;
}
else
{
invalidFitness = false;
_is.seekg(pos); // rewind
_is >> repFitness;
}
}
/**
* Write object. Called printOn since it prints the object _on_ a stream.
* @param _os A std::ostream.
*/
virtual void printOn(std::ostream& _os) const {
// the latest version of the code. Very similar to the old code
if (invalid()) {
_os << "INVALID ";
}
else
{
_os << repFitness << ' ';
}
}
//@}
private:
Fitness repFitness; // value of fitness for this chromosome
bool invalidFitness; // true if the value of fitness is invalid
};
//-----------------------------------------------------------------------------
#endif

View file

@ -0,0 +1 @@
D

View file

@ -0,0 +1 @@
eo/src/MGE

View file

@ -0,0 +1 @@
:ext:evomarc@eodev.cvs.sourceforge.net:/cvsroot/eodev

View file

@ -0,0 +1,116 @@
# Makefile.am for eo/src
SUBDIRS = es ga gp do utils other
lib_LIBRARIES = libeo.a
libeo_a_SOURCES = eoFunctorStore.cpp \
eoPersistent.cpp \
eoPrintable.cpp \
eoCtrlCContinue.cpp \
eoParetoFitness.cpp \
eoScalarFitnessAssembled.cpp
pkginclude_HEADERS = eo \
EO.h \
apply.h \
eoAlgo.h \
eoBreed.h \
eoCellularEasyEA.h \
eoCloneOps.h \
eoCombinedContinue.h \
eoCombinedInit.h \
eoContinue.h \
eoCounter.h \
eoCtrlCContinue.h \
eoDetSelect.h \
eoDetTournamentSelect.h \
eoDistribUpdater.h \
eoDistribution.h \
eoDominanceMap.h \
eoEDA.h \
eoEasyEA.h \
eoEvalContinue.h \
eoEvalFunc.h \
eoEvalFuncCounter.h \
eoEvalFuncPtr.h \
eoFactory.h \
eoFitContinue.h \
eoFitnessScalingSelect.h \
eoFlOrBinOp.h \
eoFlOrMonOp.h \
eoFlOrQuadOp.h \
eoFunctor.h \
eoFunctorStore.h \
eoG3Replacement.h \
eoGenContinue.h \
eoGenOp.h \
eoGeneralBreeder.h \
eoInit.h \
eoInvalidateOps.h \
eoLinearFitScaling.h \
eoMGGReplacement.h \
eoMerge.h \
eoMergeReduce.h \
eoNDSorting.h \
eoObject.h \
eoOneToOneBreeder.h \
eoOp.h \
eoOpContainer.h \
eoOpSelMason.h \
eoParetoConstraintFitness.h \
eoParetoFitness.h \
eoParetoRanking.h \
eoPerf2Worth.h \
eoPeriodicContinue.h \
eoPersistent.h \
eoPop.h \
eoPopAlgo.h \
eoPopEvalFunc.h \
eoPopulator.h \
eoPrintable.h \
eoPropGAGenOp.h \
eoProportionalCombinedOp.h \
eoProportionalSelect.h \
eoRandomSelect.h \
eoRanking.h \
eoRankingSelect.h \
eoReduce.h \
eoReduceMerge.h \
eoReduceMergeReduce.h \
eoReduceSplit.h \
eoReplacement.h \
eoSGA.h \
eoSGAGenOp.h \
eoSGATransform.h \
eoSTLFunctor.h \
eoScalarFitness.h \
eoScalarFitnessAssembled.cpp \
eoScalarFitnessAssembled.h \
eoSelect.h \
eoSelectFactory.h \
eoSelectFromWorth.h \
eoSelectMany.h \
eoSelectNumber.h \
eoSelectOne.h \
eoSelectPerc.h \
eoSequentialSelect.h \
eoSharing.h \
eoSharingSelect.h \
eoSimpleEDA.h \
eoSteadyFitContinue.h \
eoStochTournamentSelect.h \
eoStochasticUniversalSelect.h \
eoSurviveAndDie.h \
eoTransform.h \
eoTruncSelect.h \
eoTruncatedSelectMany.h \
eoTruncatedSelectOne.h \
eoVariableLengthCrossover.h \
eoVariableLengthMutation.h \
eoVector.h \
es.h \
ga.h
AM_CXXFLAGS = -I$(top_srcdir)/src

View file

@ -0,0 +1,44 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// eoApply.h
// (c) Maarten Keijzer 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
mak@dhi.dk
*/
//-----------------------------------------------------------------------------
#ifndef _apply_h
#define _apply_h
#include <eoFunctor.h>
#include <vector>
/**
Applies a unary function to a std::vector of things.
*/
template <class EOT>
void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
{
for (unsigned i = 0; i < _pop.size(); ++i)
{
_proc(_pop[i]);
}
}
#endif

View file

@ -0,0 +1 @@
Makefile.in

View file

@ -0,0 +1,16 @@
/.cvsignore/1.1/Fri Sep 17 17:00:04 2004//
/Makefile.am/1.3/Wed Sep 22 18:18:30 2004//
/Readme/1.2/Tue Sep 4 06:35:58 2001//
/make_algo_easea.h/1.2/Thu Feb 27 19:25:26 2003//
/make_algo_pareto.h/1.3/Mon Apr 4 20:41:05 2005//
/make_algo_scalar.h/1.15/Tue Sep 28 17:13:34 2004//
/make_checkpoint.h/1.13/Wed Oct 5 21:34:19 2005//
/make_checkpoint_FDC.h/1.3/Thu Feb 27 19:25:25 2003//
/make_checkpoint_assembled.h/1.4/Wed Oct 5 21:34:19 2005//
/make_checkpoint_pareto.h/1.10/Mon Oct 10 13:34:21 2005//
/make_continue.h/1.8/Mon Sep 12 17:53:25 2005//
/make_continue_pareto.h/1.2/Thu Feb 27 19:25:25 2003//
/make_general_replacement.h/1.4/Sun Apr 27 06:08:11 2003//
/make_pop.h/1.8/Mon Sep 26 10:18:15 2005//
/make_run.h/1.1/Tue Apr 24 04:52:04 2001//
D

View file

@ -0,0 +1 @@
eo/src/do

View file

@ -0,0 +1 @@
:ext:evomarc@eodev.cvs.sourceforge.net:/cvsroot/eodev

View file

@ -0,0 +1,15 @@
pkginclude_HEADERS = make_algo_easea.h \
make_algo_pareto.h \
make_algo_scalar.h \
make_checkpoint.h \
make_checkpoint_FDC.h \
make_checkpoint_assembled.h \
make_checkpoint_pareto.h \
make_continue.h \
make_continue_pareto.h \
make_general_replacement.h \
make_pop.h \
make_run.h
EXTRA_DIST = Readme

View file

@ -0,0 +1,36 @@
This directory contains templatized code that is supposed to be
instanciated and compiled in an actual library for every type of EOT
The user can then modify and recompile only the part he/she wishes to
change (as in any library!).
See in EO src/ga dir the corresponding .cpp files, that simply instanciate
the functions here for eoBit<double> AND eoBit<eoMinimizingFitness>
and in EO test dir the t-eoGA.cpp file that is a sample program that uses
the whole facility.
All make_XXX.h file define some parser-based constructions of basic
Evolutionary Algorithms components, using state-based memory management
(see in src/utils dir, or read the tutorial).
In this src/do dir, the following ***representation indedendent*** code
is defined
make_algo_scalar.h The selection/replacement for scalar fitnesses
make_checkpoint.h The output facilities
make_continue.h The stpping criteria
make_pop.h Init of the population (from an EOT initializer)
make_run.h Run the algorithm
See also (NOW MOVED TO util DIR, as it was useful everywhere)
make_help.cpp Help on demand (+ status file)
Note:
-----
two additional make_XXX.h files need to be defined for each representation
make_genotype.h Builds an initializer for the corresponding EOType
make_op.h Builds a general Operator to be used in the algo
MS, April 23, 2001
July 23, 2001

View file

@ -0,0 +1,368 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// make_algo_easea.h
// (c) Marc Schoenauer and Pierre Collet, 2002
/*
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: Pierre.Collet@polytechnique.fr
Marc.Schoenauer@polytechnique.fr
mkeijzer@dhi.dk
*/
//-----------------------------------------------------------------------------
#ifndef _make_algo_easea_h
#define _make_algo_easea_h
#include <utils/eoData.h> // for eo_is_a_rate
// everything tha's needed for the algorithms - SCALAR fitness
// Selection
// the eoSelectOne's
#include <eoRandomSelect.h>
#include <eoSequentialSelect.h>
#include <eoDetTournamentSelect.h>
#include <eoProportionalSelect.h>
#include <eoFitnessScalingSelect.h>
#include <eoRankingSelect.h>
#include <eoStochTournamentSelect.h>
// #include <eoSelect.h> included in all others
// Breeders
#include <eoGeneralBreeder.h>
// Replacement
#include "make_general_replacement.h"
#include "eoMGGReplacement.h"
#include "eoG3Replacement.h"
// Algorithm (only this one needed)
#include <eoEasyEA.h>
// also need the parser and param includes
#include <utils/eoParser.h>
#include <utils/eoState.h>
/*
* This function builds the algorithm (i.e. selection and replacement)
* from existing continue (or checkpoint) and operators
*
* It uses a parser (to get user parameters) and a state (to store the memory)
* the last argument is an individual, needed for 2 reasons
* it disambiguates the call after instanciations
* some operator might need some private information about the indis
*
* This is why the template is the complete EOT even though only the fitness
* is actually templatized here
*/
template <class EOT>
eoAlgo<EOT> & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<EOT>& _eval, eoContinue<EOT>& _continue, eoGenOp<EOT>& _op)
{
// the selection
eoValueParam<eoParamParamType>& selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", "Selection: Roulette, Ranking(p,e), DetTour(T), StochTour(t), Sequential(ordered/unordered) or EliteSequentialSelect", 'S', "Evolution Engine");
eoParamParamType & ppSelect = selectionParam.value(); // std::pair<std::string,std::vector<std::string> >
eoSelectOne<EOT>* select ;
if (ppSelect.first == std::string("DetTour"))
{
unsigned detSize;
if (!ppSelect.second.size()) // no parameter added
{
std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl;
detSize = 2;
// put back 2 in parameter for consistency (and status file)
ppSelect.second.push_back(std::string("2"));
}
else // parameter passed by user as DetTour(T)
detSize = atoi(ppSelect.second[0].c_str());
select = new eoDetTournamentSelect<EOT>(detSize);
}
else if (ppSelect.first == std::string("StochTour"))
{
double p;
if (!ppSelect.second.size()) // no parameter added
{
std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl;
p = 1;
// put back p in parameter for consistency (and status file)
ppSelect.second.push_back(std::string("1"));
}
else // parameter passed by user as DetTour(T)
p = atof(ppSelect.second[0].c_str());
select = new eoStochTournamentSelect<EOT>(p);
}
else if (ppSelect.first == std::string("Ranking"))
{
double p,e;
if (ppSelect.second.size()==2) // 2 parameters: pressure and exponent
{
p = atof(ppSelect.second[0].c_str());
e = atof(ppSelect.second[1].c_str());
}
else if (ppSelect.second.size()==1) // 1 parameter: pressure
{
std::cerr << "WARNING, no exponent to Ranking, using 1" << std::endl;
e = 1;
ppSelect.second.push_back(std::string("1"));
p = atof(ppSelect.second[0].c_str());
}
else // no parameters ... or garbage
{
std::cerr << "WARNING, no parameter to Ranking, using (2,1)" << std::endl;
p=2;
e=1;
// put back in parameter for consistency (and status file)
ppSelect.second.resize(2); // just in case
ppSelect.second[0] = (std::string("2"));
ppSelect.second[1] = (std::string("1"));
}
// check for authorized values
// pressure in (0,1]
if ( (p<=1) || (p>2) )
{
std::cerr << "WARNING, selective pressure must be in (1,2] in Ranking, using 2\n";
p=2;
ppSelect.second[0] = (std::string("2"));
}
// exponent >0
if (e<=0)
{
std::cerr << "WARNING, exponent must be positive in Ranking, using 1\n";
e=1;
ppSelect.second[1] = (std::string("1"));
}
// now we're OK
eoPerf2Worth<EOT> & p2w = _state.storeFunctor( new eoRanking<EOT>(p,e) );
select = new eoRouletteWorthSelect<EOT>(p2w);
}
else if (ppSelect.first == std::string("Sequential")) // one after the other
{
bool b;
if (ppSelect.second.size() == 0) // no argument -> default = ordered
{
b=true;
// put back in parameter for consistency (and status file)
ppSelect.second.push_back(std::string("ordered"));
}
else
b = !(ppSelect.second[0] == std::string("unordered"));
select = new eoSequentialSelect<EOT>(b);
}
else if (ppSelect.first == std::string("EliteSequential")) // Best first, one after the other in random order afterwards
{
select = new eoEliteSequentialSelect<EOT>;
}
else if (ppSelect.first == std::string("Roulette")) // no argument (yet)
{
select = new eoProportionalSelect<EOT>;
}
else if (ppSelect.first == std::string("Random")) // no argument
{
select = new eoRandomSelect<EOT>;
}
else
{
std::string stmp = std::string("Invalid selection: ") + ppSelect.first;
throw std::runtime_error(stmp.c_str());
}
_state.storeFunctor(select);
// the number of offspring
eoValueParam<eoHowMany>& offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring", "Nb of offspring (percentage or absolute)", 'O', "Evolution Engine");
/////////////////////////////////////////////////////
// the replacement
/////////////////////////////////////////////////////
/** Replacement type - high level: predefined replacements
* ESComma :
* elite = 0
* surviveParents=0 (no reduce)
* surviveOffspring=100% (no reduce)
* reduceFinal = Deterministic
*
* ESPlus : idem, except for
* surviveParents = 100%
*
* GGA : generational GA - idem ESComma except for
* offspringRate = 100%
* all reducers are unused
*
* SSGA(T/t) : Steady-State GA
* surviveParents = 1.0 - offspringRate
* reduceFinal = DetTour(T>1) ou StochTour(0.5<t<1)
*
* EP(T) : Evolutionary Programming
* offspringRate=100%
* surviveParents = 100%
* surviveOffspring = 100%
* reduceFinal = EP(T)
*
* G3 and MGG are excetions at the moment, treated on their own
*
*/
eoParamParamType & replacementParam = _parser.createParam(eoParamParamType("General"), "replacement", "Type of replacement: General, or Generational, ESComma, ESPlus, SSGA(T), EP(T), G3, MGG(T)", '\0', "Evolution Engine").value();
// the pointer
eoReplacement<EOT> * ptReplace;
// first, separate G3 and MGG
// maybe one day we have a common class - but is it really necessary???
if (replacementParam.first == std::string("G3"))
{
// reduce the parents: by default, survive parents = -2 === 2 parents die
eoHowMany surviveParents = _parser.createParam(eoHowMany(-2,false), "surviveParents", "Nb of surviving parents (percentage or absolute)", '\0', "Evolution Engine / Replacement").value();
// at the moment, this is the only argument
ptReplace = new eoG3Replacement<EOT>(-surviveParents); // must receive nb of eliminated parets!
_state.storeFunctor(ptReplace);
}
else if (replacementParam.first == std::string("MGG"))
{
float t;
unsigned tSize;
// reduce the parents: by default, survive parents = -2 === 2 parents die
eoHowMany surviveParents = _parser.createParam(eoHowMany(-2,false), "surviveParents", "Nb of surviving parents (percentage or absolute)", '\0', "Evolution Engine / Replacement").value();
// the tournament size
if (!replacementParam.second.size()) // no parameter added
{
std::cerr << "WARNING, no parameter passed to MGG replacement, using 2" << std::endl;
tSize = 2;
// put back 2 in parameter for consistency (and status file)
replacementParam.second.push_back(std::string("2"));
}
else
{
t = atof(replacementParam.second[0].c_str());
if (t>=2)
{ // build the appropriate deafult value
tSize = unsigned(t);
}
else
{
throw std::runtime_error("Sorry, only deterministic tournament available at the moment");
}
}
ptReplace = new eoMGGReplacement<EOT>(-surviveParents, tSize);
_state.storeFunctor(ptReplace);
}
else { // until the end of what was the only loop/switch
// the default deafult values
eoHowMany elite (0.0);
bool strongElitism (false);
eoHowMany surviveParents (0.0);
eoParamParamType reduceParentType ("Deterministic");
eoHowMany surviveOffspring (1.0);
eoParamParamType reduceOffspringType ("Deterministic");
eoParamParamType reduceFinalType ("Deterministic");
// depending on the value entered by the user, change some of the above
double t;
// ---------- General
if (replacementParam.first == std::string("General"))
{
; // defaults OK
}
// ---------- ESComma
else if (replacementParam.first == std::string("ESComma"))
{
; // OK too
}
// ---------- ESPlus
else if (replacementParam.first == std::string("ESPlus"))
{
surviveParents = eoHowMany(1.0);
}
// ---------- Generational
else if (replacementParam.first == std::string("Generational"))
{
; // OK too (we should check nb of offspring)
}
// ---------- EP
else if (replacementParam.first == std::string("EP"))
{
if (!replacementParam.second.size()) // no parameter added
{
std::cerr << "WARNING, no parameter passed to EP replacement, using 6" << std::endl;
// put back 6 in parameter for consistency (and status file)
replacementParam.second.push_back(std::string("6"));
}
// by coincidence, the syntax for the EP reducer is the same than here:
reduceFinalType = replacementParam;
surviveParents = eoHowMany(1.0);
}
// ---------- SSGA
else if (replacementParam.first == std::string("SSGA"))
{
if (!replacementParam.second.size()) // no parameter added
{
std::cerr << "WARNING, no parameter passed to SSGA replacement, using 2" << std::endl;
// put back 2 in parameter for consistency (and status file)
replacementParam.second.push_back(std::string("2"));
reduceParentType = eoParamParamType(std::string("DetTour(2)"));
}
else
{
t = atof(replacementParam.second[0].c_str());
if (t>=2)
{ // build the appropriate deafult value
reduceParentType = eoParamParamType(std::string("DetTour(") + replacementParam.second[0].c_str() + ")");
}
else // check for [0.5,1] will be made in make_general_replacement
{ // build the appropriate deafult value
reduceParentType = eoParamParamType(std::string("StochTour(") + replacementParam.second[0].c_str() + ")");
}
}
//
surviveParents = eoHowMany(-1);
surviveOffspring = eoHowMany(1);
}
else // no replacement recognized
{
throw std::runtime_error("Invalid replacement type " + replacementParam.first);
}
ptReplace = & make_general_replacement<EOT>(
_parser, _state, elite, strongElitism, surviveParents, reduceParentType, surviveOffspring, reduceOffspringType, reduceFinalType);
} // end of the ugly construct due to G3 and MGG - totaly heterogeneous at the moment
///////////////////////////////
// the general breeder
///////////////////////////////
eoGeneralBreeder<EOT> *breed =
new eoGeneralBreeder<EOT>(*select, _op, offspringRateParam.value());
_state.storeFunctor(breed);
///////////////////////////////
// now the eoEasyEA
///////////////////////////////
eoAlgo<EOT> *algo = new eoEasyEA<EOT>(_continue, _eval, *breed, *ptReplace);
_state.storeFunctor(algo);
// that's it!
return *algo;
}
#endif

View file

@ -0,0 +1,203 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// make_algo_pareto.h
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2002
/*
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
Marc.Schoenauer@inria.fr
mkeijzer@dhi.dk
*/
//-----------------------------------------------------------------------------
#ifndef _make_algo_pareto_h
#define _make_algo_pareto_h
#include "utils/eoData.h" // for eo_is_a_rate
// everything tha's needed for the algorithms - SCALAR fitness
// Selection
// the eoSelectOne's
#include "eoSelectFromWorth.h"
#include "eoNDSorting.h"
// Breeders
#include "eoGeneralBreeder.h"
// Replacement - at the moment limited to eoNDPlusReplacement, locally defined
#include "eoReplacement.h"
template <class EOT, class WorthT = double>
class eoNDPlusReplacement : public eoReplacement<EOT>
{
public:
eoNDPlusReplacement(eoPerf2Worth<EOT, WorthT>& _perf2worth) : perf2worth(_perf2worth) {}
struct WorthPair : public std::pair<WorthT, const EOT*>
{
bool operator<(const WorthPair& other) const { return other.first < this->first; }
};
void operator()(eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
{
unsigned sz = _parents.size();
_parents.reserve(_parents.size() + _offspring.size());
copy(_offspring.begin(), _offspring.end(), back_inserter(_parents));
// calculate worths
perf2worth(_parents);
perf2worth.sort_pop(_parents);
perf2worth.resize(_parents, sz);
_offspring.clear();
}
private :
eoPerf2Worth<EOT, WorthT>& perf2worth;
};
// Algorithm (only this one needed)
#include "eoEasyEA.h"
// also need the parser and param includes
#include "utils/eoParser.h"
#include "utils/eoState.h"
/*
* This function builds the algorithm (i.e. selection and replacement)
* from existing continue (or checkpoint) and operators
*
* It uses a parser (to get user parameters) and a state (to store the memory)
* the last argument is an individual, needed for 2 reasons
* it disambiguates the call after instanciations
* some operator might need some private information about the indis
*
* This is why the template is the complete EOT even though only the fitness
* is actually templatized here
*/
template <class EOT>
eoAlgo<EOT> & do_make_algo_pareto(eoParser& _parser, eoState& _state, eoEvalFunc<EOT>& _eval, eoContinue<EOT>& _continue, eoGenOp<EOT>& _op)
{
// the selection
std::string & selStr = _parser.createParam(std::string("NSGA-II"), "selCrit", "Pareto Selection Criterion: NSGA, NSGA-II, ParetoRanking", 'S', "Evolution Engine").value();
double nicheSize = _parser.createParam(1.0, "nicheSize", "Size of niche for NSGA-I", '\0', "Evolution Engine").value();
eoPerf2Worth<EOT, double> *p2w;
if ( (selStr == std::string("NSGA")) || (selStr == std::string("NSGA-I") ) )
p2w = new eoNDSorting_I<EOT>(nicheSize);
else if (selStr == std::string("NSGA-II"))
p2w = new eoNDSorting_II<EOT>();
else if (selStr == std::string("ParetoRanking"))
{
eoDominanceMap<EOT>& dominance = _state.storeFunctor(new eoDominanceMap<EOT>);
p2w = new eoParetoRanking<EOT>(dominance);
}
_state.storeFunctor(p2w);
// now the selector (from p2w) - cut-and-pasted from make_algo_scalar!
// only all classes are now ...FromWorth ...
// only the ranking is not re-implemented (yet?)
eoValueParam<eoParamParamType>& selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", "Selection: Roulette, DetTour(T), StochTour(t) or Random", 'S', "Evolution Engine");
eoParamParamType & ppSelect = selectionParam.value(); // std::pair<std::string,std::vector<std::string> >
eoSelectOne<EOT>* select ;
if (ppSelect.first == std::string("DetTour"))
{
unsigned detSize;
if (!ppSelect.second.size()) // no parameter added
{
std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl;
detSize = 2;
// put back 2 in parameter for consistency (and status file)
ppSelect.second.push_back(std::string("2"));
}
else // parameter passed by user as DetTour(T)
detSize = atoi(ppSelect.second[0].c_str());
select = new eoDetTournamentWorthSelect<EOT>(*p2w, detSize);
}
else if (ppSelect.first == std::string("StochTour"))
{
double p;
if (!ppSelect.second.size()) // no parameter added
{
std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl;
p = 1;
// put back p in parameter for consistency (and status file)
ppSelect.second.push_back(std::string("1"));
}
else // parameter passed by user as DetTour(T)
p = atof(ppSelect.second[0].c_str());
select = new eoStochTournamentWorthSelect<EOT>(*p2w, p);
}
// else if (ppSelect.first == std::string("Sequential")) // one after the other
// {
// bool b;
// if (ppSelect.second.size() == 0) // no argument -> default = ordered
// {
// b=true;
// // put back in parameter for consistency (and status file)
// ppSelect.second.push_back(std::string("ordered"));
// }
// else
// b = !(ppSelect.second[0] == std::string("unordered"));
// select = new eoSequentialWorthSelect<EOT>(b);
// }
else if (ppSelect.first == std::string("Roulette")) // no argument (yet)
{
select = new eoRouletteWorthSelect<EOT>(*p2w);
}
else if (ppSelect.first == std::string("Random")) // no argument, no perf2Worth
{
select = new eoRandomSelect<EOT>;
}
else
{
std::string stmp = std::string("Invalid selection: ") + ppSelect.first;
throw std::runtime_error(stmp.c_str());
}
_state.storeFunctor(select);
// the number of offspring
eoValueParam<eoHowMany>& offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring", "Nb of offspring (percentage or absolute)", 'O', "Evolution Engine");
// the replacement
// actually limited to eoNDPlusReplacement
eoReplacement<EOT> & replace = _state.storeFunctor(
new eoNDPlusReplacement<EOT, double>(*p2w)
);
// the general breeder
eoGeneralBreeder<EOT> *breed =
new eoGeneralBreeder<EOT>(*select, _op, offspringRateParam.value());
_state.storeFunctor(breed);
// now the eoEasyEA
eoAlgo<EOT> *algo = new eoEasyEA<EOT>(_continue, _eval, *breed, replace);
_state.storeFunctor(algo);
// that's it!
return *algo;
}
#endif

View file

@ -0,0 +1,311 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// make_algo_scalar.h
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
/*
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
Marc.Schoenauer@polytechnique.fr
mkeijzer@dhi.dk
*/
//-----------------------------------------------------------------------------
#ifndef _make_algo_scalar_h
#define _make_algo_scalar_h
#include <utils/eoData.h> // for eo_is_a_rate
// everything tha's needed for the algorithms - SCALAR fitness
// Selection
// the eoSelectOne's
#include <eoRandomSelect.h>
#include <eoSequentialSelect.h>
#include <eoDetTournamentSelect.h>
#include <eoProportionalSelect.h>
#include <eoFitnessScalingSelect.h>
#include <eoRankingSelect.h>
#include <eoStochTournamentSelect.h>
#include <eoSharingSelect.h>
#include <utils/eoDistance.h>
// Breeders
#include <eoGeneralBreeder.h>
// Replacement
// #include <eoReplacement.h>
#include <eoMergeReduce.h>
#include <eoReduceMerge.h>
#include <eoSurviveAndDie.h>
// distance
#include <utils/eoDistance.h>
// Algorithm (only this one needed)
#include <eoEasyEA.h>
// also need the parser and param includes
#include <utils/eoParser.h>
#include <utils/eoState.h>
/*
* This function builds the algorithm (i.e. selection and replacement)
* from existing continue (or checkpoint) and operators
*
* It uses a parser (to get user parameters) and a state (to store the memory)
* the last argument is an individual, needed for 2 reasons
* it disambiguates the call after instanciations
* some operator might need some private information about the indis
*
* This is why the template is the complete EOT even though only the fitness
* is actually templatized here
*/
template <class EOT>
eoAlgo<EOT> & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<EOT>& _eval, eoContinue<EOT>& _continue, eoGenOp<EOT>& _op, eoDistance<EOT> * _dist = NULL)
{
// the selection : help and comment depend on whether or not a distance is passed
std::string comment;
if (_dist == NULL)
comment = "Selection: DetTour(T), StochTour(t), Roulette, Ranking(p,e) or Sequential(ordered/unordered)";
else
comment = "Selection: DetTour(T), StochTour(t), Roulette, Ranking(p,e), Sharing(sigma_share) or Sequential(ordered/unordered)";
eoValueParam<eoParamParamType>& selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", comment, 'S', "Evolution Engine");
eoParamParamType & ppSelect = selectionParam.value(); // std::pair<std::string,std::vector<std::string> >
eoSelectOne<EOT>* select ;
if (ppSelect.first == std::string("DetTour"))
{
unsigned detSize;
if (!ppSelect.second.size()) // no parameter added
{
std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl;
detSize = 2;
// put back 2 in parameter for consistency (and status file)
ppSelect.second.push_back(std::string("2"));
}
else // parameter passed by user as DetTour(T)
detSize = atoi(ppSelect.second[0].c_str());
select = new eoDetTournamentSelect<EOT>(detSize);
}
else if (ppSelect.first == std::string("Sharing"))
{
double nicheSize;
if (!ppSelect.second.size()) // no parameter added
{
std::cerr << "WARNING, no parameter passed to Sharing, using 0.5" << std::endl;
nicheSize = 0.5;
// put back 2 in parameter for consistency (and status file)
ppSelect.second.push_back(std::string("0.5"));
}
else // parameter passed by user as DetTour(T)
nicheSize = atof(ppSelect.second[0].c_str());
if (_dist == NULL) // no distance
throw std::runtime_error("You didn't specify a distance when calling make_algo_scalar and using sharing");
select = new eoSharingSelect<EOT>(nicheSize, *_dist);
}
else if (ppSelect.first == std::string("StochTour"))
{
double p;
if (!ppSelect.second.size()) // no parameter added
{
std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl;
p = 1;
// put back p in parameter for consistency (and status file)
ppSelect.second.push_back(std::string("1"));
}
else // parameter passed by user as DetTour(T)
p = atof(ppSelect.second[0].c_str());
select = new eoStochTournamentSelect<EOT>(p);
}
else if (ppSelect.first == std::string("Ranking"))
{
double p,e;
if (ppSelect.second.size()==2) // 2 parameters: pressure and exponent
{
p = atof(ppSelect.second[0].c_str());
e = atof(ppSelect.second[1].c_str());
}
else if (ppSelect.second.size()==1) // 1 parameter: pressure
{
std::cerr << "WARNING, no exponent to Ranking, using 1" << std::endl;
e = 1;
ppSelect.second.push_back(std::string("1"));
p = atof(ppSelect.second[0].c_str());
}
else // no parameters ... or garbage
{
std::cerr << "WARNING, no parameter to Ranking, using (2,1)" << std::endl;
p=2;
e=1;
// put back in parameter for consistency (and status file)
ppSelect.second.resize(2); // just in case
ppSelect.second[0] = (std::string("2"));
ppSelect.second[1] = (std::string("1"));
}
// check for authorized values
// pressure in (0,1]
if ( (p<=1) || (p>2) )
{
std::cerr << "WARNING, selective pressure must be in (0,1] in Ranking, using 2\n";
p=2;
ppSelect.second[0] = (std::string("2"));
}
// exponent >0
if (e<=0)
{
std::cerr << "WARNING, exponent must be positive in Ranking, using 1\n";
e=1;
ppSelect.second[1] = (std::string("1"));
}
// now we're OK
eoPerf2Worth<EOT> & p2w = _state.storeFunctor( new eoRanking<EOT>(p,e) );
select = new eoRouletteWorthSelect<EOT>(p2w);
}
else if (ppSelect.first == std::string("Sequential")) // one after the other
{
bool b;
if (ppSelect.second.size() == 0) // no argument -> default = ordered
{
b=true;
// put back in parameter for consistency (and status file)
ppSelect.second.push_back(std::string("ordered"));
}
else
b = !(ppSelect.second[0] == std::string("unordered"));
select = new eoSequentialSelect<EOT>(b);
}
else if (ppSelect.first == std::string("Roulette")) // no argument (yet)
{
select = new eoProportionalSelect<EOT>;
}
else if (ppSelect.first == std::string("Random")) // no argument
{
select = new eoRandomSelect<EOT>;
}
else
{
std::string stmp = std::string("Invalid selection: ") + ppSelect.first;
throw std::runtime_error(stmp.c_str());
}
_state.storeFunctor(select);
// the number of offspring
eoValueParam<eoHowMany>& offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring", "Nb of offspring (percentage or absolute)", 'O', "Evolution Engine");
// the replacement
eoValueParam<eoParamParamType>& replacementParam = _parser.createParam(eoParamParamType("Comma"), "replacement", "Replacement: Comma, Plus or EPTour(T), SSGAWorst, SSGADet(T), SSGAStoch(t)", 'R', "Evolution Engine");
eoParamParamType & ppReplace = replacementParam.value(); // std::pair<std::string,std::vector<std::string> >
eoReplacement<EOT>* replace ;
if (ppReplace.first == std::string("Comma")) // Comma == generational
{
replace = new eoCommaReplacement<EOT>;
}
else if (ppReplace.first == std::string("Plus"))
{
replace = new eoPlusReplacement<EOT>;
}
else if (ppReplace.first == std::string("EPTour"))
{
unsigned detSize;
if (!ppReplace.second.size()) // no parameter added
{
std::cerr << "WARNING, no parameter passed to EPTour, using 6" << std::endl;
detSize = 6;
// put back in parameter for consistency (and status file)
ppReplace.second.push_back(std::string("6"));
}
else // parameter passed by user as EPTour(T)
detSize = atoi(ppSelect.second[0].c_str());
replace = new eoEPReplacement<EOT>(detSize);
}
else if (ppReplace.first == std::string("SSGAWorst"))
{
replace = new eoSSGAWorseReplacement<EOT>;
}
else if (ppReplace.first == std::string("SSGADet"))
{
unsigned detSize;
if (!ppReplace.second.size()) // no parameter added
{
std::cerr << "WARNING, no parameter passed to SSGADet, using 2" << std::endl;
detSize = 2;
// put back in parameter for consistency (and status file)
ppReplace.second.push_back(std::string("2"));
}
else // parameter passed by user as SSGADet(T)
detSize = atoi(ppSelect.second[0].c_str());
replace = new eoSSGADetTournamentReplacement<EOT>(detSize);
}
else if (ppReplace.first == std::string("SSGAStoch"))
{
double p;
if (!ppReplace.second.size()) // no parameter added
{
std::cerr << "WARNING, no parameter passed to SSGAStoch, using 1" << std::endl;
p = 1;
// put back in parameter for consistency (and status file)
ppReplace.second.push_back(std::string("1"));
}
else // parameter passed by user as SSGADet(T)
p = atof(ppSelect.second[0].c_str());
replace = new eoSSGAStochTournamentReplacement<EOT>(p);
}
else
{
std::string stmp = std::string("Invalid replacement: ") + ppReplace.first;
throw std::runtime_error(stmp.c_str());
}
_state.storeFunctor(replace);
// adding weak elitism
eoValueParam<bool>& weakElitismParam = _parser.createParam(false, "weakElitism", "Old best parent replaces new worst offspring *if necessary*", 'w', "Evolution Engine");
if (weakElitismParam.value())
{
eoReplacement<EOT> *replaceTmp = replace;
replace = new eoWeakElitistReplacement<EOT>(*replaceTmp);
_state.storeFunctor(replace);
}
// the general breeder
eoGeneralBreeder<EOT> *breed =
new eoGeneralBreeder<EOT>(*select, _op, offspringRateParam.value());
_state.storeFunctor(breed);
// now the eoEasyEA
eoAlgo<EOT> *algo = new eoEasyEA<EOT>(_continue, _eval, *breed, *replace);
_state.storeFunctor(algo);
// that's it!
return *algo;
}
#endif

Some files were not shown because too many files have changed in this diff Show more