git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@481 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
a398cd4e3d
commit
445f5fcb94
6 changed files with 149 additions and 141 deletions
|
|
@ -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)
|
||||
|
||||
######################################################################################
|
||||
######################################################################################
|
||||
|
|
|
|||
11
trunk/paradiseo-peo/tutorial/Lesson1/build/lesson.param
Normal file
11
trunk/paradiseo-peo/tutorial/Lesson1/build/lesson.param
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
## miscallenous parameters
|
||||
|
||||
--debug=false
|
||||
|
||||
## deployment schema
|
||||
|
||||
--schema=schema.xml
|
||||
|
||||
## parameters
|
||||
|
||||
--inst=../../examples/tsp/benchs/eil101.tsp
|
||||
18
trunk/paradiseo-peo/tutorial/Lesson1/build/schema.xml
Normal file
18
trunk/paradiseo-peo/tutorial/Lesson1/build/schema.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<schema>
|
||||
<group scheduler="0">
|
||||
<node name="0" num_workers="0">
|
||||
</node>
|
||||
|
||||
<node name="1" num_workers="0">
|
||||
<runner>1</runner>
|
||||
</node>
|
||||
|
||||
<node name="2" num_workers="1">
|
||||
</node>
|
||||
<node name="3" num_workers="1">
|
||||
</node>
|
||||
</group>
|
||||
</schema>
|
||||
|
||||
12
trunk/paradiseo-peo/tutorial/Lesson2/build/lesson.param
Normal file
12
trunk/paradiseo-peo/tutorial/Lesson2/build/lesson.param
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
## miscallenous parameters
|
||||
|
||||
--debug=false
|
||||
|
||||
## deployment schema
|
||||
|
||||
--schema=schema.xml
|
||||
|
||||
## parameters
|
||||
|
||||
--inst=../../examples/tsp/benchs/eil101.tsp
|
||||
|
||||
18
trunk/paradiseo-peo/tutorial/Lesson2/build/schema.xml
Normal file
18
trunk/paradiseo-peo/tutorial/Lesson2/build/schema.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<schema>
|
||||
<group scheduler="0">
|
||||
<node name="0" num_workers="0">
|
||||
</node>
|
||||
|
||||
<node name="1" num_workers="0">
|
||||
<runner>1</runner>
|
||||
</node>
|
||||
|
||||
<node name="2" num_workers="1">
|
||||
</node>
|
||||
<node name="3" num_workers="1">
|
||||
</node>
|
||||
</group>
|
||||
</schema>
|
||||
|
||||
|
|
@ -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 <paradiseo>
|
||||
|
||||
|
||||
#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 <eoEvalFunc <Route> *> 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 <Route> ox_pop (POP_SIZE, route_init); /* Population */
|
||||
|
||||
eoGenContinue <Route> ox_cont (NUM_GEN); /* A fixed number of iterations */
|
||||
eoCheckPoint <Route> ox_checkpoint (ox_cont); /* Checkpoint */
|
||||
peoParaPopEval <Route> ox_pop_eval (part_eval, merge_eval);
|
||||
eoStochTournamentSelect <Route> ox_select_one;
|
||||
eoSelectNumber <Route> ox_select (ox_select_one, POP_SIZE);
|
||||
eoSGATransform <Route> ox_transform (order_cross, CROSS_RATE, city_swap_mut, MUT_RATE);
|
||||
peoSeqTransform <Route> ox_para_transform (ox_transform);
|
||||
eoEPReplacement <Route> ox_replace (2);
|
||||
|
||||
/* The migration policy */
|
||||
eoPeriodicContinue <Route> ox_mig_cont (MIG_FREQ); /* Migration occurs periodically */
|
||||
eoRandomSelect <Route> ox_mig_select_one; /* Emigrants are randomly selected */
|
||||
eoSelectNumber <Route> ox_mig_select (ox_mig_select_one, MIG_SIZE);
|
||||
eoPlusReplacement <Route> ox_mig_replace; /* Immigrants replace the worse individuals */
|
||||
|
||||
peoAsyncIslandMig <Route> ox_mig (ox_mig_cont, ox_mig_select, ox_mig_replace, topo, ox_pop, ox_pop);
|
||||
//peoSyncIslandMig <Route> ox_mig (MIG_FREQ, ox_mig_select, ox_mig_replace, topo, ox_pop, ox_pop);
|
||||
|
||||
ox_checkpoint.add (ox_mig);
|
||||
|
||||
peoEA <Route> 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 <Route> pmx_pop (POP_SIZE, route_init); /* Population */
|
||||
// init, eval operators, EA operators -------------------------------------------------------------------------------------------------------------
|
||||
|
||||
eoGenContinue <Route> pmx_cont (NUM_GEN); /* A fixed number of iterations */
|
||||
eoCheckPoint <Route> pmx_checkpoint (pmx_cont); /* Checkpoint */
|
||||
peoSeqPopEval <Route> pmx_pop_eval (full_eval);
|
||||
eoRankingSelect <Route> pmx_select_one;
|
||||
eoSelectNumber <Route> pmx_select (pmx_select_one, POP_SIZE);
|
||||
eoSGATransform <Route> pmx_transform (pm_cross, CROSS_RATE, city_swap_mut, MUT_RATE);
|
||||
peoSeqTransform <Route> pmx_para_transform (pmx_transform);
|
||||
eoPlusReplacement <Route> 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 <Route> pmx_mig_cont (MIG_FREQ); /* Migration occurs periodically */
|
||||
eoRandomSelect <Route> pmx_mig_select_one; /* Emigrants are randomly selected */
|
||||
eoSelectNumber <Route> pmx_mig_select (pmx_mig_select_one, MIG_SIZE);
|
||||
eoPlusReplacement <Route> pmx_mig_replace; /* Immigrants replace the worse individuals */
|
||||
peoAsyncIslandMig <Route> pmx_mig (pmx_mig_cont, pmx_mig_select, pmx_mig_replace, topo, pmx_pop, pmx_pop);
|
||||
//peoSyncIslandMig <Route> 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 <TwoOpt> pmx_two_opt_move_select;
|
||||
moHC <TwoOpt> 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 <Route> pmx_ls_cont (MIG_FREQ); /* Hybridization occurs periodically */
|
||||
eoRandomSelect <Route> pmx_ls_select_one; /* ? */
|
||||
eoSelectNumber <Route> pmx_ls_select (pmx_ls_select_one, HYBRID_SIZE);
|
||||
eoPlusReplacement <Route> pmx_ls_replace;
|
||||
|
||||
peoSyncMultiStart <Route> pmx_ls (pmx_ls_cont, pmx_ls_select, pmx_ls_replace, hc, pmx_pop);
|
||||
pmx_checkpoint.add (pmx_ls);
|
||||
// evolutionary algorithm components --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
peoEA <Route> 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 <Route> edge_pop (POP_SIZE, route_init); /* Population */
|
||||
MergeRouteEval merge_eval;
|
||||
|
||||
eoGenContinue <Route> edge_cont (NUM_GEN); /* A fixed number of iterations */
|
||||
eoCheckPoint <Route> edge_checkpoint (edge_cont); /* Checkpoint */
|
||||
peoSeqPopEval <Route> edge_pop_eval (full_eval);
|
||||
eoRankingSelect <Route> edge_select_one;
|
||||
eoSelectNumber <Route> edge_select (edge_select_one, POP_SIZE);
|
||||
peoParaSGATransform <Route> edge_para_transform (edge_cross, CROSS_RATE, city_swap_mut, MUT_RATE);
|
||||
eoPlusReplacement <Route> 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 <Route> edge_mig_cont (MIG_FREQ); /* Migration occurs periodically */
|
||||
eoRandomSelect <Route> edge_mig_select_one; /* Emigrants are randomly selected */
|
||||
eoSelectNumber <Route> edge_mig_select (edge_mig_select_one, MIG_SIZE);
|
||||
eoPlusReplacement <Route> edge_mig_replace; /* Immigrants replace the worse individuals */
|
||||
peoAsyncIslandMig <Route> edge_mig (edge_mig_cont, edge_mig_select, edge_mig_replace, topo, edge_pop, edge_pop);
|
||||
//peoSyncIslandMig <Route> 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 <Route> 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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue