diff --git a/trunk/paradiseo-peo/src/peo.h b/trunk/paradiseo-peo/src/peo.h index 4f7acbc4d..b2262b22d 100644 --- a/trunk/paradiseo-peo/src/peo.h +++ b/trunk/paradiseo-peo/src/peo.h @@ -324,8 +324,7 @@ #include "core/eoPop_mesg.h" #include "core/eoVector_mesg.h" -#include "peoEA.h" -#include "peoParallelAlgorithmWrapper.h" +#include "peoWrapper.h" /* <------- components for parallel algorithms -------> */ #include "peoSeqTransform.h" @@ -340,15 +339,12 @@ #include "peoAsyncIslandMig.h" /* Synchronous multi-start model */ -#include "peoSyncMultiStart.h" -#include "peoSynchronousMultiStart.h" +#include "peoMultiStart.h" /* <------- components for parallel algorithms -------> */ /* Parallel PSO */ -#include "peoInitializer.h" -#include "peoPSO.h" #include "peoPSOSelect.h" -#include "peoPSOReplacement.h" -#include "peoPSOVelocity.h" +#include "peoWorstPositionReplacement.h" +#include "peoGlobalBestVelocity.h" #endif diff --git a/trunk/paradiseo-peo/src/peoEA.h b/trunk/paradiseo-peo/src/peoEA.h deleted file mode 100644 index 59cf3e5da..000000000 --- a/trunk/paradiseo-peo/src/peoEA.h +++ /dev/null @@ -1,179 +0,0 @@ -/* -* -* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 -* (C) OPAC Team, LIFL, 2002-2007 -* -* Sebastien Cahon, Alexandru-Adrian Tantar -* -* This software is governed by the CeCILL license under French law and -* abiding by the rules of distribution of free software. You can use, -* modify and/ or redistribute the software under the terms of the CeCILL -* license as circulated by CEA, CNRS and INRIA at the following URL -* "http://www.cecill.info". -* -* As a counterpart to the access to the source code and rights to copy, -* modify and redistribute granted by the license, users are provided only -* with a limited warranty and the software's author, the holder of the -* economic rights, and the successive licensors have only limited liability. -* -* In this respect, the user's attention is drawn to the risks associated -* with loading, using, modifying and/or developing or reproducing the -* software by the user in light of its specific status of free software, -* that may mean that it is complicated to manipulate, and that also -* therefore means that it is reserved for developers and experienced -* professionals having in-depth computer knowledge. Users are therefore -* encouraged to load and test the software's suitability as regards their -* requirements in conditions enabling the security of their systems and/or -* data to be ensured and, more generally, to use and operate it in the -* same conditions as regards security. -* The fact that you are presently reading this means that you have had -* knowledge of the CeCILL license and that you accept its terms. -* -* ParadisEO WebSite : http://paradiseo.gforge.inria.fr -* 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() -{ - - eoPop< EOT > dummy; - printDebugMessage( "peoEA: performing the first evaluation of the population." ); - pop_eval(dummy, *pop ); - - do - { - - eoPop< EOT > off; - - printDebugMessage( "peoEA: performing the selection step." ); - select( *pop, off ); - trans( off ); - - printDebugMessage( "peoEA: performing the evaluation of the population." ); - - pop_eval(dummy, off ); - - printDebugMessage( "peoEA: performing the replacement of the population." ); - replace( *pop, off ); - - printDebugMessage( "peoEA: deciding of the continuation." ); - - } - while ( cont( *pop ) ); -} - -#endif diff --git a/trunk/paradiseo-peo/src/peoPSOVelocity.h b/trunk/paradiseo-peo/src/peoGlobalBestVelocity.h similarity index 92% rename from trunk/paradiseo-peo/src/peoPSOVelocity.h rename to trunk/paradiseo-peo/src/peoGlobalBestVelocity.h index 997a92dd7..8416a2f4d 100644 --- a/trunk/paradiseo-peo/src/peoPSOVelocity.h +++ b/trunk/paradiseo-peo/src/peoGlobalBestVelocity.h @@ -1,4 +1,4 @@ -/* +/* * * (c) OPAC Team, October 2007 * @@ -33,8 +33,8 @@ * Contact: clive.canape@inria.fr */ -#ifndef _peoPSOVelocity_h -#define _peoPSOVelocity_h +#ifndef _peoGlobalBestVelocity_h +#define _peoGlobalBestVelocity_h //----------------------------------------------------------------------------- @@ -47,13 +47,13 @@ #include template -class peoPSOVelocity : public eoReplacement +class peoGlobalBestVelocity : public eoReplacement { public: typedef typename POT::ParticleVelocityType VelocityType; - peoPSOVelocity( const double & _c3, + peoGlobalBestVelocity( const double & _c3, eoVelocity < POT > &_velocity): c3 (_c3), velocity (_velocity) diff --git a/trunk/paradiseo-peo/src/peoInitializer.h b/trunk/paradiseo-peo/src/peoInitializer.h deleted file mode 100644 index b82fb30a9..000000000 --- a/trunk/paradiseo-peo/src/peoInitializer.h +++ /dev/null @@ -1,99 +0,0 @@ -/* -* -* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 -* (C) OPAC Team, INRIA, 2007 -* -* Clive Canape -* -* This software is governed by the CeCILL license under French law and -* abiding by the rules of distribution of free software. You can use, -* modify and/ or redistribute the software under the terms of the CeCILL -* license as circulated by CEA, CNRS and INRIA at the following URL -* "http://www.cecill.info". -* -* As a counterpart to the access to the source code and rights to copy, -* modify and redistribute granted by the license, users are provided only -* with a limited warranty and the software's author, the holder of the -* economic rights, and the successive licensors have only limited liability. -* -* In this respect, the user's attention is drawn to the risks associated -* with loading, using, modifying and/or developing or reproducing the -* software by the user in light of its specific status of free software, -* that may mean that it is complicated to manipulate, and that also -* therefore means that it is reserved for developers and experienced -* professionals having in-depth computer knowledge. Users are therefore -* encouraged to load and test the software's suitability as regards their -* requirements in conditions enabling the security of their systems and/or -* data to be ensured and, more generally, to use and operate it in the -* same conditions as regards security. -* The fact that you are presently reading this means that you have had -* knowledge of the CeCILL license and that you accept its terms. -* -* ParadisEO WebSite : http://paradiseo.gforge.inria.fr -* Contact: clive.canape@inria.fr -* -*/ - -#ifndef _peoInitializer_H -#define _peoInitializer_H - -/** - Base (name) class for parallel initialization of algorithm PSO - - @see eoInitializerBase -*/ - -template class peoInitializer : public eoInitializerBase - { - public: - - - //! Constructor - //! @param _proc Evaluation function - //! @param _initVelo Initialization of the velocity - //! @param _initBest Initialization of the best - //! @param _pop Population - peoInitializer( - peoPopEval< POT >& _proc, - eoVelocityInit < POT > &_initVelo, - eoParticleBestInit &_initBest, - eoPop < POT > &_pop - ) : proc(_proc), initVelo(_initVelo), initBest(_initBest) - { - pop = &_pop; - } - - //! Give the name of the class - //! @return The name of the class - virtual std::string className (void) const - { - return "peoInitializer"; - } - - //! void operator () - //! Parallel initialization of the population - virtual void operator()() - { - proc(dummyPop,*pop); - apply < POT > (initVelo, *pop); - apply < POT > (initBest, *pop); - } - - private : - - /* - @param proc First evaluation - @param initVelo Initialization of the velocity - @param initBest Initialization of the best - @param pop Population - */ - peoPopEval< POT >& proc; - eoVelocityInit < POT > & initVelo; - eoParticleBestInit & initBest; - eoPop * pop; - eoPop< POT > dummyPop; - }; -#endif - - - diff --git a/trunk/paradiseo-peo/src/peoSynchronousMultiStart.h b/trunk/paradiseo-peo/src/peoMultiStart.h similarity index 86% rename from trunk/paradiseo-peo/src/peoSynchronousMultiStart.h rename to trunk/paradiseo-peo/src/peoMultiStart.h index 1011dc0a5..319c00ffd 100644 --- a/trunk/paradiseo-peo/src/peoSynchronousMultiStart.h +++ b/trunk/paradiseo-peo/src/peoMultiStart.h @@ -1,5 +1,5 @@ /* -* +* * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 * @@ -33,8 +33,8 @@ * Contact: paradiseo-help@lists.gforge.inria.fr * */ -#ifndef __peoSynchronousMultiStart_h -#define __peoSynchronousMultiStart_h +#ifndef __peoMultiStart_h +#define __peoMultiStart_h #include @@ -42,12 +42,12 @@ #include "core/messaging.h" -template < typename EntityType > class peoSynchronousMultiStart : public Service +template < typename EntityType > class peoMultiStart : public Service { public: - template < typename AlgorithmType > peoSynchronousMultiStart( AlgorithmType& externalAlgorithm ) + template < typename AlgorithmType > peoMultiStart( AlgorithmType& externalAlgorithm ) { singularAlgorithm = new Algorithm< AlgorithmType >( externalAlgorithm ); @@ -56,7 +56,7 @@ template < typename EntityType > class peoSynchronousMultiStart : public Service aggregationFunction = new NoAggregationFunction(); } - template < typename AlgorithmReturnType, typename AlgorithmDataType > peoSynchronousMultiStart( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) ) + template < typename AlgorithmReturnType, typename AlgorithmDataType > peoMultiStart( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) ) { singularAlgorithm = new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm ); @@ -65,7 +65,7 @@ template < typename EntityType > class peoSynchronousMultiStart : public Service aggregationFunction = new NoAggregationFunction(); } - template < typename AlgorithmType, typename AggregationFunctionType > peoSynchronousMultiStart( std::vector< AlgorithmType* >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction ) + template < typename AlgorithmType, typename AggregationFunctionType > peoMultiStart( std::vector< AlgorithmType* >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction ) { for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ ) @@ -78,7 +78,7 @@ template < typename EntityType > class peoSynchronousMultiStart : public Service } template < typename AlgorithmReturnType, typename AlgorithmDataType, typename AggregationFunctionType > - peoSynchronousMultiStart( std::vector< AlgorithmReturnType (*)( AlgorithmDataType& ) >& externalAlgorithms, + peoMultiStart( std::vector< AlgorithmReturnType (*)( AlgorithmDataType& ) >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction ) { @@ -91,7 +91,7 @@ template < typename EntityType > class peoSynchronousMultiStart : public Service aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction ); } - ~peoSynchronousMultiStart() + ~peoMultiStart() { for ( unsigned int index = 0; index < data.size(); index++ ) delete data[ index ]; @@ -264,7 +264,7 @@ template < typename EntityType > class peoSynchronousMultiStart : public Service }; -template < typename EntityType > void peoSynchronousMultiStart< EntityType >::packData() +template < typename EntityType > void peoMultiStart< EntityType >::packData() { pack( functionIndex ); @@ -281,7 +281,7 @@ template < typename EntityType > void peoSynchronousMultiStart< EntityType >::pa } } -template < typename EntityType > void peoSynchronousMultiStart< EntityType >::unpackData() +template < typename EntityType > void peoMultiStart< EntityType >::unpackData() { unpack( functionIndex ); @@ -289,7 +289,7 @@ template < typename EntityType > void peoSynchronousMultiStart< EntityType >::un unpack( entityTypeInstance ); } -template < typename EntityType > void peoSynchronousMultiStart< EntityType >::execute() +template < typename EntityType > void peoMultiStart< EntityType >::execute() { // wrapping the unpacked data - the definition of an abstract algorithm imposes @@ -300,14 +300,14 @@ template < typename EntityType > void peoSynchronousMultiStart< EntityType >::ex delete entityWrapper; } -template < typename EntityType > void peoSynchronousMultiStart< EntityType >::packResult() +template < typename EntityType > void peoMultiStart< EntityType >::packResult() { pack( dataIndex ); pack( entityTypeInstance ); } -template < typename EntityType > void peoSynchronousMultiStart< EntityType >::unpackResult() +template < typename EntityType > void peoMultiStart< EntityType >::unpackResult() { unpack( dataIndex ); @@ -329,10 +329,10 @@ template < typename EntityType > void peoSynchronousMultiStart< EntityType >::un } } -template < typename EntityType > void peoSynchronousMultiStart< EntityType >::notifySendingData() +template < typename EntityType > void peoMultiStart< EntityType >::notifySendingData() {} -template < typename EntityType > void peoSynchronousMultiStart< EntityType >::notifySendingAllResourceRequests() +template < typename EntityType > void peoMultiStart< EntityType >::notifySendingAllResourceRequests() { getOwner()->setPassive(); diff --git a/trunk/paradiseo-peo/src/peoPSO.h b/trunk/paradiseo-peo/src/peoPSO.h deleted file mode 100644 index 96f7b9adf..000000000 --- a/trunk/paradiseo-peo/src/peoPSO.h +++ /dev/null @@ -1,130 +0,0 @@ -/* -* -* (c) OPAC Team, October 2007 -* -* Clive Canape -* -* This software is governed by the CeCILL license under French law and -* abiding by the rules of distribution of free software. You can use, -* modify and/ or redistribute the software under the terms of the CeCILL -* license as circulated by CEA, CNRS and INRIA at the following URL -* "http://www.cecill.info". -* -* As a counterpart to the access to the source code and rights to copy, -* modify and redistribute granted by the license, users are provided only -* with a limited warranty and the software's author, the holder of the -* economic rights, and the successive licensors have only limited liability. -* -* In this respect, the user's attention is drawn to the risks associated -* with loading, using, modifying and/or developing or reproducing the -* software by the user in light of its specific status of free software, -* that may mean that it is complicated to manipulate, and that also -* therefore means that it is reserved for developers and experienced -* professionals having in-depth computer knowledge. Users are therefore -* encouraged to load and test the software's suitability as regards their -* requirements in conditions enabling the security of their systems and/or -* data to be ensured and, more generally, to use and operate it in the -* same conditions as regards security. -* The fact that you are presently reading this means that you have had -* knowledge of the CeCILL license and that you accept its terms. -* -* ParadisEO WebSite : http://paradiseo.gforge.inria.fr -* Contact: paradiseo-help@lists.gforge.inria.fr -* Contact: clive.canape@inria.fr -*/ - -#ifndef __peoPSO_h -#define __peoPSO_h - -#include -#include -#include -#include -#include -#include -#include "peoPopEval.h" -#include "core/runner.h" -#include "core/peo_debug.h" - -//! Class providing an elementary ParadisEO evolutionary algorithm. - -//! The peoPSO class offers an elementary Particle Swarm Optimization implementation. In addition, as compared -//! with the algorithms provided by the EO framework, the peoPSO class has the underlying necessary structure -//! for including, for example, parallel evaluation, etc. - -template < class POT > class peoPSO : public Runner - { - - public: - - - //! Constructor for the Particle Swarm Optimization - //! @param eoContinue< POT >& __cont - continuation criterion specifying whether the algorithm should continue or not; - //! @param peoPopEval< POT >& __pop_eval - evaluation operator; it allows the specification of parallel evaluation operators, aggregate evaluation functions, etc.; - //! @param eoVelocity< POT >& __velocity - velocity operator; - //! @param eoFlight< POT >& __flight - flight operator; - peoPSO( - eoInitializerBase & _Init, - eoContinue< POT >& __cont, - peoPopEval< POT >& __pop_eval, - eoVelocity < POT > &_velocity, - eoFlight < POT > &_flight); - - //! Particle Swarm Optimization 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. - void operator()( eoPop< POT >& __pop ); - - private: - - eoInitializerBase & Init; - eoContinue< POT >& cont; - peoPopEval< POT >& pop_eval; - eoPop< POT >* pop; - eoVelocity < POT > &velocity; - eoFlight < POT > &flight; - }; - - -template < class POT > peoPSO< POT > :: peoPSO( - eoInitializerBase & _Init, - eoContinue< POT >& __cont, - peoPopEval< POT >& __pop_eval, - eoVelocity < POT > &__velocity, - eoFlight < POT > &__flight -) : Init(_Init),cont( __cont ), pop_eval(__pop_eval ),velocity( __velocity),flight( __flight) -{ - pop_eval.setOwner( *this ); -} - - -template< class POT > void peoPSO< POT > :: operator ()( eoPop< POT >& __pop ) -{ - - pop = &__pop; -} - - -template< class POT > void peoPSO< POT > :: run() -{ - eoPop< POT > dummy; - printDebugMessage( "Performing the first evaluation of the population." ); - Init(); - velocity.getTopology().setup(*pop); - do - { - printDebugMessage( "Performing the velocity evaluation." ); - velocity.apply ( *pop ); - printDebugMessage( "Performing the flight." ); - flight.apply ( *pop ); - printDebugMessage( "Performing the evaluation." ); - pop_eval(dummy,*pop); - velocity.updateNeighborhood( *pop ); - } - while ( cont( *pop ) ); -} - - -#endif diff --git a/trunk/paradiseo-peo/src/peoSyncMultiStart.h b/trunk/paradiseo-peo/src/peoSyncMultiStart.h deleted file mode 100644 index 84f920212..000000000 --- a/trunk/paradiseo-peo/src/peoSyncMultiStart.h +++ /dev/null @@ -1,217 +0,0 @@ -/* -* -* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 -* (C) OPAC Team, LIFL, 2002-2007 -* -* Sebastien Cahon, Alexandru-Adrian Tantar -* -* This software is governed by the CeCILL license under French law and -* abiding by the rules of distribution of free software. You can use, -* modify and/ or redistribute the software under the terms of the CeCILL -* license as circulated by CEA, CNRS and INRIA at the following URL -* "http://www.cecill.info". -* -* As a counterpart to the access to the source code and rights to copy, -* modify and redistribute granted by the license, users are provided only -* with a limited warranty and the software's author, the holder of the -* economic rights, and the successive licensors have only limited liability. -* -* In this respect, the user's attention is drawn to the risks associated -* with loading, using, modifying and/or developing or reproducing the -* software by the user in light of its specific status of free software, -* that may mean that it is complicated to manipulate, and that also -* therefore means that it is reserved for developers and experienced -* professionals having in-depth computer knowledge. Users are therefore -* encouraged to load and test the software's suitability as regards their -* requirements in conditions enabling the security of their systems and/or -* data to be ensured and, more generally, to use and operate it in the -* same conditions as regards security. -* The fact that you are presently reading this means that you have had -* knowledge of the CeCILL license and that you accept its terms. -* -* ParadisEO WebSite : http://paradiseo.gforge.inria.fr -* Contact: paradiseo-help@lists.gforge.inria.fr -* -*/ - -#ifndef __peoSyncMultiStart_h -#define __peoSyncMultiStart_h - -#include -#include - -#include -#include -#include - -#include "core/service.h" -#include "core/messaging.h" -#include "core/peo_debug.h" - - -extern int getNodeRank(); - - -//! Class providing the basis for the synchronous multi-start model. - -//! The peoSyncMultiStart class provides the basis for implementing the synchronous multi-start model, -//! for launching several solution-based algorithms in parallel on a specified initial population. As a simple -//! example, several hill climbing algorithms may be synchronously launched on the specified population, each -//! algorithm acting upon one individual only, the final result being integrated back in the population. A -//! peoSyncMultiStart object can be specified as checkpoint object for a classic ParadisEO evolutionary algorithm -//! thus allowing for simple hybridization schemes which combine the evolutionary approach with a local search approach, -//! for example, executed at the end of each generation. -template< class EOT > class peoSyncMultiStart : public Service, public eoUpdater -{ - -public: - - //! Constructor function - several simple parameters are required for defining the characteristics of the multi-start model. - //! - //! @param eoContinue< EOT >& __cont - defined for including further functionality - no semantics associated at this time; - //! @param eoSelect< EOT >& __select - selection strategy for obtaining a subset of the initial population on which to apply the specified algorithm; - //! @param eoReplacement< EOT >& __replace - replacement strategy for integrating the resulting individuals in the initial population; - //! @param moAlgo< EOT >& __ls - algorithm to be applied on each of the selected individuals - a moAlgo< EOT >-derived object must be specified; - //! @param eoPop< EOT >& __pop - the initial population from which the individuals are selected for applying the specified algorithm. - peoSyncMultiStart( - - eoContinue< EOT >& __cont, - eoSelect< EOT >& __select, - eoReplacement< EOT >& __replace, - moAlgo< EOT >& __ls, - eoPop< EOT >& __pop - ); - - //! Operator which synchronously executes the specified algorithm on the individuals selected from the initial population. - //! There is no need to explicitly call the operator - automatically called as checkpoint operator. - void operator()(); - - //! Auxiliary function for transferring data between the process requesting the synchronous execution of the specified - //! algorithm and the process which actually executes the algorithm. There is no need to explicitly call the function. - void packData(); - - //! Auxiliary function for transferring data between the process requesting the synchronous execution of the specified - //! algorithm and the process which actually executes the algorithm. There is no need to explicitly call the function. - void unpackData(); - - //! Auxiliary function for actually executing the specified algorithm on one assigned individual. There is no need to - //! explicitly call the function. - void execute(); - - //! Auxiliary function for transferring data between the process requesting the synchronous execution of the specified - //! algorithm and the process which actually executes the algorithm. There is no need to explicitly call the function. - void packResult(); - - //! Auxiliary function for transferring data between the process requesting the synchronous execution of the specified - //! algorithm and the process which actually executes the algorithm. There is no need to explicitly call the function. - void unpackResult(); - - //! Auxiliary function for notifications between the process requesting the synchronous multi-start execution - //! and the processes that performs the actual execution phase. There is no need to explicitly call the function. - void notifySendingData(); - - //! Auxiliary function for notifications between the process requesting the synchronous multi-start execution - //! and the processes that performs the actual execution phase. There is no need to explicitly call the function. - void notifySendingAllResourceRequests(); - -private: - - eoContinue< EOT >& cont; - eoSelect< EOT >& select; - eoReplacement< EOT >& replace; - - moAlgo< EOT >& ls; - - eoPop< EOT >& pop; - eoPop< EOT > sel; - eoPop< EOT > impr_sel; - - EOT sol; - unsigned idx; - unsigned num_term; -}; - - -template< class EOT > peoSyncMultiStart< EOT > :: peoSyncMultiStart( - - eoContinue < EOT >& __cont, - eoSelect< EOT >& __select, - eoReplacement< EOT >& __replace, - moAlgo < EOT >& __ls, - eoPop< EOT >& __pop - -) : cont( __cont ), select( __select ), replace( __replace ), ls( __ls ), pop( __pop ) -{} - - -template< class EOT > void peoSyncMultiStart< EOT > :: packData() -{ - - pack( sel[ idx++ ] ); -} - - -template< class EOT > void peoSyncMultiStart< EOT > :: unpackData() -{ - - unpack( sol ); -} - - -template< class EOT > void peoSyncMultiStart< EOT > :: execute() -{ - - ls( sol ); -} - - -template< class EOT > void peoSyncMultiStart< EOT > :: packResult() -{ - - pack( sol ); -} - - -template< class EOT > void peoSyncMultiStart< EOT > :: unpackResult() -{ - - unpack( sol ); - impr_sel.push_back( sol ); - num_term++; - - if ( num_term == sel.size() ) - { - - getOwner()->setActive(); - replace( pop, impr_sel ); - - printDebugMessage( "replacing the improved individuals in the population." ); - resume(); - } -} - - -template< class EOT > void peoSyncMultiStart< EOT > :: operator()() -{ - - printDebugMessage( "performing the parallel multi-start hybridization." ); - select( pop, sel ); - impr_sel.clear(); - idx = num_term = 0; - requestResourceRequest( sel.size() ); - stop(); -} - - -template< class EOT > void peoSyncMultiStart< EOT > :: notifySendingData() -{} - - -template< class EOT > void peoSyncMultiStart< EOT > :: notifySendingAllResourceRequests() -{ - - getOwner()->setPassive(); -} - - -#endif diff --git a/trunk/paradiseo-peo/src/peoPSOReplacement.h b/trunk/paradiseo-peo/src/peoWorstPositionReplacement.h similarity index 92% rename from trunk/paradiseo-peo/src/peoPSOReplacement.h rename to trunk/paradiseo-peo/src/peoWorstPositionReplacement.h index ef6261cf3..7925a5ab7 100644 --- a/trunk/paradiseo-peo/src/peoPSOReplacement.h +++ b/trunk/paradiseo-peo/src/peoWorstPositionReplacement.h @@ -1,4 +1,4 @@ -/* +/* * * (c) OPAC Team, October 2007 * @@ -33,8 +33,8 @@ * Contact: clive.canape@inria.fr */ -#ifndef _peoPSOReplacement_h -#define _peoPSOReplacement_h +#ifndef _peoWorstPositionReplacement_h +#define _peoWorstPositionReplacement_h //----------------------------------------------------------------------------- @@ -46,10 +46,10 @@ #include template -class peoPSOReplacement : public eoReplacement +class peoWorstPositionReplacement : public eoReplacement { public: - peoPSOReplacement() + peoWorstPositionReplacement() {} void operator()(eoPop& _dest, eoPop& _source) diff --git a/trunk/paradiseo-peo/src/peoParallelAlgorithmWrapper.h b/trunk/paradiseo-peo/src/peoWrapper.h similarity index 88% rename from trunk/paradiseo-peo/src/peoParallelAlgorithmWrapper.h rename to trunk/paradiseo-peo/src/peoWrapper.h index c27b66844..1e380d2c8 100644 --- a/trunk/paradiseo-peo/src/peoParallelAlgorithmWrapper.h +++ b/trunk/paradiseo-peo/src/peoWrapper.h @@ -1,5 +1,5 @@ /* -* +* * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 * @@ -44,28 +44,28 @@ -class peoParallelAlgorithmWrapper : public Runner +class peoWrapper : public Runner { public: - template< typename AlgorithmType > peoParallelAlgorithmWrapper( AlgorithmType& externalAlgorithm ) + template< typename AlgorithmType > peoWrapper( AlgorithmType& externalAlgorithm ) : algorithm( new Algorithm< AlgorithmType, void >( externalAlgorithm ) ) {} - template< typename AlgorithmType, typename AlgorithmDataType > peoParallelAlgorithmWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData ) + template< typename AlgorithmType, typename AlgorithmDataType > peoWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData ) : algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) ) {} - template< typename AlgorithmReturnType > peoParallelAlgorithmWrapper( AlgorithmReturnType& (*externalAlgorithm)() ) + template< typename AlgorithmReturnType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)() ) : algorithm( new FunctionAlgorithm< AlgorithmReturnType, void >( externalAlgorithm ) ) {} - template< typename AlgorithmReturnType, typename AlgorithmDataType > peoParallelAlgorithmWrapper( AlgorithmReturnType& (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData ) + template< typename AlgorithmReturnType, typename AlgorithmDataType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData ) : algorithm( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm, externalData ) ) {} - ~peoParallelAlgorithmWrapper() + ~peoWrapper() { delete algorithm; diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/main1.cpp b/trunk/paradiseo-peo/tutorial/Wrapper/main1.cpp index 926930f44..7d9212333 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/main1.cpp +++ b/trunk/paradiseo-peo/tutorial/Wrapper/main1.cpp @@ -52,7 +52,7 @@ int main( int __argc, char** __argv ) pop.append (POP_SIZE, random); // Wrapper - peoParallelAlgorithmWrapper parallelEA( eaAlg, pop); + peoWrapper parallelEA( eaAlg, pop); peo :: run(); peo :: finalize(); if (getNodeRank()==1) @@ -83,7 +83,7 @@ int main( int __argc, char** __argv ) // Wrapper peo :: init( __argc, __argv ); - peoParallelAlgorithmWrapper parallelEA2( eaAlg2, pop2); + peoWrapper parallelEA2( eaAlg2, pop2); peo :: run(); peo :: finalize(); if (getNodeRank()==1) diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/main2.cpp b/trunk/paradiseo-peo/tutorial/Wrapper/main2.cpp index 778e6e382..e07a31884 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/main2.cpp +++ b/trunk/paradiseo-peo/tutorial/Wrapper/main2.cpp @@ -53,7 +53,7 @@ int main( int __argc, char** __argv ) // Population*/ eoPop < Indi > pop; pop.append (POP_SIZE, random); - peoParallelAlgorithmWrapper parallelEA( eaAlg, pop); + peoWrapper parallelEA( eaAlg, pop); eval.setOwner(parallelEA); transform.setOwner(parallelEA); peo :: run(); diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/main3.cpp b/trunk/paradiseo-peo/tutorial/Wrapper/main3.cpp index b142ec7e7..89e443da3 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/main3.cpp +++ b/trunk/paradiseo-peo/tutorial/Wrapper/main3.cpp @@ -51,7 +51,7 @@ int main( int __argc, char** __argv ) // Parallel algorithm eoSyncEasyPSO psa(init,checkpoint,eval, velocity, flight); - peoParallelAlgorithmWrapper parallelPSO( psa, pop); + peoWrapper parallelPSO( psa, pop); eval.setOwner(parallelPSO); peo :: run(); peo :: finalize(); diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp b/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp index 296f0163c..63b93f7ef 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp +++ b/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp @@ -58,7 +58,7 @@ int main( int __argc, char** __argv ) eoPeriodicContinue< Indi > mig_cont( MIG_FREQ ); peoPSOSelect mig_selec(topology); eoSelectNumber< Indi > mig_select(mig_selec); - peoPSOReplacement mig_replace; + peoWorstPositionReplacement mig_replace; // Second @@ -87,7 +87,7 @@ int main( int __argc, char** __argv ) eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ ); peoPSOSelect mig_selec2(topology2); eoSelectNumber< Indi > mig_select2(mig_selec2); - peoPSOReplacement mig_replace2; + peoWorstPositionReplacement mig_replace2; @@ -102,11 +102,11 @@ int main( int __argc, char** __argv ) // Parallel algorithm eoSyncEasyPSO psa(init,checkpoint,eval, velocity, flight); - peoParallelAlgorithmWrapper parallelPSO( psa, pop); + peoWrapper parallelPSO( psa, pop); eval.setOwner(parallelPSO); mig.setOwner(parallelPSO); eoSyncEasyPSO psa2(init2,checkpoint2,eval2, velocity2, flight2); - peoParallelAlgorithmWrapper parallelPSO2( psa2, pop2); + peoWrapper parallelPSO2( psa2, pop2); eval2.setOwner(parallelPSO2); mig2.setOwner(parallelPSO2); peo :: run(); diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/main5.cpp b/trunk/paradiseo-peo/tutorial/Wrapper/main5.cpp index b87f87e97..8af2a5478 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/main5.cpp +++ b/trunk/paradiseo-peo/tutorial/Wrapper/main5.cpp @@ -49,7 +49,7 @@ int main (int __argc, char * * __argv) peoSeqTransform para_transform (transform); eoEPReplacement replace (2); eoEasyEA< Route > eaAlg( checkpoint, eval, select, para_transform, replace ); - peoParallelAlgorithmWrapper parallelEA( eaAlg, pop); + peoWrapper parallelEA( eaAlg, pop); peo :: run (); peo :: finalize (); @@ -62,8 +62,8 @@ int main (int __argc, char * * __argv) // Local search peo :: init (__argc, __argv); - peoSynchronousMultiStart initParallelHC (hc); - peoParallelAlgorithmWrapper parallelHC (initParallelHC, pop); + peoMultiStart initParallelHC (hc); + peoWrapper parallelHC (initParallelHC, pop); initParallelHC.setOwner(parallelHC); peo :: run( ); peo :: finalize( ); diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/main6.cpp b/trunk/paradiseo-peo/tutorial/Wrapper/main6.cpp index 1c9e79b8c..a3ba5fc98 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/main6.cpp +++ b/trunk/paradiseo-peo/tutorial/Wrapper/main6.cpp @@ -38,8 +38,8 @@ int main (int __argc, char * * __argv) 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); eoPop pop (POP_SIZE, route_init); - peoSynchronousMultiStart initParallelHC (hc); - peoParallelAlgorithmWrapper parallelHC (initParallelHC, pop); + peoMultiStart initParallelHC (hc); + peoWrapper parallelHC (initParallelHC, pop); initParallelHC.setOwner(parallelHC); peo :: run( ); peo :: finalize( ); @@ -63,7 +63,7 @@ int main (int __argc, char * * __argv) peoSeqTransform para_transform (transform); eoEPReplacement replace (2); eoEasyEA< Route > eaAlg( checkpoint, eval, select, para_transform, replace ); - peoParallelAlgorithmWrapper parallelEA( eaAlg, pop); + peoWrapper parallelEA( eaAlg, pop); peo :: run (); peo :: finalize (); diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/main7.cpp b/trunk/paradiseo-peo/tutorial/Wrapper/main7.cpp index 1030411dd..36e5c3143 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/main7.cpp +++ b/trunk/paradiseo-peo/tutorial/Wrapper/main7.cpp @@ -42,8 +42,8 @@ int main( int __argc, char** __argv ) eoPop < Indi > pop(POP_SIZE); eoInitFixedLength < Indi > randomSeq (VEC_SIZE, uGen); - peoSynchronousMultiStart initRandom (randomSeq); - peoParallelAlgorithmWrapper random (initRandom,pop); + peoMultiStart initRandom (randomSeq); + peoWrapper random (initRandom,pop); initRandom.setOwner(random); peo :: run( ); peo :: finalize( ); @@ -55,7 +55,7 @@ int main( int __argc, char** __argv ) peoParaPopEval< Indi > eval(plainEval); eoInitializer init(eval,veloRandom,localInit,topology,pop); eoSyncEasyPSO psa(init,checkpoint,eval, velocity, flight); - peoParallelAlgorithmWrapper parallelPSO( psa, pop); + peoWrapper parallelPSO( psa, pop); eval.setOwner(parallelPSO); peo :: run(); peo :: finalize();