// "peoEA.h" // (c) OPAC Team, LIFL, August 2005 /* Contact: paradiseo-help@lists.gforge.inria.fr */ #ifndef __peoEA_h #define __peoEA_h #include #include #include #include #include #include "peoPopEval.h" #include "peoTransform.h" #include "core/runner.h" #include "core/peo_debug.h" //! Class providing an elementary ParadisEO evolutionary algorithm. //! The peoEA class offers an elementary evolutionary algorithm implementation. In addition, as compared //! with the algorithms provided by the EO framework, the peoEA class has the underlying necessary structure //! for including, for example, parallel evaluation and parallel transformation operators, migration operators //! etc. Although there is no restriction on using the algorithms provided by the EO framework, the drawback resides //! in the fact that the EO implementation is exclusively sequential and, in consequence, no parallelism is provided. //! A simple example for constructing a peoEA object: //! //! //! //! //! //! //! //! //! //! //! //! //! //! //! //! //! //! //! //! //! //! //!
...    
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
...    
template < class EOT > class peoEA : public Runner { public: //! Constructor for the evolutionary algorithm object - several basic parameters have to be specified, //! allowing for different levels of parallelism. Depending on the requirements, a sequential or a parallel //! evaluation operator may be specified or, in the same manner, a sequential or a parallel transformation //! operator may be given as parameter. Out of the box objects may be provided, from the EO package, for example, //! or custom defined ones may be specified, provided that they are derived from the correct base classes. //! //! @param eoContinue< EOT >& __cont - continuation criterion specifying whether the algorithm should continue or not; //! @param peoPopEval< EOT >& __pop_eval - evaluation operator; it allows the specification of parallel evaluation operators, aggregate evaluation functions, etc.; //! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of offspring individuals; //! @param peoTransform< EOT >& __trans - transformation operator, i.e. crossover and mutation; allows for sequential or parallel transform; //! @param eoReplacement< EOT >& __replace - replacement strategy for integrating the offspring individuals in the initial population; peoEA( eoContinue< EOT >& __cont, peoPopEval< EOT >& __pop_eval, eoSelect< EOT >& __select, peoTransform< EOT >& __trans, eoReplacement< EOT >& __replace ); //! Evolutionary algorithm function - a side effect of the fact that the class is derived from the Runner class, //! thus requiring the existence of a run function, the algorithm being executed on a distinct thread. void run(); //! Function operator for specifying the population to be associated with the algorithm. //! //! @param eoPop< EOT >& __pop - initial population of the algorithm, to be iteratively evolved; void operator()( eoPop< EOT >& __pop ); private: eoContinue< EOT >& cont; peoPopEval< EOT >& pop_eval; eoSelect< EOT >& select; peoTransform< EOT >& trans; eoReplacement< EOT >& replace; eoPop< EOT >* pop; }; template < class EOT > peoEA< EOT > :: peoEA( eoContinue< EOT >& __cont, peoPopEval< EOT >& __pop_eval, eoSelect< EOT >& __select, peoTransform< EOT >& __trans, eoReplacement< EOT >& __replace ) : cont( __cont ), pop_eval( __pop_eval ), select( __select ), trans( __trans ), replace( __replace ) { trans.setOwner( *this ); pop_eval.setOwner( *this ); } template< class EOT > void peoEA< EOT > :: operator ()( eoPop< EOT >& __pop ) { pop = &__pop; } template< class EOT > void peoEA< EOT > :: run() { printDebugMessage( "performing the first evaluation of the population." ); pop_eval( *pop ); do { eoPop< EOT > off; printDebugMessage( "performing the selection step." ); select( *pop, off ); trans( off ); printDebugMessage( "performing the evaluation of the population." ); pop_eval( off ); printDebugMessage( "performing the replacement of the population." ); replace( *pop, off ); printDebugMessage( "deciding of the continuation." ); } while ( cont( *pop ) ); } #endif