00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "param.h"
00041 #include "route_init.h"
00042 #include "route_eval.h"
00043
00044 #include "order_xover.h"
00045 #include "edge_xover.h"
00046 #include "partial_mapped_xover.h"
00047 #include "city_swap.h"
00048 #include "part_route_eval.h"
00049 #include "merge_route_eval.h"
00050 #include "two_opt_init.h"
00051 #include "two_opt_next.h"
00052 #include "two_opt_incr_eval.h"
00053
00054 #include <peo>
00055
00056 #define POP_SIZE 10
00057 #define NUM_GEN 10
00058 #define CROSS_RATE 1.0
00059 #define MUT_RATE 0.01
00060
00061 #define MIG_FREQ 1
00062 #define MIG_SIZE 5
00063
00064
00065 int main (int __argc, char * * __argv) {
00066
00067 peo :: init (__argc, __argv);
00068
00069
00070 loadParameters (__argc, __argv);
00071
00072
00073
00074 RingTopology topo;
00075
00076
00077
00078
00079
00080 RouteInit route_init;
00081 RouteEval full_eval;
00082
00083 OrderXover order_cross;
00084 CitySwap city_swap_mut;
00085
00086 eoPop <Route> ox_pop (POP_SIZE, route_init);
00087
00088 eoGenContinue <Route> ox_cont (NUM_GEN);
00089 eoCheckPoint <Route> ox_checkpoint (ox_cont);
00090 peoSeqPopEval <Route> ox_pop_eval (full_eval);
00091 eoStochTournamentSelect <Route> ox_select_one;
00092 eoSelectNumber <Route> ox_select (ox_select_one, POP_SIZE);
00093 eoSGATransform <Route> ox_transform (order_cross, CROSS_RATE, city_swap_mut, MUT_RATE);
00094 peoSeqTransform <Route> ox_seq_transform (ox_transform);
00095 eoEPReplacement <Route> ox_replace (2);
00096
00097
00098
00099 eoPeriodicContinue <Route> ox_mig_cont (MIG_FREQ);
00100 eoStochTournamentSelect <Route> ox_mig_select_one;
00101 eoSelectNumber <Route> ox_mig_select (ox_mig_select_one, MIG_SIZE);
00102 eoPlusReplacement <Route> ox_mig_replace;
00103
00104 peoAsyncIslandMig <Route> ox_mig (ox_mig_cont, ox_mig_select, ox_mig_replace, topo, ox_pop, ox_pop);
00105 ox_checkpoint.add (ox_mig);
00106
00107 peoEA <Route> ox_ea (ox_checkpoint, ox_pop_eval, ox_select, ox_seq_transform, ox_replace);
00108 ox_mig.setOwner (ox_ea);
00109
00110 ox_ea (ox_pop);
00111
00112
00113
00114
00115
00116
00117 RouteInit route_init2;
00118 RouteEval full_eval2;
00119
00120 OrderXover order_cross2;
00121 CitySwap city_swap_mut2;
00122
00123
00124 eoPop <Route> ox_pop2 (POP_SIZE, route_init2);
00125
00126
00127 eoGenContinue <Route> ox_cont2 (NUM_GEN);
00128 eoCheckPoint <Route> ox_checkpoint2 (ox_cont2);
00129 peoSeqPopEval <Route> ox_pop_eval2 (full_eval2);
00130 eoStochTournamentSelect <Route> ox_select_one2;
00131 eoSelectNumber <Route> ox_select2 (ox_select_one2, POP_SIZE);
00132 eoSGATransform <Route> ox_transform2 (order_cross2, CROSS_RATE, city_swap_mut2, MUT_RATE);
00133 peoSeqTransform <Route> ox_seq_transform2 (ox_transform2);
00134 eoEPReplacement <Route> ox_replace2 (2);
00135
00136
00137 eoPeriodicContinue <Route> ox_mig_cont2 (MIG_FREQ);
00138 eoStochTournamentSelect <Route> ox_mig_select_one2;
00139 eoSelectNumber <Route> ox_mig_select2 (ox_mig_select_one2, MIG_SIZE);
00140 eoPlusReplacement <Route> ox_mig_replace2;
00141
00142 peoAsyncIslandMig <Route> ox_mig2 (ox_mig_cont2, ox_mig_select2, ox_mig_replace2, topo, ox_pop2, ox_pop2);
00143 ox_checkpoint2.add (ox_mig2);
00144
00145 peoEA <Route> ox_ea2 (ox_checkpoint2, ox_pop_eval2, ox_select2, ox_seq_transform2, ox_replace2);
00146 ox_mig2.setOwner (ox_ea2);
00147
00148 ox_ea2 (ox_pop2);
00149
00150
00151
00152
00153 peo :: run ();
00154 peo :: finalize ();
00155
00156
00157
00158 if ( getNodeRank() == 1 ) {
00159
00160 std::cout << "EA[ 0 ] -----> " << ox_pop.best_element().fitness() << std::endl;
00161 std::cout << "EA[ 1 ] -----> " << ox_pop2.best_element().fitness() << std::endl;
00162 }
00163
00164
00165 return 0;
00166 }