From 4116f0a7ac5e168546e4071239f5689d3ee597e0 Mon Sep 17 00:00:00 2001 From: canape Date: Thu, 6 Dec 2007 14:33:47 +0000 Subject: [PATCH] For the wrapper ... git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@831 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-peo/src/core/eoVector_mesg.h | 27 +++++++++++++++----- trunk/paradiseo-peo/src/peoEA.h | 5 ++-- trunk/paradiseo-peo/src/peoInitializer.h | 3 ++- trunk/paradiseo-peo/src/peoPSO.h | 4 +-- trunk/paradiseo-peo/src/peoParaPopEval.h | 20 ++++++++++----- trunk/paradiseo-peo/src/peoPopEval.h | 5 ++-- trunk/paradiseo-peo/src/peoSeqPopEval.h | 5 ++++ 7 files changed, 49 insertions(+), 20 deletions(-) diff --git a/trunk/paradiseo-peo/src/core/eoVector_mesg.h b/trunk/paradiseo-peo/src/core/eoVector_mesg.h index ccf6fbf9c..0869a84b5 100644 --- a/trunk/paradiseo-peo/src/core/eoVector_mesg.h +++ b/trunk/paradiseo-peo/src/core/eoVector_mesg.h @@ -80,8 +80,15 @@ template void unpack (eoVector & __v) { template void pack (const eoVectorParticle & __v) { - pack (__v.fitness ()) ; - pack (__v.best()); + if (__v.invalid()) { + pack((unsigned)0); + } + else { + pack((unsigned)1); + pack (__v.fitness ()); + pack (__v.best()); + } + unsigned len = __v.size (); pack (len); for (unsigned i = 0 ; i < len; i ++) @@ -94,11 +101,19 @@ template void pack (const eoVectorParticle template void unpack (eoVectorParticle & __v) { - F fit; - unpack(fit); - __v.fitness (fit); - unpack(fit); +unsigned valid; unpack(valid); + + if (! valid) { + __v.invalidate(); + } + else { + F fit; + unpack (fit); + __v.fitness (fit); + unpack(fit); __v.best(fit); + + } unsigned len; unpack (len); __v.resize (len); diff --git a/trunk/paradiseo-peo/src/peoEA.h b/trunk/paradiseo-peo/src/peoEA.h index c2604d1ce..59cf3e5da 100644 --- a/trunk/paradiseo-peo/src/peoEA.h +++ b/trunk/paradiseo-peo/src/peoEA.h @@ -150,8 +150,9 @@ template< class EOT > void peoEA< EOT > :: operator ()( eoPop< EOT >& __pop ) template< class EOT > void peoEA< EOT > :: run() { + eoPop< EOT > dummy; printDebugMessage( "peoEA: performing the first evaluation of the population." ); - pop_eval( *pop ); + pop_eval(dummy, *pop ); do { @@ -164,7 +165,7 @@ template< class EOT > void peoEA< EOT > :: run() printDebugMessage( "peoEA: performing the evaluation of the population." ); - pop_eval( off ); + pop_eval(dummy, off ); printDebugMessage( "peoEA: performing the replacement of the population." ); replace( *pop, off ); diff --git a/trunk/paradiseo-peo/src/peoInitializer.h b/trunk/paradiseo-peo/src/peoInitializer.h index a62e2eba7..b82fb30a9 100644 --- a/trunk/paradiseo-peo/src/peoInitializer.h +++ b/trunk/paradiseo-peo/src/peoInitializer.h @@ -74,7 +74,7 @@ template class peoInitializer : public eoInitializerBase //! Parallel initialization of the population virtual void operator()() { - proc(*pop); + proc(dummyPop,*pop); apply < POT > (initVelo, *pop); apply < POT > (initBest, *pop); } @@ -91,6 +91,7 @@ template class peoInitializer : public eoInitializerBase eoVelocityInit < POT > & initVelo; eoParticleBestInit & initBest; eoPop * pop; + eoPop< POT > dummyPop; }; #endif diff --git a/trunk/paradiseo-peo/src/peoPSO.h b/trunk/paradiseo-peo/src/peoPSO.h index 192bbbfc7..96f7b9adf 100644 --- a/trunk/paradiseo-peo/src/peoPSO.h +++ b/trunk/paradiseo-peo/src/peoPSO.h @@ -109,7 +109,7 @@ template< class POT > void peoPSO< POT > :: operator ()( eoPop< POT >& __pop ) template< class POT > void peoPSO< POT > :: run() { - + eoPop< POT > dummy; printDebugMessage( "Performing the first evaluation of the population." ); Init(); velocity.getTopology().setup(*pop); @@ -120,7 +120,7 @@ template< class POT > void peoPSO< POT > :: run() printDebugMessage( "Performing the flight." ); flight.apply ( *pop ); printDebugMessage( "Performing the evaluation." ); - pop_eval(*pop); + pop_eval(dummy,*pop); velocity.updateNeighborhood( *pop ); } while ( cont( *pop ) ); diff --git a/trunk/paradiseo-peo/src/peoParaPopEval.h b/trunk/paradiseo-peo/src/peoParaPopEval.h index 28eac56cf..206fa5f32 100644 --- a/trunk/paradiseo-peo/src/peoParaPopEval.h +++ b/trunk/paradiseo-peo/src/peoParaPopEval.h @@ -76,7 +76,8 @@ template< class EOT > class peoParaPopEval : public peoPopEval< EOT > //! Operator for applying the evaluation functor (direct or aggregate) for each individual of the specified population. //! //! @param eoPop< EOT >& __pop - population to be evaluated by applying the evaluation functor specified in the constructor. - void operator()( eoPop< EOT >& __pop ); + void operator()(eoPop< EOT >& __pop); + void operator()( eoPop< EOT >& __dummy, eoPop< EOT >& __pop ); //! Auxiliary function for transferring data between the process requesting an evaluation operation and the process that //! performs the actual evaluation phase. There is no need to explicitly call the function. @@ -145,8 +146,12 @@ template< class EOT > peoParaPopEval< EOT > :: peoParaPopEval( ) : funcs( __funcs ), merge_eval( __merge_eval ) {} +template< class EOT > void peoParaPopEval< EOT >::operator()(eoPop< EOT >& __dummy, eoPop< EOT >& __pop ) +{ + this->operator()(__pop); +} -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++ ) { @@ -166,7 +171,7 @@ 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-- ); @@ -180,7 +185,7 @@ template< class EOT > void peoParaPopEval< EOT > :: packData() template< class EOT > void peoParaPopEval< EOT > :: unpackData() -{ +{ unpack( num_func ); /* Unpacking the solution */ unpack( sol ); @@ -191,13 +196,14 @@ 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 ); } template< class EOT > void peoParaPopEval< EOT > :: packResult() -{ +{ /* Packing the fitness of the solution */ pack( sol.fitness() ); /* Packing the @ of the individual */ @@ -206,7 +212,7 @@ template< class EOT > void peoParaPopEval< EOT > :: packResult() template< class EOT > void peoParaPopEval< EOT > :: unpackResult() -{ +{ typename EOT :: Fitness fit; /* Unpacking the computed fitness */ @@ -243,7 +249,7 @@ template< class EOT > void peoParaPopEval< EOT > :: notifySendingData() template< class EOT > void peoParaPopEval< EOT > :: notifySendingAllResourceRequests() -{ +{ getOwner()->setPassive(); } diff --git a/trunk/paradiseo-peo/src/peoPopEval.h b/trunk/paradiseo-peo/src/peoPopEval.h index e25c846d9..41f0f9d88 100644 --- a/trunk/paradiseo-peo/src/peoPopEval.h +++ b/trunk/paradiseo-peo/src/peoPopEval.h @@ -44,13 +44,14 @@ //! The peoPopEval class provides the interface for constructing ParadisEO specific evaluation functors. //! The derived classes may be used as wrappers for EO-derived evaluation functors. In order to have an example, //! please refer to the implementation of the peoSeqPopEval and peoParaPopEval classes. -template< class EOT > class peoPopEval : public Service +template< class EOT > class peoPopEval : public Service, public eoPopEvalFunc { public: //! Interface function providing the signature for constructing an evaluation functor. - virtual void operator()( eoPop< EOT >& __pop ) = 0; + virtual void operator()( eoPop< EOT >& __tmp, eoPop< EOT >& __pop )=0; + }; #endif diff --git a/trunk/paradiseo-peo/src/peoSeqPopEval.h b/trunk/paradiseo-peo/src/peoSeqPopEval.h index ecc2157df..3ff7ee468 100644 --- a/trunk/paradiseo-peo/src/peoSeqPopEval.h +++ b/trunk/paradiseo-peo/src/peoSeqPopEval.h @@ -60,6 +60,7 @@ template< class EOT > class peoSeqPopEval : public peoPopEval< EOT > //! //! @param eoPop< EOT >& __pop - population to be evaluated. void operator()( eoPop< EOT >& __pop ); + void operator()( eoPop< EOT > &__dummy,eoPop< EOT >&__pop); private: @@ -70,6 +71,10 @@ template< class EOT > class peoSeqPopEval : public peoPopEval< EOT > template< class EOT > peoSeqPopEval< EOT > :: peoSeqPopEval( eoEvalFunc< EOT >& __eval ) : eval( __eval ) {} +template< class EOT > void peoSeqPopEval< EOT > :: operator()( eoPop< EOT >& __dummy,eoPop< EOT >& __pop ) +{ + this->operator()(__pop); +} template< class EOT > void peoSeqPopEval< EOT > :: operator()( eoPop< EOT >& __pop ) {