main.cpp

00001 // "main_ga.cpp"
00002 
00003 // (c) OPAC Team, LIFL, January 2006
00004 
00005 /* 
00006    Contact: paradiseo-help@lists.gforge.inria.fr
00007 */
00008 
00009 #include "param.h"
00010 #include "route_init.h"
00011 #include "route_eval.h"
00012 
00013 #include "order_xover.h"
00014 #include "edge_xover.h"
00015 #include "partial_mapped_xover.h"
00016 #include "city_swap.h"
00017 #include "part_route_eval.h"
00018 #include "merge_route_eval.h"
00019 #include "two_opt_init.h"
00020 #include "two_opt_next.h"
00021 #include "two_opt_incr_eval.h"
00022 
00023 #include <paradiseo>
00024 
00025 #define POP_SIZE 10
00026 #define NUM_GEN 100
00027 #define CROSS_RATE 1.0
00028 #define MUT_RATE 0.01
00029 #define NUM_PART_EVALS 2
00030 
00031 #define MIG_FREQ 10
00032 #define MIG_SIZE 10
00033 #define HYBRID_SIZE 3
00034 
00035 int main (int __argc, char * * __argv) {
00036 
00037   peo :: init (__argc, __argv);
00038 
00039   loadParameters (__argc, __argv); /* Processing some parameters relative to the tackled
00040                                       problem (TSP) */
00041 
00042   RouteInit route_init; /* Its builds random routes */  
00043   RouteEval full_eval; /* Full route evaluator */
00044 
00045   MergeRouteEval merge_eval; 
00046   
00047   std :: vector <eoEvalFunc <Route> *> part_eval;
00048   for (unsigned i = 1 ; i <= NUM_PART_EVALS ; i ++)
00049     part_eval.push_back (new PartRouteEval ((float) (i - 1) / NUM_PART_EVALS, (float) i / NUM_PART_EVALS));
00050   
00051   OrderXover order_cross; /* Recombination */
00052   PartialMappedXover pm_cross;
00053   EdgeXover edge_cross;
00054   CitySwap city_swap_mut;  /* Mutation */
00055 
00056   RingTopology topo;
00057  
00060   eoPop <Route> ox_pop (POP_SIZE, route_init);  /* Population */
00061   
00062   eoGenContinue <Route> ox_cont (NUM_GEN); /* A fixed number of iterations */  
00063   eoCheckPoint <Route> ox_checkpoint (ox_cont); /* Checkpoint */
00064   peoParaPopEval <Route> ox_pop_eval (part_eval, merge_eval);  
00065   eoStochTournamentSelect <Route> ox_select_one;
00066   eoSelectNumber <Route> ox_select (ox_select_one, POP_SIZE);
00067   eoSGATransform <Route> ox_transform (order_cross, CROSS_RATE, city_swap_mut, MUT_RATE);
00068   peoSeqTransform <Route> ox_para_transform (ox_transform);    
00069   eoEPReplacement <Route> ox_replace (2);
00070   
00071   /* The migration policy */
00072   eoPeriodicContinue <Route> ox_mig_cont (MIG_FREQ); /* Migration occurs periodically */
00073   eoRandomSelect <Route> ox_mig_select_one; /* Emigrants are randomly selected */
00074   eoSelectNumber <Route> ox_mig_select (ox_mig_select_one, MIG_SIZE);
00075   eoPlusReplacement <Route> ox_mig_replace; /* Immigrants replace the worse individuals */
00076   
00077   peoAsyncIslandMig <Route> ox_mig (ox_mig_cont, ox_mig_select, ox_mig_replace, topo, ox_pop, ox_pop);
00078   //peoSyncIslandMig <Route> ox_mig (MIG_FREQ, ox_mig_select, ox_mig_replace, topo, ox_pop, ox_pop);
00079   
00080   ox_checkpoint.add (ox_mig);
00081   
00082   peoEA <Route> ox_ea (ox_checkpoint, ox_pop_eval, ox_select, ox_para_transform, ox_replace);
00083   ox_mig.setOwner (ox_ea);
00084   
00085   ox_ea (ox_pop);   /* Application to the given population */    
00086 
00089   eoPop <Route> pmx_pop (POP_SIZE, route_init);  /* Population */
00090 
00091   eoGenContinue <Route> pmx_cont (NUM_GEN); /* A fixed number of iterations */  
00092   eoCheckPoint <Route> pmx_checkpoint (pmx_cont); /* Checkpoint */
00093   peoSeqPopEval <Route> pmx_pop_eval (full_eval);  
00094   eoRankingSelect <Route> pmx_select_one;
00095   eoSelectNumber <Route> pmx_select (pmx_select_one, POP_SIZE);
00096   eoSGATransform <Route> pmx_transform (pm_cross, CROSS_RATE, city_swap_mut, MUT_RATE);
00097   peoSeqTransform <Route> pmx_para_transform (pmx_transform);    
00098   eoPlusReplacement <Route> pmx_replace;
00099 
00100   /* The migration policy */
00101   eoPeriodicContinue <Route> pmx_mig_cont (MIG_FREQ); /* Migration occurs periodically */
00102   eoRandomSelect <Route> pmx_mig_select_one; /* Emigrants are randomly selected */
00103   eoSelectNumber <Route> pmx_mig_select (pmx_mig_select_one, MIG_SIZE);
00104   eoPlusReplacement <Route> pmx_mig_replace; /* Immigrants replace the worse individuals */
00105   peoAsyncIslandMig <Route> pmx_mig (pmx_mig_cont, pmx_mig_select, pmx_mig_replace, topo, pmx_pop, pmx_pop);
00106   //peoSyncIslandMig <Route> pmx_mig (MIG_FREQ, pmx_mig_select, pmx_mig_replace, topo, pmx_pop, pmx_pop);
00107   pmx_checkpoint.add (pmx_mig);
00108   
00109   /* Hybridization with a Local Search */
00110   TwoOptInit pmx_two_opt_init;
00111   TwoOptNext pmx_two_opt_next;
00112   TwoOptIncrEval pmx_two_opt_incr_eval;
00113   moBestImprSelect <TwoOpt> pmx_two_opt_move_select;
00114   moHC <TwoOpt> hc (pmx_two_opt_init, pmx_two_opt_next, pmx_two_opt_incr_eval, pmx_two_opt_move_select, full_eval);
00115 
00116   eoPeriodicContinue <Route> pmx_ls_cont (MIG_FREQ); /* Hybridization occurs periodically */
00117   eoRandomSelect <Route> pmx_ls_select_one; /* ? */
00118   eoSelectNumber <Route> pmx_ls_select (pmx_ls_select_one, HYBRID_SIZE); 
00119   eoPlusReplacement <Route> pmx_ls_replace;
00120 
00121   peoSyncMultiStart <Route> pmx_ls (pmx_ls_cont, pmx_ls_select, pmx_ls_replace, hc, pmx_pop);
00122   pmx_checkpoint.add (pmx_ls);
00123 
00124   peoEA <Route> pmx_ea (pmx_checkpoint, pmx_pop_eval, pmx_select, pmx_para_transform, pmx_replace);
00125   pmx_mig.setOwner (pmx_ea);
00126   pmx_ls.setOwner (pmx_ea);
00127 
00128   pmx_ea (pmx_pop);   /* Application to the given population */    
00129 
00132   eoPop <Route> edge_pop (POP_SIZE, route_init);  /* Population */
00133 
00134   eoGenContinue <Route> edge_cont (NUM_GEN); /* A fixed number of iterations */  
00135   eoCheckPoint <Route> edge_checkpoint (edge_cont); /* Checkpoint */
00136   peoSeqPopEval <Route> edge_pop_eval (full_eval);  
00137   eoRankingSelect <Route> edge_select_one;
00138   eoSelectNumber <Route> edge_select (edge_select_one, POP_SIZE);        
00139   peoParaSGATransform <Route> edge_para_transform (edge_cross, CROSS_RATE, city_swap_mut, MUT_RATE);
00140   eoPlusReplacement <Route> edge_replace;
00141 
00142   /* The migration policy */
00143   eoPeriodicContinue <Route> edge_mig_cont (MIG_FREQ); /* Migration occurs periodically */
00144   eoRandomSelect <Route> edge_mig_select_one; /* Emigrants are randomly selected */
00145   eoSelectNumber <Route> edge_mig_select (edge_mig_select_one, MIG_SIZE);
00146   eoPlusReplacement <Route> edge_mig_replace; /* Immigrants replace the worse individuals */
00147   peoAsyncIslandMig <Route> edge_mig (edge_mig_cont, edge_mig_select, edge_mig_replace, topo, edge_pop, edge_pop);
00148   //peoSyncIslandMig <Route> edge_mig (MIG_FREQ, edge_mig_select, edge_mig_replace, topo, edge_pop, edge_pop);
00149   edge_checkpoint.add (edge_mig);
00150 
00151   peoEA <Route> edge_ea (edge_checkpoint, edge_pop_eval, edge_select, edge_para_transform, edge_replace);
00152 
00153   edge_mig.setOwner (edge_ea);
00154 
00155   edge_ea (edge_pop);   /* Application to the given population */    
00156   
00157   peo :: run ();
00158 
00159   peo :: finalize (); /* Termination */
00160 
00161   return 0;
00162 }

Generated on Tue Jan 9 15:47:44 2007 for ParadisEO-PEO Lesson2 by  doxygen 1.4.7