00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef _MSC_VER
00021 #pragma warning(disable:4786)
00022 #endif
00023
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027
00028 #include <iostream>
00029 #include "gp/eoParseTree.h"
00030 #include "eo"
00031
00032 using namespace gp_parse_tree;
00033 using namespace std;
00034
00035
00036
00037 #include "node.h"
00038 #include "parameters.h"
00039 #include "fitness.h"
00040
00041
00042
00043
00044
00045 typedef eoParseTree<FitnessType, Node > EoType;
00046 typedef eoPop<EoType> Pop;
00047
00048
00049
00050 int main(int argc, char *argv[])
00051 {
00052
00053
00054 vector<Node> initSequence;
00055
00056
00057 Parameters parameter(argc, argv);
00058
00059
00060 rng.reseed(parameter.randomseed);
00061
00062
00063 eoValueParam<unsigned> generationCounter(0, "Gen.");
00064
00065
00066
00067
00068
00069 eoIncrementor<unsigned> increment(generationCounter.value());
00070
00071
00072
00073
00074
00075 RegFitness eval(generationCounter, initSequence, parameter);
00076
00077
00078 eoParseTreeDepthInit<FitnessType, Node> initializer(parameter.InitMaxDepth, initSequence, true, true);
00079
00080
00081 Pop pop(parameter.population_size, initializer);
00082
00083
00084 apply<EoType>(eval, pop);
00085
00086 generationCounter.value()++;
00087
00088
00089
00090
00091 eoSubtreeXOver<FitnessType, Node> xover(parameter.MaxSize);
00092
00093
00094 eoBranchMutation<FitnessType, Node> mutation(initializer, parameter.MaxSize);
00095
00096
00097
00098
00099
00100
00101
00102 eoSGATransform<EoType> transform(xover, parameter.xover_rate, mutation, parameter.mutation_rate);
00103
00104
00105
00106 eoDetTournamentSelect<EoType> selectOne(parameter.tournamentsize);
00107
00108 eoSelectMany<EoType> select(selectOne, parameter.offspring_size, eo_is_an_integer);
00109
00110
00111
00112
00113
00114
00115 eoCommaReplacement<EoType> replace;
00116
00117
00118 eoGenContinue<EoType> term(parameter.nGenerations);
00119
00120 eoCheckPoint<EoType> checkPoint(term);
00121
00122
00123 eoAverageStat<EoType> avg;
00124 eoBestFitnessStat<EoType> best;
00125
00126
00127
00128
00129 checkPoint.add(increment);
00130 checkPoint.add(avg);
00131 checkPoint.add(best);
00132
00133 #ifdef HAVE_GNUPLOT
00134 eoGnuplot1DMonitor gnuplotmonitor("gnuplotBestStats");
00135 gnuplotmonitor.add(generationCounter);
00136 gnuplotmonitor.add(best);
00137
00138 eoValueParam<string> dummy1("", "Smallest Tree Size");
00139 gnuplotmonitor.add(dummy1);
00140
00141 eoGnuplot1DMonitor gnuplotAvgmonitor("gnuplotAvgStats");
00142 gnuplotAvgmonitor.add(generationCounter);
00143 gnuplotAvgmonitor.add(avg);
00144
00145 eoValueParam<string> dummy2("", "Average Tree Size");
00146 gnuplotAvgmonitor.add(dummy2);
00147
00148 checkPoint.add(gnuplotmonitor);
00149 checkPoint.add(gnuplotAvgmonitor);
00150 #endif
00151
00152 eoEasyEA<EoType> gp(checkPoint, eval, select, transform, replace);
00153
00154 cout << "Initialization done" << endl;
00155
00156
00157 try
00158 {
00159 gp(pop);
00160 }
00161 catch (exception& e)
00162 {
00163 cout << "exception: " << e.what() << endl;;
00164 exit(EXIT_FAILURE);
00165 }
00166
00167 return 1;
00168
00169 };
00170
00171
00172