From 8d35fad13654a080d2ce71afc8fb3ee7128274cb Mon Sep 17 00:00:00 2001 From: evomarc Date: Sun, 28 Jan 2001 07:00:41 +0000 Subject: [PATCH] Added the includes ga.h and es.h Removed the old eoEsObjectiveBounds and evolutionar_strategies from es dir --- eo/src/Makefile.am | 5 +- eo/src/es.h | 65 +++++++++++++++++++++ eo/src/es/Makefile.am | 5 +- eo/src/ga.h | 46 +++++++++++++++ eo/src/obsolete/Makefile.am | 3 +- eo/src/obsolete/eoEsObjectiveBounds.h | 81 +++++++++++++++++++++++++++ eo/src/obsolete/evolution_strategies | 15 +++++ eo/src/utils/Makefile.am | 3 +- eo/test/t-eoESFull.cpp | 18 +++--- 9 files changed, 225 insertions(+), 16 deletions(-) create mode 100644 eo/src/es.h create mode 100644 eo/src/ga.h create mode 100644 eo/src/obsolete/eoEsObjectiveBounds.h create mode 100644 eo/src/obsolete/evolution_strategies diff --git a/eo/src/Makefile.am b/eo/src/Makefile.am index 9ca97b44e..81b547aad 100644 --- a/eo/src/Makefile.am +++ b/eo/src/Makefile.am @@ -4,12 +4,11 @@ ## ############################################################################### -SUBDIRS = es ga utils other +SUBDIRS = es ga gp utils other CPPFLAGS = -O2 lib_LIBRARIES = libeo.a libeo_a_SOURCES = eoPrintable.cpp eoPersistent.cpp eoFunctorStore.cpp libeoincdir = $(includedir)/eo -libeoinc_HEADERS = eo EO.h apply.h eoAlgo.h eoBackInserter.h eoBreed.h eoCombinedContinue.h eoContinue.h eoCounter.h eoDetTournamentSelect.h eoDetTournamentInserter.h eoEasyEA.h eoEvalFunc.h eoEvalFuncPtr.h eoEvolutionStrategy.h eoFactory.h eoFitContinue.h eoFixedLength.h eoFunctor.h eoFunctorStore.h eoGOpBreeder.h eoGOpSelector.h eoGenContinue.h eoIndiSelector.h eoInit.h eoInplaceTransform.h eoInserter.h eoMerge.h eoObject.h eoOp.h eoOpFactory.h eoOpSelMason.h eoOpSelector.h eoPersistent.h eoPop.h eoPrintable.h eoProportionalSelect.h eoProportionalGOpSel.h eoProportionalOpSel.h eoRandomSelect.h eoReduce.h eoReplacement.h eoSGA.h eoScalarFitness.h eoSelect.h eoSelectFactory.h eoSelectOne.h eoSelectPerc.h eoSequentialGOpSel.h eoSteadyStateEA.h eoSteadyStateInserter.h eoSteadyStateTransform.h eoStochTournamentSelect.h eoStochTournamentInserter.h eoTransform.h eoVariableLength.h eoWrappedOps.h - +libeoinc_HEADERS = eo EO.h apply.h eoAlgo.h eoBackInserter.h eoBreed.h eoCombinedContinue.h eoContinue.h eoCounter.h eoDetSelect.h eoDetTournamentInserter.h eoDetTournamentSelect.h eoEasyEA.h eoEvalFunc.h eoEvalFuncPtr.h eoEvolutionStrategy.h eoFactory.h eoFitContinue.h eoFitnessScalingSelect.h eoFixedLength.h eoFunctor.h eoFunctorStore.h eoGOpBreeder.h eoGOpSelector.h eoGenContinue.h eoGenericBinOp.h eoGenericMonOp.h eoGenericQuadOp.h eoIndiSelector.h eoInit.h eoInplaceTransform.h eoInserter.h eoMerge.h eoMergeReduce.h eoObject.h eoOp.h eoOpFactory.h eoOpSelMason.h eoOpSelector.h eoPersistent.h eoPop.h eoPrintable.h eoProportionalCombinedOp.h eoProportionalGOpSel.h eoProportionalOpSel.h eoProportionalSelect.h eoQud2BinOp.h eoRandomSelect.h eoRankingSelect.h eoReduce.h eoReduceMerge.h eoReplacement.h eoSGA.h eoSGATransform.h eoScalarFitness.h eoSelect.h eoSelectFactory.h eoSelectMany.h eoSelectNumber.h eoSelectOne.h eoSelectPerc.h eoSequentialGOpSel.h eoSteadyFitContinue.h eoSteadyStateEA.h eoSteadyStateInserter.h eoSteadyStateTransform.h eoStochTournamentInserter.h eoStochTournamentSelect.h eoSurviveAndDie.h eoTransform.h eoVariableLength.h eoVariableLengthCrossover.h eoVariableLengthMutation.h eoWrappedOps.h es.h ga.h diff --git a/eo/src/es.h b/eo/src/es.h new file mode 100644 index 000000000..d96b9746b --- /dev/null +++ b/eo/src/es.h @@ -0,0 +1,65 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// es.h +// (c) GeNeura Team 1998 - Maarten Keijzer 2000 - Marc Schoenauer 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: Marc.Schoenauer@polytechnique.fr + mak@dhi.dk + todos@geneura.ugr.es, http://geneura.ugr.es + */ +//----------------------------------------------------------------------------- + +#ifdef _MSC_VER +// to avoid long name warnings +#pragma warning(disable:4786) +#endif + +#ifndef _es_h +#define _es_h + +// contains the include specific to real representations, i.e. in src/es dir +//----------------------------------------------------------------------------- + +// the genotypes - from plain vector to full correlated mutation +#include +#include +#include +#include + +// the initialization +#include + +// general operators +#include +#include + +// and their generic counterparts +#include + +// the ES-mutations +#include +#include + +// the crossover - to be continued +#include + +#endif _es_h + +// Local Variables: +// mode: C++ +// End: diff --git a/eo/src/es/Makefile.am b/eo/src/es/Makefile.am index 6b89d98a6..8b275335f 100644 --- a/eo/src/es/Makefile.am +++ b/eo/src/es/Makefile.am @@ -5,7 +5,4 @@ ############################################################################### libeoincdir = $(includedir)/eo/es -libeoinc_HEADERS = evolution_strategies eoEsChromInit.h eoEsFull.h eoEsMutate.h eoEsMutationInit.h eoEsObjectiveBounds.h eoEsSimple.h eoEsStdev.h - - - +libeoinc_HEADERS = eoEsChromInit.h eoEsFull.h eoEsMutate.h eoEsMutationInit.h eoEsSimple.h eoEsStdev.h eoEsStdevXOver.h eoGenericRealOp.h eoNormalMutation.h eoReal.h eoRealBounds.h eoRealOp.h diff --git a/eo/src/ga.h b/eo/src/ga.h new file mode 100644 index 000000000..4e2720795 --- /dev/null +++ b/eo/src/ga.h @@ -0,0 +1,46 @@ +//----------------------------------------------------------------------------- +// ga.h +// (c) GeNeura Team 1998 - 2000, Marc Schoenauer 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 + */ +//----------------------------------------------------------------------------- + +#ifdef _MSC_VER +// to avoid long name warnings +#pragma warning(disable:4786) +#endif + +#ifndef _ga_h +#define _ga_h + +// all bitstring-specific files +#include + +// the operators +#include + +// #include + +//----------------------------------------------------------------------------- + +#endif _ga_h + +// Local Variables: +// mode: C++ +// End: diff --git a/eo/src/obsolete/Makefile.am b/eo/src/obsolete/Makefile.am index 56fae4df6..1a94e144a 100644 --- a/eo/src/obsolete/Makefile.am +++ b/eo/src/obsolete/Makefile.am @@ -10,4 +10,5 @@ lib_LIBRARIES = libeoobsolete.a libeoobsolete_a_SOURCES = eoParserUtils.cpp libeoobsoleteincdir = $(includedir)/eo/obsolete -libeoobsoleteinc_HEADERS = eoProblem.h eoParser.h eoParserUtils.h +libeoobsoleteinc_HEADERS = eo1d.h eo1dWDistance.h eo2d.h eo2dVector.h eoAtomBitFlip.h eoAtomCreep.h eoAtomMutation.h eoAtomMutator.h eoAtomRandom.h eoBin.h eoBreeder.h eoCopyElite.h eoDetTournament.h eoDetTournamentIndiSelector.h eoDistance.h eoDup.h eoES.h eoESChrom.h eoESFullChrom.h eoESFullMut.h eoEsObjectiveBounds.h eoEvalFuncPtrCnt.h eoFitTerm.h eoFitness.h eoGenTerm.h eoGeneration.h eoID.h eoInclusion.h eoInsertion.h eoKill.h eoLottery.h eoMutation.h eoNegExp.h eoNonUniform.h eoNormal.h eoParser.h eoParserUtils.h eoPopOps.h eoProblem.h eoProportional.h eoRandomBreed.h eoRandomIndiSelector.h eoRandomSelect.h eoRank.h eoRnd.h eoScheme.h eoSelectRandom.h eoStochTournament.h eoStringMutation.h eoTerm.h eoTournament.h eoTranspose.h eoUniform.h eoUniformXOver.h eoVector.h eoXOver2.h + diff --git a/eo/src/obsolete/eoEsObjectiveBounds.h b/eo/src/obsolete/eoEsObjectiveBounds.h new file mode 100644 index 000000000..f6e2fdda0 --- /dev/null +++ b/eo/src/obsolete/eoEsObjectiveBounds.h @@ -0,0 +1,81 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// eoEsObjectiveBounds.h +// (c) Maarten Keijzer 2000, GeNeura Team, 1998 - EEAAX 1999 +/* + 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 + mak@dhi.dk + */ +//----------------------------------------------------------------------------- + +#ifndef _eoEsObjectiveBounds_h +#define _eoEsObjectiveBounds_h + +/** +\defgroup EvolutionStrategies + + Various classes for the initialization and mutation of real valued vectors. + + Supports simple mutations and various more adaptable mutations, including + correlated mutations. + +*/ + + +/** +\class eoEsObjectiveBounds eoEsObjectiveBounds.h es/eoEsObjectiveBounds.h +\ingroup EvolutionStrategies + + Defines the minima and maxima of the object variables. Needed by eoEsChromInit + and eoEsMutate + + @see eoEsChromInit eoEsMutate +*/ +class eoEsObjectiveBounds +{ + public : + + /** + Objective bounds for a global minimum and maximum + */ + eoEsObjectiveBounds(int _nGenes, double _min, double _max) : repMinimum(_nGenes), repMaximum(_nGenes) + { + std::fill(repMinimum.begin(), repMinimum.end(), _min); + std::fill(repMaximum.begin(), repMaximum.end(), _max); + } + + /** + Objective bounds for a per gene minimum and maximum + */ + eoEsObjectiveBounds(const std::vector& _min, const std::vector& _max) + : repMinimum(_min), repMaximum(_max) {} + + typedef double doubleype; + + double minimum(size_t i) { return repMinimum[i]; } + double maximum(size_t i) { return repMaximum[i]; } + + unsigned chromSize(void) const { return repMinimum.size(); } + + private : + std::vector repMinimum; + std::vector repMaximum; +}; + +#endif diff --git a/eo/src/obsolete/evolution_strategies b/eo/src/obsolete/evolution_strategies new file mode 100644 index 000000000..d1c729ba9 --- /dev/null +++ b/eo/src/obsolete/evolution_strategies @@ -0,0 +1,15 @@ +#ifndef _eoEs_h +#define _eoEs_h + +#include +#include +#include +#include + +#include +#include + +#include + + +#endif diff --git a/eo/src/utils/Makefile.am b/eo/src/utils/Makefile.am index 8c3d7000b..17f4510b1 100644 --- a/eo/src/utils/Makefile.am +++ b/eo/src/utils/Makefile.am @@ -10,6 +10,7 @@ lib_LIBRARIES = libeoutils.a libeoutils_a_SOURCES = eoParser.cpp eoRNG.cpp eoState.cpp eoUpdater.cpp eoFileMonitor.cpp eoStdoutMonitor.cpp libeoincdir = $(includedir)/eo/utils -libeoinc_HEADERS = compatibility.h eoParam.h eoRNG.h rnd_generators.h eoData.h eoParser.h eoState.h selectors.h eoStat.h eoMonitor.h eoFileMonitor.h eoUpdater.h checkpointing eoCheckPoint.h eoStdoutMonitor.h eoGnuplot1DMonitor.h +libeoinc_HEADERS = compatibility.h eoCheckPoint.h eoData.h eoDistance.h eoFileMonitor.h eoGnuplot1DMonitor.h eoHowMany.h eoMonitor.h eoParam.h eoParser.h eoRNG.h eoStat.h eoState.h eoStdoutMonitor.h eoUpdatable.h eoUpdater.h rnd_generators.h selectors.h + diff --git a/eo/test/t-eoESFull.cpp b/eo/test/t-eoESFull.cpp index ca28941f7..177b625bc 100644 --- a/eo/test/t-eoESFull.cpp +++ b/eo/test/t-eoESFull.cpp @@ -16,7 +16,7 @@ using namespace std; #include // representation specific -#include +#include #include "real_value.h" // the sphere fitness @@ -25,7 +25,7 @@ using namespace std; typedef eoMinimizingFitness FitT; template -void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoEsObjectiveBounds& _bounds, eoValueParam _load_name); +void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoRealVectorBounds& _bounds, eoValueParam _load_name); int main(int argc, char *argv[]) { @@ -39,8 +39,8 @@ int main(int argc, char *argv[]) eoValueParam& stdevs = parser.createParam(false, "Stdev", "Use adaptive mutation rates", 's'); eoValueParam& corr = parser.createParam(false, "Correl", "Use correlated mutations", 'c'); eoValueParam& chromSize = parser.createParam(unsigned(50), "ChromSize", "Number of chromosomes", 'n'); - eoValueParam& minimum = parser.createParam(-1.e5, "Min", "Minimum for Objective Variables", 'l'); - eoValueParam& maximum = parser.createParam(1.e5, "Max", "Maximum for Objective Variables", 'h'); + eoValueParam& minimum = parser.createParam(-1.0, "Min", "Minimum for Objective Variables", 'l'); + eoValueParam& maximum = parser.createParam(1.0, "Max", "Maximum for Objective Variables", 'h'); eoState state; state.registerObject(parser); @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) state.registerObject(rng); - eoEsObjectiveBounds bounds(chromSize.value(), minimum.value(), maximum.value()); + eoRealVectorBounds bounds(chromSize.value(), minimum.value(), maximum.value()); // Run the appropriate algorithm if (stdevs.value() == false && corr.value() == false) @@ -84,7 +84,7 @@ int main(int argc, char *argv[]) } template -void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoEsObjectiveBounds& _bounds, eoValueParam _load_name) +void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoRealVectorBounds& _bounds, eoValueParam _load_name) { // evaluation eoEvalFuncPtr&> eval( real_value ); @@ -128,7 +128,7 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoEsObjectiveBounds& monitor.add(average); - eoGenContinue cnt(20); + eoGenContinue cnt(100); eoCheckPoint checkpoint(cnt); checkpoint.add(monitor); checkpoint.add(average); @@ -140,4 +140,8 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state, eoEsObjectiveBounds& eoEvolutionStrategy es(checkpoint, eval, opSel, lambda_rate.value(), eoEvolutionStrategy::comma_strategy()); es(pop); + + pop.sort(); + cout << "Final population\n" << pop << endl; + }