From 5eb6eb9a09d9e7117a5c360b3d99f7a592bd6f18 Mon Sep 17 00:00:00 2001 From: canape Date: Tue, 6 Nov 2007 15:16:45 +0000 Subject: [PATCH] Parallel initialization for PSO git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@763 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-peo/src/peo.h | 1 + trunk/paradiseo-peo/src/peoEvalFuncPSO.h | 37 ++++++++- trunk/paradiseo-peo/src/peoInitializer.h | 98 ++++++++++++++++++++++++ trunk/paradiseo-peo/src/peoPSO.h | 10 ++- 4 files changed, 139 insertions(+), 7 deletions(-) create mode 100644 trunk/paradiseo-peo/src/peoInitializer.h diff --git a/trunk/paradiseo-peo/src/peo.h b/trunk/paradiseo-peo/src/peo.h index a785a0dec..3ec407c7c 100644 --- a/trunk/paradiseo-peo/src/peo.h +++ b/trunk/paradiseo-peo/src/peo.h @@ -340,6 +340,7 @@ #include "peoSyncMultiStart.h" /* Parallel PSO */ +#include "peoInitializer.h" #include "peoPSO.h" #include "peoEvalFuncPSO.h" #include "peoPSOSelect.h" diff --git a/trunk/paradiseo-peo/src/peoEvalFuncPSO.h b/trunk/paradiseo-peo/src/peoEvalFuncPSO.h index be5e366de..c7d17e30c 100644 --- a/trunk/paradiseo-peo/src/peoEvalFuncPSO.h +++ b/trunk/paradiseo-peo/src/peoEvalFuncPSO.h @@ -1,11 +1,40 @@ -/* "peoEvalFuncPSO.h" +/* +* +* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 +* (C) OPAC Team, INRIA, 2007 * -* -* (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: clive.canape@inria.fr * -* Contact: clive.canape@inria.fr */ + #ifndef PEOEVALFUNCPSO_H #define PEOEVALFUNCPSO_H diff --git a/trunk/paradiseo-peo/src/peoInitializer.h b/trunk/paradiseo-peo/src/peoInitializer.h new file mode 100644 index 000000000..2f0ea133e --- /dev/null +++ b/trunk/paradiseo-peo/src/peoInitializer.h @@ -0,0 +1,98 @@ +/* +* +* 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(*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; +}; +#endif + + + diff --git a/trunk/paradiseo-peo/src/peoPSO.h b/trunk/paradiseo-peo/src/peoPSO.h index 4d64a060e..e18250ffc 100644 --- a/trunk/paradiseo-peo/src/peoPSO.h +++ b/trunk/paradiseo-peo/src/peoPSO.h @@ -63,6 +63,7 @@ public: //! @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, @@ -77,6 +78,7 @@ public: private: + eoInitializerBase & Init; eoContinue< POT >& cont; peoPopEval< POT >& pop_eval; eoPop< POT >* pop; @@ -86,12 +88,12 @@ private: template < class POT > peoPSO< POT > :: peoPSO( - + eoInitializerBase & _Init, eoContinue< POT >& __cont, peoPopEval< POT >& __pop_eval, eoVelocity < POT > &__velocity, eoFlight < POT > &__flight - ) : cont( __cont ), pop_eval(__pop_eval ),velocity( __velocity),flight( __flight) + ) : Init(_Init),cont( __cont ), pop_eval(__pop_eval ),velocity( __velocity),flight( __flight) { pop_eval.setOwner( *this ); } @@ -106,8 +108,10 @@ template< class POT > void peoPSO< POT > :: operator ()( eoPop< POT >& __pop ) { template< class POT > void peoPSO< POT > :: run() { printDebugMessage( "Performing the first evaluation of the population." ); + Init(); + velocity.getTopology().setup(*pop); do { - printDebugMessage( "Performing the velocity evaluation." ); + printDebugMessage( "Performing the velocity evaluation." ); velocity.apply ( *pop ); printDebugMessage( "Performing the flight." ); flight.apply ( *pop );