diff --git a/trunk/paradiseo-peo/src/core/communicable.cpp b/trunk/paradiseo-peo/src/core/communicable.cpp index 36f04eaa0..39909dccd 100644 --- a/trunk/paradiseo-peo/src/core/communicable.cpp +++ b/trunk/paradiseo-peo/src/core/communicable.cpp @@ -57,7 +57,6 @@ void Communicable :: unlock () { } void Communicable :: stop () { - sem_wait (& sem_stop); } diff --git a/trunk/paradiseo-peo/src/core/eoVector_comm.h b/trunk/paradiseo-peo/src/core/eoVector_comm.h index 27cb3fbee..e8585e422 100644 --- a/trunk/paradiseo-peo/src/core/eoVector_comm.h +++ b/trunk/paradiseo-peo/src/core/eoVector_comm.h @@ -1,5 +1,4 @@ // "eoVector_comm.h" - // (c) OPAC Team, LIFL, August 2005 /* @@ -35,4 +34,36 @@ template void unpack (eoVector & __v) { unpack (__v [i]); } +template void pack (const eoVectorParticle & __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 void unpack (eoVectorParticle & __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 diff --git a/trunk/paradiseo-peo/src/core/messaging.h b/trunk/paradiseo-peo/src/core/messaging.h index 573375020..c61eb4a6c 100644 --- a/trunk/paradiseo-peo/src/core/messaging.h +++ b/trunk/paradiseo-peo/src/core/messaging.h @@ -54,9 +54,10 @@ template void pack (const std :: pair & __pair) { pack (__pair.second); } + // -/* Float */ +/* Char */ extern void unpack (char & __c); /* Float */ @@ -101,4 +102,5 @@ template void unpack (std :: pair & __pair) { unpack (__pair.second); } + #endif diff --git a/trunk/paradiseo-peo/src/peoEA.h b/trunk/paradiseo-peo/src/peoEA.h index 516b70af9..ad4d3710d 100644 --- a/trunk/paradiseo-peo/src/peoEA.h +++ b/trunk/paradiseo-peo/src/peoEA.h @@ -131,6 +131,7 @@ template< class EOT > void peoEA< EOT > :: run() { trans( off ); printDebugMessage( "performing the evaluation of the population." ); + pop_eval( off ); printDebugMessage( "performing the replacement of the population." ); diff --git a/trunk/paradiseo-peo/src/peoEvalFuncPSO.h b/trunk/paradiseo-peo/src/peoEvalFuncPSO.h new file mode 100644 index 000000000..d08515bd2 --- /dev/null +++ b/trunk/paradiseo-peo/src/peoEvalFuncPSO.h @@ -0,0 +1,34 @@ +// "peoPSO.h" + +// (c) OPAC Team, October 2007 + +/* + Contact: clive.canape@inria.fr +*/ + +#ifndef PEOEVALFUNCPSO_H +#define PEOEVALFUNCPSO_H + +#include + +#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 { + + peoEvalFuncPSO( FitT (* _eval)( FunctionArg ) ) + : eoEvalFunc(), evalFunc( _eval ) {}; + + virtual void operator() ( POT & _peo ) + { + _peo.fitness((*evalFunc)( _peo )); + }; + + private: + FitT (* evalFunc )( FunctionArg ); +}; + +#endif + diff --git a/trunk/paradiseo-peo/src/peoPSO.h b/trunk/paradiseo-peo/src/peoPSO.h new file mode 100644 index 000000000..73b7b4a9f --- /dev/null +++ b/trunk/paradiseo-peo/src/peoPSO.h @@ -0,0 +1,82 @@ +// "peoPSO.h" + +// (c) OPAC Team, October 2007 + +/* + 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" + + +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 diff --git a/trunk/paradiseo-peo/src/peoParaPopEval.h b/trunk/paradiseo-peo/src/peoParaPopEval.h index 8e9760d89..4f9697802 100644 --- a/trunk/paradiseo-peo/src/peoParaPopEval.h +++ b/trunk/paradiseo-peo/src/peoParaPopEval.h @@ -120,20 +120,15 @@ template< class EOT > peoParaPopEval< EOT > :: peoParaPopEval( template< class EOT > void peoParaPopEval< EOT >::operator()( eoPop< EOT >& __pop ) { - - for ( unsigned i = 0; i < __pop.size(); i++ ) { - - __pop[ i ].fitness( typename EOT :: Fitness() ); - + for ( unsigned i = 0; i < __pop.size(); i++ ) { + __pop[ i ].fitness(typename EOT :: Fitness() ); progression[ &__pop[ i ] ].first = funcs.size() - 1; progression[ &__pop[ i ] ].second = funcs.size(); - for ( unsigned j = 0; j < funcs.size(); j++ ) { /* Queuing the 'invalid' solution and its associated owner */ tasks.push( &__pop[ i ] ); } } - total = funcs.size() * __pop.size(); requestResourceRequest( funcs.size() * __pop.size() ); stop(); @@ -141,7 +136,6 @@ template< class EOT > void peoParaPopEval< EOT >::operator()( eoPop< EOT >& __po template< class EOT > void peoParaPopEval< EOT > :: packData() { - // printDebugMessage ("debut pakc data"); pack( progression[ tasks.front() ].first-- ); @@ -155,7 +149,6 @@ template< class EOT > void peoParaPopEval< EOT > :: packData() { template< class EOT > void peoParaPopEval< EOT > :: unpackData() { - unpack( num_func ); /* Unpacking the solution */ unpack( sol ); @@ -165,15 +158,13 @@ template< class EOT > void peoParaPopEval< EOT > :: unpackData() { template< class EOT > void peoParaPopEval< EOT > :: execute() { - /* Computing the fitness of the solution */ - funcs[ num_func ]->operator()( sol ); + funcs[ num_func ]->operator()( sol ); } template< class EOT > void peoParaPopEval< EOT > :: packResult() { - - /* Packing the fitness of the solution */ + /* Packing the fitness of the solution */ pack( sol.fitness() ); /* Packing the @ of the individual */ pack( ad_sol ); @@ -181,7 +172,6 @@ template< class EOT > void peoParaPopEval< EOT > :: packResult() { template< class EOT > void peoParaPopEval< EOT > :: unpackResult() { - typename EOT :: Fitness fit; /* 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 > :: notifySendingAllResourceRequests() { - getOwner()->setPassive(); } diff --git a/trunk/paradiseo-peo/tutorial/Lesson2/main.cpp b/trunk/paradiseo-peo/tutorial/Lesson2/main.cpp index c6a384006..b30b647e0 100644 --- a/trunk/paradiseo-peo/tutorial/Lesson2/main.cpp +++ b/trunk/paradiseo-peo/tutorial/Lesson2/main.cpp @@ -22,8 +22,8 @@ #include -#define POP_SIZE 10 -#define NUM_GEN 100 +#define POP_SIZE 2 +#define NUM_GEN 2 #define CROSS_RATE 1.0 #define MUT_RATE 0.01 @@ -33,7 +33,7 @@ // by default, parallel evaluation of the population is performed; // for parallel fitness evaluation, uncomment the following line -// #define PARALLEL_FIT_EVALUATION +#define PARALLEL_FIT_EVALUATION int main( int __argc, char** __argv ) { @@ -105,6 +105,7 @@ int main( int __argc, char** __argv ) { peo :: run( ); peo :: finalize( ); + // shutting down the ParadisEO-PEO environment return 0; diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/route_eval.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/route_eval.cpp index 0fed8d481..f654ed4d3 100644 --- a/trunk/paradiseo-peo/tutorial/examples/tsp/route_eval.cpp +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/route_eval.cpp @@ -9,6 +9,6 @@ #include "route_eval.h" void RouteEval :: operator () (Route & __route) { - + std::cout<<"\nICI"; __route.fitness (- (int) length (__route)); }