From 445f5fcb9436f7ad1882cdbdd106cea513c1dfcf Mon Sep 17 00:00:00 2001 From: atantar Date: Mon, 2 Jul 2007 08:52:25 +0000 Subject: [PATCH] git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@481 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-peo/tutorial/CMakeLists.txt | 4 +- .../tutorial/Lesson1/build/lesson.param | 11 ++ .../tutorial/Lesson1/build/schema.xml | 18 ++ .../tutorial/Lesson2/build/lesson.param | 12 ++ .../tutorial/Lesson2/build/schema.xml | 18 ++ .../tutorial/Lesson2/src/main.cpp | 179 +++++++----------- 6 files changed, 125 insertions(+), 117 deletions(-) create mode 100644 trunk/paradiseo-peo/tutorial/Lesson1/build/lesson.param create mode 100644 trunk/paradiseo-peo/tutorial/Lesson1/build/schema.xml create mode 100644 trunk/paradiseo-peo/tutorial/Lesson2/build/lesson.param create mode 100644 trunk/paradiseo-peo/tutorial/Lesson2/build/schema.xml diff --git a/trunk/paradiseo-peo/tutorial/CMakeLists.txt b/trunk/paradiseo-peo/tutorial/CMakeLists.txt index 236970dc6..dc4c1ec6e 100644 --- a/trunk/paradiseo-peo/tutorial/CMakeLists.txt +++ b/trunk/paradiseo-peo/tutorial/CMakeLists.txt @@ -11,6 +11,6 @@ SET(TSP_EXAMPLE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/examples/tsp CACHE PATH "TSP exa ### 2) Where must cmake go now ? ###################################################################################### -SUBDIRS(examples Lesson1 Lesson2) +SUBDIRS(examples Lesson1 Lesson2 Lesson3) -###################################################################################### \ No newline at end of file +###################################################################################### diff --git a/trunk/paradiseo-peo/tutorial/Lesson1/build/lesson.param b/trunk/paradiseo-peo/tutorial/Lesson1/build/lesson.param new file mode 100644 index 000000000..b77cef09f --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson1/build/lesson.param @@ -0,0 +1,11 @@ +## miscallenous parameters + +--debug=false + +## deployment schema + +--schema=schema.xml + +## parameters + +--inst=../../examples/tsp/benchs/eil101.tsp diff --git a/trunk/paradiseo-peo/tutorial/Lesson1/build/schema.xml b/trunk/paradiseo-peo/tutorial/Lesson1/build/schema.xml new file mode 100644 index 000000000..3edea1488 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson1/build/schema.xml @@ -0,0 +1,18 @@ + + + + + + + + + 1 + + + + + + + + + diff --git a/trunk/paradiseo-peo/tutorial/Lesson2/build/lesson.param b/trunk/paradiseo-peo/tutorial/Lesson2/build/lesson.param new file mode 100644 index 000000000..04952c91b --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson2/build/lesson.param @@ -0,0 +1,12 @@ +## miscallenous parameters + +--debug=false + +## deployment schema + +--schema=schema.xml + +## parameters + +--inst=../../examples/tsp/benchs/eil101.tsp + diff --git a/trunk/paradiseo-peo/tutorial/Lesson2/build/schema.xml b/trunk/paradiseo-peo/tutorial/Lesson2/build/schema.xml new file mode 100644 index 000000000..3edea1488 --- /dev/null +++ b/trunk/paradiseo-peo/tutorial/Lesson2/build/schema.xml @@ -0,0 +1,18 @@ + + + + + + + + + 1 + + + + + + + + + diff --git a/trunk/paradiseo-peo/tutorial/Lesson2/src/main.cpp b/trunk/paradiseo-peo/tutorial/Lesson2/src/main.cpp index 9b2c43538..d1a07f019 100644 --- a/trunk/paradiseo-peo/tutorial/Lesson2/src/main.cpp +++ b/trunk/paradiseo-peo/tutorial/Lesson2/src/main.cpp @@ -1,4 +1,4 @@ -// "main_ga.cpp" +// "main.cpp" // (c) OPAC Team, LIFL, January 2006 @@ -6,157 +6,106 @@ Contact: paradiseo-help@lists.gforge.inria.fr */ -#include "param.h" +#include "route.h" #include "route_init.h" #include "route_eval.h" #include "order_xover.h" -#include "edge_xover.h" -#include "partial_mapped_xover.h" #include "city_swap.h" -#include "part_route_eval.h" + +#include "param.h" + #include "merge_route_eval.h" -#include "two_opt_init.h" -#include "two_opt_next.h" -#include "two_opt_incr_eval.h" +#include "part_route_eval.h" + #include + #define POP_SIZE 10 #define NUM_GEN 100 #define CROSS_RATE 1.0 #define MUT_RATE 0.01 + #define NUM_PART_EVALS 2 -#define MIG_FREQ 10 -#define MIG_SIZE 10 -#define HYBRID_SIZE 3 -int main (int __argc, char * * __argv) { +// by default, parallel evaluation of the population is performed; +// for parallel fitness evaluation, uncomment the following line - peo :: init (__argc, __argv); +// #define PARALLEL_FIT_EVALUATION - loadParameters (__argc, __argv); /* Processing some parameters relative to the tackled - problem (TSP) */ - RouteInit route_init; /* Its builds random routes */ - RouteEval full_eval; /* Full route evaluator */ +int main( int __argc, char** __argv ) { - MergeRouteEval merge_eval; - - std :: vector *> part_eval; - for (unsigned i = 1 ; i <= NUM_PART_EVALS ; i ++) - part_eval.push_back (new PartRouteEval ((float) (i - 1) / NUM_PART_EVALS, (float) i / NUM_PART_EVALS)); - - OrderXover order_cross; /* Recombination */ - PartialMappedXover pm_cross; - EdgeXover edge_cross; - CitySwap city_swap_mut; /* Mutation */ + // initializing the ParadisEO-PEO environment + peo :: init( __argc, __argv ); - RingTopology topo; - - /** The first EA **/ - eoPop ox_pop (POP_SIZE, route_init); /* Population */ - - eoGenContinue ox_cont (NUM_GEN); /* A fixed number of iterations */ - eoCheckPoint ox_checkpoint (ox_cont); /* Checkpoint */ - peoParaPopEval ox_pop_eval (part_eval, merge_eval); - eoStochTournamentSelect ox_select_one; - eoSelectNumber ox_select (ox_select_one, POP_SIZE); - eoSGATransform ox_transform (order_cross, CROSS_RATE, city_swap_mut, MUT_RATE); - peoSeqTransform ox_para_transform (ox_transform); - eoEPReplacement ox_replace (2); - - /* The migration policy */ - eoPeriodicContinue ox_mig_cont (MIG_FREQ); /* Migration occurs periodically */ - eoRandomSelect ox_mig_select_one; /* Emigrants are randomly selected */ - eoSelectNumber ox_mig_select (ox_mig_select_one, MIG_SIZE); - eoPlusReplacement ox_mig_replace; /* Immigrants replace the worse individuals */ - - peoAsyncIslandMig ox_mig (ox_mig_cont, ox_mig_select, ox_mig_replace, topo, ox_pop, ox_pop); - //peoSyncIslandMig ox_mig (MIG_FREQ, ox_mig_select, ox_mig_replace, topo, ox_pop, ox_pop); - - ox_checkpoint.add (ox_mig); - - peoEA ox_ea (ox_checkpoint, ox_pop_eval, ox_select, ox_para_transform, ox_replace); - ox_mig.setOwner (ox_ea); - - ox_ea (ox_pop); /* Application to the given population */ + // processing the command line specified parameters + loadParameters( __argc, __argv ); - /** The second EA **/ - eoPop pmx_pop (POP_SIZE, route_init); /* Population */ + // init, eval operators, EA operators ------------------------------------------------------------------------------------------------------------- - eoGenContinue pmx_cont (NUM_GEN); /* A fixed number of iterations */ - eoCheckPoint pmx_checkpoint (pmx_cont); /* Checkpoint */ - peoSeqPopEval pmx_pop_eval (full_eval); - eoRankingSelect pmx_select_one; - eoSelectNumber pmx_select (pmx_select_one, POP_SIZE); - eoSGATransform pmx_transform (pm_cross, CROSS_RATE, city_swap_mut, MUT_RATE); - peoSeqTransform pmx_para_transform (pmx_transform); - eoPlusReplacement pmx_replace; + RouteInit route_init; // random init object - creates random Route objects + RouteEval full_eval; // evaluator object - offers a fitness value for a specified Route object - /* The migration policy */ - eoPeriodicContinue pmx_mig_cont (MIG_FREQ); /* Migration occurs periodically */ - eoRandomSelect pmx_mig_select_one; /* Emigrants are randomly selected */ - eoSelectNumber pmx_mig_select (pmx_mig_select_one, MIG_SIZE); - eoPlusReplacement pmx_mig_replace; /* Immigrants replace the worse individuals */ - peoAsyncIslandMig pmx_mig (pmx_mig_cont, pmx_mig_select, pmx_mig_replace, topo, pmx_pop, pmx_pop); - //peoSyncIslandMig pmx_mig (MIG_FREQ, pmx_mig_select, pmx_mig_replace, topo, pmx_pop, pmx_pop); - pmx_checkpoint.add (pmx_mig); - - /* Hybridization with a Local Search */ - TwoOptInit pmx_two_opt_init; - TwoOptNext pmx_two_opt_next; - TwoOptIncrEval pmx_two_opt_incr_eval; - moBestImprSelect pmx_two_opt_move_select; - moHC hc (pmx_two_opt_init, pmx_two_opt_next, pmx_two_opt_incr_eval, pmx_two_opt_move_select, full_eval); + OrderXover crossover; // crossover operator - creates two offsprings out of two specified parents + CitySwap mutation; // mutation operator - randomly mutates one gene for a specified individual + // ------------------------------------------------------------------------------------------------------------------------------------------------ - eoPeriodicContinue pmx_ls_cont (MIG_FREQ); /* Hybridization occurs periodically */ - eoRandomSelect pmx_ls_select_one; /* ? */ - eoSelectNumber pmx_ls_select (pmx_ls_select_one, HYBRID_SIZE); - eoPlusReplacement pmx_ls_replace; - peoSyncMultiStart pmx_ls (pmx_ls_cont, pmx_ls_select, pmx_ls_replace, hc, pmx_pop); - pmx_checkpoint.add (pmx_ls); + // evolutionary algorithm components -------------------------------------------------------------------------------------------------------------- - peoEA pmx_ea (pmx_checkpoint, pmx_pop_eval, pmx_select, pmx_para_transform, pmx_replace); - pmx_mig.setOwner (pmx_ea); - pmx_ls.setOwner (pmx_ea); + eoPop< Route > population( POP_SIZE, route_init ); // initial population for the algorithm having POP_SIZE individuals - pmx_ea (pmx_pop); /* Application to the given population */ - /** The third EA **/ + #ifdef PARALLEL_FIT_EVALUATION - eoPop edge_pop (POP_SIZE, route_init); /* Population */ + MergeRouteEval merge_eval; - eoGenContinue edge_cont (NUM_GEN); /* A fixed number of iterations */ - eoCheckPoint edge_checkpoint (edge_cont); /* Checkpoint */ - peoSeqPopEval edge_pop_eval (full_eval); - eoRankingSelect edge_select_one; - eoSelectNumber edge_select (edge_select_one, POP_SIZE); - peoParaSGATransform edge_para_transform (edge_cross, CROSS_RATE, city_swap_mut, MUT_RATE); - eoPlusReplacement edge_replace; + std :: vector< eoEvalFunc< Route >* > part_eval; + for ( unsigned index = 1; index <= NUM_PART_EVALS; index++ ) + part_eval.push_back( new PartRouteEval( ( float )( index - 1 ) / NUM_PART_EVALS, ( float )index / NUM_PART_EVALS ) ); - /* The migration policy */ - eoPeriodicContinue edge_mig_cont (MIG_FREQ); /* Migration occurs periodically */ - eoRandomSelect edge_mig_select_one; /* Emigrants are randomly selected */ - eoSelectNumber edge_mig_select (edge_mig_select_one, MIG_SIZE); - eoPlusReplacement edge_mig_replace; /* Immigrants replace the worse individuals */ - peoAsyncIslandMig edge_mig (edge_mig_cont, edge_mig_select, edge_mig_replace, topo, edge_pop, edge_pop); - //peoSyncIslandMig edge_mig (MIG_FREQ, edge_mig_select, edge_mig_replace, topo, edge_pop, edge_pop); - edge_checkpoint.add (edge_mig); + peoParaPopEval< Route > ox_pop_eval( part_eval, merge_eval ); - peoEA edge_ea (edge_checkpoint, edge_pop_eval, edge_select, edge_para_transform, edge_replace); + #else - edge_mig.setOwner (edge_ea); + peoParaPopEval< Route > ox_pop_eval( full_eval ); - edge_ea (edge_pop); /* Application to the given population */ - - peo :: run (); + #endif - peo :: finalize (); /* Termination */ - return 0; + + peoParaPopEval< Route > eaPopEval( full_eval ); // evaluator object - to be applied at each iteration on the entire population + + eoGenContinue< Route > eaCont( NUM_GEN ); // continuation criterion - the algorithm will iterate for NUM_GEN generations + eoCheckPoint< Route > eaCheckpointContinue( eaCont ); // checkpoint object - verify at each iteration if the continuation criterion is met + + eoRankingSelect< Route > selectionStrategy; // selection strategy - applied at each iteration for selecting parent individuals + eoSelectNumber< Route > eaSelect( selectionStrategy, POP_SIZE ); // selection object - POP_SIZE individuals are selected at each iteration + + // transform operator - includes the crossover and the mutation operators with a specified associated rate + eoSGATransform< Route > transform( crossover, CROSS_RATE, mutation, MUT_RATE ); + peoSeqTransform< Route > eaTransform( transform ); // ParadisEO transform operator (please remark the peo prefix) - wraps an e EO transform object + + eoPlusReplacement< Route > eaReplace; // replacement strategy - for replacing the initial population with offspring individuals + // ------------------------------------------------------------------------------------------------------------------------------------------------ + + + // ParadisEO-PEO evolutionary algorithm ----------------------------------------------------------------------------------------------------------- + + peoEA< Route > eaAlg( eaCheckpointContinue, eaPopEval, eaSelect, eaTransform, eaReplace ); + + eaAlg( population ); // specifying the initial population for the algorithm, to be iteratively evolved + // ------------------------------------------------------------------------------------------------------------------------------------------------ + + + peo :: run( ); + peo :: finalize( ); + // shutting down the ParadisEO-PEO environment + + return 0; }