Addition of the function PSO : Parallel evaluation
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@650 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
2cef623c31
commit
43fbde1096
9 changed files with 161 additions and 23 deletions
|
|
@ -57,7 +57,6 @@ void Communicable :: unlock () {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Communicable :: stop () {
|
void Communicable :: stop () {
|
||||||
|
|
||||||
sem_wait (& sem_stop);
|
sem_wait (& sem_stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
// "eoVector_comm.h"
|
// "eoVector_comm.h"
|
||||||
|
|
||||||
// (c) OPAC Team, LIFL, August 2005
|
// (c) OPAC Team, LIFL, August 2005
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -35,4 +34,36 @@ template <class F, class T> void unpack (eoVector <F, T> & __v) {
|
||||||
unpack (__v [i]);
|
unpack (__v [i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V> & __v) {
|
||||||
|
|
||||||
|
pack (__v.fitness ()) ;
|
||||||
|
pack (__v.best());
|
||||||
|
unsigned len = __v.size ();
|
||||||
|
pack (len);
|
||||||
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
|
pack (__v [i]);
|
||||||
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
|
pack (__v.bestPositions[i]);
|
||||||
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
|
pack (__v.velocities[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class F, class T, class V> void unpack (eoVectorParticle <F, T, V> & __v) {
|
||||||
|
|
||||||
|
F fit;
|
||||||
|
unpack(fit);
|
||||||
|
__v.fitness (fit);
|
||||||
|
unpack(fit);
|
||||||
|
__v.best(fit);
|
||||||
|
unsigned len;
|
||||||
|
unpack (len);
|
||||||
|
__v.resize (len);
|
||||||
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
|
unpack (__v [i]);
|
||||||
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
|
unpack (__v.bestPositions[i]);
|
||||||
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
|
unpack (__v.velocities[i]);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,10 @@ template <class U, class V> void pack (const std :: pair <U, V> & __pair) {
|
||||||
pack (__pair.second);
|
pack (__pair.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
/* Float */
|
/* Char */
|
||||||
extern void unpack (char & __c);
|
extern void unpack (char & __c);
|
||||||
|
|
||||||
/* Float */
|
/* Float */
|
||||||
|
|
@ -101,4 +102,5 @@ template <class U, class V> void unpack (std :: pair <U, V> & __pair) {
|
||||||
unpack (__pair.second);
|
unpack (__pair.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,7 @@ template< class EOT > void peoEA< EOT > :: run() {
|
||||||
trans( off );
|
trans( off );
|
||||||
|
|
||||||
printDebugMessage( "performing the evaluation of the population." );
|
printDebugMessage( "performing the evaluation of the population." );
|
||||||
|
|
||||||
pop_eval( off );
|
pop_eval( off );
|
||||||
|
|
||||||
printDebugMessage( "performing the replacement of the population." );
|
printDebugMessage( "performing the replacement of the population." );
|
||||||
|
|
|
||||||
34
trunk/paradiseo-peo/src/peoEvalFuncPSO.h
Normal file
34
trunk/paradiseo-peo/src/peoEvalFuncPSO.h
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
// "peoPSO.h"
|
||||||
|
|
||||||
|
// (c) OPAC Team, October 2007
|
||||||
|
|
||||||
|
/*
|
||||||
|
Contact: clive.canape@inria.fr
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PEOEVALFUNCPSO_H
|
||||||
|
#define PEOEVALFUNCPSO_H
|
||||||
|
|
||||||
|
#include <eoEvalFunc.h>
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
template< class POT, class FitT = POT::Fitness, class FunctionArg = const POT& >
|
||||||
|
#else
|
||||||
|
template< class POT, class FitT = typename POT::Fitness, class FunctionArg = const POT& >
|
||||||
|
#endif
|
||||||
|
struct peoEvalFuncPSO: public eoEvalFunc<POT> {
|
||||||
|
|
||||||
|
peoEvalFuncPSO( FitT (* _eval)( FunctionArg ) )
|
||||||
|
: eoEvalFunc<POT>(), evalFunc( _eval ) {};
|
||||||
|
|
||||||
|
virtual void operator() ( POT & _peo )
|
||||||
|
{
|
||||||
|
_peo.fitness((*evalFunc)( _peo ));
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
FitT (* evalFunc )( FunctionArg );
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
82
trunk/paradiseo-peo/src/peoPSO.h
Normal file
82
trunk/paradiseo-peo/src/peoPSO.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
// "peoPSO.h"
|
||||||
|
|
||||||
|
// (c) OPAC Team, October 2007
|
||||||
|
|
||||||
|
/*
|
||||||
|
Contact: clive.canape@inria.fr
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __peoPSO_h
|
||||||
|
#define __peoPSO_h
|
||||||
|
|
||||||
|
#include <eoContinue.h>
|
||||||
|
#include <eoEvalFunc.h>
|
||||||
|
#include <eoPopEvalFunc.h>
|
||||||
|
#include <eoPSO.h>
|
||||||
|
#include <eoVelocity.h>
|
||||||
|
#include <eoFlight.h>
|
||||||
|
#include "peoPopEval.h"
|
||||||
|
#include "core/runner.h"
|
||||||
|
#include "core/peo_debug.h"
|
||||||
|
|
||||||
|
|
||||||
|
template < class POT > class peoPSO : public Runner {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
peoPSO(
|
||||||
|
eoContinue< POT >& __cont,
|
||||||
|
peoPopEval< POT >& __pop_eval,
|
||||||
|
eoVelocity < POT > &_velocity,
|
||||||
|
eoFlight < POT > &_flight);
|
||||||
|
|
||||||
|
|
||||||
|
void run();
|
||||||
|
|
||||||
|
|
||||||
|
void operator()( eoPop< POT >& __pop );
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
eoContinue< POT >& cont;
|
||||||
|
peoPopEval< POT >& pop_eval;
|
||||||
|
eoPop< POT >* pop;
|
||||||
|
eoVelocity < POT > &velocity;
|
||||||
|
eoFlight < POT > &flight;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template < class POT > peoPSO< POT > :: peoPSO(
|
||||||
|
|
||||||
|
eoContinue< POT >& __cont,
|
||||||
|
peoPopEval< POT >& __pop_eval,
|
||||||
|
eoVelocity < POT > &__velocity,
|
||||||
|
eoFlight < POT > &__flight
|
||||||
|
) : 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() {
|
||||||
|
|
||||||
|
printDebugMessage( "Performing the first evaluation of the population." );
|
||||||
|
do {
|
||||||
|
printDebugMessage( "Performing the velocity evaluation." );
|
||||||
|
velocity.apply ( *pop );
|
||||||
|
printDebugMessage( "Performing the flight." );
|
||||||
|
flight.apply ( *pop );
|
||||||
|
printDebugMessage( "Performing the evaluation." );
|
||||||
|
pop_eval(*pop);
|
||||||
|
velocity.updateNeighborhood( *pop );
|
||||||
|
} while ( cont( *pop ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -120,20 +120,15 @@ template< class EOT > peoParaPopEval< EOT > :: peoParaPopEval(
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaPopEval< EOT >::operator()( eoPop< EOT >& __pop ) {
|
template< class EOT > void peoParaPopEval< EOT >::operator()( eoPop< EOT >& __pop ) {
|
||||||
|
|
||||||
for ( unsigned i = 0; i < __pop.size(); i++ ) {
|
for ( unsigned i = 0; i < __pop.size(); i++ ) {
|
||||||
|
__pop[ i ].fitness(typename EOT :: Fitness() );
|
||||||
__pop[ i ].fitness( typename EOT :: Fitness() );
|
|
||||||
|
|
||||||
progression[ &__pop[ i ] ].first = funcs.size() - 1;
|
progression[ &__pop[ i ] ].first = funcs.size() - 1;
|
||||||
progression[ &__pop[ i ] ].second = funcs.size();
|
progression[ &__pop[ i ] ].second = funcs.size();
|
||||||
|
|
||||||
for ( unsigned j = 0; j < funcs.size(); j++ ) {
|
for ( unsigned j = 0; j < funcs.size(); j++ ) {
|
||||||
/* Queuing the 'invalid' solution and its associated owner */
|
/* Queuing the 'invalid' solution and its associated owner */
|
||||||
tasks.push( &__pop[ i ] );
|
tasks.push( &__pop[ i ] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
total = funcs.size() * __pop.size();
|
total = funcs.size() * __pop.size();
|
||||||
requestResourceRequest( funcs.size() * __pop.size() );
|
requestResourceRequest( funcs.size() * __pop.size() );
|
||||||
stop();
|
stop();
|
||||||
|
|
@ -141,7 +136,6 @@ template< class EOT > void peoParaPopEval< EOT >::operator()( eoPop< EOT >& __po
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaPopEval< EOT > :: packData() {
|
template< class EOT > void peoParaPopEval< EOT > :: packData() {
|
||||||
|
|
||||||
// printDebugMessage ("debut pakc data");
|
// printDebugMessage ("debut pakc data");
|
||||||
pack( progression[ tasks.front() ].first-- );
|
pack( progression[ tasks.front() ].first-- );
|
||||||
|
|
||||||
|
|
@ -155,7 +149,6 @@ template< class EOT > void peoParaPopEval< EOT > :: packData() {
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaPopEval< EOT > :: unpackData() {
|
template< class EOT > void peoParaPopEval< EOT > :: unpackData() {
|
||||||
|
|
||||||
unpack( num_func );
|
unpack( num_func );
|
||||||
/* Unpacking the solution */
|
/* Unpacking the solution */
|
||||||
unpack( sol );
|
unpack( sol );
|
||||||
|
|
@ -165,14 +158,12 @@ template< class EOT > void peoParaPopEval< EOT > :: unpackData() {
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaPopEval< EOT > :: execute() {
|
template< class EOT > void peoParaPopEval< EOT > :: execute() {
|
||||||
|
|
||||||
/* Computing the fitness of the solution */
|
/* Computing the fitness of the solution */
|
||||||
funcs[ num_func ]->operator()( sol );
|
funcs[ num_func ]->operator()( sol );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaPopEval< EOT > :: packResult() {
|
template< class EOT > void peoParaPopEval< EOT > :: packResult() {
|
||||||
|
|
||||||
/* Packing the fitness of the solution */
|
/* Packing the fitness of the solution */
|
||||||
pack( sol.fitness() );
|
pack( sol.fitness() );
|
||||||
/* Packing the @ of the individual */
|
/* Packing the @ of the individual */
|
||||||
|
|
@ -181,7 +172,6 @@ template< class EOT > void peoParaPopEval< EOT > :: packResult() {
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaPopEval< EOT > :: unpackResult() {
|
template< class EOT > void peoParaPopEval< EOT > :: unpackResult() {
|
||||||
|
|
||||||
typename EOT :: Fitness fit;
|
typename EOT :: Fitness fit;
|
||||||
|
|
||||||
/* Unpacking the computed fitness */
|
/* Unpacking the computed fitness */
|
||||||
|
|
@ -212,12 +202,10 @@ template< class EOT > void peoParaPopEval< EOT > :: unpackResult() {
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaPopEval< EOT > :: notifySendingData() {
|
template< class EOT > void peoParaPopEval< EOT > :: notifySendingData() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaPopEval< EOT > :: notifySendingAllResourceRequests() {
|
template< class EOT > void peoParaPopEval< EOT > :: notifySendingAllResourceRequests() {
|
||||||
|
|
||||||
getOwner()->setPassive();
|
getOwner()->setPassive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@
|
||||||
#include <peo>
|
#include <peo>
|
||||||
|
|
||||||
|
|
||||||
#define POP_SIZE 10
|
#define POP_SIZE 2
|
||||||
#define NUM_GEN 100
|
#define NUM_GEN 2
|
||||||
#define CROSS_RATE 1.0
|
#define CROSS_RATE 1.0
|
||||||
#define MUT_RATE 0.01
|
#define MUT_RATE 0.01
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
// by default, parallel evaluation of the population is performed;
|
// by default, parallel evaluation of the population is performed;
|
||||||
// for parallel fitness evaluation, uncomment the following line
|
// for parallel fitness evaluation, uncomment the following line
|
||||||
|
|
||||||
// #define PARALLEL_FIT_EVALUATION
|
#define PARALLEL_FIT_EVALUATION
|
||||||
|
|
||||||
|
|
||||||
int main( int __argc, char** __argv ) {
|
int main( int __argc, char** __argv ) {
|
||||||
|
|
@ -105,6 +105,7 @@ int main( int __argc, char** __argv ) {
|
||||||
|
|
||||||
peo :: run( );
|
peo :: run( );
|
||||||
peo :: finalize( );
|
peo :: finalize( );
|
||||||
|
|
||||||
// shutting down the ParadisEO-PEO environment
|
// shutting down the ParadisEO-PEO environment
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,6 @@
|
||||||
#include "route_eval.h"
|
#include "route_eval.h"
|
||||||
|
|
||||||
void RouteEval :: operator () (Route & __route) {
|
void RouteEval :: operator () (Route & __route) {
|
||||||
|
std::cout<<"\nICI";
|
||||||
__route.fitness (- (int) length (__route));
|
__route.fitness (- (int) length (__route));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue