Some changes to make gpsymreg compile correctly on windows/cygwin systems
This commit is contained in:
parent
af05dfacb9
commit
7764554056
1 changed files with 170 additions and 166 deletions
|
|
@ -1,166 +1,170 @@
|
||||||
/*
|
/*
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Lesser General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this library; if not, write to the Free Software
|
along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
jeggermo@liacs.nl
|
jeggermo@liacs.nl
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(disable:4786)
|
#pragma warning(disable:4786)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <gp/eoParseTree.h>
|
#include <gp/eoParseTree.h>
|
||||||
#include <eo>
|
#include <eo>
|
||||||
|
|
||||||
using namespace gp_parse_tree;
|
using namespace gp_parse_tree;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "parameters.h"
|
#include "parameters.h"
|
||||||
#include "fitness.h"
|
#include "fitness.h"
|
||||||
|
|
||||||
|
|
||||||
// TYPE DECLARATIONS FOR GP
|
// TYPE DECLARATIONS FOR GP
|
||||||
|
|
||||||
|
|
||||||
typedef eoParseTree<FitnessType, Node > EoType;
|
typedef eoParseTree<FitnessType, Node > EoType;
|
||||||
typedef eoPop<EoType> Pop;
|
typedef eoPop<EoType> Pop;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
// SC debug
|
||||||
// the vector containing the possible nodes
|
#ifdef NEVERDEF // patch to make run the installation of EO
|
||||||
vector<Node> initSequence;
|
|
||||||
|
// the vector containing the possible nodes
|
||||||
// initialise parameters
|
vector<Node> initSequence;
|
||||||
Parameters parameter(argc, argv);
|
|
||||||
|
// initialise parameters
|
||||||
// set the randomseed
|
Parameters parameter(argc, argv);
|
||||||
rng.reseed(parameter.randomseed);
|
|
||||||
|
// set the randomseed
|
||||||
// Create a generation counter
|
rng.reseed(parameter.randomseed);
|
||||||
eoValueParam<unsigned> generationCounter(0, "Gen.");
|
|
||||||
|
// Create a generation counter
|
||||||
// Create an incrementor (sub-class of eoUpdater). Note that the
|
eoValueParam<unsigned> generationCounter(0, "Gen.");
|
||||||
// parameter's value is passed by reference,
|
|
||||||
// so every time the incrementer is updated (every generation),
|
// Create an incrementor (sub-class of eoUpdater). Note that the
|
||||||
// the data in generationCounter will change.
|
// parameter's value is passed by reference,
|
||||||
eoIncrementor<unsigned> increment(generationCounter.value());
|
// so every time the incrementer is updated (every generation),
|
||||||
|
// the data in generationCounter will change.
|
||||||
|
eoIncrementor<unsigned> increment(generationCounter.value());
|
||||||
// create an instantiation of the fitness/evaluation function
|
|
||||||
// it initializes the initSequence vector
|
|
||||||
// the parameters are passed on as well
|
// create an instantiation of the fitness/evaluation function
|
||||||
RegFitness<FitnessType, Node > eval(generationCounter, initSequence, parameter);
|
// it initializes the initSequence vector
|
||||||
|
// the parameters are passed on as well
|
||||||
// Depth Initializor, defaults to grow method.
|
RegFitness<FitnessType, Node > eval(generationCounter, initSequence, parameter);
|
||||||
eoGpDepthInitializer<FitnessType, Node> initializer(parameter.InitMaxDepth, initSequence);
|
|
||||||
|
// Depth Initializor, defaults to grow method.
|
||||||
// create the initial population
|
eoGpDepthInitializer<FitnessType, Node> initializer(parameter.InitMaxDepth, initSequence);
|
||||||
Pop pop(parameter.population_size, initializer);
|
|
||||||
|
// create the initial population
|
||||||
// and evaluate the individuals
|
Pop pop(parameter.population_size, initializer);
|
||||||
apply<EoType>(eval, pop);
|
|
||||||
|
// and evaluate the individuals
|
||||||
generationCounter.value()++; // set the generationCounter to 1
|
apply<EoType>(eval, pop);
|
||||||
|
|
||||||
|
generationCounter.value()++; // set the generationCounter to 1
|
||||||
// define X-OVER
|
|
||||||
|
|
||||||
eoSubtreeXOver<FitnessType, Node> xover(parameter.MaxSize);
|
// define X-OVER
|
||||||
|
|
||||||
// define MUTATION
|
eoSubtreeXOver<FitnessType, Node> xover(parameter.MaxSize);
|
||||||
eoBranchMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
|
|
||||||
// eoExpansionMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
|
// define MUTATION
|
||||||
// eoCollapseSubtreeMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
|
eoBranchMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
|
||||||
// eoPointMutation<FitnessType, Node> mutation(initSequence);
|
// eoExpansionMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
|
||||||
// eoHoistMutation<FitnessType, Node> mutation;
|
// eoCollapseSubtreeMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
|
||||||
|
// eoPointMutation<FitnessType, Node> mutation(initSequence);
|
||||||
// The operators are encapsulated into an eoTRansform object,
|
// eoHoistMutation<FitnessType, Node> mutation;
|
||||||
// that performs sequentially crossover and mutation
|
|
||||||
eoSGATransform<EoType> transform(xover, parameter.xover_rate, mutation, parameter.mutation_rate);
|
// The operators are encapsulated into an eoTRansform object,
|
||||||
|
// that performs sequentially crossover and mutation
|
||||||
// The robust tournament selection
|
eoSGATransform<EoType> transform(xover, parameter.xover_rate, mutation, parameter.mutation_rate);
|
||||||
// in our case 5-tournament selection
|
|
||||||
eoDetTournamentSelect<EoType> selectOne(parameter.tournamentsize);
|
// The robust tournament selection
|
||||||
// is now encapsulated in a eoSelectMany
|
// in our case 5-tournament selection
|
||||||
eoSelectMany<EoType> select(selectOne, parameter.offspring_size, eo_is_an_integer);
|
eoDetTournamentSelect<EoType> selectOne(parameter.tournamentsize);
|
||||||
|
// is now encapsulated in a eoSelectMany
|
||||||
// and the generational replacement
|
eoSelectMany<EoType> select(selectOne, parameter.offspring_size, eo_is_an_integer);
|
||||||
//eoGenerationalReplacement<EoType> replace;
|
|
||||||
// or the SteadtState replacment
|
// and the generational replacement
|
||||||
//eoSSGAWorseReplacement<EoType> replace;
|
//eoGenerationalReplacement<EoType> replace;
|
||||||
// or comma selection
|
// or the SteadtState replacment
|
||||||
eoCommaReplacement<EoType> replace;
|
//eoSSGAWorseReplacement<EoType> replace;
|
||||||
|
// or comma selection
|
||||||
// Terminators
|
eoCommaReplacement<EoType> replace;
|
||||||
eoGenContinue<EoType> term(parameter.nGenerations);
|
|
||||||
|
// Terminators
|
||||||
eoCheckPoint<EoType> checkPoint(term);
|
eoGenContinue<EoType> term(parameter.nGenerations);
|
||||||
|
|
||||||
// STATISTICS
|
eoCheckPoint<EoType> checkPoint(term);
|
||||||
eoAverageStat<EoType> avg;
|
|
||||||
eoBestFitnessStat<EoType> best;
|
// STATISTICS
|
||||||
|
eoAverageStat<EoType> avg;
|
||||||
|
eoBestFitnessStat<EoType> best;
|
||||||
// Add it to the checkpoint,
|
|
||||||
// so the counter is updated (here, incremented) every generation
|
|
||||||
checkPoint.add(increment);
|
// Add it to the checkpoint,
|
||||||
checkPoint.add(avg);
|
// so the counter is updated (here, incremented) every generation
|
||||||
checkPoint.add(best);
|
checkPoint.add(increment);
|
||||||
|
checkPoint.add(avg);
|
||||||
eoGnuplot1DMonitor gnuplotmonitor("gnuplotBestStats");
|
checkPoint.add(best);
|
||||||
gnuplotmonitor.add(generationCounter);
|
|
||||||
gnuplotmonitor.add(best);
|
eoGnuplot1DMonitor gnuplotmonitor("gnuplotBestStats");
|
||||||
// we need to add a empty string variable if we want to seed the second fitness value
|
gnuplotmonitor.add(generationCounter);
|
||||||
eoValueParam<string> dummy1("", "Smallest Tree Size");
|
gnuplotmonitor.add(best);
|
||||||
gnuplotmonitor.add(dummy1);
|
// we need to add a empty string variable if we want to seed the second fitness value
|
||||||
|
eoValueParam<string> dummy1("", "Smallest Tree Size");
|
||||||
eoGnuplot1DMonitor gnuplotAvgmonitor("gnuplotAvgStats");
|
gnuplotmonitor.add(dummy1);
|
||||||
gnuplotAvgmonitor.add(generationCounter);
|
|
||||||
gnuplotAvgmonitor.add(avg);
|
eoGnuplot1DMonitor gnuplotAvgmonitor("gnuplotAvgStats");
|
||||||
// we need to add a empty string variable if we want to seed the second fitness value
|
gnuplotAvgmonitor.add(generationCounter);
|
||||||
eoValueParam<string> dummy2("", "Average Tree Size");
|
gnuplotAvgmonitor.add(avg);
|
||||||
gnuplotAvgmonitor.add(dummy2);
|
// we need to add a empty string variable if we want to seed the second fitness value
|
||||||
|
eoValueParam<string> dummy2("", "Average Tree Size");
|
||||||
checkPoint.add(gnuplotmonitor);
|
gnuplotAvgmonitor.add(dummy2);
|
||||||
checkPoint.add(gnuplotAvgmonitor);
|
|
||||||
|
checkPoint.add(gnuplotmonitor);
|
||||||
// GP Generation
|
checkPoint.add(gnuplotAvgmonitor);
|
||||||
eoEasyEA<EoType> gp(checkPoint, eval, select, transform, replace);
|
|
||||||
|
// GP Generation
|
||||||
cout << "Initialization done" << endl;
|
eoEasyEA<EoType> gp(checkPoint, eval, select, transform, replace);
|
||||||
|
|
||||||
|
cout << "Initialization done" << endl;
|
||||||
try
|
|
||||||
{
|
|
||||||
gp(pop);
|
try
|
||||||
}
|
{
|
||||||
catch (exception& e)
|
gp(pop);
|
||||||
{
|
}
|
||||||
cout << "exception: " << e.what() << endl;;
|
catch (exception& e)
|
||||||
exit(EXIT_FAILURE);
|
{
|
||||||
}
|
cout << "exception: " << e.what() << endl;;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
return 1;
|
|
||||||
};
|
#endif // NEVERDEF
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue