From 04fcf88b4ca1540a68c59eae22279c0e661c1057 Mon Sep 17 00:00:00 2001 From: tlegrand Date: Tue, 11 Sep 2007 14:20:16 +0000 Subject: [PATCH] Changed file format (to avoid Visual Studio errors): MAC --> DOS --- eo/app/gpsymreg/main.cpp | 516 ++++++++++++++++++++++++++------------- 1 file changed, 344 insertions(+), 172 deletions(-) diff --git a/eo/app/gpsymreg/main.cpp b/eo/app/gpsymreg/main.cpp index aeb7c645..c05d4207 100644 --- a/eo/app/gpsymreg/main.cpp +++ b/eo/app/gpsymreg/main.cpp @@ -1,172 +1,344 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU 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 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 - jeggermo@liacs.nl -*/ - -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include "gp/eoParseTree.h" -#include "eo" - -using namespace gp_parse_tree; -using namespace std; - -//----------------------------------------------------------------------------- - -#include "node.h" -#include "parameters.h" -#include "fitness.h" - - -// TYPE DECLARATIONS FOR GP - - -typedef eoParseTree EoType; -typedef eoPop Pop; - -//----------------------------------------------------------------------------- - -int main(int argc, char *argv[]) -{ - - // the vector containing the possible nodes - vector initSequence; - - // initialise parameters - Parameters parameter(argc, argv); - - // set the randomseed - rng.reseed(parameter.randomseed); - - // Create a generation counter - eoValueParam generationCounter(0, "Gen."); - - // Create an incrementor (sub-class of eoUpdater). Note that the - // parameter's value is passed by reference, - // so every time the incrementer is updated (every generation), - // the data in generationCounter will change. - eoIncrementor increment(generationCounter.value()); - - - // create an instantiation of the fitness/evaluation function - // it initializes the initSequence vector - // the parameters are passed on as well - RegFitness eval(generationCounter, initSequence, parameter); - - // Depth Initializor, set for Ramped Half and Half Initialization - eoParseTreeDepthInit initializer(parameter.InitMaxDepth, initSequence, true, true); - - // create the initial population - Pop pop(parameter.population_size, initializer); - - // and evaluate the individuals - apply(eval, pop); - - generationCounter.value()++; // set the generationCounter to 1 - - - // define X-OVER - - eoSubtreeXOver xover(parameter.MaxSize); - - // define MUTATION - eoBranchMutation mutation(initializer, parameter.MaxSize); -// eoExpansionMutation mutation(initializer, parameter.MaxSize); -// eoCollapseSubtreeMutation mutation(initializer, parameter.MaxSize); -// eoPointMutation mutation(initSequence); -// eoHoistMutation mutation; - - // The operators are encapsulated into an eoTRansform object, - // that performs sequentially crossover and mutation - eoSGATransform transform(xover, parameter.xover_rate, mutation, parameter.mutation_rate); - - // The robust tournament selection - // in our case 5-tournament selection - eoDetTournamentSelect selectOne(parameter.tournamentsize); - // is now encapsulated in a eoSelectMany - eoSelectMany select(selectOne, parameter.offspring_size, eo_is_an_integer); - - // and the generational replacement - //eoGenerationalReplacement replace; - // or the SteadtState replacment - //eoSSGAWorseReplacement replace; - // or comma selection - eoCommaReplacement replace; - - // Terminators - eoGenContinue term(parameter.nGenerations); - - eoCheckPoint checkPoint(term); - - // STATISTICS - eoAverageStat avg; - eoBestFitnessStat best; - - - // Add it to the checkpoint, - // so the counter is updated (here, incremented) every generation - checkPoint.add(increment); - checkPoint.add(avg); - checkPoint.add(best); - -#ifdef HAVE_GNUPLOT - eoGnuplot1DMonitor gnuplotmonitor("gnuplotBestStats"); - gnuplotmonitor.add(generationCounter); - gnuplotmonitor.add(best); - // we need to add a empty string variable if we want to seed the second fitness value - eoValueParam dummy1("", "Smallest Tree Size"); - gnuplotmonitor.add(dummy1); - - eoGnuplot1DMonitor gnuplotAvgmonitor("gnuplotAvgStats"); - gnuplotAvgmonitor.add(generationCounter); - gnuplotAvgmonitor.add(avg); - // we need to add a empty string variable if we want to seed the second fitness value - eoValueParam dummy2("", "Average Tree Size"); - gnuplotAvgmonitor.add(dummy2); - - checkPoint.add(gnuplotmonitor); - checkPoint.add(gnuplotAvgmonitor); -#endif - // GP Generation - eoEasyEA gp(checkPoint, eval, select, transform, replace); - - cout << "Initialization done" << endl; - - - try - { - gp(pop); - } - catch (exception& e) - { - cout << "exception: " << e.what() << endl;; - exit(EXIT_FAILURE); - } - - return 1; - -}; - - - +/* + + This program is free software; you can redistribute it and/or modify + + it under the terms of the GNU 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 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 + + jeggermo@liacs.nl + +*/ + + + +#ifdef _MSC_VER + +#pragma warning(disable:4786) + +#endif + + + +#ifdef HAVE_CONFIG_H + +#include + +#endif + + + +#include + +#include "gp/eoParseTree.h" + +#include "eo" + + + +using namespace gp_parse_tree; + +using namespace std; + + + +//----------------------------------------------------------------------------- + + + +#include "node.h" + +#include "parameters.h" + +#include "fitness.h" + + + + + +// TYPE DECLARATIONS FOR GP + + + + + +typedef eoParseTree EoType; + +typedef eoPop Pop; + + + +//----------------------------------------------------------------------------- + + + +int main(int argc, char *argv[]) + +{ + + + + // the vector containing the possible nodes + + vector initSequence; + + + + // initialise parameters + + Parameters parameter(argc, argv); + + + + // set the randomseed + + rng.reseed(parameter.randomseed); + + + + // Create a generation counter + + eoValueParam generationCounter(0, "Gen."); + + + + // Create an incrementor (sub-class of eoUpdater). Note that the + + // parameter's value is passed by reference, + + // so every time the incrementer is updated (every generation), + + // the data in generationCounter will change. + + eoIncrementor increment(generationCounter.value()); + + + + + + // create an instantiation of the fitness/evaluation function + + // it initializes the initSequence vector + + // the parameters are passed on as well + + RegFitness eval(generationCounter, initSequence, parameter); + + + + // Depth Initializor, set for Ramped Half and Half Initialization + + eoParseTreeDepthInit initializer(parameter.InitMaxDepth, initSequence, true, true); + + + + // create the initial population + + Pop pop(parameter.population_size, initializer); + + + + // and evaluate the individuals + + apply(eval, pop); + + + + generationCounter.value()++; // set the generationCounter to 1 + + + + + + // define X-OVER + + + + eoSubtreeXOver xover(parameter.MaxSize); + + + + // define MUTATION + + eoBranchMutation mutation(initializer, parameter.MaxSize); + +// eoExpansionMutation mutation(initializer, parameter.MaxSize); + +// eoCollapseSubtreeMutation mutation(initializer, parameter.MaxSize); + +// eoPointMutation mutation(initSequence); + +// eoHoistMutation mutation; + + + + // The operators are encapsulated into an eoTRansform object, + + // that performs sequentially crossover and mutation + + eoSGATransform transform(xover, parameter.xover_rate, mutation, parameter.mutation_rate); + + + + // The robust tournament selection + + // in our case 5-tournament selection + + eoDetTournamentSelect selectOne(parameter.tournamentsize); + + // is now encapsulated in a eoSelectMany + + eoSelectMany select(selectOne, parameter.offspring_size, eo_is_an_integer); + + + + // and the generational replacement + + //eoGenerationalReplacement replace; + + // or the SteadtState replacment + + //eoSSGAWorseReplacement replace; + + // or comma selection + + eoCommaReplacement replace; + + + + // Terminators + + eoGenContinue term(parameter.nGenerations); + + + + eoCheckPoint checkPoint(term); + + + + // STATISTICS + + eoAverageStat avg; + + eoBestFitnessStat best; + + + + + + // Add it to the checkpoint, + + // so the counter is updated (here, incremented) every generation + + checkPoint.add(increment); + + checkPoint.add(avg); + + checkPoint.add(best); + + + +#ifdef HAVE_GNUPLOT + + eoGnuplot1DMonitor gnuplotmonitor("gnuplotBestStats"); + + gnuplotmonitor.add(generationCounter); + + gnuplotmonitor.add(best); + + // we need to add a empty string variable if we want to seed the second fitness value + + eoValueParam dummy1("", "Smallest Tree Size"); + + gnuplotmonitor.add(dummy1); + + + + eoGnuplot1DMonitor gnuplotAvgmonitor("gnuplotAvgStats"); + + gnuplotAvgmonitor.add(generationCounter); + + gnuplotAvgmonitor.add(avg); + + // we need to add a empty string variable if we want to seed the second fitness value + + eoValueParam dummy2("", "Average Tree Size"); + + gnuplotAvgmonitor.add(dummy2); + + + + checkPoint.add(gnuplotmonitor); + + checkPoint.add(gnuplotAvgmonitor); + +#endif + + // GP Generation + + eoEasyEA gp(checkPoint, eval, select, transform, replace); + + + + cout << "Initialization done" << endl; + + + + + + try + + { + + gp(pop); + + } + + catch (exception& e) + + { + + cout << "exception: " << e.what() << endl;; + + exit(EXIT_FAILURE); + + } + + + + return 1; + + + +}; + + + + + + +