For the wrapper ...

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@831 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
canape 2007-12-06 14:33:47 +00:00
commit 4116f0a7ac
7 changed files with 49 additions and 20 deletions

View file

@ -80,8 +80,15 @@ template <class F, class T> void unpack (eoVector <F, T> & __v) {
template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V> & __v) { template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V> & __v) {
pack (__v.fitness ()) ; if (__v.invalid()) {
pack (__v.best()); pack((unsigned)0);
}
else {
pack((unsigned)1);
pack (__v.fitness ());
pack (__v.best());
}
unsigned len = __v.size (); unsigned len = __v.size ();
pack (len); pack (len);
for (unsigned i = 0 ; i < len; i ++) for (unsigned i = 0 ; i < len; i ++)
@ -94,11 +101,19 @@ template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V>
template <class F, class T, class V> void unpack (eoVectorParticle <F, T, V> & __v) { template <class F, class T, class V> void unpack (eoVectorParticle <F, T, V> & __v) {
F fit; unsigned valid; unpack(valid);
unpack(fit);
__v.fitness (fit); if (! valid) {
unpack(fit); __v.invalidate();
}
else {
F fit;
unpack (fit);
__v.fitness (fit);
unpack(fit);
__v.best(fit); __v.best(fit);
}
unsigned len; unsigned len;
unpack (len); unpack (len);
__v.resize (len); __v.resize (len);

View file

@ -150,8 +150,9 @@ template< class EOT > void peoEA< EOT > :: operator ()( eoPop< EOT >& __pop )
template< class EOT > void peoEA< EOT > :: run() template< class EOT > void peoEA< EOT > :: run()
{ {
eoPop< EOT > dummy;
printDebugMessage( "peoEA: performing the first evaluation of the population." ); printDebugMessage( "peoEA: performing the first evaluation of the population." );
pop_eval( *pop ); pop_eval(dummy, *pop );
do do
{ {
@ -164,7 +165,7 @@ template< class EOT > void peoEA< EOT > :: run()
printDebugMessage( "peoEA: performing the evaluation of the population." ); printDebugMessage( "peoEA: performing the evaluation of the population." );
pop_eval( off ); pop_eval(dummy, off );
printDebugMessage( "peoEA: performing the replacement of the population." ); printDebugMessage( "peoEA: performing the replacement of the population." );
replace( *pop, off ); replace( *pop, off );

View file

@ -74,7 +74,7 @@ template <class POT> class peoInitializer : public eoInitializerBase <POT>
//! Parallel initialization of the population //! Parallel initialization of the population
virtual void operator()() virtual void operator()()
{ {
proc(*pop); proc(dummyPop,*pop);
apply < POT > (initVelo, *pop); apply < POT > (initVelo, *pop);
apply < POT > (initBest, *pop); apply < POT > (initBest, *pop);
} }
@ -91,6 +91,7 @@ template <class POT> class peoInitializer : public eoInitializerBase <POT>
eoVelocityInit < POT > & initVelo; eoVelocityInit < POT > & initVelo;
eoParticleBestInit <POT> & initBest; eoParticleBestInit <POT> & initBest;
eoPop <POT> * pop; eoPop <POT> * pop;
eoPop< POT > dummyPop;
}; };
#endif #endif

View file

@ -109,7 +109,7 @@ template< class POT > void peoPSO< POT > :: operator ()( eoPop< POT >& __pop )
template< class POT > void peoPSO< POT > :: run() template< class POT > void peoPSO< POT > :: run()
{ {
eoPop< POT > dummy;
printDebugMessage( "Performing the first evaluation of the population." ); printDebugMessage( "Performing the first evaluation of the population." );
Init(); Init();
velocity.getTopology().setup(*pop); velocity.getTopology().setup(*pop);
@ -120,7 +120,7 @@ template< class POT > void peoPSO< POT > :: run()
printDebugMessage( "Performing the flight." ); printDebugMessage( "Performing the flight." );
flight.apply ( *pop ); flight.apply ( *pop );
printDebugMessage( "Performing the evaluation." ); printDebugMessage( "Performing the evaluation." );
pop_eval(*pop); pop_eval(dummy,*pop);
velocity.updateNeighborhood( *pop ); velocity.updateNeighborhood( *pop );
} }
while ( cont( *pop ) ); while ( cont( *pop ) );

View file

@ -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. //! 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. //! @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 //! 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. //! 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 ) ) : 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++ ) 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() 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-- );
@ -180,7 +185,7 @@ 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 );
@ -191,13 +196,14 @@ 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 */
@ -206,7 +212,7 @@ 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 */
@ -243,7 +249,7 @@ 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();
} }

View file

@ -44,13 +44,14 @@
//! The <b>peoPopEval</b> class provides the interface for constructing ParadisEO specific evaluation functors. //! The <b>peoPopEval</b> class provides the interface for constructing ParadisEO specific evaluation functors.
//! The derived classes may be used as wrappers for <b>EO</b>-derived evaluation functors. In order to have an example, //! The derived classes may be used as wrappers for <b>EO</b>-derived evaluation functors. In order to have an example,
//! please refer to the implementation of the <b>peoSeqPopEval</b> and <b>peoParaPopEval</b> classes. //! please refer to the implementation of the <b>peoSeqPopEval</b> and <b>peoParaPopEval</b> classes.
template< class EOT > class peoPopEval : public Service template< class EOT > class peoPopEval : public Service, public eoPopEvalFunc<EOT>
{ {
public: public:
//! Interface function providing the signature for constructing an evaluation functor. //! 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 #endif

View file

@ -60,6 +60,7 @@ template< class EOT > class peoSeqPopEval : public peoPopEval< EOT >
//! //!
//! @param eoPop< EOT >& __pop - population to be evaluated. //! @param eoPop< EOT >& __pop - population to be evaluated.
void operator()( eoPop< EOT >& __pop ); void operator()( eoPop< EOT >& __pop );
void operator()( eoPop< EOT > &__dummy,eoPop< EOT >&__pop);
private: 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 > 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 ) template< class EOT > void peoSeqPopEval< EOT > :: operator()( eoPop< EOT >& __pop )
{ {