| do { | |
| select( population, offsprings ); | // select the offsprings from the current population |
| transform( offsprings ); | // crossover and mutation operators are applied on the selected offsprings |
| evaluate( offsprings ); | // evaluation step of the resulting offsprings |
| replace( population, offsprings ); | // replace the individuals in the current population whith individuals from the offspring population, according to a specified replacement strategy |
| } while ( eaCheckpointContinue( population ) ); | // checkpoint operators are applied on the current population |
The peoEA class offers an elementary evolutionary algorithm implementation. The peoEA class has the underlying structure for including parallel evaluation and parallel transformation operators, migration operators etc. Although there is no restriction on using the algorithms provided by the EO framework, no parallelism is provided - the EO implementation is exclusively sequential.
The source-code for this tutorial may be found in the paradiseo-peo/examples/lesson1 directory, in the main.cpp file. For a complete reference on the TSP-related classes and definitions please refer to the files under the paradiseo-peo/examples/shared. After the installation phase you should end up having an tspExample executable file in the paradiseo-peo/examples/lesson1 directory. We will discuss testing and launching aspects later in the tutorial.
The construction of a ParadisEO-PEO evolutionary algorithm requires following a few simple steps - please take your time to study the signature of the peoEA constructor:
| peoEA( eoContinue< EOT >& __cont, peoPopEval< EOT >& __pop_eval, eoSelect< EOT >& __select, peoTransform< EOT >& __trans, eoReplacement< EOT >& __replace ); |
|
A few remarks have to be made: while most of the parameters are passed as EO-specific types, the evaluation and the transformation objects have to be derived from the ParadisEO-PEO peoPopEval and peoTransform classes. Derived classes like the peoParaPopEval and peoParaSGATransform classes allow for parallel evaluation of the population and parallel transformation operators, respectively. Wrappers are provided thus allowing to make use of the EO classes.
In the followings, the main required elements for building an evolutionary algorithm are enumerated. For complete details regarding the implementation aspects of each of the components, please refer to the common shared source code. Each of the bellow refered header files may be found in the pardiseo-peo/examples/shared directory.
For our case study, the TSP, each city is defined as a Node in the node.h header file - in fact an unsigned value defined as typedef unsigned Node. Moreover, each individual (of the evolutionary algorithm) is represented as a Route object, a vector of Node objects, in the route.h header file - typedef eoVector< int, Node > Route. The definition of the Route object implies two elements: (1) a route is a vector of nodes, and (2) the fitness is an integer value (please refer to the eoVector definition in the EO framework).
In addition you should also take a look in the route_init.h header file which includes the RouteInit class, defined for initializing in random manner Route objects.
The fitness function for our TSP case study is implemented in the route_eval.h header file. The class is derived from the eoEvalFunc EO class, being defined as class RouteEval : public eoEvalFunc< Route >.
The transform operators, crossover and mutation, for the herein presended example are defined in the order_xover.h and the city_swap.h header files, respectively.
For our example we chose to use the eoRankingSelect strategy, provided in the EO framework.
| ... | |
| eoPop< EOT > population( POP_SIZE, popInitializer ); | // creation of a population with POP_SIZE individuals - the popInitializer is a functor to be called for each individual |
| eoGenContinue< EOT > eaCont( NUM_GEN ); | // number of generations for the evolutionary algorithm |
| eoCheckPoint< EOT > eaCheckpointContinue( eaCont ); | // checkpoint incorporating the continuation criterion - startpoint for adding other checkpoint objects |
| peoSeqPopEval< EOT > eaPopEval( evalFunction ); | // sequential evaluation functor wrapper - evalFunction represents the actual evaluation functor |
| eoRankingSelect< EOT > selectionStrategy; | // selection strategy for creating the offspring population - a simple ranking selection in this case |
| eoSelectNumber< EOT > eaSelect( selectionStrategy, POP_SIZE ); | // the number of individuals to be selected for creating the offspring population |
| eoRankingSelect< EOT > selectionStrategy; | // selection strategy for creating the offspring population - a simple ranking selection in this case |
| eoSGATransform< EOT > transform( crossover, CROSS_RATE, mutation, MUT_RATE ); | // transformation operator - crossover and mutation operators with their associated probabilities |
| peoSeqTransform< EOT > eaTransform( transform ); | // ParadisEO specific sequential operator - a parallel version may be specified in the same manner |
| eoPlusReplacement< EOT > eaReplace; | // replacement strategy - for integrating the offspring resulting individuals in the initial population |
| peoEA< EOT > eaAlg( eaCheckpointContinue, eaPopEval, eaSelect, eaTransform, eaReplace ); | // ParadisEO evolutionary algorithm integrating the above defined objects |
| eaAlg( population ); | // specifying the initial population for the algorithm |
| ... |
1.4.7