Changed file format (to avoid Visual Studio errors): MAC --> DOS

This commit is contained in:
tlegrand 2007-09-11 14:20:16 +00:00
commit 04fcf88b4c

View file

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