New style for PEO
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@789 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
39709d3d12
commit
9c87b3b0c0
132 changed files with 3781 additions and 3396 deletions
|
|
@ -58,6 +58,8 @@ structure:
|
||||||
|
|
|
|
||||||
|
|
|
|
||||||
+-- tutorial APPLICATIONS
|
+-- tutorial APPLICATIONS
|
||||||
|
|
|
||||||
|
+-- examples TSP
|
||||||
|
|
|
|
||||||
+-- Introduction Technical introduction
|
+-- Introduction Technical introduction
|
||||||
|
|
|
|
||||||
|
|
@ -69,7 +71,9 @@ structure:
|
||||||
|
|
|
|
||||||
+-- Lesson4 PSO and EA completely parallel
|
+-- Lesson4 PSO and EA completely parallel
|
||||||
|
|
|
|
||||||
+-- Lesson5 Multi-start : several local searches
|
+-- Lesson5 Hybridization
|
||||||
|
|
|
||||||
|
+-- Lesson6 Multi-start : several local searches
|
||||||
|
|
||||||
===================================================================
|
===================================================================
|
||||||
NOTES
|
NOTES
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <communicable.cpp>
|
* <communicable.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -46,7 +46,8 @@ static std :: map <const Communicable *, unsigned> comm_to_key; /* Map of regist
|
||||||
|
|
||||||
unsigned Communicable :: num_comm = 0;
|
unsigned Communicable :: num_comm = 0;
|
||||||
|
|
||||||
Communicable :: Communicable () {
|
Communicable :: Communicable ()
|
||||||
|
{
|
||||||
|
|
||||||
comm_to_key [this] = key = ++ num_comm;
|
comm_to_key [this] = key = ++ num_comm;
|
||||||
key_to_comm.push_back (this);
|
key_to_comm.push_back (this);
|
||||||
|
|
@ -54,41 +55,48 @@ Communicable :: Communicable () {
|
||||||
sem_init (& sem_stop, 0, 0);
|
sem_init (& sem_stop, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Communicable :: ~ Communicable () {
|
Communicable :: ~ Communicable ()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
COMM_ID Communicable :: getKey () {
|
COMM_ID Communicable :: getKey ()
|
||||||
|
{
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
Communicable * getCommunicable (COMM_ID __key) {
|
Communicable * getCommunicable (COMM_ID __key)
|
||||||
|
{
|
||||||
|
|
||||||
assert (__key < key_to_comm.size ());
|
assert (__key < key_to_comm.size ());
|
||||||
return key_to_comm [__key];
|
return key_to_comm [__key];
|
||||||
}
|
}
|
||||||
|
|
||||||
COMM_ID getKey (const Communicable * __comm) {
|
COMM_ID getKey (const Communicable * __comm)
|
||||||
|
{
|
||||||
|
|
||||||
return comm_to_key [__comm];
|
return comm_to_key [__comm];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Communicable :: lock () {
|
void Communicable :: lock ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_wait (& sem_lock);
|
sem_wait (& sem_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Communicable :: unlock () {
|
void Communicable :: unlock ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_post (& sem_lock);
|
sem_post (& sem_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Communicable :: stop () {
|
void Communicable :: stop ()
|
||||||
|
{
|
||||||
sem_wait (& sem_stop);
|
sem_wait (& sem_stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Communicable :: resume () {
|
void Communicable :: resume ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_post (& sem_stop);
|
sem_post (& sem_stop);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <communicable.h>
|
* <communicable.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -41,34 +41,35 @@
|
||||||
|
|
||||||
typedef unsigned COMM_ID;
|
typedef unsigned COMM_ID;
|
||||||
|
|
||||||
class Communicable {
|
class Communicable
|
||||||
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
Communicable ();
|
Communicable ();
|
||||||
|
|
||||||
virtual ~ Communicable ();
|
|
||||||
|
|
||||||
COMM_ID getKey ();
|
virtual ~ Communicable ();
|
||||||
|
|
||||||
void lock (); /* It suspends the current process if the semaphore is locked */
|
COMM_ID getKey ();
|
||||||
void unlock (); /* It unlocks the shared semaphore */
|
|
||||||
|
|
||||||
void stop (); /* It suspends the current process */
|
void lock (); /* It suspends the current process if the semaphore is locked */
|
||||||
void resume (); /* It resumes ___________ */
|
void unlock (); /* It unlocks the shared semaphore */
|
||||||
|
|
||||||
protected :
|
|
||||||
|
|
||||||
COMM_ID key;
|
void stop (); /* It suspends the current process */
|
||||||
|
void resume (); /* It resumes ___________ */
|
||||||
|
|
||||||
sem_t sem_lock;
|
protected :
|
||||||
|
|
||||||
sem_t sem_stop;
|
|
||||||
|
|
||||||
static unsigned num_comm;
|
COMM_ID key;
|
||||||
};
|
|
||||||
|
|
||||||
extern Communicable * getCommunicable (COMM_ID __key);
|
sem_t sem_lock;
|
||||||
|
|
||||||
|
sem_t sem_stop;
|
||||||
|
|
||||||
|
static unsigned num_comm;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Communicable * getCommunicable (COMM_ID __key);
|
||||||
|
|
||||||
//extern COMM_ID getKey (const Communicable * __comm);
|
//extern COMM_ID getKey (const Communicable * __comm);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <cooperative.h>
|
* <cooperative.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -42,28 +42,29 @@
|
||||||
|
|
||||||
typedef unsigned COOP_ID;
|
typedef unsigned COOP_ID;
|
||||||
|
|
||||||
class Cooperative : public Communicable {
|
class Cooperative : public Communicable
|
||||||
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
Runner * getOwner ();
|
Runner * getOwner ();
|
||||||
|
|
||||||
void setOwner (Runner & __runner);
|
void setOwner (Runner & __runner);
|
||||||
|
|
||||||
virtual void pack () = 0;
|
virtual void pack () = 0;
|
||||||
|
|
||||||
virtual void unpack () = 0;
|
|
||||||
|
|
||||||
void send (Cooperative * __coop);
|
virtual void unpack () = 0;
|
||||||
|
|
||||||
virtual void notifySending ();
|
void send (Cooperative * __coop);
|
||||||
|
|
||||||
private :
|
virtual void notifySending ();
|
||||||
|
|
||||||
Runner * owner;
|
private :
|
||||||
|
|
||||||
};
|
Runner * owner;
|
||||||
|
|
||||||
extern Cooperative * getCooperative (COOP_ID __key);
|
};
|
||||||
|
|
||||||
|
extern Cooperative * getCooperative (COOP_ID __key);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <eoPop_comm.h>
|
* <eoPop_comm.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -41,17 +41,19 @@
|
||||||
|
|
||||||
#include "messaging.h"
|
#include "messaging.h"
|
||||||
|
|
||||||
template <class EOT> void pack (const eoPop <EOT> & __pop) {
|
template <class EOT> void pack (const eoPop <EOT> & __pop)
|
||||||
|
{
|
||||||
|
|
||||||
pack ((unsigned) __pop.size ());
|
pack ((unsigned) __pop.size ());
|
||||||
for (unsigned i = 0; i < __pop.size (); i ++)
|
for (unsigned i = 0; i < __pop.size (); i ++)
|
||||||
pack (__pop [i]);
|
pack (__pop [i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class EOT> void unpack (eoPop <EOT> & __pop) {
|
template <class EOT> void unpack (eoPop <EOT> & __pop)
|
||||||
|
{
|
||||||
|
|
||||||
unsigned n;
|
unsigned n;
|
||||||
|
|
||||||
unpack (n);
|
unpack (n);
|
||||||
__pop.resize (n);
|
__pop.resize (n);
|
||||||
for (unsigned i = 0; i < n; i ++)
|
for (unsigned i = 0; i < n; i ++)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <eoVector_comm.h>
|
* <eoVector_comm.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -41,34 +41,36 @@
|
||||||
|
|
||||||
#include "messaging.h"
|
#include "messaging.h"
|
||||||
|
|
||||||
template <class F, class T> void pack (const eoVector <F, T> & __v) {
|
template <class F, class T> void pack (const eoVector <F, T> & __v)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
if ( !__v.invalid() )
|
if ( !__v.invalid() )
|
||||||
{
|
{
|
||||||
pack( (unsigned int) 1 );
|
pack( (unsigned int) 1 );
|
||||||
pack (__v.fitness ()) ;
|
pack (__v.fitness ()) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pack( (unsigned int) 0 );
|
pack( (unsigned int) 0 );
|
||||||
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 ++)
|
||||||
pack (__v [i]);
|
pack (__v [i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class F, class T> void unpack (eoVector <F, T> & __v) {
|
template <class F, class T> void unpack (eoVector <F, T> & __v)
|
||||||
|
{
|
||||||
|
|
||||||
F fit;
|
F fit;
|
||||||
unsigned int vfit;
|
unsigned int vfit;
|
||||||
unpack( vfit );
|
unpack( vfit );
|
||||||
if ( vfit )
|
if ( vfit )
|
||||||
{
|
{
|
||||||
unpack (fit);
|
unpack (fit);
|
||||||
__v.fitness (fit);
|
__v.fitness (fit);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
__v.invalidate();
|
__v.invalidate();
|
||||||
unsigned len;
|
unsigned len;
|
||||||
unpack (len);
|
unpack (len);
|
||||||
__v.resize (len);
|
__v.resize (len);
|
||||||
|
|
@ -76,21 +78,23 @@ 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) {
|
template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V> & __v)
|
||||||
|
{
|
||||||
|
|
||||||
pack (__v.fitness ()) ;
|
pack (__v.fitness ()) ;
|
||||||
pack (__v.best());
|
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 ++)
|
||||||
pack (__v [i]);
|
pack (__v [i]);
|
||||||
for (unsigned i = 0 ; i < len; i ++)
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
pack (__v.bestPositions[i]);
|
pack (__v.bestPositions[i]);
|
||||||
for (unsigned i = 0 ; i < len; i ++)
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
pack (__v.velocities[i]);
|
pack (__v.velocities[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
F fit;
|
||||||
unpack(fit);
|
unpack(fit);
|
||||||
|
|
@ -101,11 +105,11 @@ template <class F, class T, class V> void unpack (eoVectorParticle <F, T, V> & _
|
||||||
unpack (len);
|
unpack (len);
|
||||||
__v.resize (len);
|
__v.resize (len);
|
||||||
for (unsigned i = 0 ; i < len; i ++)
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
unpack (__v [i]);
|
unpack (__v [i]);
|
||||||
for (unsigned i = 0 ; i < len; i ++)
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
unpack (__v.bestPositions[i]);
|
unpack (__v.bestPositions[i]);
|
||||||
for (unsigned i = 0 ; i < len; i ++)
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
unpack (__v.velocities[i]);
|
unpack (__v.velocities[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <messaging.h>
|
* <messaging.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -40,44 +40,46 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
/* Char */
|
/* Char */
|
||||||
extern void pack (const char & __c);
|
extern void pack (const char & __c);
|
||||||
|
|
||||||
/* Float */
|
/* Float */
|
||||||
extern void pack (const float & __f, int __nitem = 1);
|
extern void pack (const float & __f, int __nitem = 1);
|
||||||
|
|
||||||
/* Double */
|
/* Double */
|
||||||
extern void pack (const double & __d, int __nitem = 1);
|
extern void pack (const double & __d, int __nitem = 1);
|
||||||
|
|
||||||
/* Integer */
|
/* Integer */
|
||||||
extern void pack (const int & __i, int __nitem = 1);
|
extern void pack (const int & __i, int __nitem = 1);
|
||||||
|
|
||||||
/* Unsigned int. */
|
/* Unsigned int. */
|
||||||
extern void pack (const unsigned int & __ui, int __nitem = 1);
|
extern void pack (const unsigned int & __ui, int __nitem = 1);
|
||||||
|
|
||||||
/* Short int. */
|
/* Short int. */
|
||||||
extern void pack (const short & __sh, int __nitem = 1);
|
extern void pack (const short & __sh, int __nitem = 1);
|
||||||
|
|
||||||
/* Unsigned short */
|
/* Unsigned short */
|
||||||
extern void pack (const unsigned short & __ush, int __nitem = 1);
|
extern void pack (const unsigned short & __ush, int __nitem = 1);
|
||||||
|
|
||||||
/* Long */
|
/* Long */
|
||||||
extern void pack (const long & __l, int __nitem = 1);
|
extern void pack (const long & __l, int __nitem = 1);
|
||||||
|
|
||||||
/* Unsigned long */
|
/* Unsigned long */
|
||||||
extern void pack (const unsigned long & __ul, int __nitem = 1);
|
extern void pack (const unsigned long & __ul, int __nitem = 1);
|
||||||
|
|
||||||
/* String */
|
/* String */
|
||||||
extern void pack (const char * __str);
|
extern void pack (const char * __str);
|
||||||
|
|
||||||
/* Pointer */
|
/* Pointer */
|
||||||
template <class T> void pack (const T * __ptr) {
|
template <class T> void pack (const T * __ptr)
|
||||||
|
{
|
||||||
pack ((unsigned long) __ptr);
|
|
||||||
|
pack ((unsigned long) __ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pair */
|
/* Pair */
|
||||||
template <class U, class V> void pack (const std :: pair <U, V> & __pair) {
|
template <class U, class V> void pack (const std :: pair <U, V> & __pair)
|
||||||
|
{
|
||||||
|
|
||||||
pack (__pair.first);
|
pack (__pair.first);
|
||||||
pack (__pair.second);
|
pack (__pair.second);
|
||||||
}
|
}
|
||||||
|
|
@ -86,46 +88,48 @@ template <class U, class V> void pack (const std :: pair <U, V> & __pair) {
|
||||||
//
|
//
|
||||||
|
|
||||||
/* Char */
|
/* Char */
|
||||||
extern void unpack (char & __c);
|
extern void unpack (char & __c);
|
||||||
|
|
||||||
/* Float */
|
/* Float */
|
||||||
extern void unpack (float & __f, int __nitem = 1);
|
extern void unpack (float & __f, int __nitem = 1);
|
||||||
|
|
||||||
/* Double */
|
/* Double */
|
||||||
extern void unpack (double & __d, int __nitem = 1);
|
extern void unpack (double & __d, int __nitem = 1);
|
||||||
|
|
||||||
/* Integer */
|
/* Integer */
|
||||||
extern void unpack (int & __i, int __nitem = 1);
|
extern void unpack (int & __i, int __nitem = 1);
|
||||||
|
|
||||||
/* Unsigned int. */
|
/* Unsigned int. */
|
||||||
extern void unpack (unsigned int & __ui, int __nitem = 1);
|
extern void unpack (unsigned int & __ui, int __nitem = 1);
|
||||||
|
|
||||||
/* Short int. */
|
/* Short int. */
|
||||||
extern void unpack (short & __sh, int __nitem = 1);
|
extern void unpack (short & __sh, int __nitem = 1);
|
||||||
|
|
||||||
/* Unsigned short */
|
/* Unsigned short */
|
||||||
extern void unpack (unsigned short & __ush, int __nitem = 1);
|
extern void unpack (unsigned short & __ush, int __nitem = 1);
|
||||||
|
|
||||||
/* Long */
|
/* Long */
|
||||||
extern void unpack (long & __l, int __nitem = 1);
|
extern void unpack (long & __l, int __nitem = 1);
|
||||||
|
|
||||||
/* Unsigned long */
|
/* Unsigned long */
|
||||||
extern void unpack (unsigned long & __ul, int __nitem = 1);
|
extern void unpack (unsigned long & __ul, int __nitem = 1);
|
||||||
|
|
||||||
/* String */
|
/* String */
|
||||||
extern void unpack (char * __str);
|
extern void unpack (char * __str);
|
||||||
|
|
||||||
/* Pointer */
|
/* Pointer */
|
||||||
template <class T> void unpack (T * & __ptr) {
|
template <class T> void unpack (T * & __ptr)
|
||||||
|
{
|
||||||
|
|
||||||
unsigned long p;
|
unsigned long p;
|
||||||
unpack (p);
|
unpack (p);
|
||||||
__ptr = (T *) p;
|
__ptr = (T *) p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pair */
|
/* Pair */
|
||||||
template <class U, class V> void unpack (std :: pair <U, V> & __pair) {
|
template <class U, class V> void unpack (std :: pair <U, V> & __pair)
|
||||||
|
{
|
||||||
|
|
||||||
unpack (__pair.first);
|
unpack (__pair.first);
|
||||||
unpack (__pair.second);
|
unpack (__pair.second);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peo_debug.cpp>
|
* <peo_debug.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -56,7 +56,8 @@ static char host [MAX_BUFF_SIZE];
|
||||||
|
|
||||||
std :: vector <FILE *> files;
|
std :: vector <FILE *> files;
|
||||||
|
|
||||||
void setDebugMode (bool __dbg) {
|
void setDebugMode (bool __dbg)
|
||||||
|
{
|
||||||
|
|
||||||
debug = __dbg;
|
debug = __dbg;
|
||||||
gethostname (host, MAX_BUFF_SIZE);
|
gethostname (host, MAX_BUFF_SIZE);
|
||||||
|
|
@ -64,8 +65,9 @@ void setDebugMode (bool __dbg) {
|
||||||
|
|
||||||
extern int getNodeRank ();
|
extern int getNodeRank ();
|
||||||
|
|
||||||
void initDebugging () {
|
void initDebugging ()
|
||||||
|
{
|
||||||
|
|
||||||
mkdir (DEBUG_PATH, S_IRWXU);
|
mkdir (DEBUG_PATH, S_IRWXU);
|
||||||
// files.push_back (stdout);
|
// files.push_back (stdout);
|
||||||
char buff [MAX_BUFF_SIZE];
|
char buff [MAX_BUFF_SIZE];
|
||||||
|
|
@ -73,33 +75,37 @@ void initDebugging () {
|
||||||
files.push_back (fopen (buff, "w"));
|
files.push_back (fopen (buff, "w"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void endDebugging () {
|
void endDebugging ()
|
||||||
|
{
|
||||||
|
|
||||||
for (unsigned i = 0; i < files.size (); i ++)
|
for (unsigned i = 0; i < files.size (); i ++)
|
||||||
if (files [i] != stdout)
|
if (files [i] != stdout)
|
||||||
fclose (files [i]);
|
fclose (files [i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printDebugMessage (const char * __mess) {
|
void printDebugMessage (const char * __mess)
|
||||||
|
{
|
||||||
|
|
||||||
if (debug) {
|
if (debug)
|
||||||
|
{
|
||||||
|
|
||||||
char buff [MAX_BUFF_SIZE];
|
char buff [MAX_BUFF_SIZE];
|
||||||
time_t t = time (0);
|
time_t t = time (0);
|
||||||
|
|
||||||
/* Date */
|
/* Date */
|
||||||
sprintf (buff, "[%s][%s: ", host, ctime (& t));
|
sprintf (buff, "[%s][%s: ", host, ctime (& t));
|
||||||
* strchr (buff, '\n') = ']';
|
* strchr (buff, '\n') = ']';
|
||||||
for (unsigned i = 0; i < files.size (); i ++)
|
for (unsigned i = 0; i < files.size (); i ++)
|
||||||
fprintf (files [i], buff);
|
fprintf (files [i], buff);
|
||||||
|
|
||||||
/* Message */
|
/* Message */
|
||||||
sprintf (buff, "%s", __mess);
|
sprintf (buff, "%s", __mess);
|
||||||
|
|
||||||
for (unsigned i = 0; i < files.size (); i ++) {
|
for (unsigned i = 0; i < files.size (); i ++)
|
||||||
fputs (buff, files [i]);
|
{
|
||||||
fputs ("\n", files [i]);
|
fputs (buff, files [i]);
|
||||||
fflush (files [i]);
|
fputs ("\n", files [i]);
|
||||||
|
fflush (files [i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peo_debug.h>
|
* <peo_debug.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peo_fin.cpp>
|
* <peo_fin.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -39,7 +39,8 @@
|
||||||
#include "runner.h"
|
#include "runner.h"
|
||||||
#include "rmc.h"
|
#include "rmc.h"
|
||||||
|
|
||||||
void peo :: finalize () {
|
void peo :: finalize ()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage ("waiting for the termination of all threads");
|
printDebugMessage ("waiting for the termination of all threads");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peo_fin.h>
|
* <peo_fin.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -37,8 +37,9 @@
|
||||||
#ifndef __peo_finalize_h
|
#ifndef __peo_finalize_h
|
||||||
#define __peo_finalize_h
|
#define __peo_finalize_h
|
||||||
|
|
||||||
namespace peo {
|
namespace peo
|
||||||
|
{
|
||||||
|
|
||||||
extern void finalize ();
|
extern void finalize ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peo_init.cpp>
|
* <peo_init.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -41,24 +41,26 @@
|
||||||
#include "peo_debug.h"
|
#include "peo_debug.h"
|
||||||
#include "rmc.h"
|
#include "rmc.h"
|
||||||
|
|
||||||
namespace peo {
|
namespace peo
|
||||||
|
{
|
||||||
|
|
||||||
int * argc;
|
int * argc;
|
||||||
|
|
||||||
char * * * argv;
|
char * * * argv;
|
||||||
|
|
||||||
void init (int & __argc, char * * & __argv) {
|
void init (int & __argc, char * * & __argv)
|
||||||
|
{
|
||||||
|
|
||||||
argc = & __argc;
|
argc = & __argc;
|
||||||
|
|
||||||
argv = & __argv;
|
argv = & __argv;
|
||||||
|
|
||||||
/* Initializing the the Resource Management and Communication */
|
/* Initializing the the Resource Management and Communication */
|
||||||
initRMC (__argc, __argv);
|
initRMC (__argc, __argv);
|
||||||
|
|
||||||
/* Loading the common parameters */
|
/* Loading the common parameters */
|
||||||
loadParameters (__argc, __argv);
|
loadParameters (__argc, __argv);
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
initDebugging ();
|
initDebugging ();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peo_init.h>
|
* <peo_init.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -37,12 +37,13 @@
|
||||||
#ifndef __peo_init_h
|
#ifndef __peo_init_h
|
||||||
#define __peo_init_h
|
#define __peo_init_h
|
||||||
|
|
||||||
namespace peo {
|
namespace peo
|
||||||
|
{
|
||||||
|
|
||||||
extern int * argc;
|
extern int * argc;
|
||||||
|
|
||||||
extern char * * * argv;
|
extern char * * * argv;
|
||||||
|
|
||||||
extern void init (int & __argc, char * * & __argv);
|
extern void init (int & __argc, char * * & __argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peo_param.cpp>
|
* <peo_param.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -41,7 +41,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void peo :: loadParameters (int & __argc, char * * & __argv) {
|
void peo :: loadParameters (int & __argc, char * * & __argv)
|
||||||
|
{
|
||||||
|
|
||||||
eoParser parser (__argc, __argv);
|
eoParser parser (__argc, __argv);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peo_param.h>
|
* <peo_param.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -37,8 +37,9 @@
|
||||||
#ifndef __peo_param_h
|
#ifndef __peo_param_h
|
||||||
#define __peo_param_h
|
#define __peo_param_h
|
||||||
|
|
||||||
namespace peo {
|
namespace peo
|
||||||
|
{
|
||||||
|
|
||||||
extern void loadParameters (int & __argc, char * * & __argv);
|
extern void loadParameters (int & __argc, char * * & __argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peo_run.cpp>
|
* <peo_run.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -39,8 +39,9 @@
|
||||||
#include "rmc.h"
|
#include "rmc.h"
|
||||||
#include "runner.h"
|
#include "runner.h"
|
||||||
|
|
||||||
void peo :: run () {
|
void peo :: run ()
|
||||||
|
{
|
||||||
|
|
||||||
startRunners ();
|
startRunners ();
|
||||||
|
|
||||||
runRMC ();
|
runRMC ();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peo_run.h>
|
* <peo_run.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -37,8 +37,9 @@
|
||||||
#ifndef __peo_run_h
|
#ifndef __peo_run_h
|
||||||
#define __peo_run_h
|
#define __peo_run_h
|
||||||
|
|
||||||
namespace peo {
|
namespace peo
|
||||||
|
{
|
||||||
|
|
||||||
extern void run ();
|
extern void run ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <reac_thread.cpp>
|
* <reac_thread.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -40,25 +40,29 @@ static bool the_end = false;
|
||||||
|
|
||||||
static std :: vector <ReactiveThread *> reac_threads;
|
static std :: vector <ReactiveThread *> reac_threads;
|
||||||
|
|
||||||
ReactiveThread :: ReactiveThread () {
|
ReactiveThread :: ReactiveThread ()
|
||||||
|
{
|
||||||
|
|
||||||
reac_threads.push_back (this);
|
reac_threads.push_back (this);
|
||||||
sem_init (& sem, 0, 0);
|
sem_init (& sem, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReactiveThread :: sleep () {
|
void ReactiveThread :: sleep ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_wait (& sem);
|
sem_wait (& sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReactiveThread :: wakeUp () {
|
void ReactiveThread :: wakeUp ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_post (& sem);
|
sem_post (& sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopReactiveThreads () {
|
void stopReactiveThreads ()
|
||||||
|
{
|
||||||
|
|
||||||
the_end = true;
|
the_end = true;
|
||||||
for (unsigned i = 0; i < reac_threads.size (); i ++)
|
for (unsigned i = 0; i < reac_threads.size (); i ++)
|
||||||
reac_threads [i] -> wakeUp ();
|
reac_threads [i] -> wakeUp ();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <reac_thread.h>
|
* <reac_thread.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -41,22 +41,23 @@
|
||||||
|
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
class ReactiveThread : public Thread {
|
class ReactiveThread : public Thread
|
||||||
|
{
|
||||||
public:
|
|
||||||
|
|
||||||
/* Ctor */
|
public:
|
||||||
ReactiveThread ();
|
|
||||||
|
|
||||||
void sleep ();
|
/* Ctor */
|
||||||
|
ReactiveThread ();
|
||||||
void wakeUp ();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
sem_t sem;
|
void sleep ();
|
||||||
|
|
||||||
};
|
void wakeUp ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
sem_t sem;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
extern void stopReactiveThreads ();
|
extern void stopReactiveThreads ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <ring_topo.cpp>
|
* <ring_topo.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -37,17 +37,19 @@
|
||||||
#include "ring_topo.h"
|
#include "ring_topo.h"
|
||||||
|
|
||||||
void RingTopology :: setNeighbors (Cooperative * __mig,
|
void RingTopology :: setNeighbors (Cooperative * __mig,
|
||||||
std :: vector <Cooperative *> & __from,
|
std :: vector <Cooperative *> & __from,
|
||||||
std :: vector <Cooperative *> & __to) {
|
std :: vector <Cooperative *> & __to)
|
||||||
|
{
|
||||||
__from.clear () ;
|
__from.clear () ;
|
||||||
__to.clear () ;
|
__to.clear () ;
|
||||||
|
|
||||||
int len = mig.size () ;
|
int len = mig.size () ;
|
||||||
|
|
||||||
for (int i = 0 ; i < len ; i ++)
|
for (int i = 0 ; i < len ; i ++)
|
||||||
if (mig [i] == __mig) {
|
if (mig [i] == __mig)
|
||||||
__from.push_back (mig [(i - 1 + len) % len]) ;
|
{
|
||||||
__to.push_back (mig [(i + 1) % len]) ;
|
__from.push_back (mig [(i - 1 + len) % len]) ;
|
||||||
break;
|
__to.push_back (mig [(i + 1) % len]) ;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <ring_topo.h>
|
* <ring_topo.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -39,14 +39,15 @@
|
||||||
|
|
||||||
#include "topology.h"
|
#include "topology.h"
|
||||||
|
|
||||||
class RingTopology : public Topology {
|
class RingTopology : public Topology
|
||||||
|
{
|
||||||
public :
|
|
||||||
|
public :
|
||||||
void setNeighbors (Cooperative * __mig,
|
|
||||||
std :: vector <Cooperative *> & __from,
|
void setNeighbors (Cooperative * __mig,
|
||||||
std :: vector <Cooperative *> & __to);
|
std :: vector <Cooperative *> & __from,
|
||||||
|
std :: vector <Cooperative *> & __to);
|
||||||
};
|
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <rmc.h>
|
* <rmc.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
extern void initRMC (int & __argc, char * * & __argv);
|
extern void initRMC (int & __argc, char * * & __argv);
|
||||||
|
|
||||||
extern void runRMC (); /* Resource Management and Communication */
|
extern void runRMC (); /* Resource Management and Communication */
|
||||||
|
|
||||||
extern void finalizeRMC ();
|
extern void finalizeRMC ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <runner.cpp>
|
* <runner.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -43,47 +43,53 @@
|
||||||
|
|
||||||
static unsigned num_act = 0; /* Number of active runners */
|
static unsigned num_act = 0; /* Number of active runners */
|
||||||
|
|
||||||
static std :: vector <pthread_t *> ll_threads; /* Low-level runner threads */
|
static std :: vector <pthread_t *> ll_threads; /* Low-level runner threads */
|
||||||
|
|
||||||
static std :: vector <Runner *> the_runners;
|
static std :: vector <Runner *> the_runners;
|
||||||
|
|
||||||
static unsigned num_runners = 0;
|
static unsigned num_runners = 0;
|
||||||
|
|
||||||
Runner :: Runner () {
|
Runner :: Runner ()
|
||||||
|
{
|
||||||
|
|
||||||
id = ++ num_runners;
|
id = ++ num_runners;
|
||||||
the_runners.push_back (this);
|
the_runners.push_back (this);
|
||||||
sem_init (& sem_start, 0, 0);
|
sem_init (& sem_start, 0, 0);
|
||||||
num_act ++;
|
num_act ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int getNodeRank ();
|
extern int getNodeRank ();
|
||||||
|
|
||||||
extern int getNumberOfNodes ();
|
extern int getNumberOfNodes ();
|
||||||
|
|
||||||
void unpackTerminationOfRunner () {
|
void unpackTerminationOfRunner ()
|
||||||
|
{
|
||||||
|
|
||||||
RUNNER_ID id;
|
RUNNER_ID id;
|
||||||
unpack (id);
|
unpack (id);
|
||||||
num_act --;
|
num_act --;
|
||||||
printDebugMessage ("I'm noticed of the termination of a runner");
|
printDebugMessage ("I'm noticed of the termination of a runner");
|
||||||
if (! num_act) {
|
if (! num_act)
|
||||||
printDebugMessage ("all the runners have terminated. Now stopping the reactive threads.");
|
{
|
||||||
stopReactiveThreads ();
|
printDebugMessage ("all the runners have terminated. Now stopping the reactive threads.");
|
||||||
}
|
stopReactiveThreads ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool atLeastOneActiveRunner () {
|
bool atLeastOneActiveRunner ()
|
||||||
|
{
|
||||||
|
|
||||||
return num_act;
|
return num_act;
|
||||||
}
|
}
|
||||||
|
|
||||||
RUNNER_ID Runner :: getID () {
|
RUNNER_ID Runner :: getID ()
|
||||||
|
{
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner :: start () {
|
void Runner :: start ()
|
||||||
|
{
|
||||||
|
|
||||||
setActive ();
|
setActive ();
|
||||||
sem_post (& sem_start);
|
sem_post (& sem_start);
|
||||||
|
|
@ -91,7 +97,8 @@ void Runner :: start () {
|
||||||
terminate ();
|
terminate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner :: notifySendingTermination () {
|
void Runner :: notifySendingTermination ()
|
||||||
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
char b [1000];
|
char b [1000];
|
||||||
|
|
@ -100,32 +107,37 @@ void Runner :: notifySendingTermination () {
|
||||||
*/
|
*/
|
||||||
printDebugMessage ("je suis informe que tout le monde a recu ma terminaison");
|
printDebugMessage ("je suis informe que tout le monde a recu ma terminaison");
|
||||||
setPassive ();
|
setPassive ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner :: waitStarting () {
|
void Runner :: waitStarting ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_wait (& sem_start);
|
sem_wait (& sem_start);
|
||||||
}
|
}
|
||||||
|
|
||||||
Runner * getRunner (RUNNER_ID __key) {
|
Runner * getRunner (RUNNER_ID __key)
|
||||||
|
{
|
||||||
|
|
||||||
return dynamic_cast <Runner *> (getCommunicable (__key));
|
return dynamic_cast <Runner *> (getCommunicable (__key));
|
||||||
}
|
}
|
||||||
|
|
||||||
void startRunners () {
|
void startRunners ()
|
||||||
|
{
|
||||||
|
|
||||||
/* Runners */
|
/* Runners */
|
||||||
for (unsigned i = 0; i < the_runners.size (); i ++)
|
for (unsigned i = 0; i < the_runners.size (); i ++)
|
||||||
if (the_runners [i] -> isLocal ()) {
|
if (the_runners [i] -> isLocal ())
|
||||||
addThread (the_runners [i], ll_threads);
|
{
|
||||||
the_runners [i] -> waitStarting ();
|
addThread (the_runners [i], ll_threads);
|
||||||
}
|
the_runners [i] -> waitStarting ();
|
||||||
|
}
|
||||||
printDebugMessage ("launched the parallel runners");
|
printDebugMessage ("launched the parallel runners");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void joinRunners () {
|
void joinRunners ()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
joinThreads (ll_threads);
|
joinThreads (ll_threads);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <runner.h>
|
* <runner.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -44,40 +44,41 @@
|
||||||
|
|
||||||
typedef unsigned RUNNER_ID;
|
typedef unsigned RUNNER_ID;
|
||||||
|
|
||||||
class Runner : public Communicable, public Thread {
|
class Runner : public Communicable, public Thread
|
||||||
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
Runner ();
|
Runner ();
|
||||||
|
|
||||||
void start ();
|
void start ();
|
||||||
|
|
||||||
void waitStarting ();
|
void waitStarting ();
|
||||||
|
|
||||||
bool isLocal ();
|
bool isLocal ();
|
||||||
|
|
||||||
void terminate ();
|
void terminate ();
|
||||||
|
|
||||||
virtual void run () = 0;
|
virtual void run () = 0;
|
||||||
|
|
||||||
RUNNER_ID getID ();
|
|
||||||
|
|
||||||
void packTermination ();
|
RUNNER_ID getID ();
|
||||||
|
|
||||||
void notifySendingTermination ();
|
void packTermination ();
|
||||||
|
|
||||||
private :
|
void notifySendingTermination ();
|
||||||
|
|
||||||
sem_t sem_start;
|
private :
|
||||||
|
|
||||||
unsigned id;
|
sem_t sem_start;
|
||||||
};
|
|
||||||
|
unsigned id;
|
||||||
|
};
|
||||||
|
|
||||||
extern bool atLeastOneActiveRunner ();
|
extern bool atLeastOneActiveRunner ();
|
||||||
|
|
||||||
extern void unpackTerminationOfRunner ();
|
extern void unpackTerminationOfRunner ();
|
||||||
|
|
||||||
extern Runner * getRunner (RUNNER_ID __key);
|
extern Runner * getRunner (RUNNER_ID __key);
|
||||||
|
|
||||||
extern void startRunners ();
|
extern void startRunners ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <service.cpp>
|
* <service.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -36,51 +36,55 @@
|
||||||
|
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
|
|
||||||
void Service :: setOwner (Thread & __owner) {
|
void Service :: setOwner (Thread & __owner)
|
||||||
|
{
|
||||||
|
|
||||||
owner = & __owner;
|
owner = & __owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread * Service :: getOwner () {
|
Thread * Service :: getOwner ()
|
||||||
|
{
|
||||||
|
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
Service * getService (SERVICE_ID __key) {
|
Service * getService (SERVICE_ID __key)
|
||||||
|
{
|
||||||
|
|
||||||
return dynamic_cast <Service *> (getCommunicable (__key));
|
return dynamic_cast <Service *> (getCommunicable (__key));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service :: notifySendingData () {
|
void Service :: notifySendingData ()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
void Service :: notifySendingResourceRequest () {
|
void Service :: notifySendingResourceRequest ()
|
||||||
|
{
|
||||||
|
|
||||||
num_sent_rr --;
|
num_sent_rr --;
|
||||||
if (! num_sent_rr)
|
if (! num_sent_rr)
|
||||||
notifySendingAllResourceRequests ();
|
notifySendingAllResourceRequests ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service :: notifySendingAllResourceRequests () {
|
void Service :: notifySendingAllResourceRequests ()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service :: packData () {
|
void Service :: packData ()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service :: unpackData () {
|
void Service :: unpackData ()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service :: execute () {
|
void Service :: execute ()
|
||||||
|
{
|
||||||
}
|
|
||||||
|
|
||||||
void Service :: packResult () {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service :: unpackResult () {
|
void Service :: packResult ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Service :: unpackResult ()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <service.h>
|
* <service.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -42,37 +42,38 @@
|
||||||
|
|
||||||
typedef unsigned SERVICE_ID;
|
typedef unsigned SERVICE_ID;
|
||||||
|
|
||||||
class Service : public Communicable {
|
class Service : public Communicable
|
||||||
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
void setOwner (Thread & __owner);
|
void setOwner (Thread & __owner);
|
||||||
|
|
||||||
Thread * getOwner ();
|
|
||||||
|
|
||||||
void requestResourceRequest (unsigned __how_many = 1);
|
Thread * getOwner ();
|
||||||
void packResourceRequest ();
|
|
||||||
|
|
||||||
virtual void packData ();
|
void requestResourceRequest (unsigned __how_many = 1);
|
||||||
virtual void unpackData ();
|
void packResourceRequest ();
|
||||||
|
|
||||||
virtual void execute ();
|
virtual void packData ();
|
||||||
|
virtual void unpackData ();
|
||||||
virtual void packResult ();
|
|
||||||
virtual void unpackResult ();
|
|
||||||
|
|
||||||
virtual void notifySendingData ();
|
virtual void execute ();
|
||||||
virtual void notifySendingResourceRequest ();
|
|
||||||
virtual void notifySendingAllResourceRequests ();
|
|
||||||
|
|
||||||
private :
|
virtual void packResult ();
|
||||||
|
virtual void unpackResult ();
|
||||||
|
|
||||||
Thread * owner; /* Owner thread (i.e. 'uses' that service) */
|
virtual void notifySendingData ();
|
||||||
|
virtual void notifySendingResourceRequest ();
|
||||||
|
virtual void notifySendingAllResourceRequests ();
|
||||||
|
|
||||||
unsigned num_sent_rr; /* Number of RR not really sent (i.e. still in the sending queue)*/
|
private :
|
||||||
|
|
||||||
};
|
Thread * owner; /* Owner thread (i.e. 'uses' that service) */
|
||||||
|
|
||||||
extern Service * getService (SERVICE_ID __key);
|
unsigned num_sent_rr; /* Number of RR not really sent (i.e. still in the sending queue)*/
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Service * getService (SERVICE_ID __key);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <thread.cpp>
|
* <thread.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -42,68 +42,79 @@ static std :: vector <Thread *> threads;
|
||||||
|
|
||||||
unsigned num_act = 0;
|
unsigned num_act = 0;
|
||||||
|
|
||||||
Thread :: Thread () {
|
Thread :: Thread ()
|
||||||
|
{
|
||||||
|
|
||||||
threads.push_back (this);
|
threads.push_back (this);
|
||||||
act = false;
|
act = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread :: ~ Thread () {
|
Thread :: ~ Thread ()
|
||||||
|
{
|
||||||
|
|
||||||
/* Nothing ! */
|
/* Nothing ! */
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int getNodeRank ();
|
extern int getNodeRank ();
|
||||||
|
|
||||||
void Thread :: setActive () {
|
void Thread :: setActive ()
|
||||||
|
{
|
||||||
|
|
||||||
if (! act ) {
|
if (! act )
|
||||||
|
{
|
||||||
|
|
||||||
act = true;
|
act = true;
|
||||||
num_act ++;
|
num_act ++;
|
||||||
// if (getNodeRank () == 1)
|
// if (getNodeRank () == 1)
|
||||||
// printf ("On passe a %d\n", num_act);
|
// printf ("On passe a %d\n", num_act);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread :: setPassive () {
|
void Thread :: setPassive ()
|
||||||
|
{
|
||||||
|
|
||||||
if (act) {
|
if (act)
|
||||||
|
{
|
||||||
|
|
||||||
act = false;
|
act = false;
|
||||||
num_act --;
|
num_act --;
|
||||||
// if (getNodeRank () == 1)
|
// if (getNodeRank () == 1)
|
||||||
// printf ("On passe a %d\n", num_act);
|
// printf ("On passe a %d\n", num_act);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool atLeastOneActiveThread () {
|
bool atLeastOneActiveThread ()
|
||||||
|
{
|
||||||
|
|
||||||
return num_act;
|
return num_act;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned numberOfActiveThreads () {
|
unsigned numberOfActiveThreads ()
|
||||||
|
{
|
||||||
|
|
||||||
return num_act;
|
return num_act;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void * launch (void * __arg) {
|
static void * launch (void * __arg)
|
||||||
|
{
|
||||||
|
|
||||||
Thread * thr = (Thread *) __arg;
|
Thread * thr = (Thread *) __arg;
|
||||||
thr -> start ();
|
thr -> start ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads) {
|
void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads)
|
||||||
|
{
|
||||||
|
|
||||||
pthread_t * ll_thr = new pthread_t;
|
pthread_t * ll_thr = new pthread_t;
|
||||||
__ll_threads.push_back (ll_thr);
|
__ll_threads.push_back (ll_thr);
|
||||||
pthread_create (ll_thr, 0, launch, __hl_thread);
|
pthread_create (ll_thr, 0, launch, __hl_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void joinThreads (std :: vector <pthread_t *> & __threads) {
|
void joinThreads (std :: vector <pthread_t *> & __threads)
|
||||||
|
{
|
||||||
|
|
||||||
for (unsigned i = 0; i < __threads.size (); i ++)
|
for (unsigned i = 0; i < __threads.size (); i ++)
|
||||||
pthread_join (* __threads [i], 0);
|
pthread_join (* __threads [i], 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <thread.h>
|
* <thread.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -41,27 +41,28 @@
|
||||||
|
|
||||||
/* A high-level thread */
|
/* A high-level thread */
|
||||||
|
|
||||||
class Thread {
|
class Thread
|
||||||
|
{
|
||||||
public:
|
|
||||||
|
|
||||||
/* Ctor */
|
public:
|
||||||
Thread ();
|
|
||||||
|
|
||||||
/* Dtor */
|
/* Ctor */
|
||||||
virtual ~ Thread ();
|
Thread ();
|
||||||
|
|
||||||
/* Go ! */
|
|
||||||
virtual void start () = 0;
|
|
||||||
|
|
||||||
void setActive ();/* It means the current process is going to send messages soon */
|
/* Dtor */
|
||||||
void setPassive ();/* The current process is not going to perform send operations
|
virtual ~ Thread ();
|
||||||
(but it may receive messages) */
|
|
||||||
|
|
||||||
private :
|
/* Go ! */
|
||||||
|
virtual void start () = 0;
|
||||||
bool act;
|
|
||||||
};
|
void setActive ();/* It means the current process is going to send messages soon */
|
||||||
|
void setPassive ();/* The current process is not going to perform send operations
|
||||||
|
(but it may receive messages) */
|
||||||
|
|
||||||
|
private :
|
||||||
|
|
||||||
|
bool act;
|
||||||
|
};
|
||||||
|
|
||||||
extern void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads);
|
extern void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads);
|
||||||
|
|
||||||
|
|
@ -69,7 +70,7 @@ extern void joinThreads (std :: vector <pthread_t *> & __ll_threads);
|
||||||
|
|
||||||
extern bool atLeastOneActiveThread (); /* It returns 'true' iff at least one process is going
|
extern bool atLeastOneActiveThread (); /* It returns 'true' iff at least one process is going
|
||||||
to send messages */
|
to send messages */
|
||||||
|
|
||||||
extern unsigned numberOfActiveThreads ();
|
extern unsigned numberOfActiveThreads ();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <topology.cpp>
|
* <topology.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -36,13 +36,15 @@
|
||||||
|
|
||||||
#include "topology.h"
|
#include "topology.h"
|
||||||
|
|
||||||
Topology :: ~ Topology () {
|
Topology :: ~ Topology ()
|
||||||
|
{
|
||||||
|
|
||||||
/* Nothing ! */
|
/* Nothing ! */
|
||||||
}
|
}
|
||||||
|
|
||||||
void Topology :: add (Cooperative & __mig) {
|
void Topology :: add (Cooperative & __mig)
|
||||||
|
{
|
||||||
mig.push_back (& __mig) ;
|
|
||||||
}
|
mig.push_back (& __mig) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <topology.h>
|
* <topology.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -41,21 +41,22 @@
|
||||||
|
|
||||||
#include "cooperative.h"
|
#include "cooperative.h"
|
||||||
|
|
||||||
class Topology {
|
class Topology
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~Topology ();
|
virtual ~Topology ();
|
||||||
|
|
||||||
void add (Cooperative & __mig);
|
void add (Cooperative & __mig);
|
||||||
|
|
||||||
virtual void setNeighbors (Cooperative * __mig,
|
virtual void setNeighbors (Cooperative * __mig,
|
||||||
std :: vector <Cooperative *> & __from,
|
std :: vector <Cooperative *> & __from,
|
||||||
std :: vector <Cooperative *> & __to) = 0;
|
std :: vector <Cooperative *> & __to) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
std :: vector <Cooperative *> mig ;
|
std :: vector <Cooperative *> mig ;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peo.h>
|
* <peo.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -114,7 +114,7 @@
|
||||||
//! for nonlinear numerical optimization). Whereas some time-out detection can be used to
|
//! for nonlinear numerical optimization). Whereas some time-out detection can be used to
|
||||||
//! address the former issue, the latter one can be partially overcome if the grain is set to very
|
//! address the former issue, the latter one can be partially overcome if the grain is set to very
|
||||||
//! small values, as individuals will be sent out for evaluations upon request of the workers.</li>
|
//! small values, as individuals will be sent out for evaluations upon request of the workers.</li>
|
||||||
//!
|
//!
|
||||||
//! <li> <i>Distributed evaluation of a single solution</i>. The quality of each solution is evaluated in
|
//! <li> <i>Distributed evaluation of a single solution</i>. The quality of each solution is evaluated in
|
||||||
//! a parallel centralized way. That model is particularly interesting when the evaluation
|
//! a parallel centralized way. That model is particularly interesting when the evaluation
|
||||||
//! function can be itself parallelized as it is CPU time-consuming and/or IO intensive. In
|
//! function can be itself parallelized as it is CPU time-consuming and/or IO intensive. In
|
||||||
|
|
@ -146,11 +146,11 @@
|
||||||
//! <ul>
|
//! <ul>
|
||||||
//! <li><i>Parallel exploration of neighboring candidates</i>. It is a low-level Farmer-Worker model
|
//! <li><i>Parallel exploration of neighboring candidates</i>. It is a low-level Farmer-Worker model
|
||||||
//! that does not alter the behavior of the heuristic. A sequential search computes the same
|
//! that does not alter the behavior of the heuristic. A sequential search computes the same
|
||||||
//! results slower.At the beginning of each iteration, the farmer duplicates the current solution
|
//! results slower.At the beginning of each iteration, the farmer duplicates the current solution
|
||||||
//! between distributed nodes. Each one manages some candidates and the results are returned to the farmer.
|
//! between distributed nodes. Each one manages some candidates and the results are returned to the farmer.
|
||||||
//! The model is efficient if the evaluation of a each solution is time-consuming and/or there are a great
|
//! The model is efficient if the evaluation of a each solution is time-consuming and/or there are a great
|
||||||
//! deal of candidate neighbors to evaluate. This is obviously not applicable to SA since only one candidate
|
//! deal of candidate neighbors to evaluate. This is obviously not applicable to SA since only one candidate
|
||||||
//! is evaluated at each iteration. Likewise, the efficiency of the model for HC is not always guaranteed as
|
//! is evaluated at each iteration. Likewise, the efficiency of the model for HC is not always guaranteed as
|
||||||
//! the number of neighboring solutions to process before finding one that improves the current objective function may
|
//! the number of neighboring solutions to process before finding one that improves the current objective function may
|
||||||
//! be highly variable.</li>
|
//! be highly variable.</li>
|
||||||
//!
|
//!
|
||||||
|
|
@ -278,7 +278,7 @@
|
||||||
//!
|
//!
|
||||||
//! The basisc of the ParadisEO framework philosophy are exposed in a few simple tutorials:
|
//! The basisc of the ParadisEO framework philosophy are exposed in a few simple tutorials:
|
||||||
//! <ul>
|
//! <ul>
|
||||||
//! <li>
|
//! <li>
|
||||||
//! <a href="lesson1/html/main.html" style="text-decoration:none;"> creating a simple ParadisEO evolutionary algorithm</a>;
|
//! <a href="lesson1/html/main.html" style="text-decoration:none;"> creating a simple ParadisEO evolutionary algorithm</a>;
|
||||||
//! </li>
|
//! </li>
|
||||||
//! </ul>
|
//! </ul>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoAggEvalFunc.h>
|
* <peoAggEvalFunc.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -50,9 +50,8 @@
|
||||||
//! </table>
|
//! </table>
|
||||||
//!
|
//!
|
||||||
//! The aggregation object is called in an iterative manner for each of the results obtained by applying partial evaluation functions.
|
//! The aggregation object is called in an iterative manner for each of the results obtained by applying partial evaluation functions.
|
||||||
template< class EOT > class peoAggEvalFunc : public eoBF< EOT&, const typename EOT :: Fitness&, void > {
|
template< class EOT > class peoAggEvalFunc : public eoBF< EOT&, const typename EOT :: Fitness&, void >
|
||||||
|
{};
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoAsyncIslandMig.h>
|
* <peoAsyncIslandMig.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -74,7 +74,7 @@
|
||||||
//! <tr><td>} <b>while</b> ( eaCheckpointContinue( population ) ); </td> <td>// checkpoint operators are applied on the current population, including the migration operator, if any specified </td></tr>
|
//! <tr><td>} <b>while</b> ( eaCheckpointContinue( population ) ); </td> <td>// checkpoint operators are applied on the current population, including the migration operator, if any specified </td></tr>
|
||||||
//! </table>
|
//! </table>
|
||||||
//!
|
//!
|
||||||
//! Constructing an asynchronous island migration model requires having defined (1) a topological migration model,
|
//! Constructing an asynchronous island migration model requires having defined (1) a topological migration model,
|
||||||
//! (2) the control parameters of the migration process, (3) a checkpoint object associated with an evolutionary algorithm,
|
//! (2) the control parameters of the migration process, (3) a checkpoint object associated with an evolutionary algorithm,
|
||||||
//! and (4) an owner object must be set. The owner object must be derived from the <b>Runner</b> class (for example
|
//! and (4) an owner object must be set. The owner object must be derived from the <b>Runner</b> class (for example
|
||||||
//! a peoEA object represents a possible owner).
|
//! a peoEA object represents a possible owner).
|
||||||
|
|
@ -82,14 +82,14 @@
|
||||||
//!
|
//!
|
||||||
//! <ol>
|
//! <ol>
|
||||||
//! <li> topological model to be followed when performing migrations: <br/>
|
//! <li> topological model to be followed when performing migrations: <br/>
|
||||||
//! <br/>
|
//! <br/>
|
||||||
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
|
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
|
||||||
//! <tr><td>RingTopology migTopology; </td> <td>// a simple ring topological model - each island communicates with two other islands</td></tr>
|
//! <tr><td>RingTopology migTopology; </td> <td>// a simple ring topological model - each island communicates with two other islands</td></tr>
|
||||||
//! </table>
|
//! </table>
|
||||||
//! </li>
|
//! </li>
|
||||||
//!
|
//!
|
||||||
//! <li> the continuation criterion, selection and replacement strategy etc. are defined: <br/>
|
//! <li> the continuation criterion, selection and replacement strategy etc. are defined: <br/>
|
||||||
//! <br/>
|
//! <br/>
|
||||||
//! <table style="border:none; border-spacing:0px; font-size:8pt;" border="0">
|
//! <table style="border:none; border-spacing:0px; font-size:8pt;" border="0">
|
||||||
//! <tr><td>eoPop< EOT > population( POP_SIZE, popInitializer ); </td> <td>// population of individuals to be used for the evolutionary algorithm</td></tr>
|
//! <tr><td>eoPop< EOT > population( POP_SIZE, popInitializer ); </td> <td>// population of individuals to be used for the evolutionary algorithm</td></tr>
|
||||||
//! <tr><td> </td> <td> </td></tr>
|
//! <tr><td> </td> <td> </td></tr>
|
||||||
|
|
@ -98,16 +98,16 @@
|
||||||
//! <tr><td>eoSelectNumber< EOT > migSelect( migSelectStrategy, MIG_SIZE ); </td> <td>// number of individuals to be selected using the specified strategy</td></tr>
|
//! <tr><td>eoSelectNumber< EOT > migSelect( migSelectStrategy, MIG_SIZE ); </td> <td>// number of individuals to be selected using the specified strategy</td></tr>
|
||||||
//! <tr><td>eoPlusReplacement< EOT > migReplace; </td> <td>// immigration strategy - the worse individuals in the destination population are replaced by the immigrant individuals</td></tr>
|
//! <tr><td>eoPlusReplacement< EOT > migReplace; </td> <td>// immigration strategy - the worse individuals in the destination population are replaced by the immigrant individuals</td></tr>
|
||||||
//! <tr><td> </td> <td> </td></tr>
|
//! <tr><td> </td> <td> </td></tr>
|
||||||
//! <tr><td>peoAsyncIslandMig< EOT > asyncMigration(
|
//! <tr><td>peoAsyncIslandMig< EOT > asyncMigration(
|
||||||
//! <br/> migCont, migSelect, migReplace, migTopology,
|
//! <br/> migCont, migSelect, migReplace, migTopology,
|
||||||
//! <br/> population, population
|
//! <br/> population, population
|
||||||
//! <br/> ); </td>
|
//! <br/> ); </td>
|
||||||
//! <td>// asynchronous migration object - the emigrant individuals are selected from the same from population in which the immigrant individuals are being integrated </td></tr>
|
//! <td>// asynchronous migration object - the emigrant individuals are selected from the same from population in which the immigrant individuals are being integrated </td></tr>
|
||||||
//! </table>
|
//! </table>
|
||||||
//! </li>
|
//! </li>
|
||||||
//!
|
//!
|
||||||
//! <li> creation of a checkpoint object as part of the definition of an evolutionary algoritm (details of th EA not given as being out of scope): <br/>
|
//! <li> creation of a checkpoint object as part of the definition of an evolutionary algoritm (details of th EA not given as being out of scope): <br/>
|
||||||
//! <br/>
|
//! <br/>
|
||||||
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
|
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
|
||||||
//! <tr><td>... </td> <td> </td></tr>
|
//! <tr><td>... </td> <td> </td></tr>
|
||||||
//! <tr><td>eoGenContinue< EOT > eaCont( NUM_GEN ); </td> <td>// the evolutionary algorithm will stop after NUM_GEN generations</td></tr>
|
//! <tr><td>eoGenContinue< EOT > eaCont( NUM_GEN ); </td> <td>// the evolutionary algorithm will stop after NUM_GEN generations</td></tr>
|
||||||
|
|
@ -119,7 +119,7 @@
|
||||||
//! </li>
|
//! </li>
|
||||||
//!
|
//!
|
||||||
//! <li> definition of an owner evolutionary algorithm (an object inheriting the <b>Runner</b> class): <br/>
|
//! <li> definition of an owner evolutionary algorithm (an object inheriting the <b>Runner</b> class): <br/>
|
||||||
//! <br/>
|
//! <br/>
|
||||||
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
|
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
|
||||||
//! <tr><td>peoEA< EOT > eaAlg( eaCheckpointContinue, eaPopEval, eaSelect, eaTransform, eaReplace); </td> <td>// evolutionary algorithm having as checkpoint the eaCheckpointContinue object defined above </td></tr>
|
//! <tr><td>peoEA< EOT > eaAlg( eaCheckpointContinue, eaPopEval, eaSelect, eaTransform, eaReplace); </td> <td>// evolutionary algorithm having as checkpoint the eaCheckpointContinue object defined above </td></tr>
|
||||||
//! <tr><td>asyncMigration.setOwner( eaAlg ); </td> <td>// setting the evolutionary algorithm as owner of the migration object </td></tr>
|
//! <tr><td>asyncMigration.setOwner( eaAlg ); </td> <td>// setting the evolutionary algorithm as owner of the migration object </td></tr>
|
||||||
|
|
@ -137,149 +137,157 @@
|
||||||
//! islands requires the reiteration of the steps 2 through 4 for creating distinct algorithms, with distinct populations and
|
//! islands requires the reiteration of the steps 2 through 4 for creating distinct algorithms, with distinct populations and
|
||||||
//! the associated distinctly parametrized migration objects. The interconnecting element is the underlying topology, defined at step 1
|
//! the associated distinctly parametrized migration objects. The interconnecting element is the underlying topology, defined at step 1
|
||||||
//! (the same C++ migTopology object has to be passed as parameter for all the migration objects, in order to interconnect them).
|
//! (the same C++ migTopology object has to be passed as parameter for all the migration objects, in order to interconnect them).
|
||||||
template< class EOT > class peoAsyncIslandMig : public Cooperative, public eoUpdater {
|
template< class EOT > class peoAsyncIslandMig : public Cooperative, public eoUpdater
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Constructor for the peoAsyncIslandMig class; the characteristics of the migration model are defined
|
//! Constructor for the peoAsyncIslandMig class; the characteristics of the migration model are defined
|
||||||
//! through the specified parameters - out of the box objects provided in EO, etc., or custom, derived objects may be passed as parameters.
|
//! through the specified parameters - out of the box objects provided in EO, etc., or custom, derived objects may be passed as parameters.
|
||||||
//!
|
//!
|
||||||
//! @param eoContinue< EOT >& __cont - continuation criterion specifying whether the migration is performed or not;
|
//! @param eoContinue< EOT >& __cont - continuation criterion specifying whether the migration is performed or not;
|
||||||
//! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of emigrant individuals out of the source population;
|
//! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of emigrant individuals out of the source population;
|
||||||
//! @param eoReplacement< EOT >& __replace - replacement strategy used for integrating the immigrant individuals in the destination population;
|
//! @param eoReplacement< EOT >& __replace - replacement strategy used for integrating the immigrant individuals in the destination population;
|
||||||
//! @param Topology& __topology - topological model to be followed when performing migrations;
|
//! @param Topology& __topology - topological model to be followed when performing migrations;
|
||||||
//! @param eoPop< EOT >& __source - source population from which the emigrant individuals are selected;
|
//! @param eoPop< EOT >& __source - source population from which the emigrant individuals are selected;
|
||||||
//! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated.
|
//! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated.
|
||||||
peoAsyncIslandMig(
|
peoAsyncIslandMig(
|
||||||
eoContinue< EOT >& __cont,
|
eoContinue< EOT >& __cont,
|
||||||
eoSelect< EOT >& __select,
|
eoSelect< EOT >& __select,
|
||||||
eoReplacement< EOT >& __replace,
|
eoReplacement< EOT >& __replace,
|
||||||
Topology& __topology,
|
Topology& __topology,
|
||||||
eoPop< EOT >& __source,
|
eoPop< EOT >& __source,
|
||||||
eoPop< EOT >& __destination
|
eoPop< EOT >& __destination
|
||||||
);
|
);
|
||||||
|
|
||||||
//! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected
|
//! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected
|
||||||
//! from the source population and sent to the next island (defined by the topology object) while the immigrant
|
//! from the source population and sent to the next island (defined by the topology object) while the immigrant
|
||||||
//! individuals are integrated in the destination population. There is no need to explicitly call the function - the
|
//! individuals are integrated in the destination population. There is no need to explicitly call the function - the
|
||||||
//! wrapper checkpoint object (please refer to the above example) will perform the call when required.
|
//! wrapper checkpoint object (please refer to the above example) will perform the call when required.
|
||||||
void operator()();
|
void operator()();
|
||||||
|
|
||||||
//! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function.
|
//! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function.
|
||||||
void pack();
|
void pack();
|
||||||
//! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function.
|
//! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function.
|
||||||
void unpack();
|
void unpack();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void emigrate();
|
void emigrate();
|
||||||
void immigrate();
|
void immigrate();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
eoContinue< EOT >& cont; // continuator
|
eoContinue< EOT >& cont; // continuator
|
||||||
eoSelect< EOT >& select; // the selection strategy
|
eoSelect< EOT >& select; // the selection strategy
|
||||||
eoReplacement< EOT >& replace; // the replacement strategy
|
eoReplacement< EOT >& replace; // the replacement strategy
|
||||||
Topology& topology; // the neighboring topology
|
Topology& topology; // the neighboring topology
|
||||||
|
|
||||||
// source and destination populations
|
// source and destination populations
|
||||||
eoPop< EOT >& source;
|
eoPop< EOT >& source;
|
||||||
eoPop< EOT >& destination;
|
eoPop< EOT >& destination;
|
||||||
|
|
||||||
// immigrants & emigrants in the queue
|
// immigrants & emigrants in the queue
|
||||||
std :: queue< eoPop< EOT > > imm;
|
std :: queue< eoPop< EOT > > imm;
|
||||||
std :: queue< eoPop< EOT > > em;
|
std :: queue< eoPop< EOT > > em;
|
||||||
|
|
||||||
std :: queue< Cooperative* > coop_em;
|
std :: queue< Cooperative* > coop_em;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > peoAsyncIslandMig< EOT > :: peoAsyncIslandMig(
|
template< class EOT > peoAsyncIslandMig< EOT > :: peoAsyncIslandMig(
|
||||||
|
|
||||||
eoContinue< EOT >& __cont,
|
eoContinue< EOT >& __cont,
|
||||||
eoSelect< EOT >& __select,
|
eoSelect< EOT >& __select,
|
||||||
eoReplacement< EOT >& __replace,
|
eoReplacement< EOT >& __replace,
|
||||||
Topology& __topology,
|
Topology& __topology,
|
||||||
eoPop< EOT >& __source,
|
eoPop< EOT >& __source,
|
||||||
eoPop< EOT >& __destination
|
eoPop< EOT >& __destination
|
||||||
|
|
||||||
) : cont( __cont ), select( __select ), replace( __replace ), topology( __topology ), source( __source ), destination( __destination )
|
) : cont( __cont ), select( __select ), replace( __replace ), topology( __topology ), source( __source ), destination( __destination )
|
||||||
{
|
{
|
||||||
|
|
||||||
__topology.add( *this );
|
__topology.add( *this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoAsyncIslandMig< EOT > :: pack()
|
template< class EOT > void peoAsyncIslandMig< EOT > :: pack()
|
||||||
{
|
{
|
||||||
|
|
||||||
lock(); {
|
lock ();
|
||||||
|
{
|
||||||
|
|
||||||
:: pack( coop_em.front()->getKey() );
|
:: pack( coop_em.front()->getKey() );
|
||||||
:: pack( em.front() );
|
:: pack( em.front() );
|
||||||
coop_em.pop();
|
coop_em.pop();
|
||||||
em.pop();
|
em.pop();
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoAsyncIslandMig< EOT > :: unpack()
|
template< class EOT > void peoAsyncIslandMig< EOT > :: unpack()
|
||||||
{
|
{
|
||||||
|
|
||||||
lock(); {
|
lock ();
|
||||||
|
{
|
||||||
|
|
||||||
eoPop< EOT > mig;
|
eoPop< EOT > mig;
|
||||||
:: unpack( mig );
|
:: unpack( mig );
|
||||||
imm.push( mig );
|
imm.push( mig );
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoAsyncIslandMig< EOT > :: emigrate()
|
template< class EOT > void peoAsyncIslandMig< EOT > :: emigrate()
|
||||||
{
|
{
|
||||||
|
|
||||||
std :: vector< Cooperative* >in, out;
|
std :: vector< Cooperative* >in, out;
|
||||||
topology.setNeighbors( this, in, out );
|
topology.setNeighbors( this, in, out );
|
||||||
|
|
||||||
for ( unsigned i = 0; i < out.size(); i++ ) {
|
for ( unsigned i = 0; i < out.size(); i++ )
|
||||||
|
{
|
||||||
eoPop< EOT > mig;
|
|
||||||
select( source, mig );
|
eoPop< EOT > mig;
|
||||||
em.push( mig );
|
select( source, mig );
|
||||||
coop_em.push( out[i] );
|
em.push( mig );
|
||||||
send( out[i] );
|
coop_em.push( out[i] );
|
||||||
printDebugMessage( "sending some emigrants." );
|
send( out[i] );
|
||||||
}
|
printDebugMessage( "sending some emigrants." );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoAsyncIslandMig< EOT > :: immigrate()
|
template< class EOT > void peoAsyncIslandMig< EOT > :: immigrate()
|
||||||
{
|
{
|
||||||
|
|
||||||
lock(); {
|
lock ();
|
||||||
|
{
|
||||||
|
|
||||||
while ( !imm.empty() ) {
|
while ( !imm.empty() )
|
||||||
|
{
|
||||||
|
|
||||||
replace( destination, imm.front() );
|
replace( destination, imm.front() );
|
||||||
imm.pop();
|
imm.pop();
|
||||||
printDebugMessage( "receiving some immigrants." );
|
printDebugMessage( "receiving some immigrants." );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoAsyncIslandMig< EOT > :: operator()() {
|
template< class EOT > void peoAsyncIslandMig< EOT > :: operator()()
|
||||||
|
{
|
||||||
|
|
||||||
if ( !cont( source ) ) {
|
if ( !cont( source ) )
|
||||||
|
{
|
||||||
|
|
||||||
emigrate(); // sending emigrants
|
emigrate(); // sending emigrants
|
||||||
immigrate(); // receiving immigrants
|
immigrate(); // receiving immigrants
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoEA.h>
|
* <peoEA.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -53,7 +53,7 @@
|
||||||
//! The peoEA class offers an elementary evolutionary algorithm implementation. In addition, as compared
|
//! The peoEA class offers an elementary evolutionary algorithm implementation. In addition, as compared
|
||||||
//! with the algorithms provided by the EO framework, the peoEA class has the underlying necessary structure
|
//! with the algorithms provided by the EO framework, the peoEA class has the underlying necessary structure
|
||||||
//! for including, for example, parallel evaluation and parallel transformation operators, migration operators
|
//! for including, for example, parallel evaluation and parallel transformation operators, migration operators
|
||||||
//! etc. Although there is no restriction on using the algorithms provided by the EO framework, the drawback resides
|
//! etc. Although there is no restriction on using the algorithms provided by the EO framework, the drawback resides
|
||||||
//! in the fact that the EO implementation is exclusively sequential and, in consequence, no parallelism is provided.
|
//! in the fact that the EO implementation is exclusively sequential and, in consequence, no parallelism is provided.
|
||||||
//! A simple example for constructing a peoEA object:
|
//! A simple example for constructing a peoEA object:
|
||||||
//!
|
//!
|
||||||
|
|
@ -79,95 +79,100 @@
|
||||||
//! <tr><td>eaAlg( population ); </td> <td>// specifying the initial population for the algorithm </td></tr>
|
//! <tr><td>eaAlg( population ); </td> <td>// specifying the initial population for the algorithm </td></tr>
|
||||||
//! <tr><td>... </td> <td> </td></tr>
|
//! <tr><td>... </td> <td> </td></tr>
|
||||||
//! </table>
|
//! </table>
|
||||||
template < class EOT > class peoEA : public Runner {
|
template < class EOT > class peoEA : public Runner
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Constructor for the evolutionary algorithm object - several basic parameters have to be specified,
|
//! Constructor for the evolutionary algorithm object - several basic parameters have to be specified,
|
||||||
//! allowing for different levels of parallelism. Depending on the requirements, a sequential or a parallel
|
//! allowing for different levels of parallelism. Depending on the requirements, a sequential or a parallel
|
||||||
//! evaluation operator may be specified or, in the same manner, a sequential or a parallel transformation
|
//! evaluation operator may be specified or, in the same manner, a sequential or a parallel transformation
|
||||||
//! operator may be given as parameter. Out of the box objects may be provided, from the EO package, for example,
|
//! operator may be given as parameter. Out of the box objects may be provided, from the EO package, for example,
|
||||||
//! or custom defined ones may be specified, provided that they are derived from the correct base classes.
|
//! or custom defined ones may be specified, provided that they are derived from the correct base classes.
|
||||||
//!
|
//!
|
||||||
//! @param eoContinue< EOT >& __cont - continuation criterion specifying whether the algorithm should continue or not;
|
//! @param eoContinue< EOT >& __cont - continuation criterion specifying whether the algorithm should continue or not;
|
||||||
//! @param peoPopEval< EOT >& __pop_eval - evaluation operator; it allows the specification of parallel evaluation operators, aggregate evaluation functions, etc.;
|
//! @param peoPopEval< EOT >& __pop_eval - evaluation operator; it allows the specification of parallel evaluation operators, aggregate evaluation functions, etc.;
|
||||||
//! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of offspring individuals;
|
//! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of offspring individuals;
|
||||||
//! @param peoTransform< EOT >& __trans - transformation operator, i.e. crossover and mutation; allows for sequential or parallel transform;
|
//! @param peoTransform< EOT >& __trans - transformation operator, i.e. crossover and mutation; allows for sequential or parallel transform;
|
||||||
//! @param eoReplacement< EOT >& __replace - replacement strategy for integrating the offspring individuals in the initial population;
|
//! @param eoReplacement< EOT >& __replace - replacement strategy for integrating the offspring individuals in the initial population;
|
||||||
peoEA(
|
peoEA(
|
||||||
eoContinue< EOT >& __cont,
|
eoContinue< EOT >& __cont,
|
||||||
peoPopEval< EOT >& __pop_eval,
|
peoPopEval< EOT >& __pop_eval,
|
||||||
eoSelect< EOT >& __select,
|
eoSelect< EOT >& __select,
|
||||||
peoTransform< EOT >& __trans,
|
peoTransform< EOT >& __trans,
|
||||||
eoReplacement< EOT >& __replace
|
eoReplacement< EOT >& __replace
|
||||||
);
|
);
|
||||||
|
|
||||||
//! Evolutionary algorithm function - a side effect of the fact that the class is derived from the <b>Runner</b> class,
|
//! Evolutionary algorithm function - a side effect of the fact that the class is derived from the <b>Runner</b> class,
|
||||||
//! thus requiring the existence of a <i>run</i> function, the algorithm being executed on a distinct thread.
|
//! thus requiring the existence of a <i>run</i> function, the algorithm being executed on a distinct thread.
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
//! Function operator for specifying the population to be associated with the algorithm.
|
|
||||||
//!
|
|
||||||
//! @param eoPop< EOT >& __pop - initial population of the algorithm, to be iteratively evolved;
|
|
||||||
void operator()( eoPop< EOT >& __pop );
|
|
||||||
|
|
||||||
private:
|
//! Function operator for specifying the population to be associated with the algorithm.
|
||||||
|
//!
|
||||||
|
//! @param eoPop< EOT >& __pop - initial population of the algorithm, to be iteratively evolved;
|
||||||
|
void operator()( eoPop< EOT >& __pop );
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
eoContinue< EOT >& cont;
|
eoContinue< EOT >& cont;
|
||||||
peoPopEval< EOT >& pop_eval;
|
peoPopEval< EOT >& pop_eval;
|
||||||
eoSelect< EOT >& select;
|
eoSelect< EOT >& select;
|
||||||
peoTransform< EOT >& trans;
|
peoTransform< EOT >& trans;
|
||||||
eoReplacement< EOT >& replace;
|
eoReplacement< EOT >& replace;
|
||||||
eoPop< EOT >* pop;
|
eoPop< EOT >* pop;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template < class EOT > peoEA< EOT > :: peoEA(
|
template < class EOT > peoEA< EOT > :: peoEA(
|
||||||
|
|
||||||
eoContinue< EOT >& __cont,
|
eoContinue< EOT >& __cont,
|
||||||
peoPopEval< EOT >& __pop_eval,
|
peoPopEval< EOT >& __pop_eval,
|
||||||
eoSelect< EOT >& __select,
|
eoSelect< EOT >& __select,
|
||||||
peoTransform< EOT >& __trans,
|
peoTransform< EOT >& __trans,
|
||||||
eoReplacement< EOT >& __replace
|
eoReplacement< EOT >& __replace
|
||||||
|
|
||||||
) : cont( __cont ), pop_eval( __pop_eval ), select( __select ), trans( __trans ), replace( __replace )
|
) : cont( __cont ), pop_eval( __pop_eval ), select( __select ), trans( __trans ), replace( __replace )
|
||||||
{
|
{
|
||||||
|
|
||||||
trans.setOwner( *this );
|
trans.setOwner( *this );
|
||||||
pop_eval.setOwner( *this );
|
pop_eval.setOwner( *this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoEA< EOT > :: operator ()( eoPop< EOT >& __pop ) {
|
template< class EOT > void peoEA< EOT > :: operator ()( eoPop< EOT >& __pop )
|
||||||
|
{
|
||||||
|
|
||||||
pop = &__pop;
|
pop = &__pop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoEA< EOT > :: run() {
|
template< class EOT > void peoEA< EOT > :: run()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage( "performing the first evaluation of the population." );
|
printDebugMessage( "performing the first evaluation of the population." );
|
||||||
pop_eval( *pop );
|
pop_eval( *pop );
|
||||||
|
|
||||||
do {
|
|
||||||
|
|
||||||
eoPop< EOT > off;
|
do
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage( "performing the selection step." );
|
eoPop< EOT > off;
|
||||||
select( *pop, off );
|
|
||||||
trans( off );
|
|
||||||
|
|
||||||
printDebugMessage( "performing the evaluation of the population." );
|
printDebugMessage( "performing the selection step." );
|
||||||
|
select( *pop, off );
|
||||||
|
trans( off );
|
||||||
|
|
||||||
pop_eval( off );
|
printDebugMessage( "performing the evaluation of the population." );
|
||||||
|
|
||||||
printDebugMessage( "performing the replacement of the population." );
|
pop_eval( off );
|
||||||
replace( *pop, off );
|
|
||||||
|
|
||||||
printDebugMessage( "deciding of the continuation." );
|
printDebugMessage( "performing the replacement of the population." );
|
||||||
|
replace( *pop, off );
|
||||||
} while ( cont( *pop ) );
|
|
||||||
|
printDebugMessage( "deciding of the continuation." );
|
||||||
|
|
||||||
|
}
|
||||||
|
while ( cont( *pop ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoEvalFunc.h>
|
* <peoEvalFunc.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, INRIA, 2007
|
* (C) OPAC Team, INRIA, 2007
|
||||||
|
|
@ -42,19 +42,21 @@ template< class EOT, class FitT = EOT::Fitness, class FunctionArg = const EOT& >
|
||||||
#else
|
#else
|
||||||
template< class EOT, class FitT = typename EOT::Fitness, class FunctionArg = const EOT& >
|
template< class EOT, class FitT = typename EOT::Fitness, class FunctionArg = const EOT& >
|
||||||
#endif
|
#endif
|
||||||
struct peoEvalFunc: public eoEvalFunc<EOT> {
|
struct peoEvalFunc: public eoEvalFunc<EOT>
|
||||||
|
|
||||||
peoEvalFunc( FitT (* _eval)( FunctionArg ) )
|
|
||||||
: eoEvalFunc<EOT>(), evalFunc( _eval ) {};
|
|
||||||
|
|
||||||
virtual void operator() ( EOT & _peo )
|
|
||||||
{
|
{
|
||||||
_peo.fitness((*evalFunc)( _peo ));
|
|
||||||
};
|
peoEvalFunc( FitT (* _eval)( FunctionArg ) )
|
||||||
|
: eoEvalFunc<EOT>(), evalFunc( _eval )
|
||||||
private:
|
{};
|
||||||
|
|
||||||
|
virtual void operator() ( EOT & _peo )
|
||||||
|
{
|
||||||
|
_peo.fitness((*evalFunc)( _peo ));
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
FitT (* evalFunc )( FunctionArg );
|
FitT (* evalFunc )( FunctionArg );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoEvalFuncPSO.h>
|
* <peoEvalFuncPSO.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, INRIA, 2007
|
* (C) OPAC Team, INRIA, 2007
|
||||||
|
|
@ -42,27 +42,29 @@
|
||||||
|
|
||||||
//! peoEvalFuncPSO: This class
|
//! peoEvalFuncPSO: This class
|
||||||
//! takes an existing function pointer and converts it into a evaluation
|
//! takes an existing function pointer and converts it into a evaluation
|
||||||
//! function class.
|
//! function class.
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
template< class POT, class FitT = POT::Fitness, class FunctionArg = const POT& >
|
template< class POT, class FitT = POT::Fitness, class FunctionArg = const POT& >
|
||||||
#else
|
#else
|
||||||
template< class POT, class FitT = typename POT::Fitness, class FunctionArg = const POT& >
|
template< class POT, class FitT = typename POT::Fitness, class FunctionArg = const POT& >
|
||||||
#endif
|
#endif
|
||||||
struct peoEvalFuncPSO: public eoEvalFunc<POT> {
|
struct peoEvalFuncPSO: public eoEvalFunc<POT>
|
||||||
|
|
||||||
peoEvalFuncPSO( FitT (* _eval)( FunctionArg ) )
|
|
||||||
: eoEvalFunc<POT>(), evalFunc( _eval ) {};
|
|
||||||
|
|
||||||
//!Applies the evaluation function to a PEO
|
|
||||||
virtual void operator() ( POT & _peo )
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
peoEvalFuncPSO( FitT (* _eval)( FunctionArg ) )
|
||||||
|
: eoEvalFunc<POT>(), evalFunc( _eval )
|
||||||
|
{};
|
||||||
|
|
||||||
|
//!Applies the evaluation function to a PEO
|
||||||
|
virtual void operator() ( POT & _peo )
|
||||||
|
{
|
||||||
_peo.fitness((*evalFunc)( _peo ));
|
_peo.fitness((*evalFunc)( _peo ));
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FitT (* evalFunc )( FunctionArg );
|
FitT (* evalFunc )( FunctionArg );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoInitializer.h>
|
* <peoInitializer.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, INRIA, 2007
|
* (C) OPAC Team, INRIA, 2007
|
||||||
|
|
@ -44,55 +44,55 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <class POT> class peoInitializer : public eoInitializerBase <POT>
|
template <class POT> class peoInitializer : public eoInitializerBase <POT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
//! Constructor
|
|
||||||
//! @param _proc Evaluation function
|
//! Constructor
|
||||||
//! @param _initVelo Initialization of the velocity
|
//! @param _proc Evaluation function
|
||||||
//! @param _initBest Initialization of the best
|
//! @param _initVelo Initialization of the velocity
|
||||||
//! @param _pop Population
|
//! @param _initBest Initialization of the best
|
||||||
peoInitializer(
|
//! @param _pop Population
|
||||||
peoPopEval< POT >& _proc,
|
peoInitializer(
|
||||||
eoVelocityInit < POT > &_initVelo,
|
peoPopEval< POT >& _proc,
|
||||||
eoParticleBestInit <POT> &_initBest,
|
eoVelocityInit < POT > &_initVelo,
|
||||||
eoPop < POT > &_pop
|
eoParticleBestInit <POT> &_initBest,
|
||||||
) : proc(_proc), initVelo(_initVelo), initBest(_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";
|
pop = &_pop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Give the name of the class
|
||||||
|
//! @return The name of the class
|
||||||
|
virtual std::string className (void) const
|
||||||
|
{
|
||||||
|
return "peoInitializer";
|
||||||
|
}
|
||||||
|
|
||||||
//! void operator ()
|
//! void operator ()
|
||||||
//! Parallel initialization of the population
|
//! Parallel initialization of the population
|
||||||
virtual void operator()()
|
virtual void operator()()
|
||||||
{
|
{
|
||||||
proc(*pop);
|
proc(*pop);
|
||||||
apply < POT > (initVelo, *pop);
|
apply < POT > (initVelo, *pop);
|
||||||
apply < POT > (initBest, *pop);
|
apply < POT > (initBest, *pop);
|
||||||
}
|
}
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@param proc First evaluation
|
@param proc First evaluation
|
||||||
@param initVelo Initialization of the velocity
|
@param initVelo Initialization of the velocity
|
||||||
@param initBest Initialization of the best
|
@param initBest Initialization of the best
|
||||||
@param pop Population
|
@param pop Population
|
||||||
*/
|
*/
|
||||||
peoPopEval< POT >& proc;
|
peoPopEval< POT >& proc;
|
||||||
eoVelocityInit < POT > & initVelo;
|
eoVelocityInit < POT > & initVelo;
|
||||||
eoParticleBestInit <POT> & initBest;
|
eoParticleBestInit <POT> & initBest;
|
||||||
eoPop <POT> * pop;
|
eoPop <POT> * pop;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoNoAggEvalFunc.h>
|
* <peoNoAggEvalFunc.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -44,18 +44,20 @@
|
||||||
//! The peoNoAggEvalFunc class does nothing more than an association between a fitness value and a specified individual.
|
//! The peoNoAggEvalFunc class does nothing more than an association between a fitness value and a specified individual.
|
||||||
//! The class is provided as a mean of declaring that no aggregation is required for the evaluation function - the fitness
|
//! The class is provided as a mean of declaring that no aggregation is required for the evaluation function - the fitness
|
||||||
//! value is explicitly specified.
|
//! value is explicitly specified.
|
||||||
template< class EOT > class peoNoAggEvalFunc : public peoAggEvalFunc< EOT > {
|
template< class EOT > class peoNoAggEvalFunc : public peoAggEvalFunc< EOT >
|
||||||
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
//! Operator which sets as fitness the <b>__fit</b> value for the <b>__sol</b> individual
|
//! Operator which sets as fitness the <b>__fit</b> value for the <b>__sol</b> individual
|
||||||
void operator()( EOT& __sol, const typename EOT :: Fitness& __fit );
|
void operator()( EOT& __sol, const typename EOT :: Fitness& __fit );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoNoAggEvalFunc< EOT > :: operator()( EOT& __sol, const typename EOT :: Fitness& __fit ) {
|
template< class EOT > void peoNoAggEvalFunc< EOT > :: operator()( EOT& __sol, const typename EOT :: Fitness& __fit )
|
||||||
|
{
|
||||||
|
|
||||||
__sol.fitness( __fit );
|
__sol.fitness( __fit );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
* (c) OPAC Team, October 2007
|
* (c) OPAC Team, October 2007
|
||||||
*
|
*
|
||||||
* Clive Canape
|
* Clive Canape
|
||||||
*
|
*
|
||||||
* This software is governed by the CeCILL license under French law and
|
* This software is governed by the CeCILL license under French law and
|
||||||
* abiding by the rules of distribution of free software. You can use,
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
|
@ -29,96 +29,101 @@
|
||||||
* knowledge of the CeCILL license and that you accept its terms.
|
* knowledge of the CeCILL license and that you accept its terms.
|
||||||
*
|
*
|
||||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
* Contact: clive.canape@inria.fr
|
* Contact: clive.canape@inria.fr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __peoPSO_h
|
#ifndef __peoPSO_h
|
||||||
#define __peoPSO_h
|
#define __peoPSO_h
|
||||||
|
|
||||||
#include <eoContinue.h>
|
#include <eoContinue.h>
|
||||||
#include <eoEvalFunc.h>
|
#include <eoEvalFunc.h>
|
||||||
#include <eoPopEvalFunc.h>
|
#include <eoPopEvalFunc.h>
|
||||||
#include <eoPSO.h>
|
#include <eoPSO.h>
|
||||||
#include <eoVelocity.h>
|
#include <eoVelocity.h>
|
||||||
#include <eoFlight.h>
|
#include <eoFlight.h>
|
||||||
#include "peoPopEval.h"
|
#include "peoPopEval.h"
|
||||||
#include "core/runner.h"
|
#include "core/runner.h"
|
||||||
#include "core/peo_debug.h"
|
#include "core/peo_debug.h"
|
||||||
|
|
||||||
//! Class providing an elementary ParadisEO evolutionary algorithm.
|
//! Class providing an elementary ParadisEO evolutionary algorithm.
|
||||||
|
|
||||||
//! The peoPSO class offers an elementary Particle Swarm Optimization implementation. In addition, as compared
|
//! The peoPSO class offers an elementary Particle Swarm Optimization implementation. In addition, as compared
|
||||||
//! with the algorithms provided by the EO framework, the peoPSO class has the underlying necessary structure
|
//! with the algorithms provided by the EO framework, the peoPSO class has the underlying necessary structure
|
||||||
//! for including, for example, parallel evaluation, etc.
|
//! for including, for example, parallel evaluation, etc.
|
||||||
|
|
||||||
template < class POT > class peoPSO : public Runner {
|
template < class POT > class peoPSO : public Runner
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
//! Constructor for the Particle Swarm Optimization
|
//! Constructor for the Particle Swarm Optimization
|
||||||
//! @param eoContinue< POT >& __cont - continuation criterion specifying whether the algorithm should continue or not;
|
//! @param eoContinue< POT >& __cont - continuation criterion specifying whether the algorithm should continue or not;
|
||||||
//! @param peoPopEval< POT >& __pop_eval - evaluation operator; it allows the specification of parallel evaluation operators, aggregate evaluation functions, etc.;
|
//! @param peoPopEval< POT >& __pop_eval - evaluation operator; it allows the specification of parallel evaluation operators, aggregate evaluation functions, etc.;
|
||||||
//! @param eoVelocity< POT >& __velocity - velocity operator;
|
//! @param eoVelocity< POT >& __velocity - velocity operator;
|
||||||
//! @param eoFlight< POT >& __flight - flight operator;
|
//! @param eoFlight< POT >& __flight - flight operator;
|
||||||
peoPSO(
|
peoPSO(
|
||||||
eoInitializerBase <POT> & _Init,
|
eoInitializerBase <POT> & _Init,
|
||||||
eoContinue< POT >& __cont,
|
eoContinue< POT >& __cont,
|
||||||
peoPopEval< POT >& __pop_eval,
|
peoPopEval< POT >& __pop_eval,
|
||||||
eoVelocity < POT > &_velocity,
|
eoVelocity < POT > &_velocity,
|
||||||
eoFlight < POT > &_flight);
|
eoFlight < POT > &_flight);
|
||||||
|
|
||||||
//! Particle Swarm Optimization function - a side effect of the fact that the class is derived from the Runner class
|
//! Particle Swarm Optimization function - a side effect of the fact that the class is derived from the Runner class
|
||||||
//! thus requiring the existence of a run function, the algorithm being executed on a distinct thread.
|
//! thus requiring the existence of a run function, the algorithm being executed on a distinct thread.
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
//! Function operator for specifying the population to be associated with the algorithm.
|
|
||||||
void operator()( eoPop< POT >& __pop );
|
|
||||||
|
|
||||||
private:
|
//! Function operator for specifying the population to be associated with the algorithm.
|
||||||
|
void operator()( eoPop< POT >& __pop );
|
||||||
|
|
||||||
eoInitializerBase <POT> & Init;
|
private:
|
||||||
eoContinue< POT >& cont;
|
|
||||||
peoPopEval< POT >& pop_eval;
|
eoInitializerBase <POT> & Init;
|
||||||
eoPop< POT >* pop;
|
eoContinue< POT >& cont;
|
||||||
eoVelocity < POT > &velocity;
|
peoPopEval< POT >& pop_eval;
|
||||||
eoFlight < POT > &flight;
|
eoPop< POT >* pop;
|
||||||
};
|
eoVelocity < POT > &velocity;
|
||||||
|
eoFlight < POT > &flight;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template < class POT > peoPSO< POT > :: peoPSO(
|
template < class POT > peoPSO< POT > :: peoPSO(
|
||||||
eoInitializerBase <POT> & _Init,
|
eoInitializerBase <POT> & _Init,
|
||||||
eoContinue< POT >& __cont,
|
eoContinue< POT >& __cont,
|
||||||
peoPopEval< POT >& __pop_eval,
|
peoPopEval< POT >& __pop_eval,
|
||||||
eoVelocity < POT > &__velocity,
|
eoVelocity < POT > &__velocity,
|
||||||
eoFlight < POT > &__flight
|
eoFlight < POT > &__flight
|
||||||
) : Init(_Init),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 );
|
pop_eval.setOwner( *this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class POT > void peoPSO< POT > :: operator ()( eoPop< POT >& __pop ) {
|
template< class POT > void peoPSO< POT > :: operator ()( eoPop< POT >& __pop )
|
||||||
|
{
|
||||||
|
|
||||||
pop = &__pop;
|
pop = &__pop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class POT > void peoPSO< POT > :: run() {
|
template< class POT > void peoPSO< POT > :: run()
|
||||||
|
{
|
||||||
|
|
||||||
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);
|
||||||
do {
|
do
|
||||||
printDebugMessage( "Performing the velocity evaluation." );
|
{
|
||||||
velocity.apply ( *pop );
|
printDebugMessage( "Performing the velocity evaluation." );
|
||||||
printDebugMessage( "Performing the flight." );
|
velocity.apply ( *pop );
|
||||||
flight.apply ( *pop );
|
printDebugMessage( "Performing the flight." );
|
||||||
printDebugMessage( "Performing the evaluation." );
|
flight.apply ( *pop );
|
||||||
pop_eval(*pop);
|
printDebugMessage( "Performing the evaluation." );
|
||||||
velocity.updateNeighborhood( *pop );
|
pop_eval(*pop);
|
||||||
} while ( cont( *pop ) );
|
velocity.updateNeighborhood( *pop );
|
||||||
|
}
|
||||||
|
while ( cont( *pop ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
* (c) OPAC Team, October 2007
|
* (c) OPAC Team, October 2007
|
||||||
*
|
*
|
||||||
* Clive Canape
|
* Clive Canape
|
||||||
*
|
*
|
||||||
* This software is governed by the CeCILL license under French law and
|
* This software is governed by the CeCILL license under French law and
|
||||||
* abiding by the rules of distribution of free software. You can use,
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
* knowledge of the CeCILL license and that you accept its terms.
|
* knowledge of the CeCILL license and that you accept its terms.
|
||||||
*
|
*
|
||||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
* Contact: clive.canape@inria.fr
|
* Contact: clive.canape@inria.fr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -47,27 +47,28 @@
|
||||||
|
|
||||||
template <class POT>
|
template <class POT>
|
||||||
class peoPSOReplacement : public eoReplacement<POT>
|
class peoPSOReplacement : public eoReplacement<POT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
peoPSOReplacement(){}
|
peoPSOReplacement()
|
||||||
|
{}
|
||||||
|
|
||||||
void operator()(eoPop<POT>& _dest, eoPop<POT>& _source)
|
void operator()(eoPop<POT>& _dest, eoPop<POT>& _source)
|
||||||
|
{
|
||||||
|
unsigned ind=0;
|
||||||
|
double best=_dest[0].best();
|
||||||
|
for (unsigned j=1;j<_dest.size();j++)
|
||||||
|
if (_dest[j].best() < best)
|
||||||
|
{
|
||||||
|
ind=j;
|
||||||
|
best=_dest[j].best();
|
||||||
|
}
|
||||||
|
if (_dest[ind].best() < _source[0].best())
|
||||||
{
|
{
|
||||||
unsigned ind=0;
|
_dest[ind].best(_source[0].best());
|
||||||
double best=_dest[0].best();
|
for (unsigned j=0;j<_dest[ind].size();j++)
|
||||||
for(unsigned j=1;j<_dest.size();j++)
|
_dest[ind].bestPositions[j]=_source[0].bestPositions[j];
|
||||||
if(_dest[j].best() < best)
|
|
||||||
{
|
|
||||||
ind=j;
|
|
||||||
best=_dest[j].best();
|
|
||||||
}
|
|
||||||
if(_dest[ind].best() < _source[0].best())
|
|
||||||
{
|
|
||||||
_dest[ind].best(_source[0].best());
|
|
||||||
for(unsigned j=0;j<_dest[ind].size();j++)
|
|
||||||
_dest[ind].bestPositions[j]=_source[0].bestPositions[j];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
* (c) OPAC Team, October 2007
|
* (c) OPAC Team, October 2007
|
||||||
*
|
*
|
||||||
* Clive Canape
|
* Clive Canape
|
||||||
*
|
*
|
||||||
* This software is governed by the CeCILL license under French law and
|
* This software is governed by the CeCILL license under French law and
|
||||||
* abiding by the rules of distribution of free software. You can use,
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
* knowledge of the CeCILL license and that you accept its terms.
|
* knowledge of the CeCILL license and that you accept its terms.
|
||||||
*
|
*
|
||||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
* Contact: clive.canape@inria.fr
|
* Contact: clive.canape@inria.fr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -40,21 +40,22 @@
|
||||||
#include <eoSelectOne.h>
|
#include <eoSelectOne.h>
|
||||||
|
|
||||||
template <class POT> class peoPSOSelect: public eoSelectOne<POT>
|
template <class POT> class peoPSOSelect: public eoSelectOne<POT>
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
peoPSOSelect(eoTopology < POT > & _topology):topology(_topology){}
|
|
||||||
|
|
||||||
typedef typename PO < POT >::Fitness Fitness;
|
|
||||||
|
|
||||||
virtual const POT& operator()(const eoPop<POT>& _pop)
|
|
||||||
{
|
{
|
||||||
return topology.globalBest(_pop);
|
public:
|
||||||
}
|
|
||||||
|
peoPSOSelect(eoTopology < POT > & _topology):topology(_topology)
|
||||||
|
{}
|
||||||
|
|
||||||
|
typedef typename PO < POT >::Fitness Fitness;
|
||||||
|
|
||||||
|
virtual const POT& operator()(const eoPop<POT>& _pop)
|
||||||
|
{
|
||||||
|
return topology.globalBest(_pop);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
eoTopology < POT > & topology;
|
eoTopology < POT > & topology;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
* (c) OPAC Team, October 2007
|
* (c) OPAC Team, October 2007
|
||||||
*
|
*
|
||||||
* Clive Canape
|
* Clive Canape
|
||||||
*
|
*
|
||||||
* This software is governed by the CeCILL license under French law and
|
* This software is governed by the CeCILL license under French law and
|
||||||
* abiding by the rules of distribution of free software. You can use,
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
* knowledge of the CeCILL license and that you accept its terms.
|
* knowledge of the CeCILL license and that you accept its terms.
|
||||||
*
|
*
|
||||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
* Contact: clive.canape@inria.fr
|
* Contact: clive.canape@inria.fr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -48,33 +48,34 @@
|
||||||
|
|
||||||
template <class POT>
|
template <class POT>
|
||||||
class peoPSOVelocity : public eoReplacement<POT>
|
class peoPSOVelocity : public eoReplacement<POT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef typename POT::ParticleVelocityType VelocityType;
|
|
||||||
|
|
||||||
peoPSOVelocity( const double & _c3,
|
|
||||||
eoVelocity < POT > &_velocity):
|
|
||||||
c3 (_c3),
|
|
||||||
velocity (_velocity){}
|
|
||||||
|
|
||||||
void operator()(eoPop<POT>& _dest, eoPop<POT>& _source)
|
typedef typename POT::ParticleVelocityType VelocityType;
|
||||||
{
|
|
||||||
|
peoPSOVelocity( const double & _c3,
|
||||||
VelocityType newVelocity,r3;
|
eoVelocity < POT > &_velocity):
|
||||||
r3 = (VelocityType) rng.uniform (1) * c3;
|
c3 (_c3),
|
||||||
for(unsigned i=0;i<_dest.size();i++)
|
velocity (_velocity)
|
||||||
for(unsigned j=0;j<_dest[i].size();j++)
|
{}
|
||||||
{
|
|
||||||
newVelocity= _dest[i].velocities[j] + r3 * (_source[0].bestPositions[j] - _dest[i][j]);
|
void operator()(eoPop<POT>& _dest, eoPop<POT>& _source)
|
||||||
_dest[i].velocities[j]=newVelocity;
|
{
|
||||||
}
|
|
||||||
|
VelocityType newVelocity,r3;
|
||||||
}
|
r3 = (VelocityType) rng.uniform (1) * c3;
|
||||||
|
for (unsigned i=0;i<_dest.size();i++)
|
||||||
protected:
|
for (unsigned j=0;j<_dest[i].size();j++)
|
||||||
const double & c3;
|
{
|
||||||
eoVelocity < POT > & velocity;
|
newVelocity= _dest[i].velocities[j] + r3 * (_source[0].bestPositions[j] - _dest[i][j]);
|
||||||
};
|
_dest[i].velocities[j]=newVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const double & c3;
|
||||||
|
eoVelocity < POT > & velocity;
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoParaPopEval.h>
|
* <peoParaPopEval.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -51,190 +51,200 @@
|
||||||
//! The peoParaPopEval represents a wrapper for creating a functor capable of applying in parallel
|
//! The peoParaPopEval represents a wrapper for creating a functor capable of applying in parallel
|
||||||
//! an EO-derived evaluation functor. The class offers the possibility of chosing between a single-function evaluation
|
//! an EO-derived evaluation functor. The class offers the possibility of chosing between a single-function evaluation
|
||||||
//! and an aggregate evaluation function, including several sub-evalution functions.
|
//! and an aggregate evaluation function, including several sub-evalution functions.
|
||||||
template< class EOT > class peoParaPopEval : public peoPopEval< EOT > {
|
template< class EOT > class peoParaPopEval : public peoPopEval< EOT >
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using peoPopEval< EOT > :: requestResourceRequest;
|
using peoPopEval< EOT > :: requestResourceRequest;
|
||||||
using peoPopEval< EOT > :: resume;
|
using peoPopEval< EOT > :: resume;
|
||||||
using peoPopEval< EOT > :: stop;
|
using peoPopEval< EOT > :: stop;
|
||||||
using peoPopEval< EOT > :: getOwner;
|
using peoPopEval< EOT > :: getOwner;
|
||||||
|
|
||||||
//! Constructor function - an EO-derived evaluation functor has to be specified; an internal reference
|
|
||||||
//! is set towards the specified evaluation functor.
|
|
||||||
//!
|
|
||||||
//! @param eoEvalFunc< EOT >& __eval_func - EO-derived evaluation functor to be applied in parallel on each individual of a specified population
|
|
||||||
peoParaPopEval( eoEvalFunc< EOT >& __eval_func );
|
|
||||||
|
|
||||||
//! Constructor function - a vector of EO-derived evaluation functors has to be specified as well as an aggregation function.
|
//! Constructor function - an EO-derived evaluation functor has to be specified; an internal reference
|
||||||
//!
|
//! is set towards the specified evaluation functor.
|
||||||
//! @param const std :: vector< eoEvalFunc < EOT >* >& __funcs - vector of EO-derived partial evaluation functors;
|
//!
|
||||||
//! @param peoAggEvalFunc< EOT >& __merge_eval - aggregation functor for creating a fitness value out of the partial fitness values.
|
//! @param eoEvalFunc< EOT >& __eval_func - EO-derived evaluation functor to be applied in parallel on each individual of a specified population
|
||||||
peoParaPopEval( const std :: vector< eoEvalFunc < EOT >* >& __funcs, peoAggEvalFunc< EOT >& __merge_eval );
|
peoParaPopEval( eoEvalFunc< EOT >& __eval_func );
|
||||||
|
|
||||||
//! Operator for applying the evaluation functor (direct or aggregate) for each individual of the specified population.
|
//! Constructor function - a vector of EO-derived evaluation functors has to be specified as well as an aggregation function.
|
||||||
//!
|
//!
|
||||||
//! @param eoPop< EOT >& __pop - population to be evaluated by applying the evaluation functor specified in the constructor.
|
//! @param const std :: vector< eoEvalFunc < EOT >* >& __funcs - vector of EO-derived partial evaluation functors;
|
||||||
void operator()( eoPop< EOT >& __pop );
|
//! @param peoAggEvalFunc< EOT >& __merge_eval - aggregation functor for creating a fitness value out of the partial fitness values.
|
||||||
|
peoParaPopEval( const std :: vector< eoEvalFunc < EOT >* >& __funcs, peoAggEvalFunc< EOT >& __merge_eval );
|
||||||
|
|
||||||
//! Auxiliary function for transferring data between the process requesting an evaluation operation and the process that
|
//! Operator for applying the evaluation functor (direct or aggregate) for each individual of the specified population.
|
||||||
//! performs the actual evaluation phase. There is no need to explicitly call the function.
|
//!
|
||||||
void packData();
|
//! @param eoPop< EOT >& __pop - population to be evaluated by applying the evaluation functor specified in the constructor.
|
||||||
|
void operator()( 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.
|
|
||||||
void unpackData();
|
|
||||||
|
|
||||||
//! Auxiliary function - it calls the specified evaluation functor(s). There is no need to explicitly call the function.
|
//! Auxiliary function for transferring data between the process requesting an evaluation operation and the process that
|
||||||
void execute();
|
//! performs the actual evaluation phase. There is no need to explicitly call the function.
|
||||||
|
void packData();
|
||||||
//! 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.
|
|
||||||
void packResult();
|
|
||||||
|
|
||||||
//! 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.
|
|
||||||
void unpackResult();
|
|
||||||
|
|
||||||
//! Auxiliary function for notifications between the process requesting an evaluation operation and the processes that
|
|
||||||
//! performs the actual evaluation phase. There is no need to explicitly call the function.
|
|
||||||
void notifySendingData();
|
|
||||||
|
|
||||||
//! Auxiliary function for notifications between the process requesting an evaluation operation and the processes 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.
|
||||||
void notifySendingAllResourceRequests();
|
void unpackData();
|
||||||
|
|
||||||
private:
|
//! Auxiliary function - it calls the specified evaluation functor(s). There is no need to explicitly call the function.
|
||||||
|
void execute();
|
||||||
|
|
||||||
|
//! 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.
|
||||||
|
void packResult();
|
||||||
|
|
||||||
|
//! 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.
|
||||||
|
void unpackResult();
|
||||||
|
|
||||||
|
//! Auxiliary function for notifications between the process requesting an evaluation operation and the processes that
|
||||||
|
//! performs the actual evaluation phase. There is no need to explicitly call the function.
|
||||||
|
void notifySendingData();
|
||||||
|
|
||||||
|
//! Auxiliary function for notifications between the process requesting an evaluation operation and the processes that
|
||||||
|
//! performs the actual evaluation phase. There is no need to explicitly call the function.
|
||||||
|
void notifySendingAllResourceRequests();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
const std :: vector< eoEvalFunc < EOT >* >& funcs;
|
const std :: vector< eoEvalFunc < EOT >* >& funcs;
|
||||||
std :: vector< eoEvalFunc < EOT >* > one_func;
|
std :: vector< eoEvalFunc < EOT >* > one_func;
|
||||||
|
|
||||||
peoAggEvalFunc< EOT >& merge_eval;
|
peoAggEvalFunc< EOT >& merge_eval;
|
||||||
peoNoAggEvalFunc< EOT > no_merge_eval;
|
peoNoAggEvalFunc< EOT > no_merge_eval;
|
||||||
|
|
||||||
std :: queue< EOT* >tasks;
|
std :: queue< EOT* >tasks;
|
||||||
|
|
||||||
std :: map< EOT*, std :: pair< unsigned, unsigned > > progression;
|
std :: map< EOT*, std :: pair< unsigned, unsigned > > progression;
|
||||||
|
|
||||||
unsigned num_func;
|
unsigned num_func;
|
||||||
|
|
||||||
EOT sol;
|
EOT sol;
|
||||||
|
|
||||||
EOT *ad_sol;
|
EOT *ad_sol;
|
||||||
|
|
||||||
unsigned total;
|
unsigned total;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > peoParaPopEval< EOT > :: peoParaPopEval( eoEvalFunc< EOT >& __eval_func ) :
|
template< class EOT > peoParaPopEval< EOT > :: peoParaPopEval( eoEvalFunc< EOT >& __eval_func ) :
|
||||||
|
|
||||||
funcs( one_func ), merge_eval( no_merge_eval )
|
funcs( one_func ), merge_eval( no_merge_eval )
|
||||||
{
|
{
|
||||||
|
|
||||||
one_func.push_back( &__eval_func );
|
one_func.push_back( &__eval_func );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > peoParaPopEval< EOT > :: peoParaPopEval(
|
template< class EOT > peoParaPopEval< EOT > :: peoParaPopEval(
|
||||||
|
|
||||||
const std :: vector< eoEvalFunc< EOT >* >& __funcs,
|
const std :: vector< eoEvalFunc< EOT >* >& __funcs,
|
||||||
peoAggEvalFunc< EOT >& __merge_eval
|
peoAggEvalFunc< EOT >& __merge_eval
|
||||||
|
|
||||||
) : funcs( __funcs ), merge_eval( __merge_eval )
|
) : funcs( __funcs ), merge_eval( __merge_eval )
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template< class EOT > void peoParaPopEval< EOT >::operator()( eoPop< EOT >& __pop )
|
||||||
{
|
{
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaPopEval< EOT >::operator()( eoPop< EOT >& __pop ) {
|
template< class EOT > void peoParaPopEval< EOT > :: packData()
|
||||||
for ( unsigned i = 0; i < __pop.size(); i++ ) {
|
{
|
||||||
__pop[ i ].fitness(typename EOT :: Fitness() );
|
// printDebugMessage ("debut pakc data");
|
||||||
progression[ &__pop[ i ] ].first = funcs.size() - 1;
|
pack( progression[ tasks.front() ].first-- );
|
||||||
progression[ &__pop[ i ] ].second = funcs.size();
|
|
||||||
for ( unsigned j = 0; j < funcs.size(); j++ ) {
|
/* Packing the contents :-) of the solution */
|
||||||
/* Queuing the 'invalid' solution and its associated owner */
|
pack( *tasks.front() );
|
||||||
tasks.push( &__pop[ i ] );
|
|
||||||
}
|
/* Packing the addresses of both the solution and the owner */
|
||||||
}
|
pack( tasks.front() );
|
||||||
total = funcs.size() * __pop.size();
|
tasks.pop( );
|
||||||
requestResourceRequest( funcs.size() * __pop.size() );
|
|
||||||
stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaPopEval< EOT > :: packData() {
|
template< class EOT > void peoParaPopEval< EOT > :: unpackData()
|
||||||
// printDebugMessage ("debut pakc data");
|
{
|
||||||
pack( progression[ tasks.front() ].first-- );
|
unpack( num_func );
|
||||||
|
/* Unpacking the solution */
|
||||||
/* Packing the contents :-) of the solution */
|
unpack( sol );
|
||||||
pack( *tasks.front() );
|
/* Unpacking the @ of that one */
|
||||||
|
unpack( ad_sol );
|
||||||
/* Packing the addresses of both the solution and the owner */
|
|
||||||
pack( tasks.front() );
|
|
||||||
tasks.pop( );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaPopEval< EOT > :: unpackData() {
|
template< class EOT > void peoParaPopEval< EOT > :: execute()
|
||||||
unpack( num_func );
|
{
|
||||||
/* Unpacking the solution */
|
/* Computing the fitness of the solution */
|
||||||
unpack( sol );
|
|
||||||
/* Unpacking the @ of that one */
|
|
||||||
unpack( ad_sol );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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() {
|
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 */
|
||||||
pack( ad_sol );
|
pack( ad_sol );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 */
|
|
||||||
unpack( fit );
|
|
||||||
|
|
||||||
/* Unpacking the @ of the associated individual */
|
|
||||||
unpack( ad_sol );
|
|
||||||
|
|
||||||
|
|
||||||
/* Associating the fitness the local solution */
|
|
||||||
merge_eval( *ad_sol, fit );
|
|
||||||
|
|
||||||
progression[ ad_sol ].second--;
|
/* Unpacking the computed fitness */
|
||||||
|
unpack( fit );
|
||||||
|
|
||||||
/* Notifying the container of the termination of the evaluation */
|
/* Unpacking the @ of the associated individual */
|
||||||
if ( !progression[ ad_sol ].second ) {
|
unpack( ad_sol );
|
||||||
|
|
||||||
progression.erase( ad_sol );
|
|
||||||
}
|
|
||||||
|
|
||||||
total--;
|
|
||||||
if ( !total ) {
|
|
||||||
|
|
||||||
getOwner()->setActive();
|
/* Associating the fitness the local solution */
|
||||||
resume();
|
merge_eval( *ad_sol, fit );
|
||||||
}
|
|
||||||
|
progression[ ad_sol ].second--;
|
||||||
|
|
||||||
|
/* Notifying the container of the termination of the evaluation */
|
||||||
|
if ( !progression[ ad_sol ].second )
|
||||||
|
{
|
||||||
|
|
||||||
|
progression.erase( ad_sol );
|
||||||
|
}
|
||||||
|
|
||||||
|
total--;
|
||||||
|
if ( !total )
|
||||||
|
{
|
||||||
|
|
||||||
|
getOwner()->setActive();
|
||||||
|
resume();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoParaSGATransform.h>
|
* <peoParaSGATransform.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -46,39 +46,40 @@
|
||||||
extern int getNodeRank();
|
extern int getNodeRank();
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > class peoParaSGATransform : public peoTransform< EOT > {
|
template< class EOT > class peoParaSGATransform : public peoTransform< EOT >
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using peoTransform< EOT > :: requestResourceRequest;
|
using peoTransform< EOT > :: requestResourceRequest;
|
||||||
using peoTransform< EOT > :: resume;
|
using peoTransform< EOT > :: resume;
|
||||||
using peoTransform< EOT > :: stop;
|
using peoTransform< EOT > :: stop;
|
||||||
using peoTransform< EOT > :: getOwner;
|
using peoTransform< EOT > :: getOwner;
|
||||||
|
|
||||||
peoParaSGATransform(
|
peoParaSGATransform(
|
||||||
|
|
||||||
eoQuadOp< EOT >& __cross,
|
eoQuadOp< EOT >& __cross,
|
||||||
double __cross_rate,
|
double __cross_rate,
|
||||||
eoMonOp< EOT >& __mut,
|
eoMonOp< EOT >& __mut,
|
||||||
double __mut_rate
|
double __mut_rate
|
||||||
);
|
);
|
||||||
|
|
||||||
void operator()( eoPop< EOT >& __pop );
|
void operator()( eoPop< EOT >& __pop );
|
||||||
|
|
||||||
void packData();
|
|
||||||
|
|
||||||
void unpackData();
|
|
||||||
|
|
||||||
void execute();
|
|
||||||
|
|
||||||
void packResult();
|
|
||||||
|
|
||||||
void unpackResult();
|
|
||||||
|
|
||||||
void notifySendingData();
|
|
||||||
void notifySendingAllResourceRequests();
|
|
||||||
|
|
||||||
private:
|
void packData();
|
||||||
|
|
||||||
|
void unpackData();
|
||||||
|
|
||||||
|
void execute();
|
||||||
|
|
||||||
|
void packResult();
|
||||||
|
|
||||||
|
void unpackResult();
|
||||||
|
|
||||||
|
void notifySendingData();
|
||||||
|
void notifySendingAllResourceRequests();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
eoQuadOp< EOT >& cross;
|
eoQuadOp< EOT >& cross;
|
||||||
double cross_rate;
|
double cross_rate;
|
||||||
|
|
@ -93,90 +94,95 @@ private:
|
||||||
EOT father, mother;
|
EOT father, mother;
|
||||||
|
|
||||||
unsigned num_term;
|
unsigned num_term;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< class EOT > peoParaSGATransform< EOT > :: peoParaSGATransform(
|
template< class EOT > peoParaSGATransform< EOT > :: peoParaSGATransform(
|
||||||
|
|
||||||
eoQuadOp< EOT >& __cross,
|
eoQuadOp< EOT >& __cross,
|
||||||
double __cross_rate,
|
double __cross_rate,
|
||||||
eoMonOp < EOT >& __mut,
|
eoMonOp < EOT >& __mut,
|
||||||
double __mut_rate
|
double __mut_rate
|
||||||
|
|
||||||
) : cross( __cross ), cross_rate( __cross_rate ), mut( __mut ), mut_rate( __mut_rate )
|
) : cross( __cross ), cross_rate( __cross_rate ), mut( __mut ), mut_rate( __mut_rate )
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template< class EOT > void peoParaSGATransform< EOT > :: packData()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
pack( idx );
|
||||||
|
:: pack( pop->operator[]( idx++ ) );
|
||||||
|
:: pack( pop->operator[]( idx++ ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaSGATransform< EOT > :: packData() {
|
template< class EOT > void peoParaSGATransform< EOT > :: unpackData()
|
||||||
|
{
|
||||||
|
|
||||||
pack( idx );
|
unpack( idx );
|
||||||
:: pack( pop->operator[]( idx++ ) );
|
:: unpack( father );
|
||||||
:: pack( pop->operator[]( idx++ ) );
|
:: unpack( mother );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaSGATransform< EOT > :: unpackData() {
|
template< class EOT > void peoParaSGATransform< EOT > :: execute()
|
||||||
|
{
|
||||||
|
|
||||||
unpack( idx );
|
if ( rng.uniform() < cross_rate ) cross( mother, father );
|
||||||
:: unpack( father );
|
|
||||||
:: unpack( mother );
|
if ( rng.uniform() < mut_rate ) mut( mother );
|
||||||
|
if ( rng.uniform() < mut_rate ) mut( father );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaSGATransform< EOT > :: execute() {
|
template< class EOT > void peoParaSGATransform< EOT > :: packResult()
|
||||||
|
{
|
||||||
|
|
||||||
if( rng.uniform() < cross_rate ) cross( mother, father );
|
pack( idx );
|
||||||
|
:: pack( father );
|
||||||
if( rng.uniform() < mut_rate ) mut( mother );
|
:: pack( mother );
|
||||||
if( rng.uniform() < mut_rate ) mut( father );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaSGATransform< EOT > :: packResult() {
|
template< class EOT > void peoParaSGATransform< EOT > :: unpackResult()
|
||||||
|
{
|
||||||
|
|
||||||
pack( idx );
|
unsigned sidx;
|
||||||
:: pack( father );
|
|
||||||
:: pack( mother );
|
unpack( sidx );
|
||||||
|
:: unpack( pop->operator[]( sidx++ ) );
|
||||||
|
:: unpack( pop->operator[]( sidx ) );
|
||||||
|
num_term += 2;
|
||||||
|
// Can be used with a odd size
|
||||||
|
if ( num_term == 2*(pop->size()/2) )
|
||||||
|
{
|
||||||
|
|
||||||
|
getOwner()->setActive();
|
||||||
|
resume();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaSGATransform< EOT > :: unpackResult() {
|
template< class EOT > void peoParaSGATransform< EOT > :: operator()( eoPop < EOT >& __pop )
|
||||||
|
{
|
||||||
|
|
||||||
unsigned sidx;
|
printDebugMessage( "performing the parallel transformation step." );
|
||||||
|
pop = &__pop;
|
||||||
unpack( sidx );
|
idx = 0;
|
||||||
:: unpack( pop->operator[]( sidx++ ) );
|
num_term = 0;
|
||||||
:: unpack( pop->operator[]( sidx ) );
|
requestResourceRequest( __pop.size() / 2 );
|
||||||
num_term += 2;
|
stop();
|
||||||
// Can be used with a odd size
|
|
||||||
if( num_term == 2*(pop->size()/2) ) {
|
|
||||||
|
|
||||||
getOwner()->setActive();
|
|
||||||
resume();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaSGATransform< EOT > :: operator()( eoPop < EOT >& __pop ) {
|
template< class EOT > void peoParaSGATransform< EOT > :: notifySendingData()
|
||||||
|
{}
|
||||||
printDebugMessage( "performing the parallel transformation step." );
|
|
||||||
pop = &__pop;
|
|
||||||
idx = 0;
|
|
||||||
num_term = 0;
|
|
||||||
requestResourceRequest( __pop.size() / 2 );
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaSGATransform< EOT > :: notifySendingData() {
|
template< class EOT > void peoParaSGATransform< EOT > :: notifySendingAllResourceRequests()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
getOwner()->setPassive();
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoParaSGATransform< EOT > :: notifySendingAllResourceRequests() {
|
|
||||||
|
|
||||||
getOwner()->setPassive();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoParallelAlgorithmWrapper.h>
|
* <peoParallelAlgorithmWrapper.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -44,70 +44,82 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class peoParallelAlgorithmWrapper : public Runner {
|
class peoParallelAlgorithmWrapper : public Runner
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
template< typename AlgorithmType > peoParallelAlgorithmWrapper( AlgorithmType& externalAlgorithm )
|
template< typename AlgorithmType > peoParallelAlgorithmWrapper( AlgorithmType& externalAlgorithm )
|
||||||
: algorithm( new Algorithm< AlgorithmType, void >( externalAlgorithm ) ) {
|
: algorithm( new Algorithm< AlgorithmType, void >( externalAlgorithm ) )
|
||||||
|
{}
|
||||||
|
|
||||||
}
|
template< typename AlgorithmType, typename AlgorithmDataType > peoParallelAlgorithmWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
|
||||||
|
: algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) )
|
||||||
|
{}
|
||||||
|
|
||||||
template< typename AlgorithmType, typename AlgorithmDataType > peoParallelAlgorithmWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
|
~peoParallelAlgorithmWrapper()
|
||||||
: algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) ) {
|
{
|
||||||
|
|
||||||
}
|
delete algorithm;
|
||||||
|
}
|
||||||
|
|
||||||
~peoParallelAlgorithmWrapper() {
|
void run()
|
||||||
|
{
|
||||||
delete algorithm;
|
algorithm->operator()();
|
||||||
}
|
}
|
||||||
|
|
||||||
void run() { algorithm->operator()(); }
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct AbstractAlgorithm {
|
struct AbstractAlgorithm
|
||||||
|
{
|
||||||
|
|
||||||
// virtual destructor as we will be using inheritance and polymorphism
|
// virtual destructor as we will be using inheritance and polymorphism
|
||||||
virtual ~AbstractAlgorithm() { }
|
virtual ~AbstractAlgorithm()
|
||||||
|
{ }
|
||||||
|
|
||||||
// operator to be called for executing the algorithm
|
// operator to be called for executing the algorithm
|
||||||
virtual void operator()() { }
|
virtual void operator()()
|
||||||
};
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template< typename AlgorithmType, typename AlgorithmDataType > struct Algorithm : public AbstractAlgorithm {
|
template< typename AlgorithmType, typename AlgorithmDataType > struct Algorithm : public AbstractAlgorithm
|
||||||
|
{
|
||||||
|
|
||||||
Algorithm( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
|
Algorithm( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
|
||||||
: algorithm( externalAlgorithm ), algorithmData( externalData ) {
|
: algorithm( externalAlgorithm ), algorithmData( externalData )
|
||||||
|
{}
|
||||||
|
|
||||||
}
|
virtual void operator()()
|
||||||
|
{
|
||||||
|
algorithm( algorithmData );
|
||||||
|
}
|
||||||
|
|
||||||
virtual void operator()() { algorithm( algorithmData ); }
|
AlgorithmType& algorithm;
|
||||||
|
AlgorithmDataType& algorithmData;
|
||||||
AlgorithmType& algorithm;
|
};
|
||||||
AlgorithmDataType& algorithmData;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template< typename AlgorithmType > struct Algorithm< AlgorithmType, void > : public AbstractAlgorithm {
|
template< typename AlgorithmType > struct Algorithm< AlgorithmType, void > : public AbstractAlgorithm
|
||||||
|
{
|
||||||
|
|
||||||
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm ) {
|
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm )
|
||||||
|
{}
|
||||||
|
|
||||||
}
|
virtual void operator()()
|
||||||
|
{
|
||||||
|
algorithm();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void operator()() { algorithm(); }
|
AlgorithmType& algorithm;
|
||||||
|
};
|
||||||
AlgorithmType& algorithm;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
AbstractAlgorithm* algorithm;
|
AbstractAlgorithm* algorithm;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoPopEval.h>
|
* <peoPopEval.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -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:
|
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 >& __pop ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoSeqPopEval.h>
|
* <peoSeqPopEval.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -46,35 +46,36 @@
|
||||||
//! The peoSeqPopEval class acts only as a ParadisEO specific sequential evaluation functor - a wrapper for incorporating
|
//! The peoSeqPopEval class acts only as a ParadisEO specific sequential evaluation functor - a wrapper for incorporating
|
||||||
//! an <b>eoEvalFunc< EOT ></b>-derived class as evaluation functor. The specified EO evaluation object is applyied in an
|
//! an <b>eoEvalFunc< EOT ></b>-derived class as evaluation functor. The specified EO evaluation object is applyied in an
|
||||||
//! iterative manner to each individual of a specified population.
|
//! iterative manner to each individual of a specified population.
|
||||||
template< class EOT > class peoSeqPopEval : public peoPopEval< EOT > {
|
template< class EOT > class peoSeqPopEval : public peoPopEval< EOT >
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Constructor function - it only sets an internal reference to point to the specified evaluation object.
|
//! Constructor function - it only sets an internal reference to point to the specified evaluation object.
|
||||||
//!
|
//!
|
||||||
//! @param eoEvalFunc< EOT >& __eval - evaluation object to be applied for each individual of a specified population
|
//! @param eoEvalFunc< EOT >& __eval - evaluation object to be applied for each individual of a specified population
|
||||||
peoSeqPopEval( eoEvalFunc< EOT >& __eval );
|
peoSeqPopEval( eoEvalFunc< EOT >& __eval );
|
||||||
|
|
||||||
//! Operator for evaluating all the individuals of a given population - in a sequential iterative manner.
|
//! Operator for evaluating all the individuals of a given population - in a sequential iterative manner.
|
||||||
//!
|
//!
|
||||||
//! @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 );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
eoEvalFunc< EOT >& eval;
|
eoEvalFunc< EOT >& eval;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
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 >& __pop ) {
|
template< class EOT > void peoSeqPopEval< EOT > :: operator()( eoPop< EOT >& __pop )
|
||||||
|
{
|
||||||
|
|
||||||
for ( unsigned i = 0; i < __pop.size(); i++ )
|
for ( unsigned i = 0; i < __pop.size(); i++ )
|
||||||
eval( __pop[i] );
|
eval( __pop[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoSeqTransform.h>
|
* <peoSeqTransform.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -45,49 +45,55 @@
|
||||||
//! The peoSeqTransform represent a wrapper for offering the possibility of using EO derived transform operators
|
//! The peoSeqTransform represent a wrapper for offering the possibility of using EO derived transform operators
|
||||||
//! along with the ParadisEO evolutionary algorithms. A minimal set of interface functions is also provided for creating the
|
//! along with the ParadisEO evolutionary algorithms. A minimal set of interface functions is also provided for creating the
|
||||||
//! link with the parallel architecture of the ParadisEO framework.
|
//! link with the parallel architecture of the ParadisEO framework.
|
||||||
template< class EOT > class peoSeqTransform : public peoTransform< EOT > {
|
template< class EOT > class peoSeqTransform : public peoTransform< EOT >
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Constructor function - sets an internal reference towards the specified EO-derived transform object.
|
//! Constructor function - sets an internal reference towards the specified EO-derived transform object.
|
||||||
//!
|
//!
|
||||||
//! @param eoTransform< EOT >& __trans - EO-derived transform object including crossover and mutation operators.
|
//! @param eoTransform< EOT >& __trans - EO-derived transform object including crossover and mutation operators.
|
||||||
peoSeqTransform( eoTransform< EOT >& __trans );
|
peoSeqTransform( eoTransform< EOT >& __trans );
|
||||||
|
|
||||||
//! Operator for applying the specified transform operators on each individual of the given population.
|
|
||||||
//!
|
|
||||||
//! @param eoPop< EOT >& __pop - population to be transformed by applying the crossover and mutation operators.
|
|
||||||
void operator()( eoPop< EOT >& __pop );
|
|
||||||
|
|
||||||
//! Interface function for providing a link with the parallel architecture of the ParadisEO framework.
|
|
||||||
virtual void packData() { }
|
|
||||||
|
|
||||||
//! Interface function for providing a link with the parallel architecture of the ParadisEO framework.
|
//! Operator for applying the specified transform operators on each individual of the given population.
|
||||||
virtual void unpackData() { }
|
//!
|
||||||
|
//! @param eoPop< EOT >& __pop - population to be transformed by applying the crossover and mutation operators.
|
||||||
//! Interface function for providing a link with the parallel architecture of the ParadisEO framework.
|
void operator()( eoPop< EOT >& __pop );
|
||||||
virtual void execute() { }
|
|
||||||
|
|
||||||
//! Interface function for providing a link with the parallel architecture of the ParadisEO framework.
|
|
||||||
virtual void packResult() { }
|
|
||||||
|
|
||||||
//! Interface function for providing a link with the parallel architecture of the ParadisEO framework.
|
//! Interface function for providing a link with the parallel architecture of the ParadisEO framework.
|
||||||
virtual void unpackResult() { }
|
virtual void packData()
|
||||||
|
{ }
|
||||||
|
|
||||||
private:
|
//! Interface function for providing a link with the parallel architecture of the ParadisEO framework.
|
||||||
|
virtual void unpackData()
|
||||||
|
{ }
|
||||||
|
|
||||||
eoTransform< EOT >& trans;
|
//! Interface function for providing a link with the parallel architecture of the ParadisEO framework.
|
||||||
};
|
virtual void execute()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//! Interface function for providing a link with the parallel architecture of the ParadisEO framework.
|
||||||
|
virtual void packResult()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//! Interface function for providing a link with the parallel architecture of the ParadisEO framework.
|
||||||
|
virtual void unpackResult()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
eoTransform< EOT >& trans;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > peoSeqTransform< EOT > :: peoSeqTransform( eoTransform< EOT >& __trans ) : trans( __trans ) {
|
template< class EOT > peoSeqTransform< EOT > :: peoSeqTransform( eoTransform< EOT >& __trans ) : trans( __trans )
|
||||||
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSeqTransform< EOT > :: operator()( eoPop< EOT >& __pop ) {
|
template< class EOT > void peoSeqTransform< EOT > :: operator()( eoPop< EOT >& __pop )
|
||||||
|
{
|
||||||
|
|
||||||
trans( __pop );
|
trans( __pop );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoSyncIslandMig.h>
|
* <peoSyncIslandMig.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -63,7 +63,7 @@
|
||||||
//! parameters, i.e. frequency of the migrations, selection and replacement strategies,
|
//! parameters, i.e. frequency of the migrations, selection and replacement strategies,
|
||||||
//! a topological model and the source and destination population for the migrating individuals.
|
//! a topological model and the source and destination population for the migrating individuals.
|
||||||
//! The main difference as opposed to the asynchronous migration model is the synchronization step
|
//! The main difference as opposed to the asynchronous migration model is the synchronization step
|
||||||
//! performed after selecting and sending the emigrant individuals.
|
//! performed after selecting and sending the emigrant individuals.
|
||||||
//!
|
//!
|
||||||
//! The migration operator is called at the end of each generation of an evolutionary algorithms
|
//! The migration operator is called at the end of each generation of an evolutionary algorithms
|
||||||
//! as a checkpoint object - the following code exposes the structure of a classic evolutionary algorithm:
|
//! as a checkpoint object - the following code exposes the structure of a classic evolutionary algorithm:
|
||||||
|
|
@ -139,175 +139,189 @@
|
||||||
//! islands requires the reiteration of the steps 2 through 4 for creating distinct algorithms, with distinct populations and
|
//! islands requires the reiteration of the steps 2 through 4 for creating distinct algorithms, with distinct populations and
|
||||||
//! the associated distinctly parametrized migration objects. The interconnecting element is the underlying topology, defined at step 1
|
//! the associated distinctly parametrized migration objects. The interconnecting element is the underlying topology, defined at step 1
|
||||||
//! (the same C++ migTopology object has to be passed as parameter for all the migration objects, in order to interconnect them).
|
//! (the same C++ migTopology object has to be passed as parameter for all the migration objects, in order to interconnect them).
|
||||||
template< class EOT > class peoSyncIslandMig : public Cooperative, public eoUpdater {
|
template< class EOT > class peoSyncIslandMig : public Cooperative, public eoUpdater
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Constructor for the peoSyncIslandMig class; the characteristics of the migration model are defined
|
//! Constructor for the peoSyncIslandMig class; the characteristics of the migration model are defined
|
||||||
//! through the specified parameters - out of the box objects provided in EO, etc., or custom, derived objects may be passed as parameters.
|
//! through the specified parameters - out of the box objects provided in EO, etc., or custom, derived objects may be passed as parameters.
|
||||||
//!
|
//!
|
||||||
//! @param unsigned __frequency - frequency of the migrations - the migrations occur periodically;
|
//! @param unsigned __frequency - frequency of the migrations - the migrations occur periodically;
|
||||||
//! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of emigrant individuals out of the source population;
|
//! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of emigrant individuals out of the source population;
|
||||||
//! @param eoReplacement< EOT >& __replace - replacement strategy used for integrating the immigrant individuals in the destination population;
|
//! @param eoReplacement< EOT >& __replace - replacement strategy used for integrating the immigrant individuals in the destination population;
|
||||||
//! @param Topology& __topology - topological model to be followed when performing migrations;
|
//! @param Topology& __topology - topological model to be followed when performing migrations;
|
||||||
//! @param eoPop< EOT >& __source - source population from which the emigrant individuals are selected;
|
//! @param eoPop< EOT >& __source - source population from which the emigrant individuals are selected;
|
||||||
//! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated.
|
//! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated.
|
||||||
peoSyncIslandMig(
|
peoSyncIslandMig(
|
||||||
unsigned __frequency,
|
unsigned __frequency,
|
||||||
eoSelect< EOT >& __select,
|
eoSelect< EOT >& __select,
|
||||||
eoReplacement< EOT >& __replace,
|
eoReplacement< EOT >& __replace,
|
||||||
Topology& __topology,
|
Topology& __topology,
|
||||||
eoPop< EOT >& __source,
|
eoPop< EOT >& __source,
|
||||||
eoPop< EOT >& __destination
|
eoPop< EOT >& __destination
|
||||||
);
|
);
|
||||||
|
|
||||||
//! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected
|
//! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected
|
||||||
//! from the source population and sent to the next island (defined by the topology object) while the immigrant
|
//! from the source population and sent to the next island (defined by the topology object) while the immigrant
|
||||||
//! individuals are integrated in the destination population. There is no need to explicitly call the function - the
|
//! individuals are integrated in the destination population. There is no need to explicitly call the function - the
|
||||||
//! wrapper checkpoint object (please refer to the above example) will perform the call when required.
|
//! wrapper checkpoint object (please refer to the above example) will perform the call when required.
|
||||||
void operator()();
|
void operator()();
|
||||||
|
|
||||||
//! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function.
|
//! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function.
|
||||||
void pack();
|
void pack();
|
||||||
//! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function.
|
//! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function.
|
||||||
void unpack();
|
void unpack();
|
||||||
|
|
||||||
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
|
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
|
||||||
void notifySending();
|
void notifySending();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void emigrate();
|
void emigrate();
|
||||||
void immigrate();
|
void immigrate();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
eoPeriodicContinue< EOT > cont;
|
eoPeriodicContinue< EOT > cont;
|
||||||
eoSelect< EOT >& select; // selection strategy
|
eoSelect< EOT >& select; // selection strategy
|
||||||
eoReplacement< EOT >& replace; // replacement strategy
|
eoReplacement< EOT >& replace; // replacement strategy
|
||||||
Topology& topology; // neighboring topology
|
Topology& topology; // neighboring topology
|
||||||
|
|
||||||
// source and target populations
|
// source and target populations
|
||||||
eoPop< EOT >& source;
|
eoPop< EOT >& source;
|
||||||
eoPop< EOT >& destination;
|
eoPop< EOT >& destination;
|
||||||
|
|
||||||
// immigrants & emigrants in the queue
|
// immigrants & emigrants in the queue
|
||||||
std :: queue< eoPop< EOT > > imm;
|
std :: queue< eoPop< EOT > > imm;
|
||||||
std :: queue< eoPop< EOT > > em;
|
std :: queue< eoPop< EOT > > em;
|
||||||
|
|
||||||
std :: queue< Cooperative* > coop_em;
|
std :: queue< Cooperative* > coop_em;
|
||||||
|
|
||||||
sem_t sync;
|
sem_t sync;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > peoSyncIslandMig< EOT > :: peoSyncIslandMig(
|
template< class EOT > peoSyncIslandMig< EOT > :: peoSyncIslandMig(
|
||||||
|
|
||||||
unsigned __frequency,
|
unsigned __frequency,
|
||||||
eoSelect< EOT >& __select,
|
eoSelect< EOT >& __select,
|
||||||
eoReplacement< EOT >& __replace,
|
eoReplacement< EOT >& __replace,
|
||||||
Topology& __topology,
|
Topology& __topology,
|
||||||
eoPop< EOT >& __source,
|
eoPop< EOT >& __source,
|
||||||
eoPop< EOT >& __destination
|
eoPop< EOT >& __destination
|
||||||
|
|
||||||
) : cont( __frequency ), select( __select ), replace( __replace ), topology( __topology ), source( __source ), destination( __destination )
|
) : cont( __frequency ), select( __select ), replace( __replace ), topology( __topology ), source( __source ), destination( __destination )
|
||||||
{
|
{
|
||||||
|
|
||||||
__topology.add( *this );
|
__topology.add( *this );
|
||||||
sem_init( &sync, 0, 0 );
|
sem_init( &sync, 0, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncIslandMig< EOT > :: pack() {
|
template< class EOT > void peoSyncIslandMig< EOT > :: pack()
|
||||||
|
{
|
||||||
|
|
||||||
lock(); {
|
lock ();
|
||||||
|
{
|
||||||
|
|
||||||
:: pack( coop_em.front()->getKey() );
|
:: pack( coop_em.front()->getKey() );
|
||||||
:: pack( em.front() );
|
:: pack( em.front() );
|
||||||
coop_em.pop();
|
coop_em.pop();
|
||||||
em.pop();
|
em.pop();
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncIslandMig< EOT > :: unpack() {
|
template< class EOT > void peoSyncIslandMig< EOT > :: unpack()
|
||||||
|
{
|
||||||
|
|
||||||
lock(); {
|
lock ();
|
||||||
|
{
|
||||||
|
|
||||||
eoPop< EOT > mig;
|
eoPop< EOT > mig;
|
||||||
:: unpack( mig );
|
:: unpack( mig );
|
||||||
imm.push( mig );
|
imm.push( mig );
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
sem_post( &sync );
|
sem_post( &sync );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncIslandMig< EOT > :: emigrate() {
|
template< class EOT > void peoSyncIslandMig< EOT > :: emigrate()
|
||||||
|
{
|
||||||
|
|
||||||
std :: vector< Cooperative* > in, out;
|
std :: vector< Cooperative* > in, out;
|
||||||
topology.setNeighbors( this, in, out );
|
topology.setNeighbors( this, in, out );
|
||||||
|
|
||||||
for ( unsigned i = 0; i < out.size(); i ++ ) {
|
|
||||||
|
|
||||||
eoPop< EOT > mig;
|
for ( unsigned i = 0; i < out.size(); i ++ )
|
||||||
select( source, mig );
|
{
|
||||||
em.push( mig );
|
|
||||||
coop_em.push( out[ i ] );
|
eoPop< EOT > mig;
|
||||||
send( out[ i ] );
|
select( source, mig );
|
||||||
printDebugMessage( "sending some emigrants." );
|
em.push( mig );
|
||||||
}
|
coop_em.push( out[ i ] );
|
||||||
|
send( out[ i ] );
|
||||||
|
printDebugMessage( "sending some emigrants." );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncIslandMig< EOT > :: immigrate() {
|
template< class EOT > void peoSyncIslandMig< EOT > :: immigrate()
|
||||||
|
{
|
||||||
|
|
||||||
lock(); {
|
lock ();
|
||||||
|
{
|
||||||
|
|
||||||
assert( imm.size() );
|
assert( imm.size() );
|
||||||
replace( destination, imm.front() ) ;
|
replace( destination, imm.front() ) ;
|
||||||
imm.pop();
|
imm.pop();
|
||||||
printDebugMessage( "receiving some immigrants." );
|
printDebugMessage( "receiving some immigrants." );
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncIslandMig< EOT > :: operator()() {
|
template< class EOT > void peoSyncIslandMig< EOT > :: operator()()
|
||||||
|
{
|
||||||
|
|
||||||
if ( !cont( source ) ) {
|
if ( !cont( source ) )
|
||||||
|
{
|
||||||
// sending emigrants
|
|
||||||
emigrate();
|
|
||||||
stop();
|
|
||||||
|
|
||||||
// synchronizing
|
// sending emigrants
|
||||||
sem_wait( &sync );
|
emigrate();
|
||||||
getOwner()->setActive();
|
stop();
|
||||||
|
|
||||||
// receiving immigrants
|
// synchronizing
|
||||||
immigrate();
|
sem_wait( &sync );
|
||||||
}
|
getOwner()->setActive();
|
||||||
|
|
||||||
|
// receiving immigrants
|
||||||
|
immigrate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncIslandMig< EOT > :: notifySending() {
|
template< class EOT > void peoSyncIslandMig< EOT > :: notifySending()
|
||||||
|
{
|
||||||
|
|
||||||
lock(); {
|
lock ();
|
||||||
|
{
|
||||||
|
|
||||||
if ( imm.empty() ) {
|
if ( imm.empty() )
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage( "entering pasive mode\n" );
|
printDebugMessage( "entering pasive mode\n" );
|
||||||
getOwner()->setPassive();
|
getOwner()->setPassive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
resume();
|
resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoSyncMultiStart.h>
|
* <peoSyncMultiStart.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -61,150 +61,156 @@ extern int getNodeRank();
|
||||||
//! peoSyncMultiStart object can be specified as checkpoint object for a classic ParadisEO evolutionary algorithm
|
//! peoSyncMultiStart object can be specified as checkpoint object for a classic ParadisEO evolutionary algorithm
|
||||||
//! thus allowing for simple hybridization schemes which combine the evolutionary approach with a local search approach,
|
//! thus allowing for simple hybridization schemes which combine the evolutionary approach with a local search approach,
|
||||||
//! for example, executed at the end of each generation.
|
//! for example, executed at the end of each generation.
|
||||||
template< class EOT > class peoSyncMultiStart : public Service, public eoUpdater {
|
template< class EOT > class peoSyncMultiStart : public Service, public eoUpdater
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Constructor function - several simple parameters are required for defining the characteristics of the multi-start model.
|
//! Constructor function - several simple parameters are required for defining the characteristics of the multi-start model.
|
||||||
//!
|
//!
|
||||||
//! @param eoContinue< EOT >& __cont - defined for including further functionality - no semantics associated at this time;
|
//! @param eoContinue< EOT >& __cont - defined for including further functionality - no semantics associated at this time;
|
||||||
//! @param eoSelect< EOT >& __select - selection strategy for obtaining a subset of the initial population on which to apply the specified algorithm;
|
//! @param eoSelect< EOT >& __select - selection strategy for obtaining a subset of the initial population on which to apply the specified algorithm;
|
||||||
//! @param eoReplacement< EOT >& __replace - replacement strategy for integrating the resulting individuals in the initial population;
|
//! @param eoReplacement< EOT >& __replace - replacement strategy for integrating the resulting individuals in the initial population;
|
||||||
//! @param moAlgo< EOT >& __ls - algorithm to be applied on each of the selected individuals - a <b>moAlgo< EOT ></b>-derived object must be specified;
|
//! @param moAlgo< EOT >& __ls - algorithm to be applied on each of the selected individuals - a <b>moAlgo< EOT ></b>-derived object must be specified;
|
||||||
//! @param eoPop< EOT >& __pop - the initial population from which the individuals are selected for applying the specified algorithm.
|
//! @param eoPop< EOT >& __pop - the initial population from which the individuals are selected for applying the specified algorithm.
|
||||||
peoSyncMultiStart(
|
peoSyncMultiStart(
|
||||||
|
|
||||||
eoContinue< EOT >& __cont,
|
eoContinue< EOT >& __cont,
|
||||||
eoSelect< EOT >& __select,
|
eoSelect< EOT >& __select,
|
||||||
eoReplacement< EOT >& __replace,
|
eoReplacement< EOT >& __replace,
|
||||||
moAlgo< EOT >& __ls,
|
moAlgo< EOT >& __ls,
|
||||||
eoPop< EOT >& __pop
|
eoPop< EOT >& __pop
|
||||||
);
|
);
|
||||||
|
|
||||||
//! Operator which synchronously executes the specified algorithm on the individuals selected from the initial population.
|
//! Operator which synchronously executes the specified algorithm on the individuals selected from the initial population.
|
||||||
//! There is no need to explicitly call the operator - automatically called as checkpoint operator.
|
//! There is no need to explicitly call the operator - automatically called as checkpoint operator.
|
||||||
void operator()();
|
void operator()();
|
||||||
|
|
||||||
//! Auxiliary function for transferring data between the process requesting the synchronous execution of the specified
|
//! Auxiliary function for transferring data between the process requesting the synchronous execution of the specified
|
||||||
//! algorithm and the process which actually executes the algorithm. There is no need to explicitly call the function.
|
//! algorithm and the process which actually executes the algorithm. There is no need to explicitly call the function.
|
||||||
void packData();
|
void packData();
|
||||||
|
|
||||||
//! Auxiliary function for transferring data between the process requesting the synchronous execution of the specified
|
//! Auxiliary function for transferring data between the process requesting the synchronous execution of the specified
|
||||||
//! algorithm and the process which actually executes the algorithm. There is no need to explicitly call the function.
|
//! algorithm and the process which actually executes the algorithm. There is no need to explicitly call the function.
|
||||||
void unpackData();
|
void unpackData();
|
||||||
|
|
||||||
//! Auxiliary function for actually executing the specified algorithm on one assigned individual. There is no need to
|
//! Auxiliary function for actually executing the specified algorithm on one assigned individual. There is no need to
|
||||||
//! explicitly call the function.
|
//! explicitly call the function.
|
||||||
void execute();
|
void execute();
|
||||||
|
|
||||||
//! Auxiliary function for transferring data between the process requesting the synchronous execution of the specified
|
//! Auxiliary function for transferring data between the process requesting the synchronous execution of the specified
|
||||||
//! algorithm and the process which actually executes the algorithm. There is no need to explicitly call the function.
|
//! algorithm and the process which actually executes the algorithm. There is no need to explicitly call the function.
|
||||||
void packResult();
|
void packResult();
|
||||||
|
|
||||||
//! Auxiliary function for transferring data between the process requesting the synchronous execution of the specified
|
//! Auxiliary function for transferring data between the process requesting the synchronous execution of the specified
|
||||||
//! algorithm and the process which actually executes the algorithm. There is no need to explicitly call the function.
|
//! algorithm and the process which actually executes the algorithm. There is no need to explicitly call the function.
|
||||||
void unpackResult();
|
void unpackResult();
|
||||||
|
|
||||||
//! Auxiliary function for notifications between the process requesting the synchronous multi-start execution
|
//! Auxiliary function for notifications between the process requesting the synchronous multi-start execution
|
||||||
//! and the processes that performs the actual execution phase. There is no need to explicitly call the function.
|
//! and the processes that performs the actual execution phase. There is no need to explicitly call the function.
|
||||||
void notifySendingData();
|
void notifySendingData();
|
||||||
|
|
||||||
//! Auxiliary function for notifications between the process requesting the synchronous multi-start execution
|
//! Auxiliary function for notifications between the process requesting the synchronous multi-start execution
|
||||||
//! and the processes that performs the actual execution phase. There is no need to explicitly call the function.
|
//! and the processes that performs the actual execution phase. There is no need to explicitly call the function.
|
||||||
void notifySendingAllResourceRequests();
|
void notifySendingAllResourceRequests();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
eoContinue< EOT >& cont;
|
eoContinue< EOT >& cont;
|
||||||
eoSelect< EOT >& select;
|
eoSelect< EOT >& select;
|
||||||
eoReplacement< EOT >& replace;
|
eoReplacement< EOT >& replace;
|
||||||
|
|
||||||
moAlgo< EOT >& ls;
|
moAlgo< EOT >& ls;
|
||||||
|
|
||||||
eoPop< EOT >& pop;
|
eoPop< EOT >& pop;
|
||||||
eoPop< EOT > sel;
|
eoPop< EOT > sel;
|
||||||
eoPop< EOT > impr_sel;
|
eoPop< EOT > impr_sel;
|
||||||
|
|
||||||
EOT sol;
|
EOT sol;
|
||||||
unsigned idx;
|
unsigned idx;
|
||||||
unsigned num_term;
|
unsigned num_term;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > peoSyncMultiStart< EOT > :: peoSyncMultiStart(
|
template< class EOT > peoSyncMultiStart< EOT > :: peoSyncMultiStart(
|
||||||
|
|
||||||
eoContinue < EOT >& __cont,
|
eoContinue < EOT >& __cont,
|
||||||
eoSelect< EOT >& __select,
|
eoSelect< EOT >& __select,
|
||||||
eoReplacement< EOT >& __replace,
|
eoReplacement< EOT >& __replace,
|
||||||
moAlgo < EOT >& __ls,
|
moAlgo < EOT >& __ls,
|
||||||
eoPop< EOT >& __pop
|
eoPop< EOT >& __pop
|
||||||
|
|
||||||
) : cont( __cont ), select( __select ), replace( __replace ), ls( __ls ), pop( __pop )
|
) : cont( __cont ), select( __select ), replace( __replace ), ls( __ls ), pop( __pop )
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template< class EOT > void peoSyncMultiStart< EOT > :: packData()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
:: pack( sel[ idx++ ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncMultiStart< EOT > :: packData() {
|
template< class EOT > void peoSyncMultiStart< EOT > :: unpackData()
|
||||||
|
{
|
||||||
|
|
||||||
:: pack( sel[ idx++ ] );
|
unpack( sol );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncMultiStart< EOT > :: unpackData() {
|
template< class EOT > void peoSyncMultiStart< EOT > :: execute()
|
||||||
|
{
|
||||||
|
|
||||||
unpack( sol );
|
ls( sol );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncMultiStart< EOT > :: execute() {
|
template< class EOT > void peoSyncMultiStart< EOT > :: packResult()
|
||||||
|
{
|
||||||
|
|
||||||
ls( sol );
|
pack( sol );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncMultiStart< EOT > :: packResult() {
|
template< class EOT > void peoSyncMultiStart< EOT > :: unpackResult()
|
||||||
|
{
|
||||||
|
|
||||||
pack( sol );
|
unpack( sol );
|
||||||
|
impr_sel.push_back( sol );
|
||||||
|
num_term++;
|
||||||
|
|
||||||
|
if ( num_term == sel.size() )
|
||||||
|
{
|
||||||
|
|
||||||
|
getOwner()->setActive();
|
||||||
|
replace( pop, impr_sel );
|
||||||
|
|
||||||
|
printDebugMessage( "replacing the improved individuals in the population." );
|
||||||
|
resume();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncMultiStart< EOT > :: unpackResult() {
|
template< class EOT > void peoSyncMultiStart< EOT > :: operator()()
|
||||||
|
{
|
||||||
|
|
||||||
unpack( sol );
|
printDebugMessage( "performing the parallel multi-start hybridization." );
|
||||||
impr_sel.push_back( sol );
|
select( pop, sel );
|
||||||
num_term++;
|
impr_sel.clear();
|
||||||
|
idx = num_term = 0;
|
||||||
if ( num_term == sel.size() ) {
|
requestResourceRequest( sel.size() );
|
||||||
|
stop();
|
||||||
getOwner()->setActive();
|
|
||||||
replace( pop, impr_sel );
|
|
||||||
|
|
||||||
printDebugMessage( "replacing the improved individuals in the population." );
|
|
||||||
resume();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncMultiStart< EOT > :: operator()() {
|
template< class EOT > void peoSyncMultiStart< EOT > :: notifySendingData()
|
||||||
|
{}
|
||||||
printDebugMessage( "performing the parallel multi-start hybridization." );
|
|
||||||
select( pop, sel );
|
|
||||||
impr_sel.clear();
|
|
||||||
idx = num_term = 0;
|
|
||||||
requestResourceRequest( sel.size() );
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncMultiStart< EOT > :: notifySendingData() {
|
template< class EOT > void peoSyncMultiStart< EOT > :: notifySendingAllResourceRequests()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
getOwner()->setPassive();
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoSyncMultiStart< EOT > :: notifySendingAllResourceRequests() {
|
|
||||||
|
|
||||||
getOwner()->setPassive();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoSynchronousMultiStart.h>
|
* <peoSynchronousMultiStart.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -42,227 +42,265 @@
|
||||||
#include "core/messaging.h"
|
#include "core/messaging.h"
|
||||||
|
|
||||||
|
|
||||||
template < typename EntityType > class peoSynchronousMultiStart : public Service {
|
template < typename EntityType > class peoSynchronousMultiStart : public Service
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
template < typename AlgorithmType > peoSynchronousMultiStart( AlgorithmType& externalAlgorithm ) {
|
template < typename AlgorithmType > peoSynchronousMultiStart( AlgorithmType& externalAlgorithm )
|
||||||
|
{
|
||||||
|
|
||||||
singularAlgorithm = new Algorithm< AlgorithmType >( externalAlgorithm );
|
singularAlgorithm = new Algorithm< AlgorithmType >( externalAlgorithm );
|
||||||
algorithms.push_back( singularAlgorithm );
|
algorithms.push_back( singularAlgorithm );
|
||||||
|
|
||||||
aggregationFunction = new NoAggregationFunction();
|
aggregationFunction = new NoAggregationFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename AlgorithmType, typename AggregationFunctionType > peoSynchronousMultiStart( std::vector< AlgorithmType* >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction ) {
|
template < typename AlgorithmType, typename AggregationFunctionType > peoSynchronousMultiStart( std::vector< AlgorithmType* >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction )
|
||||||
|
{
|
||||||
|
|
||||||
for ( unsigned int index = 0; index < externalAlgorithms; index++ ) {
|
for ( unsigned int index = 0; index < externalAlgorithms; index++ )
|
||||||
|
{
|
||||||
|
|
||||||
algorithms.push_back( new Algorithm< AlgorithmType >( *externalAlgorithms[ index ] ) );
|
algorithms.push_back( new Algorithm< AlgorithmType >( *externalAlgorithms[ index ] ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
aggregationFunction = new Algorithm< AggregationFunctionType >( externalAggregationFunction );
|
aggregationFunction = new Algorithm< AggregationFunctionType >( externalAggregationFunction );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
~peoSynchronousMultiStart() {
|
~peoSynchronousMultiStart()
|
||||||
|
{
|
||||||
|
|
||||||
for ( unsigned int index = 0; index < data.size(); index++ ) delete data[ index ];
|
for ( unsigned int index = 0; index < data.size(); index++ ) delete data[ index ];
|
||||||
for ( unsigned int index = 0; index < algorithms.size(); index++ ) delete algorithms[ index ];
|
for ( unsigned int index = 0; index < algorithms.size(); index++ ) delete algorithms[ index ];
|
||||||
|
|
||||||
delete aggregationFunction;
|
delete aggregationFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template < typename Type > void operator()( Type& externalData ) {
|
template < typename Type > void operator()( Type& externalData )
|
||||||
|
{
|
||||||
|
|
||||||
for ( typename Type::iterator externalDataIterator = externalData.begin(); externalDataIterator != externalData.end(); externalDataIterator++ ) {
|
for ( typename Type::iterator externalDataIterator = externalData.begin(); externalDataIterator != externalData.end(); externalDataIterator++ )
|
||||||
|
{
|
||||||
|
|
||||||
data.push_back( new DataType< EntityType >( *externalDataIterator ) );
|
data.push_back( new DataType< EntityType >( *externalDataIterator ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
functionIndex = dataIndex = idx = num_term = 0;
|
|
||||||
requestResourceRequest( data.size() * algorithms.size() );
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
functionIndex = dataIndex = idx = num_term = 0;
|
||||||
|
requestResourceRequest( data.size() * algorithms.size() );
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
template < typename Type > void operator()( const Type& externalDataBegin, const Type& externalDataEnd ) {
|
|
||||||
|
|
||||||
for ( Type externalDataIterator = externalDataBegin; externalDataIterator != externalDataEnd; externalDataIterator++ ) {
|
template < typename Type > void operator()( const Type& externalDataBegin, const Type& externalDataEnd )
|
||||||
|
{
|
||||||
|
|
||||||
data.push_back( new DataType< EntityType >( *externalDataIterator ) );
|
for ( Type externalDataIterator = externalDataBegin; externalDataIterator != externalDataEnd; externalDataIterator++ )
|
||||||
}
|
{
|
||||||
|
|
||||||
functionIndex = dataIndex = idx = num_term = 0;
|
|
||||||
requestResourceRequest( data.size() * algorithms.size() );
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
data.push_back( new DataType< EntityType >( *externalDataIterator ) );
|
||||||
|
}
|
||||||
|
|
||||||
void packData();
|
functionIndex = dataIndex = idx = num_term = 0;
|
||||||
|
requestResourceRequest( data.size() * algorithms.size() );
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
void unpackData();
|
|
||||||
|
|
||||||
void execute();
|
void packData();
|
||||||
|
|
||||||
void packResult();
|
void unpackData();
|
||||||
|
|
||||||
void unpackResult();
|
void execute();
|
||||||
|
|
||||||
void notifySendingData();
|
void packResult();
|
||||||
|
|
||||||
void notifySendingAllResourceRequests();
|
void unpackResult();
|
||||||
|
|
||||||
|
void notifySendingData();
|
||||||
|
|
||||||
private:
|
void notifySendingAllResourceRequests();
|
||||||
|
|
||||||
template < typename Type > struct DataType;
|
|
||||||
|
|
||||||
struct AbstractDataType {
|
private:
|
||||||
|
|
||||||
virtual ~AbstractDataType() { }
|
template < typename Type > struct DataType;
|
||||||
|
|
||||||
template < typename Type > operator Type& () {
|
struct AbstractDataType
|
||||||
|
{
|
||||||
|
|
||||||
return ( dynamic_cast< DataType< Type >& >( *this ) ).data;
|
virtual ~AbstractDataType()
|
||||||
}
|
{ }
|
||||||
};
|
|
||||||
|
|
||||||
template < typename Type > struct DataType : public AbstractDataType {
|
template < typename Type > operator Type& ()
|
||||||
|
{
|
||||||
|
|
||||||
DataType( Type& externalData ) : data( externalData ) { }
|
return ( dynamic_cast< DataType< Type >& >( *this ) ).data;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Type& data;
|
template < typename Type > struct DataType : public AbstractDataType
|
||||||
};
|
{
|
||||||
|
|
||||||
struct AbstractAlgorithm {
|
DataType( Type& externalData ) : data( externalData )
|
||||||
|
{ }
|
||||||
|
|
||||||
virtual ~AbstractAlgorithm() { }
|
Type& data;
|
||||||
|
};
|
||||||
|
|
||||||
virtual void operator()( AbstractDataType& dataTypeInstance ) {}
|
struct AbstractAlgorithm
|
||||||
};
|
{
|
||||||
|
|
||||||
template < typename AlgorithmType > struct Algorithm : public AbstractAlgorithm {
|
virtual ~AbstractAlgorithm()
|
||||||
|
{ }
|
||||||
|
|
||||||
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm ) { }
|
virtual void operator()( AbstractDataType& dataTypeInstance )
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
void operator()( AbstractDataType& dataTypeInstance ) { algorithm( dataTypeInstance ); }
|
template < typename AlgorithmType > struct Algorithm : public AbstractAlgorithm
|
||||||
|
{
|
||||||
|
|
||||||
AlgorithmType& algorithm;
|
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm )
|
||||||
};
|
{ }
|
||||||
|
|
||||||
|
void operator()( AbstractDataType& dataTypeInstance )
|
||||||
|
{
|
||||||
|
algorithm( dataTypeInstance );
|
||||||
|
}
|
||||||
|
|
||||||
|
AlgorithmType& algorithm;
|
||||||
|
};
|
||||||
|
|
||||||
struct AbstractAggregationAlgorithm {
|
|
||||||
|
|
||||||
virtual ~AbstractAggregationAlgorithm() { }
|
|
||||||
|
|
||||||
virtual void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) {};
|
struct AbstractAggregationAlgorithm
|
||||||
};
|
{
|
||||||
|
|
||||||
template < typename AggregationAlgorithmType > struct AggregationAlgorithm : public AbstractAggregationAlgorithm {
|
virtual ~AbstractAggregationAlgorithm()
|
||||||
|
{ }
|
||||||
|
|
||||||
AggregationAlgorithm( AggregationAlgorithmType& externalAggregationAlgorithm ) : aggregationAlgorithm( externalAggregationAlgorithm ) { }
|
virtual void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
|
||||||
|
{};
|
||||||
|
};
|
||||||
|
|
||||||
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) {
|
template < typename AggregationAlgorithmType > struct AggregationAlgorithm : public AbstractAggregationAlgorithm
|
||||||
|
{
|
||||||
|
|
||||||
aggregationAlgorithm( dataTypeInstanceA, dataTypeInstanceB );
|
AggregationAlgorithm( AggregationAlgorithmType& externalAggregationAlgorithm ) : aggregationAlgorithm( externalAggregationAlgorithm )
|
||||||
}
|
{ }
|
||||||
|
|
||||||
AggregationAlgorithmType& aggregationAlgorithm;
|
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
|
||||||
};
|
{
|
||||||
|
|
||||||
struct NoAggregationFunction : public AbstractAggregationAlgorithm {
|
aggregationAlgorithm( dataTypeInstanceA, dataTypeInstanceB );
|
||||||
|
}
|
||||||
|
|
||||||
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) {
|
AggregationAlgorithmType& aggregationAlgorithm;
|
||||||
|
};
|
||||||
|
|
||||||
static_cast< EntityType& >( dataTypeInstanceA ) = static_cast< EntityType& >( dataTypeInstanceB );
|
struct NoAggregationFunction : public AbstractAggregationAlgorithm
|
||||||
}
|
{
|
||||||
};
|
|
||||||
|
|
||||||
|
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
|
||||||
|
{
|
||||||
|
|
||||||
|
static_cast< EntityType& >( dataTypeInstanceA ) = static_cast< EntityType& >( dataTypeInstanceB );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
AbstractAlgorithm* singularAlgorithm;
|
|
||||||
|
|
||||||
std::vector< AbstractAlgorithm* > algorithms;
|
|
||||||
AbstractAggregationAlgorithm* aggregationFunction;
|
|
||||||
|
|
||||||
|
AbstractAlgorithm* singularAlgorithm;
|
||||||
|
|
||||||
EntityType entityTypeInstance;
|
std::vector< AbstractAlgorithm* > algorithms;
|
||||||
std::vector< AbstractDataType* > data;
|
AbstractAggregationAlgorithm* aggregationFunction;
|
||||||
|
|
||||||
unsigned idx;
|
|
||||||
unsigned num_term;
|
|
||||||
unsigned dataIndex;
|
|
||||||
unsigned functionIndex;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
EntityType entityTypeInstance;
|
||||||
|
std::vector< AbstractDataType* > data;
|
||||||
|
|
||||||
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::packData() {
|
unsigned idx;
|
||||||
|
unsigned num_term;
|
||||||
|
unsigned dataIndex;
|
||||||
|
unsigned functionIndex;
|
||||||
|
};
|
||||||
|
|
||||||
::pack( functionIndex );
|
|
||||||
::pack( idx );
|
|
||||||
::pack( ( EntityType& ) *data[ idx++ ] );
|
|
||||||
|
|
||||||
// done with functionIndex for the entire data set - moving to another
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::packData()
|
||||||
// function/algorithm starting all over with the entire data set ( idx is set to 0 )
|
{
|
||||||
if ( idx == data.size() ) {
|
|
||||||
|
|
||||||
++functionIndex; idx = 0;
|
::pack( functionIndex );
|
||||||
}
|
::pack( idx );
|
||||||
|
::pack( ( EntityType& ) *data[ idx++ ] );
|
||||||
|
|
||||||
|
// done with functionIndex for the entire data set - moving to another
|
||||||
|
// function/algorithm starting all over with the entire data set ( idx is set to 0 )
|
||||||
|
if ( idx == data.size() )
|
||||||
|
{
|
||||||
|
|
||||||
|
++functionIndex;
|
||||||
|
idx = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::unpackData() {
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::unpackData()
|
||||||
|
{
|
||||||
|
|
||||||
::unpack( functionIndex );
|
::unpack( functionIndex );
|
||||||
::unpack( dataIndex );
|
::unpack( dataIndex );
|
||||||
::unpack( entityTypeInstance );
|
::unpack( entityTypeInstance );
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::execute() {
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::execute()
|
||||||
|
{
|
||||||
|
|
||||||
// wrapping the unpacked data - the definition of an abstract algorithm imposes
|
// wrapping the unpacked data - the definition of an abstract algorithm imposes
|
||||||
// that its internal function operator acts only on abstract data types
|
// that its internal function operator acts only on abstract data types
|
||||||
AbstractDataType* entityWrapper = new DataType< EntityType >( entityTypeInstance );
|
AbstractDataType* entityWrapper = new DataType< EntityType >( entityTypeInstance );
|
||||||
algorithms[ functionIndex ]->operator()( *entityWrapper );
|
algorithms[ functionIndex ]->operator()( *entityWrapper );
|
||||||
|
|
||||||
delete entityWrapper;
|
delete entityWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::packResult() {
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::packResult()
|
||||||
|
{
|
||||||
|
|
||||||
::pack( dataIndex );
|
::pack( dataIndex );
|
||||||
::pack( entityTypeInstance );
|
::pack( entityTypeInstance );
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::unpackResult() {
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::unpackResult()
|
||||||
|
{
|
||||||
|
|
||||||
::unpack( dataIndex );
|
::unpack( dataIndex );
|
||||||
::unpack( entityTypeInstance );
|
::unpack( entityTypeInstance );
|
||||||
|
|
||||||
// wrapping the unpacked data - the definition of an abstract algorithm imposes
|
// wrapping the unpacked data - the definition of an abstract algorithm imposes
|
||||||
// that its internal function operator acts only on abstract data types
|
// that its internal function operator acts only on abstract data types
|
||||||
AbstractDataType* entityWrapper = new DataType< EntityType >( entityTypeInstance );
|
AbstractDataType* entityWrapper = new DataType< EntityType >( entityTypeInstance );
|
||||||
aggregationFunction->operator()( *data[ dataIndex ], *entityWrapper );
|
aggregationFunction->operator()( *data[ dataIndex ], *entityWrapper );
|
||||||
delete entityWrapper;
|
delete entityWrapper;
|
||||||
|
|
||||||
num_term++;
|
num_term++;
|
||||||
|
|
||||||
if ( num_term == data.size() * algorithms.size() ) {
|
if ( num_term == data.size() * algorithms.size() )
|
||||||
|
{
|
||||||
|
|
||||||
getOwner()->setActive();
|
getOwner()->setActive();
|
||||||
resume();
|
resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::notifySendingData() {
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::notifySendingData()
|
||||||
|
{}
|
||||||
|
|
||||||
}
|
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::notifySendingAllResourceRequests()
|
||||||
|
{
|
||||||
|
|
||||||
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::notifySendingAllResourceRequests() {
|
getOwner()->setPassive();
|
||||||
|
|
||||||
getOwner()->setPassive();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <peoTransform.h>
|
* <peoTransform.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -45,9 +45,8 @@
|
||||||
|
|
||||||
//! The peoTransform class acts only as an interface for creating transform operators - for an example
|
//! The peoTransform class acts only as an interface for creating transform operators - for an example
|
||||||
//! please refer to the <b>peoSeqTransform</b> and the <b>peoParaSGATransform</b> classes.
|
//! please refer to the <b>peoSeqTransform</b> and the <b>peoParaSGATransform</b> classes.
|
||||||
template< class EOT > class peoTransform : public Service, public eoTransform< EOT > {
|
template< class EOT > class peoTransform : public Service, public eoTransform< EOT >
|
||||||
|
{};
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <comm.cpp>
|
* <comm.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -51,42 +51,48 @@ static sem_t sem_comm_init;
|
||||||
|
|
||||||
static Communicator * the_thread;
|
static Communicator * the_thread;
|
||||||
|
|
||||||
Communicator :: Communicator (int * __argc, char * * * __argv) {
|
Communicator :: Communicator (int * __argc, char * * * __argv)
|
||||||
|
{
|
||||||
|
|
||||||
the_thread = this;
|
the_thread = this;
|
||||||
initNode (__argc, __argv);
|
initNode (__argc, __argv);
|
||||||
loadRMCParameters (* __argc, * __argv);
|
loadRMCParameters (* __argc, * __argv);
|
||||||
sem_post (& sem_comm_init);
|
sem_post (& sem_comm_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Communicator :: start () {
|
void Communicator :: start ()
|
||||||
|
{
|
||||||
|
|
||||||
while (true) {
|
while (true)
|
||||||
|
{
|
||||||
/* Zzz Zzz Zzz :-))) */
|
|
||||||
sleep ();
|
|
||||||
sendMessages ();
|
|
||||||
|
|
||||||
if (! atLeastOneActiveRunner ())
|
/* Zzz Zzz Zzz :-))) */
|
||||||
break;
|
sleep ();
|
||||||
receiveMessages ();
|
sendMessages ();
|
||||||
}
|
|
||||||
waitBuffers ();
|
if (! atLeastOneActiveRunner ())
|
||||||
|
break;
|
||||||
|
receiveMessages ();
|
||||||
|
}
|
||||||
|
waitBuffers ();
|
||||||
printDebugMessage ("finalizing");
|
printDebugMessage ("finalizing");
|
||||||
MPI_Finalize ();
|
MPI_Finalize ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initCommunication () {
|
void initCommunication ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_init (& sem_comm_init, 0, 0);
|
sem_init (& sem_comm_init, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitNodeInitialization () {
|
void waitNodeInitialization ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_wait (& sem_comm_init);
|
sem_wait (& sem_comm_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wakeUpCommunicator () {
|
void wakeUpCommunicator ()
|
||||||
|
{
|
||||||
|
|
||||||
the_thread -> wakeUp ();
|
the_thread -> wakeUp ();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <comm.h>
|
* <comm.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -40,15 +40,16 @@
|
||||||
#include "../../core/communicable.h"
|
#include "../../core/communicable.h"
|
||||||
#include "../../core/reac_thread.h"
|
#include "../../core/reac_thread.h"
|
||||||
|
|
||||||
class Communicator : public ReactiveThread {
|
class Communicator : public ReactiveThread
|
||||||
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
/* Ctor */
|
|
||||||
Communicator (int * __argc, char * * * __argv);
|
|
||||||
|
|
||||||
void start ();
|
/* Ctor */
|
||||||
};
|
Communicator (int * __argc, char * * * __argv);
|
||||||
|
|
||||||
|
void start ();
|
||||||
|
};
|
||||||
|
|
||||||
extern void initCommunication ();
|
extern void initCommunication ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <coop.cpp>
|
* <coop.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -41,28 +41,33 @@
|
||||||
#include "mess.h"
|
#include "mess.h"
|
||||||
#include "../../core/peo_debug.h"
|
#include "../../core/peo_debug.h"
|
||||||
|
|
||||||
Runner * Cooperative :: getOwner () {
|
Runner * Cooperative :: getOwner ()
|
||||||
|
{
|
||||||
|
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cooperative :: setOwner (Runner & __runner) {
|
void Cooperative :: setOwner (Runner & __runner)
|
||||||
|
{
|
||||||
|
|
||||||
owner = & __runner;
|
owner = & __runner;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cooperative :: send (Cooperative * __coop) {
|
void Cooperative :: send (Cooperative * __coop)
|
||||||
|
{
|
||||||
|
|
||||||
:: send (this, getRankOfRunner (__coop -> getOwner () -> getID ()), COOP_TAG);
|
:: send (this, getRankOfRunner (__coop -> getOwner () -> getID ()), COOP_TAG);
|
||||||
// stop ();
|
// stop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
Cooperative * getCooperative (COOP_ID __key) {
|
Cooperative * getCooperative (COOP_ID __key)
|
||||||
|
{
|
||||||
|
|
||||||
return dynamic_cast <Cooperative *> (getCommunicable (__key));
|
return dynamic_cast <Cooperative *> (getCommunicable (__key));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cooperative :: notifySending () {
|
void Cooperative :: notifySending ()
|
||||||
|
{
|
||||||
|
|
||||||
//getOwner -> setPassive ();
|
//getOwner -> setPassive ();
|
||||||
// resume ();
|
// resume ();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <mess.cpp>
|
* <mess.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -42,54 +42,60 @@
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
#define MPI_BUF_SIZE 1024*64
|
#define MPI_BUF_SIZE 1024*64
|
||||||
|
|
||||||
static char mpi_buf [MPI_BUF_SIZE];
|
static char mpi_buf [MPI_BUF_SIZE];
|
||||||
|
|
||||||
static int pos_buf ;
|
static int pos_buf ;
|
||||||
|
|
||||||
static std :: vector <char *> act_buf; /* Active buffers */
|
static std :: vector <char *> act_buf; /* Active buffers */
|
||||||
|
|
||||||
static std :: vector <MPI_Request *> act_req; /* Active requests */
|
static std :: vector <MPI_Request *> act_req; /* Active requests */
|
||||||
|
|
||||||
void cleanBuffers () {
|
void cleanBuffers ()
|
||||||
|
{
|
||||||
|
|
||||||
for (unsigned i = 0; i < act_req.size ();) {
|
for (unsigned i = 0; i < act_req.size ();)
|
||||||
|
{
|
||||||
MPI_Status stat ;
|
|
||||||
int flag ;
|
MPI_Status stat ;
|
||||||
MPI_Test (act_req [i], & flag, & stat) ;
|
int flag ;
|
||||||
if (flag) {
|
MPI_Test (act_req [i], & flag, & stat) ;
|
||||||
|
if (flag)
|
||||||
delete act_buf [i] ;
|
{
|
||||||
delete act_req [i] ;
|
|
||||||
|
delete act_buf [i] ;
|
||||||
act_buf [i] = act_buf.back () ;
|
delete act_req [i] ;
|
||||||
act_buf.pop_back () ;
|
|
||||||
|
act_buf [i] = act_buf.back () ;
|
||||||
act_req [i] = act_req.back () ;
|
act_buf.pop_back () ;
|
||||||
act_req.pop_back () ;
|
|
||||||
|
act_req [i] = act_req.back () ;
|
||||||
|
act_req.pop_back () ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
i ++;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
i ++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitBuffers () {
|
void waitBuffers ()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage ("waiting the termination of the asynchronous operations to complete");
|
printDebugMessage ("waiting the termination of the asynchronous operations to complete");
|
||||||
|
|
||||||
for (unsigned i = 0; i < act_req.size (); i ++) {
|
for (unsigned i = 0; i < act_req.size (); i ++)
|
||||||
|
{
|
||||||
MPI_Status stat ;
|
|
||||||
|
|
||||||
MPI_Wait (act_req [i], & stat) ;
|
MPI_Status stat ;
|
||||||
|
|
||||||
delete act_buf [i] ;
|
MPI_Wait (act_req [i], & stat) ;
|
||||||
delete act_req [i] ;
|
|
||||||
}
|
delete act_buf [i] ;
|
||||||
|
delete act_req [i] ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool probeMessage (int & __src, int & __tag) {
|
bool probeMessage (int & __src, int & __tag)
|
||||||
|
{
|
||||||
|
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
|
|
@ -103,36 +109,41 @@ bool probeMessage (int & __src, int & __tag) {
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitMessage () {
|
void waitMessage ()
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Status stat;
|
MPI_Status stat;
|
||||||
|
|
||||||
MPI_Probe (MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, & stat);
|
MPI_Probe (MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, & stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initMessage () {
|
void initMessage ()
|
||||||
|
{
|
||||||
|
|
||||||
pos_buf = 0;
|
pos_buf = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendMessage (int __to, int __tag) {
|
void sendMessage (int __to, int __tag)
|
||||||
|
{
|
||||||
|
|
||||||
cleanBuffers ();
|
cleanBuffers ();
|
||||||
act_buf.push_back (new char [pos_buf]);
|
act_buf.push_back (new char [pos_buf]);
|
||||||
act_req.push_back (new MPI_Request);
|
act_req.push_back (new MPI_Request);
|
||||||
memcpy (act_buf.back (), mpi_buf, pos_buf);
|
memcpy (act_buf.back (), mpi_buf, pos_buf);
|
||||||
MPI_Isend (act_buf.back (), pos_buf, MPI_PACKED, __to, __tag, MPI_COMM_WORLD, act_req.back ());
|
MPI_Isend (act_buf.back (), pos_buf, MPI_PACKED, __to, __tag, MPI_COMM_WORLD, act_req.back ());
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendMessageToAll (int __tag) {
|
void sendMessageToAll (int __tag)
|
||||||
|
{
|
||||||
|
|
||||||
for (int i = 0; i < getNumberOfNodes (); i ++)
|
for (int i = 0; i < getNumberOfNodes (); i ++)
|
||||||
sendMessage (i, __tag);
|
sendMessage (i, __tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void receiveMessage (int __from, int __tag) {
|
void receiveMessage (int __from, int __tag)
|
||||||
|
{
|
||||||
MPI_Status stat;
|
|
||||||
|
MPI_Status stat;
|
||||||
MPI_Request req;
|
MPI_Request req;
|
||||||
|
|
||||||
MPI_Irecv (mpi_buf, MPI_BUF_SIZE, MPI_PACKED, __from, __tag, MPI_COMM_WORLD, & req) ;
|
MPI_Irecv (mpi_buf, MPI_BUF_SIZE, MPI_PACKED, __from, __tag, MPI_COMM_WORLD, & req) ;
|
||||||
|
|
@ -140,126 +151,146 @@ void receiveMessage (int __from, int __tag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Char */
|
/* Char */
|
||||||
void pack (const char & __c) {
|
void pack (const char & __c)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Pack ((void *) & __c, 1, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
MPI_Pack ((void *) & __c, 1, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Float */
|
/* Float */
|
||||||
void pack (const float & __f, int __nitem) {
|
void pack (const float & __f, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Pack ((void *) & __f, __nitem, MPI_FLOAT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
MPI_Pack ((void *) & __f, __nitem, MPI_FLOAT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Double */
|
/* Double */
|
||||||
void pack (const double & __d, int __nitem) {
|
void pack (const double & __d, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Pack ((void *) & __d, __nitem, MPI_DOUBLE, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
MPI_Pack ((void *) & __d, __nitem, MPI_DOUBLE, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Integer */
|
/* Integer */
|
||||||
void pack (const int & __i, int __nitem) {
|
void pack (const int & __i, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Pack ((void *) & __i, __nitem, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
MPI_Pack ((void *) & __i, __nitem, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsigned int. */
|
/* Unsigned int. */
|
||||||
void pack (const unsigned int & __ui, int __nitem) {
|
void pack (const unsigned int & __ui, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Pack ((void *) & __ui, __nitem, MPI_UNSIGNED, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
MPI_Pack ((void *) & __ui, __nitem, MPI_UNSIGNED, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Short int. */
|
/* Short int. */
|
||||||
void pack (const short & __sh, int __nitem) {
|
void pack (const short & __sh, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Pack ((void *) & __sh, __nitem, MPI_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
MPI_Pack ((void *) & __sh, __nitem, MPI_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsigned short */
|
/* Unsigned short */
|
||||||
void pack (const unsigned short & __ush, int __nitem) {
|
void pack (const unsigned short & __ush, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Pack ((void *) & __ush, __nitem, MPI_UNSIGNED_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
MPI_Pack ((void *) & __ush, __nitem, MPI_UNSIGNED_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Long */
|
/* Long */
|
||||||
void pack (const long & __l, int __nitem) {
|
void pack (const long & __l, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Pack ((void *) & __l, __nitem, MPI_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
MPI_Pack ((void *) & __l, __nitem, MPI_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsigned long */
|
/* Unsigned long */
|
||||||
void pack (const unsigned long & __ul, int __nitem) {
|
void pack (const unsigned long & __ul, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Pack ((void *) & __ul, __nitem, MPI_UNSIGNED_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
MPI_Pack ((void *) & __ul, __nitem, MPI_UNSIGNED_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* String */
|
/* String */
|
||||||
void pack (const char * __str) {
|
void pack (const char * __str)
|
||||||
|
{
|
||||||
|
|
||||||
int len = strlen (__str) + 1;
|
int len = strlen (__str) + 1;
|
||||||
MPI_Pack (& len, 1, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
MPI_Pack (& len, 1, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
MPI_Pack ((void *) __str, len, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
MPI_Pack ((void *) __str, len, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Char */
|
/* Char */
|
||||||
void unpack (char & __c) {
|
void unpack (char & __c)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __c, 1, MPI_CHAR, MPI_COMM_WORLD);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __c, 1, MPI_CHAR, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Float */
|
/* Float */
|
||||||
void unpack (float & __f, int __nitem) {
|
void unpack (float & __f, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __f, __nitem, MPI_FLOAT, MPI_COMM_WORLD);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __f, __nitem, MPI_FLOAT, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Double */
|
/* Double */
|
||||||
void unpack (double & __d, int __nitem) {
|
void unpack (double & __d, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __d, __nitem, MPI_DOUBLE, MPI_COMM_WORLD);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __d, __nitem, MPI_DOUBLE, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Integer */
|
/* Integer */
|
||||||
void unpack (int & __i, int __nitem) {
|
void unpack (int & __i, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __i, __nitem, MPI_INT, MPI_COMM_WORLD);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __i, __nitem, MPI_INT, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsigned int. */
|
/* Unsigned int. */
|
||||||
void unpack (unsigned int & __ui, int __nitem) {
|
void unpack (unsigned int & __ui, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ui, __nitem, MPI_UNSIGNED, MPI_COMM_WORLD);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ui, __nitem, MPI_UNSIGNED, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Short int. */
|
/* Short int. */
|
||||||
void unpack (short & __sh, int __nitem) {
|
void unpack (short & __sh, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __sh, __nitem, MPI_SHORT, MPI_COMM_WORLD);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __sh, __nitem, MPI_SHORT, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsigned short */
|
/* Unsigned short */
|
||||||
void unpack (unsigned short & __ush, int __nitem) {
|
void unpack (unsigned short & __ush, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ush, __nitem, MPI_UNSIGNED_SHORT, MPI_COMM_WORLD);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ush, __nitem, MPI_UNSIGNED_SHORT, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Long */
|
/* Long */
|
||||||
void unpack (long & __l, int __nitem) {
|
void unpack (long & __l, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __l, __nitem, MPI_LONG, MPI_COMM_WORLD);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __l, __nitem, MPI_LONG, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsigned long */
|
/* Unsigned long */
|
||||||
void unpack (unsigned long & __ul, int __nitem) {
|
void unpack (unsigned long & __ul, int __nitem)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ul, __nitem, MPI_UNSIGNED_LONG, MPI_COMM_WORLD);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ul, __nitem, MPI_UNSIGNED_LONG, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* String */
|
/* String */
|
||||||
void unpack (char * __str) {
|
void unpack (char * __str)
|
||||||
|
{
|
||||||
|
|
||||||
int len;
|
int len;
|
||||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & len, 1, MPI_INT, MPI_COMM_WORLD);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & len, 1, MPI_INT, MPI_COMM_WORLD);
|
||||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, __str, len, MPI_CHAR, MPI_COMM_WORLD);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, __str, len, MPI_CHAR, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <mess.h>
|
* <mess.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <node.cpp>
|
* <node.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -46,41 +46,46 @@ static std :: map <std :: string, int> name_to_rk;
|
||||||
|
|
||||||
static std :: vector <std :: string> rk_to_name;
|
static std :: vector <std :: string> rk_to_name;
|
||||||
|
|
||||||
int getNodeRank () {
|
int getNodeRank ()
|
||||||
|
{
|
||||||
|
|
||||||
return rk;
|
return rk;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getNumberOfNodes () {
|
int getNumberOfNodes ()
|
||||||
|
{
|
||||||
|
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getRankFromName (const std :: string & __name) {
|
int getRankFromName (const std :: string & __name)
|
||||||
|
{
|
||||||
return atoi (__name.c_str ());
|
|
||||||
|
return atoi (__name.c_str ());
|
||||||
}
|
}
|
||||||
|
|
||||||
void initNode (int * __argc, char * * * __argv) {
|
void initNode (int * __argc, char * * * __argv)
|
||||||
|
{
|
||||||
|
|
||||||
int provided;
|
int provided;
|
||||||
MPI_Init_thread (__argc, __argv, MPI_THREAD_FUNNELED, & provided);
|
MPI_Init_thread (__argc, __argv, MPI_THREAD_FUNNELED, & provided);
|
||||||
assert (provided == MPI_THREAD_FUNNELED); /* The MPI implementation must be multi-threaded.
|
assert (provided == MPI_THREAD_FUNNELED); /* The MPI implementation must be multi-threaded.
|
||||||
Yet, only one thread performs the comm.
|
Yet, only one thread performs the comm.
|
||||||
operations */
|
operations */
|
||||||
MPI_Comm_rank (MPI_COMM_WORLD, & rk); /* Who ? */
|
MPI_Comm_rank (MPI_COMM_WORLD, & rk); /* Who ? */
|
||||||
MPI_Comm_size (MPI_COMM_WORLD, & sz); /* How many ? */
|
MPI_Comm_size (MPI_COMM_WORLD, & sz); /* How many ? */
|
||||||
|
|
||||||
char names [sz] [MPI_MAX_PROCESSOR_NAME];
|
char names [sz] [MPI_MAX_PROCESSOR_NAME];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
/* Processor names */
|
/* Processor names */
|
||||||
MPI_Get_processor_name (names [0], & len); /* Me */
|
MPI_Get_processor_name (names [0], & len); /* Me */
|
||||||
MPI_Allgather (names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, MPI_COMM_WORLD); /* Broadcast */
|
MPI_Allgather (names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, MPI_COMM_WORLD); /* Broadcast */
|
||||||
|
|
||||||
for (int i = 0; i < sz; i ++) {
|
for (int i = 0; i < sz; i ++)
|
||||||
rk_to_name.push_back (names [i]);
|
{
|
||||||
name_to_rk [names [i]] = i;
|
rk_to_name.push_back (names [i]);
|
||||||
}
|
name_to_rk [names [i]] = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <node.h>
|
* <node.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <param.cpp>
|
* <param.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -38,7 +38,8 @@
|
||||||
|
|
||||||
#include "schema.h"
|
#include "schema.h"
|
||||||
|
|
||||||
void loadRMCParameters (int & __argc, char * * & __argv) {
|
void loadRMCParameters (int & __argc, char * * & __argv)
|
||||||
|
{
|
||||||
|
|
||||||
eoParser parser (__argc, __argv);
|
eoParser parser (__argc, __argv);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <param.h>
|
* <param.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <recv.cpp>
|
* <recv.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -44,97 +44,103 @@
|
||||||
#include "../../core/cooperative.h"
|
#include "../../core/cooperative.h"
|
||||||
#include "../../core/peo_debug.h"
|
#include "../../core/peo_debug.h"
|
||||||
|
|
||||||
void receiveMessages () {
|
void receiveMessages ()
|
||||||
|
{
|
||||||
|
|
||||||
cleanBuffers ();
|
cleanBuffers ();
|
||||||
|
|
||||||
do {
|
|
||||||
|
|
||||||
if (! atLeastOneActiveThread ()) {
|
do
|
||||||
// printDebugMessage ("debut wait");
|
{
|
||||||
waitMessage ();
|
|
||||||
//printDebugMessage ("fin wait");
|
if (! atLeastOneActiveThread ())
|
||||||
|
{
|
||||||
|
// printDebugMessage ("debut wait");
|
||||||
|
waitMessage ();
|
||||||
|
//printDebugMessage ("fin wait");
|
||||||
|
}
|
||||||
|
|
||||||
|
int src, tag;
|
||||||
|
|
||||||
|
while (probeMessage (src, tag))
|
||||||
|
{
|
||||||
|
|
||||||
|
receiveMessage (src, tag);
|
||||||
|
initMessage ();
|
||||||
|
/*
|
||||||
|
char b [1000];
|
||||||
|
sprintf (b, "traitement recv %d\n", tag);
|
||||||
|
printDebugMessage (b);
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch (tag)
|
||||||
|
{
|
||||||
|
|
||||||
|
case RUNNER_STOP_TAG:
|
||||||
|
unpackTerminationOfRunner ();
|
||||||
|
wakeUpCommunicator ();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case COOP_TAG:
|
||||||
|
// printDebugMessage ("reception de message de cooperation");
|
||||||
|
COOP_ID coop_id;
|
||||||
|
unpack (coop_id);
|
||||||
|
getCooperative (coop_id) -> unpack ();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SCHED_REQUEST_TAG:
|
||||||
|
unpackResourceRequest ();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SCHED_RESULT_TAG:
|
||||||
|
{
|
||||||
|
/* Unpacking the resource */
|
||||||
|
SERVICE_ID serv_id;
|
||||||
|
unpack (serv_id);
|
||||||
|
Service * serv = getService (serv_id);
|
||||||
|
int dest;
|
||||||
|
unpack (dest);
|
||||||
|
WORKER_ID worker_id;
|
||||||
|
unpack (worker_id);
|
||||||
|
|
||||||
|
/* Going back ... */
|
||||||
|
initMessage ();
|
||||||
|
pack (worker_id);
|
||||||
|
pack (serv_id);
|
||||||
|
serv -> packData ();
|
||||||
|
serv -> notifySendingData ();
|
||||||
|
sendMessage (dest, TASK_DATA_TAG);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TASK_DATA_TAG:
|
||||||
|
{
|
||||||
|
WORKER_ID worker_id;
|
||||||
|
unpack (worker_id);
|
||||||
|
Worker * worker = getWorker (worker_id);
|
||||||
|
worker -> setSource (src);
|
||||||
|
worker -> unpackData ();
|
||||||
|
worker -> wakeUp ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TASK_RESULT_TAG:
|
||||||
|
{
|
||||||
|
SERVICE_ID serv_id;
|
||||||
|
unpack (serv_id);
|
||||||
|
Service * serv = getService (serv_id);
|
||||||
|
serv -> unpackResult ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TASK_DONE_TAG:
|
||||||
|
unpackTaskDone ();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
while (! atLeastOneActiveThread () && atLeastOneActiveRunner () /*&& ! allResourcesFree ()*/);
|
||||||
int src, tag;
|
|
||||||
|
|
||||||
while (probeMessage (src, tag)) {
|
|
||||||
|
|
||||||
receiveMessage (src, tag);
|
|
||||||
initMessage ();
|
|
||||||
/*
|
|
||||||
char b [1000];
|
|
||||||
sprintf (b, "traitement recv %d\n", tag);
|
|
||||||
printDebugMessage (b);
|
|
||||||
*/
|
|
||||||
|
|
||||||
switch (tag) {
|
|
||||||
|
|
||||||
case RUNNER_STOP_TAG:
|
|
||||||
unpackTerminationOfRunner ();
|
|
||||||
wakeUpCommunicator ();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COOP_TAG:
|
|
||||||
// printDebugMessage ("reception de message de cooperation");
|
|
||||||
COOP_ID coop_id;
|
|
||||||
unpack (coop_id);
|
|
||||||
getCooperative (coop_id) -> unpack ();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SCHED_REQUEST_TAG:
|
|
||||||
unpackResourceRequest ();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SCHED_RESULT_TAG:
|
|
||||||
{
|
|
||||||
/* Unpacking the resource */
|
|
||||||
SERVICE_ID serv_id;
|
|
||||||
unpack (serv_id);
|
|
||||||
Service * serv = getService (serv_id);
|
|
||||||
int dest;
|
|
||||||
unpack (dest);
|
|
||||||
WORKER_ID worker_id;
|
|
||||||
unpack (worker_id);
|
|
||||||
|
|
||||||
/* Going back ... */
|
|
||||||
initMessage ();
|
|
||||||
pack (worker_id);
|
|
||||||
pack (serv_id);
|
|
||||||
serv -> packData ();
|
|
||||||
serv -> notifySendingData ();
|
|
||||||
sendMessage (dest, TASK_DATA_TAG);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case TASK_DATA_TAG:
|
|
||||||
{
|
|
||||||
WORKER_ID worker_id;
|
|
||||||
unpack (worker_id);
|
|
||||||
Worker * worker = getWorker (worker_id);
|
|
||||||
worker -> setSource (src);
|
|
||||||
worker -> unpackData ();
|
|
||||||
worker -> wakeUp ();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case TASK_RESULT_TAG:
|
|
||||||
{
|
|
||||||
SERVICE_ID serv_id;
|
|
||||||
unpack (serv_id);
|
|
||||||
Service * serv = getService (serv_id);
|
|
||||||
serv -> unpackResult ();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case TASK_DONE_TAG:
|
|
||||||
unpackTaskDone ();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (! atLeastOneActiveThread () && atLeastOneActiveRunner () /*&& ! allResourcesFree ()*/);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <recv.h>
|
* <recv.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <rmc.cpp>
|
* <rmc.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -43,16 +43,18 @@
|
||||||
|
|
||||||
static std :: vector <pthread_t *> ll_threads; /* Low level threads */
|
static std :: vector <pthread_t *> ll_threads; /* Low level threads */
|
||||||
|
|
||||||
void runRMC () {
|
void runRMC ()
|
||||||
|
{
|
||||||
|
|
||||||
/* Worker(s) ? */
|
/* Worker(s) ? */
|
||||||
for (unsigned i = 0; i < my_node -> num_workers; i ++)
|
for (unsigned i = 0; i < my_node -> num_workers; i ++)
|
||||||
addThread (new Worker, ll_threads);
|
addThread (new Worker, ll_threads);
|
||||||
|
|
||||||
wakeUpCommunicator ();
|
wakeUpCommunicator ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initRMC (int & __argc, char * * & __argv) {
|
void initRMC (int & __argc, char * * & __argv)
|
||||||
|
{
|
||||||
|
|
||||||
/* Communication */
|
/* Communication */
|
||||||
initCommunication ();
|
initCommunication ();
|
||||||
|
|
@ -67,7 +69,8 @@ void initRMC (int & __argc, char * * & __argv) {
|
||||||
///
|
///
|
||||||
}
|
}
|
||||||
|
|
||||||
void finalizeRMC () {
|
void finalizeRMC ()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage ("before join threads RMC");
|
printDebugMessage ("before join threads RMC");
|
||||||
joinThreads (ll_threads);
|
joinThreads (ll_threads);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <runner.cpp>
|
* <runner.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -41,7 +41,8 @@
|
||||||
#include "tags.h"
|
#include "tags.h"
|
||||||
#include "schema.h"
|
#include "schema.h"
|
||||||
|
|
||||||
bool Runner :: isLocal () {
|
bool Runner :: isLocal ()
|
||||||
|
{
|
||||||
|
|
||||||
for (unsigned i = 0; i < my_node -> id_run.size (); i ++)
|
for (unsigned i = 0; i < my_node -> id_run.size (); i ++)
|
||||||
if (my_node -> id_run [i] == id)
|
if (my_node -> id_run [i] == id)
|
||||||
|
|
@ -49,13 +50,15 @@ bool Runner :: isLocal () {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner :: packTermination () {
|
void Runner :: packTermination ()
|
||||||
|
{
|
||||||
|
|
||||||
pack (id);
|
pack (id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner :: terminate () {
|
void Runner :: terminate ()
|
||||||
|
{
|
||||||
|
|
||||||
sendToAll (this, RUNNER_STOP_TAG);
|
sendToAll (this, RUNNER_STOP_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <scheduler.cpp>
|
* <scheduler.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -47,45 +47,51 @@ static std :: queue <SCHED_REQUEST> requests; /* Requests */
|
||||||
|
|
||||||
static unsigned initNumberOfRes = 0;
|
static unsigned initNumberOfRes = 0;
|
||||||
|
|
||||||
void initScheduler () {
|
void initScheduler ()
|
||||||
|
{
|
||||||
for (unsigned i = 0; i < the_schema.size (); i ++) {
|
|
||||||
|
for (unsigned i = 0; i < the_schema.size (); i ++)
|
||||||
const Node & node = the_schema [i];
|
{
|
||||||
|
|
||||||
if (node.rk_sched == my_node -> rk)
|
const Node & node = the_schema [i];
|
||||||
for (unsigned j = 0; j < node.num_workers; j ++)
|
|
||||||
resources.push (std :: pair <RANK_ID, WORKER_ID> (i, j + 1));
|
if (node.rk_sched == my_node -> rk)
|
||||||
}
|
for (unsigned j = 0; j < node.num_workers; j ++)
|
||||||
|
resources.push (std :: pair <RANK_ID, WORKER_ID> (i, j + 1));
|
||||||
|
}
|
||||||
initNumberOfRes = resources.size ();
|
initNumberOfRes = resources.size ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool allResourcesFree () {
|
bool allResourcesFree ()
|
||||||
|
{
|
||||||
|
|
||||||
return resources.size () == initNumberOfRes;
|
return resources.size () == initNumberOfRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update () {
|
static void update ()
|
||||||
|
{
|
||||||
|
|
||||||
unsigned num_alloc = std :: min (resources.size (), requests.size ());
|
unsigned num_alloc = std :: min (resources.size (), requests.size ());
|
||||||
|
|
||||||
for (unsigned i = 0; i < num_alloc; i ++) {
|
|
||||||
|
|
||||||
SCHED_REQUEST req = requests.front ();
|
|
||||||
requests.pop ();
|
|
||||||
|
|
||||||
SCHED_RESOURCE res = resources.front ();
|
|
||||||
resources.pop ();
|
|
||||||
|
|
||||||
printDebugMessage ("allocating a resource.");
|
for (unsigned i = 0; i < num_alloc; i ++)
|
||||||
initMessage ();
|
{
|
||||||
pack (req.second);
|
|
||||||
pack (res);
|
SCHED_REQUEST req = requests.front ();
|
||||||
sendMessage (req.first, SCHED_RESULT_TAG);
|
requests.pop ();
|
||||||
}
|
|
||||||
|
SCHED_RESOURCE res = resources.front ();
|
||||||
|
resources.pop ();
|
||||||
|
|
||||||
|
printDebugMessage ("allocating a resource.");
|
||||||
|
initMessage ();
|
||||||
|
pack (req.second);
|
||||||
|
pack (res);
|
||||||
|
sendMessage (req.first, SCHED_RESULT_TAG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void unpackResourceRequest () {
|
void unpackResourceRequest ()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage ("queuing a resource request.");
|
printDebugMessage ("queuing a resource request.");
|
||||||
SCHED_REQUEST req;
|
SCHED_REQUEST req;
|
||||||
|
|
@ -94,7 +100,8 @@ void unpackResourceRequest () {
|
||||||
update ();
|
update ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unpackTaskDone () {
|
void unpackTaskDone ()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage ("I'm notified a worker is now idle.");
|
printDebugMessage ("I'm notified a worker is now idle.");
|
||||||
SCHED_RESOURCE res;
|
SCHED_RESOURCE res;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <scheduler.h>
|
* <scheduler.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -53,7 +53,7 @@ extern void initScheduler ();
|
||||||
extern void unpackResourceRequest ();
|
extern void unpackResourceRequest ();
|
||||||
|
|
||||||
/* Being known a worker is now idle :-) */
|
/* Being known a worker is now idle :-) */
|
||||||
extern void unpackTaskDone ();
|
extern void unpackTaskDone ();
|
||||||
|
|
||||||
extern bool allResourcesFree ();
|
extern bool allResourcesFree ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <schema.cpp>
|
* <schema.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -47,20 +47,22 @@ std :: vector <Node> the_schema;
|
||||||
|
|
||||||
Node * my_node;
|
Node * my_node;
|
||||||
|
|
||||||
RANK_ID getRankOfRunner (RUNNER_ID __key) {
|
RANK_ID getRankOfRunner (RUNNER_ID __key)
|
||||||
|
{
|
||||||
|
|
||||||
for (unsigned i = 0; i < the_schema.size (); i ++)
|
for (unsigned i = 0; i < the_schema.size (); i ++)
|
||||||
for (unsigned j = 0; j < the_schema [i].id_run.size (); j ++)
|
for (unsigned j = 0; j < the_schema [i].id_run.size (); j ++)
|
||||||
if (the_schema [i].id_run [j] == __key)
|
if (the_schema [i].id_run [j] == __key)
|
||||||
return the_schema [i].rk;
|
return the_schema [i].rk;
|
||||||
assert (false);
|
assert (false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadNode (int __rk_sched) {
|
static void loadNode (int __rk_sched)
|
||||||
|
{
|
||||||
|
|
||||||
Node node;
|
Node node;
|
||||||
|
|
||||||
node.rk_sched = __rk_sched;
|
node.rk_sched = __rk_sched;
|
||||||
|
|
||||||
/* ATT: name*/
|
/* ATT: name*/
|
||||||
|
|
@ -68,96 +70,106 @@ static void loadNode (int __rk_sched) {
|
||||||
/* ATT: num_workers */
|
/* ATT: num_workers */
|
||||||
node.num_workers = atoi (getAttributeValue ("num_workers").c_str ());
|
node.num_workers = atoi (getAttributeValue ("num_workers").c_str ());
|
||||||
|
|
||||||
while (true) {
|
while (true)
|
||||||
|
{
|
||||||
/* TAG: <runner> | </node> */
|
|
||||||
std :: string name = getNextNode ();
|
/* TAG: <runner> | </node> */
|
||||||
assert (name == "runner" || name == "node");
|
std :: string name = getNextNode ();
|
||||||
if (name == "runner") {
|
assert (name == "runner" || name == "node");
|
||||||
/* TAG: </node> */
|
if (name == "runner")
|
||||||
node.id_run.push_back (atoi (getNextNode ().c_str ()));
|
{
|
||||||
/* TAG: </runner> */
|
/* TAG: </node> */
|
||||||
assert (getNextNode () == "runner");
|
node.id_run.push_back (atoi (getNextNode ().c_str ()));
|
||||||
|
/* TAG: </runner> */
|
||||||
|
assert (getNextNode () == "runner");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* TAG: </node> */
|
||||||
|
the_schema.push_back (node);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
/* TAG: </node> */
|
|
||||||
the_schema.push_back (node);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadGroup () {
|
static void loadGroup ()
|
||||||
|
{
|
||||||
|
|
||||||
std :: string name;
|
std :: string name;
|
||||||
|
|
||||||
/* ATT: scheduler*/
|
/* ATT: scheduler*/
|
||||||
int rk_sched = getRankFromName (getAttributeValue ("scheduler"));
|
int rk_sched = getRankFromName (getAttributeValue ("scheduler"));
|
||||||
|
|
||||||
while (true) {
|
|
||||||
|
|
||||||
/* TAG: <node> | </group> */
|
while (true)
|
||||||
name = getNextNode ();
|
{
|
||||||
assert (name == "node" || name == "group");
|
|
||||||
if (name == "node")
|
/* TAG: <node> | </group> */
|
||||||
/* TAG: <node> */
|
name = getNextNode ();
|
||||||
loadNode (rk_sched);
|
assert (name == "node" || name == "group");
|
||||||
else
|
if (name == "node")
|
||||||
/* TAG: </group> */
|
/* TAG: <node> */
|
||||||
break;
|
loadNode (rk_sched);
|
||||||
}
|
else
|
||||||
|
/* TAG: </group> */
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isScheduleNode () {
|
bool isScheduleNode ()
|
||||||
|
{
|
||||||
|
|
||||||
return my_node -> rk == my_node -> rk_sched;
|
return my_node -> rk == my_node -> rk_sched;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadSchema (const char * __filename) {
|
void loadSchema (const char * __filename)
|
||||||
|
{
|
||||||
|
|
||||||
openXMLDocument (__filename);
|
openXMLDocument (__filename);
|
||||||
|
|
||||||
std :: string name;
|
std :: string name;
|
||||||
|
|
||||||
/* TAG: <schema> */
|
/* TAG: <schema> */
|
||||||
name = getNextNode ();
|
name = getNextNode ();
|
||||||
assert (name == "schema");
|
assert (name == "schema");
|
||||||
|
|
||||||
while (true) {
|
|
||||||
|
|
||||||
/* TAG: <group> | </schema> */
|
while (true)
|
||||||
name = getNextNode ();
|
{
|
||||||
assert (name == "group" || name == "schema");
|
|
||||||
if (name == "group")
|
/* TAG: <group> | </schema> */
|
||||||
/* TAG: <group> */
|
name = getNextNode ();
|
||||||
loadGroup ();
|
assert (name == "group" || name == "schema");
|
||||||
else
|
if (name == "group")
|
||||||
/* TAG: </schema> */
|
/* TAG: <group> */
|
||||||
break;
|
loadGroup ();
|
||||||
}
|
else
|
||||||
|
/* TAG: </schema> */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Looking for my node */
|
/* Looking for my node */
|
||||||
for (unsigned i = 0; i < the_schema.size (); i ++)
|
for (unsigned i = 0; i < the_schema.size (); i ++)
|
||||||
if (the_schema [i].rk == getNodeRank ())
|
if (the_schema [i].rk == getNodeRank ())
|
||||||
my_node = & (the_schema [i]);
|
my_node = & (the_schema [i]);
|
||||||
|
|
||||||
/* About me */
|
/* About me */
|
||||||
char mess [1000];
|
char mess [1000];
|
||||||
|
|
||||||
sprintf (mess, "my rank is %d", my_node -> rk);
|
sprintf (mess, "my rank is %d", my_node -> rk);
|
||||||
printDebugMessage (mess);
|
printDebugMessage (mess);
|
||||||
if (isScheduleNode ())
|
if (isScheduleNode ())
|
||||||
printDebugMessage ("I'am a scheduler");
|
printDebugMessage ("I'am a scheduler");
|
||||||
for (unsigned i = 0; i < my_node -> id_run.size (); i ++) {
|
for (unsigned i = 0; i < my_node -> id_run.size (); i ++)
|
||||||
sprintf (mess, "I manage the runner %d", my_node -> id_run [i]);
|
{
|
||||||
printDebugMessage (mess);
|
sprintf (mess, "I manage the runner %d", my_node -> id_run [i]);
|
||||||
}
|
printDebugMessage (mess);
|
||||||
if (my_node -> num_workers) {
|
}
|
||||||
|
if (my_node -> num_workers)
|
||||||
sprintf (mess, "I manage %d worker(s)", my_node -> num_workers);
|
{
|
||||||
printDebugMessage (mess);
|
|
||||||
}
|
sprintf (mess, "I manage %d worker(s)", my_node -> num_workers);
|
||||||
|
printDebugMessage (mess);
|
||||||
|
}
|
||||||
|
|
||||||
closeXMLDocument ();
|
closeXMLDocument ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <schema.h>
|
* <schema.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -45,14 +45,15 @@
|
||||||
|
|
||||||
typedef int RANK_ID;
|
typedef int RANK_ID;
|
||||||
|
|
||||||
struct Node {
|
struct Node
|
||||||
|
{
|
||||||
RANK_ID rk; /* Rank */
|
|
||||||
std :: string name; /* Host name */
|
RANK_ID rk; /* Rank */
|
||||||
unsigned num_workers; /* Number of parallel workers */
|
std :: string name; /* Host name */
|
||||||
int rk_sched; /* rank of the scheduler */
|
unsigned num_workers; /* Number of parallel workers */
|
||||||
std :: vector <RUNNER_ID> id_run; /* List of runners */
|
int rk_sched; /* rank of the scheduler */
|
||||||
};
|
std :: vector <RUNNER_ID> id_run; /* List of runners */
|
||||||
|
};
|
||||||
|
|
||||||
extern std :: vector <Node> the_schema;
|
extern std :: vector <Node> the_schema;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <send.cpp>
|
* <send.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -49,26 +49,30 @@
|
||||||
|
|
||||||
#define TO_ALL -1
|
#define TO_ALL -1
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
|
|
||||||
Communicable * comm;
|
Communicable * comm;
|
||||||
int to;
|
int to;
|
||||||
int tag;
|
int tag;
|
||||||
|
|
||||||
|
}
|
||||||
|
SEND_REQUEST;
|
||||||
|
|
||||||
} SEND_REQUEST;
|
|
||||||
|
|
||||||
static std :: queue <SEND_REQUEST> mess;
|
static std :: queue <SEND_REQUEST> mess;
|
||||||
|
|
||||||
static sem_t sem_send;
|
static sem_t sem_send;
|
||||||
|
|
||||||
void initSending () {
|
void initSending ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_init (& sem_send, 0, 1);
|
sem_init (& sem_send, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void send (Communicable * __comm, int __to, int __tag) {
|
void send (Communicable * __comm, int __to, int __tag)
|
||||||
|
{
|
||||||
|
|
||||||
SEND_REQUEST req;
|
SEND_REQUEST req;
|
||||||
req.comm = __comm;
|
req.comm = __comm;
|
||||||
req.to = __to;
|
req.to = __to;
|
||||||
req.tag = __tag;
|
req.tag = __tag;
|
||||||
|
|
@ -79,66 +83,70 @@ void send (Communicable * __comm, int __to, int __tag) {
|
||||||
wakeUpCommunicator ();
|
wakeUpCommunicator ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendToAll (Communicable * __comm, int __tag) {
|
void sendToAll (Communicable * __comm, int __tag)
|
||||||
|
{
|
||||||
|
|
||||||
send (__comm, TO_ALL, __tag);
|
send (__comm, TO_ALL, __tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendMessages () {
|
void sendMessages ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_wait (& sem_send);
|
sem_wait (& sem_send);
|
||||||
|
|
||||||
while (! mess.empty ()) {
|
while (! mess.empty ())
|
||||||
|
{
|
||||||
SEND_REQUEST req = mess.front ();
|
|
||||||
/*
|
|
||||||
char b [1000];
|
|
||||||
sprintf (b, "traitement send %d\n", req.tag);
|
|
||||||
printDebugMessage (b);
|
|
||||||
*/
|
|
||||||
|
|
||||||
Communicable * comm = req.comm;
|
|
||||||
|
|
||||||
initMessage ();
|
SEND_REQUEST req = mess.front ();
|
||||||
|
/*
|
||||||
|
char b [1000];
|
||||||
|
sprintf (b, "traitement send %d\n", req.tag);
|
||||||
|
printDebugMessage (b);
|
||||||
|
*/
|
||||||
|
|
||||||
switch (req.tag) {
|
Communicable * comm = req.comm;
|
||||||
|
|
||||||
case RUNNER_STOP_TAG:
|
initMessage ();
|
||||||
dynamic_cast <Runner *> (comm) -> packTermination ();
|
|
||||||
dynamic_cast <Runner *> (comm) -> notifySendingTermination ();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COOP_TAG:
|
switch (req.tag)
|
||||||
dynamic_cast <Cooperative *> (comm) -> pack ();
|
{
|
||||||
dynamic_cast <Cooperative *> (comm) -> notifySending ();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SCHED_REQUEST_TAG:
|
|
||||||
dynamic_cast <Service *> (comm) -> packResourceRequest ();
|
|
||||||
dynamic_cast <Service *> (comm) -> notifySendingResourceRequest ();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TASK_RESULT_TAG:
|
case RUNNER_STOP_TAG:
|
||||||
dynamic_cast <Worker *> (comm) -> packResult ();
|
dynamic_cast <Runner *> (comm) -> packTermination ();
|
||||||
dynamic_cast <Worker *> (comm) -> notifySendingResult ();
|
dynamic_cast <Runner *> (comm) -> notifySendingTermination ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TASK_DONE_TAG:
|
case COOP_TAG:
|
||||||
dynamic_cast <Worker *> (comm) -> packTaskDone ();
|
dynamic_cast <Cooperative *> (comm) -> pack ();
|
||||||
dynamic_cast <Worker *> (comm) -> notifySendingTaskDone ();
|
dynamic_cast <Cooperative *> (comm) -> notifySending ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default :
|
|
||||||
break;
|
|
||||||
|
|
||||||
};
|
case SCHED_REQUEST_TAG:
|
||||||
|
dynamic_cast <Service *> (comm) -> packResourceRequest ();
|
||||||
if (req.to == TO_ALL)
|
dynamic_cast <Service *> (comm) -> notifySendingResourceRequest ();
|
||||||
sendMessageToAll (req.tag);
|
break;
|
||||||
else
|
|
||||||
sendMessage (req.to, req.tag);
|
|
||||||
mess.pop ();
|
|
||||||
}
|
|
||||||
|
|
||||||
sem_post (& sem_send);
|
case TASK_RESULT_TAG:
|
||||||
|
dynamic_cast <Worker *> (comm) -> packResult ();
|
||||||
|
dynamic_cast <Worker *> (comm) -> notifySendingResult ();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TASK_DONE_TAG:
|
||||||
|
dynamic_cast <Worker *> (comm) -> packTaskDone ();
|
||||||
|
dynamic_cast <Worker *> (comm) -> notifySendingTaskDone ();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default :
|
||||||
|
break;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
if (req.to == TO_ALL)
|
||||||
|
sendMessageToAll (req.tag);
|
||||||
|
else
|
||||||
|
sendMessage (req.to, req.tag);
|
||||||
|
mess.pop ();
|
||||||
|
}
|
||||||
|
|
||||||
|
sem_post (& sem_send);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <send.h>
|
* <send.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <service.cpp>
|
* <service.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -41,14 +41,16 @@
|
||||||
#include "send.h"
|
#include "send.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
|
|
||||||
void Service :: requestResourceRequest (unsigned __how_many) {
|
void Service :: requestResourceRequest (unsigned __how_many)
|
||||||
|
{
|
||||||
|
|
||||||
num_sent_rr = __how_many;
|
num_sent_rr = __how_many;
|
||||||
for (unsigned i = 0; i < __how_many; i ++)
|
for (unsigned i = 0; i < __how_many; i ++)
|
||||||
send (this, my_node -> rk_sched, SCHED_REQUEST_TAG);
|
send (this, my_node -> rk_sched, SCHED_REQUEST_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service :: packResourceRequest () {
|
void Service :: packResourceRequest ()
|
||||||
|
{
|
||||||
|
|
||||||
SCHED_REQUEST req;
|
SCHED_REQUEST req;
|
||||||
req.first = getNodeRank ();
|
req.first = getNodeRank ();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <tags.h>
|
* <tags.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <worker.cpp>
|
* <worker.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -46,76 +46,88 @@
|
||||||
|
|
||||||
static std :: vector <Worker *> key_to_worker (1); /* Vector of registered workers */
|
static std :: vector <Worker *> key_to_worker (1); /* Vector of registered workers */
|
||||||
|
|
||||||
Worker * getWorker (WORKER_ID __key) {
|
Worker * getWorker (WORKER_ID __key)
|
||||||
|
{
|
||||||
|
|
||||||
return key_to_worker [__key];
|
return key_to_worker [__key];
|
||||||
}
|
}
|
||||||
|
|
||||||
Worker :: Worker () {
|
Worker :: Worker ()
|
||||||
|
{
|
||||||
|
|
||||||
toto = false;
|
toto = false;
|
||||||
id = key_to_worker.size ();
|
id = key_to_worker.size ();
|
||||||
key_to_worker.push_back (this);
|
key_to_worker.push_back (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: packResult () {
|
void Worker :: packResult ()
|
||||||
|
{
|
||||||
|
|
||||||
pack (serv_id);
|
pack (serv_id);
|
||||||
serv -> packResult ();
|
serv -> packResult ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: unpackData () {
|
void Worker :: unpackData ()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage ("unpacking the ID. of the service.");
|
printDebugMessage ("unpacking the ID. of the service.");
|
||||||
unpack (serv_id);
|
unpack (serv_id);
|
||||||
serv = getService (serv_id);
|
serv = getService (serv_id);
|
||||||
printDebugMessage ("found the service.");
|
printDebugMessage ("found the service.");
|
||||||
serv -> unpackData ();
|
serv -> unpackData ();
|
||||||
printDebugMessage ("unpacking the data.");
|
printDebugMessage ("unpacking the data.");
|
||||||
setActive ();
|
setActive ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: packTaskDone () {
|
void Worker :: packTaskDone ()
|
||||||
|
{
|
||||||
|
|
||||||
pack (getNodeRank ());
|
pack (getNodeRank ());
|
||||||
pack (id);
|
pack (id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: notifySendingResult () {
|
void Worker :: notifySendingResult ()
|
||||||
|
{
|
||||||
|
|
||||||
/* Notifying the scheduler of the termination */
|
/* Notifying the scheduler of the termination */
|
||||||
toto = true;
|
toto = true;
|
||||||
wakeUp ();
|
wakeUp ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: notifySendingTaskDone () {
|
void Worker :: notifySendingTaskDone ()
|
||||||
|
{
|
||||||
|
|
||||||
setPassive ();
|
setPassive ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: setSource (int __rank) {
|
void Worker :: setSource (int __rank)
|
||||||
|
{
|
||||||
|
|
||||||
src = __rank;
|
src = __rank;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: start () {
|
void Worker :: start ()
|
||||||
|
{
|
||||||
|
|
||||||
while (true) {
|
while (true)
|
||||||
|
{
|
||||||
sleep ();
|
|
||||||
|
|
||||||
if (! atLeastOneActiveRunner ())
|
sleep ();
|
||||||
break;
|
|
||||||
|
if (! atLeastOneActiveRunner ())
|
||||||
if (toto) {
|
break;
|
||||||
send (this, my_node -> rk_sched, TASK_DONE_TAG);
|
|
||||||
toto = false;
|
if (toto)
|
||||||
|
{
|
||||||
|
send (this, my_node -> rk_sched, TASK_DONE_TAG);
|
||||||
|
toto = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
printDebugMessage ("executing the task.");
|
||||||
|
serv -> execute ();
|
||||||
|
send (this, src, TASK_RESULT_TAG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
|
||||||
printDebugMessage ("executing the task.");
|
|
||||||
serv -> execute ();
|
|
||||||
send (this, src, TASK_RESULT_TAG);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <worker.h>
|
* <worker.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -41,37 +41,38 @@
|
||||||
#include "../../core/reac_thread.h"
|
#include "../../core/reac_thread.h"
|
||||||
#include "../../core/service.h"
|
#include "../../core/service.h"
|
||||||
|
|
||||||
typedef unsigned WORKER_ID;
|
typedef unsigned WORKER_ID;
|
||||||
|
|
||||||
class Worker : public Communicable, public ReactiveThread {
|
class Worker : public Communicable, public ReactiveThread
|
||||||
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
Worker ();
|
Worker ();
|
||||||
|
|
||||||
void start ();
|
void start ();
|
||||||
|
|
||||||
void packResult ();
|
void packResult ();
|
||||||
|
|
||||||
void unpackData ();
|
void unpackData ();
|
||||||
|
|
||||||
void packTaskDone ();
|
void packTaskDone ();
|
||||||
|
|
||||||
void notifySendingResult ();
|
void notifySendingResult ();
|
||||||
|
|
||||||
void notifySendingTaskDone ();
|
void notifySendingTaskDone ();
|
||||||
|
|
||||||
void setSource (int __rank);
|
|
||||||
|
|
||||||
private :
|
|
||||||
|
|
||||||
WORKER_ID id;
|
void setSource (int __rank);
|
||||||
SERVICE_ID serv_id;
|
|
||||||
Service * serv;
|
|
||||||
int src;
|
|
||||||
|
|
||||||
bool toto;
|
private :
|
||||||
};
|
|
||||||
|
WORKER_ID id;
|
||||||
|
SERVICE_ID serv_id;
|
||||||
|
Service * serv;
|
||||||
|
int src;
|
||||||
|
|
||||||
|
bool toto;
|
||||||
|
};
|
||||||
|
|
||||||
extern Worker * getWorker (WORKER_ID __key);
|
extern Worker * getWorker (WORKER_ID __key);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <xml_parser.cpp>
|
* <xml_parser.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -40,51 +40,59 @@
|
||||||
|
|
||||||
static xmlTextReaderPtr reader;
|
static xmlTextReaderPtr reader;
|
||||||
|
|
||||||
void openXMLDocument (const char * __filename) {
|
void openXMLDocument (const char * __filename)
|
||||||
|
{
|
||||||
|
|
||||||
reader = xmlNewTextReaderFilename (__filename);
|
reader = xmlNewTextReaderFilename (__filename);
|
||||||
|
|
||||||
if (! reader) {
|
if (! reader)
|
||||||
|
{
|
||||||
fprintf (stderr, "unable to open '%s'.\n", __filename);
|
|
||||||
exit (1);
|
fprintf (stderr, "unable to open '%s'.\n", __filename);
|
||||||
}
|
exit (1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeXMLDocument () {
|
void closeXMLDocument ()
|
||||||
|
{
|
||||||
|
|
||||||
xmlFreeTextReader (reader);
|
xmlFreeTextReader (reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
std :: string getAttributeValue (const std :: string & __attr) {
|
std :: string getAttributeValue (const std :: string & __attr)
|
||||||
|
{
|
||||||
|
|
||||||
xmlChar * value = xmlTextReaderGetAttribute (reader, (const xmlChar *) __attr.c_str ());
|
xmlChar * value = xmlTextReaderGetAttribute (reader, (const xmlChar *) __attr.c_str ());
|
||||||
|
|
||||||
std :: string str ((const char *) value);
|
std :: string str ((const char *) value);
|
||||||
|
|
||||||
xmlFree (value);
|
xmlFree (value);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isSep (const xmlChar * __text) {
|
static bool isSep (const xmlChar * __text)
|
||||||
|
{
|
||||||
|
|
||||||
for (unsigned i = 0; i < strlen ((char *) __text); i ++)
|
for (unsigned i = 0; i < strlen ((char *) __text); i ++)
|
||||||
if (__text [i] != ' ' && __text [i] != '\t' && __text [i] != '\n')
|
if (__text [i] != ' ' && __text [i] != '\t' && __text [i] != '\n')
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std :: string getNextNode () {
|
std :: string getNextNode ()
|
||||||
|
{
|
||||||
|
|
||||||
xmlChar * name, * value;
|
xmlChar * name, * value;
|
||||||
|
|
||||||
do {
|
do
|
||||||
xmlTextReaderRead (reader);
|
{
|
||||||
name = xmlTextReaderName (reader);
|
xmlTextReaderRead (reader);
|
||||||
value = xmlTextReaderValue (reader);
|
name = xmlTextReaderName (reader);
|
||||||
// printf ("value = %s\n", value);
|
value = xmlTextReaderValue (reader);
|
||||||
} while (! strcmp ((char *) name, "#text") && isSep (value));
|
// printf ("value = %s\n", value);
|
||||||
|
}
|
||||||
|
while (! strcmp ((char *) name, "#text") && isSep (value));
|
||||||
|
|
||||||
std :: string str;
|
std :: string str;
|
||||||
|
|
||||||
|
|
@ -92,12 +100,12 @@ std :: string getNextNode () {
|
||||||
str.assign ((char *) name);
|
str.assign ((char *) name);
|
||||||
else
|
else
|
||||||
str.assign ((char *) value);
|
str.assign ((char *) value);
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
xmlFree (name);
|
xmlFree (name);
|
||||||
if (value)
|
if (value)
|
||||||
xmlFree (value);
|
xmlFree (value);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <xml_parser.h>
|
* <xml_parser.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <t-peo.cpp>
|
* <t-peo.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <t-peoInsularPSO.cpp>
|
* <t-peoInsularPSO.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -39,92 +39,93 @@
|
||||||
|
|
||||||
#include <peo>
|
#include <peo>
|
||||||
|
|
||||||
#define N 4
|
#define N 4
|
||||||
|
|
||||||
typedef eoRealParticle < double >Indi;
|
typedef eoRealParticle < double >Indi;
|
||||||
double f (const Indi & _indi)
|
double f (const Indi & _indi)
|
||||||
{
|
{
|
||||||
const double PI = 4.0 * atan(1.0);
|
const double PI = 4.0 * atan(1.0);
|
||||||
double sum=0.;
|
double sum=0.;
|
||||||
for (unsigned i = 0; i < _indi.size()-1; i++)
|
for (unsigned i = 0; i < _indi.size()-1; i++)
|
||||||
sum+=pow((_indi[i]-1),2)*(1+pow(sin(3*PI*_indi[i+1]),2));
|
sum+=pow((_indi[i]-1),2)*(1+pow(sin(3*PI*_indi[i+1]),2));
|
||||||
sum+=pow(sin(3*PI*_indi[0]),2);
|
sum+=pow(sin(3*PI*_indi[0]),2);
|
||||||
sum+=(_indi[_indi.size()-1]-1)*(1+pow(sin(2*PI*_indi[_indi.size()-1]),2));
|
sum+=(_indi[_indi.size()-1]-1)*(1+pow(sin(2*PI*_indi[_indi.size()-1]),2));
|
||||||
return (-sum);
|
return (-sum);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template < class POT > class eoPrint : public eoContinue <POT>
|
template < class POT > class eoPrint : public eoContinue <POT>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
bool operator () (const eoPop <POT> & __pop)
|
bool operator () (const eoPop <POT> & __pop)
|
||||||
{
|
{
|
||||||
double result[__pop.size()];
|
double result[__pop.size()];
|
||||||
for(unsigned i=0;i<__pop.size();i++)
|
for (unsigned i=0;i<__pop.size();i++)
|
||||||
result[i]=__pop[i].best();
|
result[i]=__pop[i].best();
|
||||||
std::sort(result,result+__pop.size());
|
std::sort(result,result+__pop.size());
|
||||||
std::cout << "\n"<<result[__pop.size()-1];
|
std::cout << "\n"<<result[__pop.size()-1];
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
void peoPSOSeq ()
|
void peoPSOSeq ()
|
||||||
{
|
{
|
||||||
|
|
||||||
const unsigned int VEC_SIZE = 4;
|
const unsigned int VEC_SIZE = 4;
|
||||||
const unsigned int POP_SIZE = 10;
|
const unsigned int POP_SIZE = 10;
|
||||||
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
||||||
const unsigned int MAX_GEN = 100;
|
const unsigned int MAX_GEN = 100;
|
||||||
const double INIT_POSITION_MIN = -50.0;
|
const double INIT_POSITION_MIN = -50.0;
|
||||||
const double INIT_POSITION_MAX = 50.0;
|
const double INIT_POSITION_MAX = 50.0;
|
||||||
const double INIT_VELOCITY_MIN = -1;
|
const double INIT_VELOCITY_MIN = -1;
|
||||||
const double INIT_VELOCITY_MAX = 1;
|
const double INIT_VELOCITY_MAX = 1;
|
||||||
const double C1 = 0.5;
|
const double C1 = 0.5;
|
||||||
const double C2 = 2;
|
const double C2 = 2;
|
||||||
rng.reseed (44);
|
rng.reseed (44);
|
||||||
std::cout<<"\n\nWith one PSO\n\n";
|
std::cout<<"\n\nWith one PSO\n\n";
|
||||||
eoEvalFuncPtr<Indi, double, const Indi& > plainEvalSeq(f);
|
eoEvalFuncPtr<Indi, double, const Indi& > plainEvalSeq(f);
|
||||||
eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq);
|
eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq);
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||||
eoFirstIsBestInit < Indi > localInit;
|
eoFirstIsBestInit < Indi > localInit;
|
||||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
eoStandardFlight < Indi > flight(bndsFlight);
|
eoStandardFlight < Indi > flight(bndsFlight);
|
||||||
eoPop < Indi > popSeq;
|
eoPop < Indi > popSeq;
|
||||||
popSeq.append (POP_SIZE, random);
|
popSeq.append (POP_SIZE, random);
|
||||||
apply(evalSeq, popSeq);;
|
apply(evalSeq, popSeq);
|
||||||
apply < Indi > (veloRandom, popSeq);
|
;
|
||||||
apply < Indi > (localInit, popSeq);
|
apply < Indi > (veloRandom, popSeq);
|
||||||
eoLinearTopology<Indi> topologySeq(NEIGHBORHOOD_SIZE);
|
apply < Indi > (localInit, popSeq);
|
||||||
topologySeq.setup(popSeq);
|
eoLinearTopology<Indi> topologySeq(NEIGHBORHOOD_SIZE);
|
||||||
eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
topologySeq.setup(popSeq);
|
||||||
eoStandardVelocity < Indi > velocitySeq (topologySeq,C1,C2,bndsSeq);
|
eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
eoGenContinue < Indi > genContSeq (MAX_GEN);
|
eoStandardVelocity < Indi > velocitySeq (topologySeq,C1,C2,bndsSeq);
|
||||||
eoPrint <Indi> printSeq;
|
eoGenContinue < Indi > genContSeq (MAX_GEN);
|
||||||
eoCombinedContinue <Indi> continuatorSeq(genContSeq);
|
eoPrint <Indi> printSeq;
|
||||||
continuatorSeq.add(printSeq);
|
eoCombinedContinue <Indi> continuatorSeq(genContSeq);
|
||||||
eoCheckPoint<Indi> checkpointSeq(continuatorSeq);
|
continuatorSeq.add(printSeq);
|
||||||
eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight);
|
eoCheckPoint<Indi> checkpointSeq(continuatorSeq);
|
||||||
psaSeq (popSeq);
|
eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight);
|
||||||
popSeq.sort ();
|
psaSeq (popSeq);
|
||||||
|
popSeq.sort ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoPSOPara()
|
void peoPSOPara()
|
||||||
{
|
{
|
||||||
char *tmp="mpiexec -n ",*tmp2=" ./t-peoPSOParaIsland @lesson.param ",tmp3[4],buffer[256];
|
char *tmp="mpiexec -n ",*tmp2=" ./t-peoPSOParaIsland @lesson.param ",tmp3[4],buffer[256];
|
||||||
sprintf(tmp3,"%d",N);
|
sprintf(tmp3,"%d",N);
|
||||||
strcpy(buffer,tmp);
|
strcpy(buffer,tmp);
|
||||||
strcat(buffer,tmp3);
|
strcat(buffer,tmp3);
|
||||||
strcat(buffer,tmp2);
|
strcat(buffer,tmp2);
|
||||||
system(buffer);
|
system(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int __argc, char *__argv[])
|
int main (int __argc, char *__argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
peoPSOSeq ();
|
peoPSOSeq ();
|
||||||
peoPSOPara();
|
peoPSOPara();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <t-peoPSO.cpp>
|
* <t-peoPSO.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -39,81 +39,82 @@
|
||||||
|
|
||||||
#include <peo>
|
#include <peo>
|
||||||
|
|
||||||
#define N 4
|
#define N 4
|
||||||
|
|
||||||
typedef eoRealParticle < double >Indi;
|
typedef eoRealParticle < double >Indi;
|
||||||
double f (const Indi & _indi)
|
double f (const Indi & _indi)
|
||||||
{
|
{
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
for (unsigned i = 0; i < _indi.size (); i++)
|
for (unsigned i = 0; i < _indi.size (); i++)
|
||||||
sum += pow(_indi[i],2);
|
sum += pow(_indi[i],2);
|
||||||
return (-sum);
|
return (-sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
double peoPSOSeq ()
|
double peoPSOSeq ()
|
||||||
{
|
{
|
||||||
clock_t beginSeq,endSeq;
|
clock_t beginSeq,endSeq;
|
||||||
double timeSeq;
|
double timeSeq;
|
||||||
const unsigned int VEC_SIZE = 2;
|
const unsigned int VEC_SIZE = 2;
|
||||||
const unsigned int POP_SIZE = 10;
|
const unsigned int POP_SIZE = 10;
|
||||||
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
||||||
const unsigned int MAX_GEN = 5000;
|
const unsigned int MAX_GEN = 5000;
|
||||||
const double FIT_CONT = -1e-6;
|
const double FIT_CONT = -1e-6;
|
||||||
const double INIT_POSITION_MIN = -5.0;
|
const double INIT_POSITION_MIN = -5.0;
|
||||||
const double INIT_POSITION_MAX = 5.0;
|
const double INIT_POSITION_MAX = 5.0;
|
||||||
const double INIT_VELOCITY_MIN = -1;
|
const double INIT_VELOCITY_MIN = -1;
|
||||||
const double INIT_VELOCITY_MAX = 1;
|
const double INIT_VELOCITY_MAX = 1;
|
||||||
const double C1 = 2;
|
const double C1 = 2;
|
||||||
const double C2 = 2;
|
const double C2 = 2;
|
||||||
rng.reseed (36);
|
rng.reseed (36);
|
||||||
beginSeq=clock();
|
beginSeq=clock();
|
||||||
eoEvalFuncPtr<Indi, double, const Indi& > plainEvalSeq(f);
|
eoEvalFuncPtr<Indi, double, const Indi& > plainEvalSeq(f);
|
||||||
eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq);
|
eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq);
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||||
eoFirstIsBestInit < Indi > localInit;
|
eoFirstIsBestInit < Indi > localInit;
|
||||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
eoStandardFlight < Indi > flight(bndsFlight);
|
eoStandardFlight < Indi > flight(bndsFlight);
|
||||||
eoPop < Indi > popSeq;
|
eoPop < Indi > popSeq;
|
||||||
popSeq.append (POP_SIZE, random);
|
popSeq.append (POP_SIZE, random);
|
||||||
apply(evalSeq, popSeq);;
|
apply(evalSeq, popSeq);
|
||||||
apply < Indi > (veloRandom, popSeq);
|
;
|
||||||
apply < Indi > (localInit, popSeq);
|
apply < Indi > (veloRandom, popSeq);
|
||||||
eoLinearTopology<Indi> topologySeq(NEIGHBORHOOD_SIZE);
|
apply < Indi > (localInit, popSeq);
|
||||||
topologySeq.setup(popSeq);
|
eoLinearTopology<Indi> topologySeq(NEIGHBORHOOD_SIZE);
|
||||||
eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
topologySeq.setup(popSeq);
|
||||||
eoStandardVelocity < Indi > velocitySeq (topologySeq,C1,C2,bndsSeq);
|
eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
eoGenContinue < Indi > genContSeq (MAX_GEN);
|
eoStandardVelocity < Indi > velocitySeq (topologySeq,C1,C2,bndsSeq);
|
||||||
eoFitContinue < Indi > fitContSeq (FIT_CONT);
|
eoGenContinue < Indi > genContSeq (MAX_GEN);
|
||||||
eoCombinedContinue <Indi> continuatorSeq (genContSeq);
|
eoFitContinue < Indi > fitContSeq (FIT_CONT);
|
||||||
continuatorSeq.add(fitContSeq);
|
eoCombinedContinue <Indi> continuatorSeq (genContSeq);
|
||||||
eoCheckPoint<Indi> checkpointSeq(continuatorSeq);
|
continuatorSeq.add(fitContSeq);
|
||||||
eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight);
|
eoCheckPoint<Indi> checkpointSeq(continuatorSeq);
|
||||||
|
eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight);
|
||||||
//Sequential
|
//Sequential
|
||||||
psaSeq (popSeq);
|
psaSeq (popSeq);
|
||||||
popSeq.sort ();
|
popSeq.sort ();
|
||||||
endSeq=clock();
|
endSeq=clock();
|
||||||
timeSeq = endSeq-beginSeq;
|
timeSeq = endSeq-beginSeq;
|
||||||
return timeSeq;
|
return timeSeq;
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoPSOPara(long int arg)
|
void peoPSOPara(long int arg)
|
||||||
{
|
{
|
||||||
char *tmp="mpiexec -n ",*tmp2=" ./t-peoPSOPara @lesson.param ",tmp3[4],buffer[256];
|
char *tmp="mpiexec -n ",*tmp2=" ./t-peoPSOPara @lesson.param ",tmp3[4],buffer[256];
|
||||||
sprintf(tmp3,"%d",N);
|
sprintf(tmp3,"%d",N);
|
||||||
strcpy(buffer,tmp);
|
strcpy(buffer,tmp);
|
||||||
strcat(buffer,tmp3);
|
strcat(buffer,tmp3);
|
||||||
strcat(buffer,tmp2);
|
strcat(buffer,tmp2);
|
||||||
sprintf(tmp3,"%ld",arg);
|
sprintf(tmp3,"%ld",arg);
|
||||||
strcat(buffer,tmp3);
|
strcat(buffer,tmp3);
|
||||||
system(buffer);
|
system(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int __argc, char *__argv[])
|
int main (int __argc, char *__argv[])
|
||||||
{
|
{
|
||||||
long int timeSeq;
|
long int timeSeq;
|
||||||
timeSeq=(long int)peoPSOSeq ();
|
timeSeq=(long int)peoPSOSeq ();
|
||||||
peoPSOPara(timeSeq);
|
peoPSOPara(timeSeq);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <t-peoPSOPara.cpp>
|
* <t-peoPSOPara.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -44,64 +44,64 @@
|
||||||
typedef eoRealParticle < double >Indi;
|
typedef eoRealParticle < double >Indi;
|
||||||
double f (const Indi & _indi)
|
double f (const Indi & _indi)
|
||||||
{
|
{
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
for (unsigned i = 0; i < _indi.size (); i++)
|
for (unsigned i = 0; i < _indi.size (); i++)
|
||||||
sum += pow(_indi[i],2);
|
sum += pow(_indi[i],2);
|
||||||
return (-sum);
|
return (-sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int __argc, char *__argv[])
|
int main (int __argc, char *__argv[])
|
||||||
{
|
{
|
||||||
peo :: init( __argc, __argv );
|
peo :: init( __argc, __argv );
|
||||||
clock_t begin,end;
|
clock_t begin,end;
|
||||||
double time;
|
double time;
|
||||||
const unsigned int VEC_SIZE = 2;
|
const unsigned int VEC_SIZE = 2;
|
||||||
const unsigned int POP_SIZE = 10;
|
const unsigned int POP_SIZE = 10;
|
||||||
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
||||||
const unsigned int MAX_GEN = 500;
|
const unsigned int MAX_GEN = 500;
|
||||||
const double FIT_CONT = -1e-6;
|
const double FIT_CONT = -1e-6;
|
||||||
const double INIT_POSITION_MIN = -5.0;
|
const double INIT_POSITION_MIN = -5.0;
|
||||||
const double INIT_POSITION_MAX = 5.0;
|
const double INIT_POSITION_MAX = 5.0;
|
||||||
const double INIT_VELOCITY_MIN = -1;
|
const double INIT_VELOCITY_MIN = -1;
|
||||||
const double INIT_VELOCITY_MAX = 1;
|
const double INIT_VELOCITY_MAX = 1;
|
||||||
const double C1 = 2;
|
const double C1 = 2;
|
||||||
const double C2 = 2;
|
const double C2 = 2;
|
||||||
rng.reseed (36);
|
rng.reseed (36);
|
||||||
if((isScheduleNode())&&(__argc >= 3))
|
if ((isScheduleNode())&&(__argc >= 3))
|
||||||
begin=clock();
|
begin=clock();
|
||||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEvalPara(f);
|
peoEvalFuncPSO<Indi, double, const Indi& > plainEvalPara(f);
|
||||||
eoEvalFuncCounter < Indi > evalStartPara (plainEvalPara);
|
eoEvalFuncCounter < Indi > evalStartPara (plainEvalPara);
|
||||||
peoParaPopEval< Indi > evalPara(plainEvalPara);
|
peoParaPopEval< Indi > evalPara(plainEvalPara);
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||||
eoFirstIsBestInit < Indi > localInit;
|
eoFirstIsBestInit < Indi > localInit;
|
||||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
eoStandardFlight < Indi > flight(bndsFlight);
|
eoStandardFlight < Indi > flight(bndsFlight);
|
||||||
eoPop < Indi > popPara;
|
eoPop < Indi > popPara;
|
||||||
popPara.append (POP_SIZE, random);
|
popPara.append (POP_SIZE, random);
|
||||||
apply(evalStartPara, popPara);
|
apply(evalStartPara, popPara);
|
||||||
apply < Indi > (veloRandom, popPara);
|
apply < Indi > (veloRandom, popPara);
|
||||||
apply < Indi > (localInit, popPara);
|
apply < Indi > (localInit, popPara);
|
||||||
eoLinearTopology<Indi> topologyPara(NEIGHBORHOOD_SIZE);
|
eoLinearTopology<Indi> topologyPara(NEIGHBORHOOD_SIZE);
|
||||||
topologyPara.setup(popPara);
|
topologyPara.setup(popPara);
|
||||||
eoRealVectorBounds bndsPara(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
eoRealVectorBounds bndsPara(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
eoStandardVelocity < Indi > velocityPara (topologyPara,C1,C2,bndsPara);
|
eoStandardVelocity < Indi > velocityPara (topologyPara,C1,C2,bndsPara);
|
||||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||||
eoFitContinue < Indi > fitContPara (FIT_CONT);
|
eoFitContinue < Indi > fitContPara (FIT_CONT);
|
||||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||||
continuatorPara.add(fitContPara);
|
continuatorPara.add(fitContPara);
|
||||||
eoCheckPoint<Indi> checkpointPara(continuatorPara);
|
eoCheckPoint<Indi> checkpointPara(continuatorPara);
|
||||||
peoPSO < Indi > psaPara(checkpointPara, evalPara, velocityPara, flight);
|
peoPSO < Indi > psaPara(checkpointPara, evalPara, velocityPara, flight);
|
||||||
psaPara(popPara);
|
psaPara(popPara);
|
||||||
peo :: run();
|
peo :: run();
|
||||||
peo :: finalize();
|
peo :: finalize();
|
||||||
if((isScheduleNode())&&(__argc >= 3))
|
if ((isScheduleNode())&&(__argc >= 3))
|
||||||
{
|
{
|
||||||
end=clock();
|
end=clock();
|
||||||
time=end-begin;
|
time=end-begin;
|
||||||
std::cout<<"\n\nEfficiency : "<<(atoi(__argv[2])/(time*getNumberOfNodes()))<<"\n";
|
std::cout<<"\n\nEfficiency : "<<(atoi(__argv[2])/(time*getNumberOfNodes()))<<"\n";
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <t-peoPSOParaIsland.cpp>
|
* <t-peoPSOParaIsland.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -44,32 +44,32 @@ typedef eoRealParticle < double >Indi;
|
||||||
|
|
||||||
//Evaluation function
|
//Evaluation function
|
||||||
double f (const Indi & _indi)
|
double f (const Indi & _indi)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const double PI = 4.0 * atan(1.0);
|
||||||
|
double sum=0.;
|
||||||
|
for (unsigned i = 0; i < _indi.size()-1; i++)
|
||||||
|
sum+=pow((_indi[i]-1),2)*(1+pow(sin(3*PI*_indi[i+1]),2));
|
||||||
|
sum+=pow(sin(3*PI*_indi[0]),2);
|
||||||
|
sum+=(_indi[_indi.size()-1]-1)*(1+pow(sin(2*PI*_indi[_indi.size()-1]),2));
|
||||||
|
return (-sum);
|
||||||
|
|
||||||
const double PI = 4.0 * atan(1.0);
|
|
||||||
double sum=0.;
|
|
||||||
for (unsigned i = 0; i < _indi.size()-1; i++)
|
|
||||||
sum+=pow((_indi[i]-1),2)*(1+pow(sin(3*PI*_indi[i+1]),2));
|
|
||||||
sum+=pow(sin(3*PI*_indi[0]),2);
|
|
||||||
sum+=(_indi[_indi.size()-1]-1)*(1+pow(sin(2*PI*_indi[_indi.size()-1]),2));
|
|
||||||
return (-sum);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template < class POT > class eoPrint : public eoContinue <POT>
|
template < class POT > class eoPrint : public eoContinue <POT>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
bool operator () (const eoPop <POT> & __pop)
|
bool operator () (const eoPop <POT> & __pop)
|
||||||
{
|
{
|
||||||
double result[__pop.size()];
|
double result[__pop.size()];
|
||||||
for(unsigned i=0;i<__pop.size();i++)
|
for (unsigned i=0;i<__pop.size();i++)
|
||||||
result[i]=__pop[i].best();
|
result[i]=__pop[i].best();
|
||||||
std::sort(result,result+__pop.size());
|
std::sort(result,result+__pop.size());
|
||||||
std::cout << "\n"<<result[__pop.size()-1];
|
std::cout << "\n"<<result[__pop.size()-1];
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
int main (int __argc, char *__argv[])
|
int main (int __argc, char *__argv[])
|
||||||
|
|
@ -78,93 +78,93 @@ int main (int __argc, char *__argv[])
|
||||||
//Initialization
|
//Initialization
|
||||||
peo :: init( __argc, __argv );
|
peo :: init( __argc, __argv );
|
||||||
//Parameters
|
//Parameters
|
||||||
|
|
||||||
const unsigned int MIG_FREQ = 1;
|
|
||||||
const unsigned int VEC_SIZE = 4;
|
|
||||||
const unsigned int POP_SIZE = 10;
|
|
||||||
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
|
||||||
const unsigned int MAX_GEN = 100;
|
|
||||||
const double INIT_POSITION_MIN = -50.0;
|
|
||||||
const double INIT_POSITION_MAX = 50.0;
|
|
||||||
const double INIT_VELOCITY_MIN = -1;
|
|
||||||
const double INIT_VELOCITY_MAX = 1;
|
|
||||||
const double C1 = 0.5;
|
|
||||||
const double C2 = 2;
|
|
||||||
rng.reseed (44);
|
|
||||||
if(getNodeRank()==1)
|
|
||||||
std::cout<<"\n\nWith two islands\n\n";
|
|
||||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
|
||||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
|
||||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
|
||||||
eoFirstIsBestInit < Indi > localInit;
|
|
||||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
|
||||||
eoStandardFlight < Indi > flight(bndsFlight);
|
|
||||||
eoEvalFuncCounter < Indi > evalSeq (plainEval);
|
|
||||||
peoParaPopEval< Indi > eval(plainEval);
|
|
||||||
eoPop < Indi > pop;
|
|
||||||
pop.append (POP_SIZE, random);
|
|
||||||
apply(evalSeq, pop);
|
|
||||||
apply < Indi > (veloRandom, pop);
|
|
||||||
apply < Indi > (localInit, pop);
|
|
||||||
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
|
||||||
topology.setup(pop);
|
|
||||||
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
|
||||||
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
|
||||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
|
||||||
eoPrint <Indi> print;
|
|
||||||
eoCombinedContinue <Indi> continuator(genContPara);
|
|
||||||
continuator.add(print);
|
|
||||||
eoCheckPoint<Indi> checkpoint(continuator);
|
|
||||||
RingTopology topologyMig;
|
|
||||||
/*******************************************************************/
|
|
||||||
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
|
||||||
peoPSOSelect<Indi> mig_selec(topology);
|
|
||||||
eoSelectNumber< Indi > mig_select(mig_selec);
|
|
||||||
peoPSOReplacement<Indi> mig_replace;
|
|
||||||
/*****************************************************************/
|
|
||||||
|
|
||||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval2(f);
|
|
||||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
|
||||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen);
|
|
||||||
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
|
||||||
eoVelocityInitFixedLength < Indi > veloRandom2 (VEC_SIZE, sGen2);
|
|
||||||
eoFirstIsBestInit < Indi > localInit2;
|
|
||||||
eoRealVectorBounds bndsFlight2(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
|
||||||
eoStandardFlight < Indi > flight2(bndsFlight2);
|
|
||||||
eoEvalFuncCounter < Indi > evalSeq2 (plainEval2);
|
|
||||||
peoParaPopEval< Indi > eval2(plainEval2);
|
|
||||||
eoPop < Indi > pop2;
|
|
||||||
pop2.append (POP_SIZE, random2);
|
|
||||||
apply(evalSeq2, pop2);
|
|
||||||
apply < Indi > (veloRandom2, pop2);
|
|
||||||
apply < Indi > (localInit2, pop2);
|
|
||||||
eoLinearTopology<Indi> topology2(NEIGHBORHOOD_SIZE);
|
|
||||||
topology2.setup(pop2);
|
|
||||||
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
|
||||||
eoStandardVelocity < Indi > velocity2 (topology2,C1,C2,bnds2);
|
|
||||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
|
||||||
eoCheckPoint<Indi> checkpoint2(genContPara2);
|
|
||||||
/*******************************************************************/
|
|
||||||
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
|
||||||
peoPSOSelect<Indi> mig_selec2(topology2);
|
|
||||||
eoSelectNumber< Indi > mig_select2(mig_selec2);
|
|
||||||
peoPSOReplacement<Indi> mig_replace2;
|
|
||||||
|
|
||||||
peoAsyncIslandMig< Indi > mig( mig_cont, mig_select, mig_replace, topologyMig, pop, pop2);
|
const unsigned int MIG_FREQ = 1;
|
||||||
checkpoint.add( mig );
|
const unsigned int VEC_SIZE = 4;
|
||||||
peoAsyncIslandMig< Indi > mig2( mig_cont2, mig_select2, mig_replace2, topologyMig, pop2, pop);
|
const unsigned int POP_SIZE = 10;
|
||||||
checkpoint2.add( mig2 );
|
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
||||||
|
const unsigned int MAX_GEN = 100;
|
||||||
peoPSO < Indi > psa(checkpoint, eval, velocity, flight);
|
const double INIT_POSITION_MIN = -50.0;
|
||||||
mig.setOwner( psa );
|
const double INIT_POSITION_MAX = 50.0;
|
||||||
psa(pop);
|
const double INIT_VELOCITY_MIN = -1;
|
||||||
peoPSO < Indi > psa2(checkpoint2, eval2, velocity2, flight2);
|
const double INIT_VELOCITY_MAX = 1;
|
||||||
mig2.setOwner( psa2 );
|
const double C1 = 0.5;
|
||||||
psa2(pop2);
|
const double C2 = 2;
|
||||||
|
rng.reseed (44);
|
||||||
peo :: run();
|
if (getNodeRank()==1)
|
||||||
peo :: finalize();
|
std::cout<<"\n\nWith two islands\n\n";
|
||||||
|
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
||||||
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
|
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
|
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||||
|
eoFirstIsBestInit < Indi > localInit;
|
||||||
|
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
|
eoStandardFlight < Indi > flight(bndsFlight);
|
||||||
|
eoEvalFuncCounter < Indi > evalSeq (plainEval);
|
||||||
|
peoParaPopEval< Indi > eval(plainEval);
|
||||||
|
eoPop < Indi > pop;
|
||||||
|
pop.append (POP_SIZE, random);
|
||||||
|
apply(evalSeq, pop);
|
||||||
|
apply < Indi > (veloRandom, pop);
|
||||||
|
apply < Indi > (localInit, pop);
|
||||||
|
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||||
|
topology.setup(pop);
|
||||||
|
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
|
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
||||||
|
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||||
|
eoPrint <Indi> print;
|
||||||
|
eoCombinedContinue <Indi> continuator(genContPara);
|
||||||
|
continuator.add(print);
|
||||||
|
eoCheckPoint<Indi> checkpoint(continuator);
|
||||||
|
RingTopology topologyMig;
|
||||||
|
/*******************************************************************/
|
||||||
|
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
||||||
|
peoPSOSelect<Indi> mig_selec(topology);
|
||||||
|
eoSelectNumber< Indi > mig_select(mig_selec);
|
||||||
|
peoPSOReplacement<Indi> mig_replace;
|
||||||
|
/*****************************************************************/
|
||||||
|
|
||||||
|
peoEvalFuncPSO<Indi, double, const Indi& > plainEval2(f);
|
||||||
|
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
|
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen);
|
||||||
|
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
|
eoVelocityInitFixedLength < Indi > veloRandom2 (VEC_SIZE, sGen2);
|
||||||
|
eoFirstIsBestInit < Indi > localInit2;
|
||||||
|
eoRealVectorBounds bndsFlight2(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
|
eoStandardFlight < Indi > flight2(bndsFlight2);
|
||||||
|
eoEvalFuncCounter < Indi > evalSeq2 (plainEval2);
|
||||||
|
peoParaPopEval< Indi > eval2(plainEval2);
|
||||||
|
eoPop < Indi > pop2;
|
||||||
|
pop2.append (POP_SIZE, random2);
|
||||||
|
apply(evalSeq2, pop2);
|
||||||
|
apply < Indi > (veloRandom2, pop2);
|
||||||
|
apply < Indi > (localInit2, pop2);
|
||||||
|
eoLinearTopology<Indi> topology2(NEIGHBORHOOD_SIZE);
|
||||||
|
topology2.setup(pop2);
|
||||||
|
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
|
eoStandardVelocity < Indi > velocity2 (topology2,C1,C2,bnds2);
|
||||||
|
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||||
|
eoCheckPoint<Indi> checkpoint2(genContPara2);
|
||||||
|
/*******************************************************************/
|
||||||
|
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
||||||
|
peoPSOSelect<Indi> mig_selec2(topology2);
|
||||||
|
eoSelectNumber< Indi > mig_select2(mig_selec2);
|
||||||
|
peoPSOReplacement<Indi> mig_replace2;
|
||||||
|
|
||||||
|
peoAsyncIslandMig< Indi > mig( mig_cont, mig_select, mig_replace, topologyMig, pop, pop2);
|
||||||
|
checkpoint.add( mig );
|
||||||
|
peoAsyncIslandMig< Indi > mig2( mig_cont2, mig_select2, mig_replace2, topologyMig, pop2, pop);
|
||||||
|
checkpoint2.add( mig2 );
|
||||||
|
|
||||||
|
peoPSO < Indi > psa(checkpoint, eval, velocity, flight);
|
||||||
|
mig.setOwner( psa );
|
||||||
|
psa(pop);
|
||||||
|
peoPSO < Indi > psa2(checkpoint2, eval2, velocity2, flight2);
|
||||||
|
mig2.setOwner( psa2 );
|
||||||
|
psa2(pop2);
|
||||||
|
|
||||||
|
peo :: run();
|
||||||
|
peo :: finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <main.cpp>
|
* <main.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, INRIA, 2007
|
* (C) OPAC Team, INRIA, 2007
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
*
|
*
|
||||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <peo>
|
#include <peo>
|
||||||
|
|
@ -42,15 +42,15 @@ typedef eoReal<double> Indi;
|
||||||
//Evaluation function
|
//Evaluation function
|
||||||
|
|
||||||
double f (const Indi & _indi)
|
double f (const Indi & _indi)
|
||||||
{
|
{
|
||||||
// Rosenbrock function f(x) = 100*(x[1]-x[0]^2)^2+(1-x[0])^2
|
// Rosenbrock function f(x) = 100*(x[1]-x[0]^2)^2+(1-x[0])^2
|
||||||
// => optimal : f* = 0 , with x* =(1,1)
|
// => optimal : f* = 0 , with x* =(1,1)
|
||||||
|
|
||||||
double sum;
|
double sum;
|
||||||
sum=_indi[1]-pow(_indi[0],2);
|
sum=_indi[1]-pow(_indi[0],2);
|
||||||
sum=100*pow(sum,2);
|
sum=100*pow(sum,2);
|
||||||
sum+=pow((1-_indi[0]),2);
|
sum+=pow((1-_indi[0]),2);
|
||||||
return (-sum);
|
return (-sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int __argc, char *__argv[])
|
int main (int __argc, char *__argv[])
|
||||||
|
|
@ -58,68 +58,68 @@ int main (int __argc, char *__argv[])
|
||||||
|
|
||||||
|
|
||||||
// Initialization of the parallel environment : thanks this instruction, ParadisEO-PEO can initialize himself
|
// Initialization of the parallel environment : thanks this instruction, ParadisEO-PEO can initialize himself
|
||||||
peo :: init( __argc, __argv );
|
peo :: init( __argc, __argv );
|
||||||
|
|
||||||
//Parameters
|
//Parameters
|
||||||
|
|
||||||
const unsigned int VEC_SIZE = 2; // Don't change this parameter when you are resolving the Rosenbrock function
|
const unsigned int VEC_SIZE = 2; // Don't change this parameter when you are resolving the Rosenbrock function
|
||||||
const unsigned int POP_SIZE = 20; // As with a sequential algorithm, you change the size of the population
|
const unsigned int POP_SIZE = 20; // As with a sequential algorithm, you change the size of the population
|
||||||
const unsigned int MAX_GEN = 300; // Define the number of maximal generation
|
const unsigned int MAX_GEN = 300; // Define the number of maximal generation
|
||||||
const double INIT_POSITION_MIN = -2.0; // For initialize x
|
const double INIT_POSITION_MIN = -2.0; // For initialize x
|
||||||
const double INIT_POSITION_MAX = 2.0; // In the case of the Rosenbrock function : -2 < x[i] < 2
|
const double INIT_POSITION_MAX = 2.0; // In the case of the Rosenbrock function : -2 < x[i] < 2
|
||||||
const float CROSS_RATE = 0.8; // Crossover rate
|
const float CROSS_RATE = 0.8; // Crossover rate
|
||||||
const double EPSILON = 0.01; // Range for real uniform mutation
|
const double EPSILON = 0.01; // Range for real uniform mutation
|
||||||
const float MUT_RATE = 0.3; // Mutation rate
|
const float MUT_RATE = 0.3; // Mutation rate
|
||||||
rng.reseed (time(0));
|
rng.reseed (time(0));
|
||||||
|
|
||||||
// Stopping
|
// Stopping
|
||||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||||
|
|
||||||
|
|
||||||
/* In this lesson, you should define a peoEvalFunc witch will allow to initialize :
|
/* In this lesson, you should define a peoEvalFunc witch will allow to initialize :
|
||||||
*
|
*
|
||||||
* - peoSeqPopEval : using to the sequential evaluation
|
* - peoSeqPopEval : using to the sequential evaluation
|
||||||
*
|
*
|
||||||
* OR
|
* OR
|
||||||
*
|
*
|
||||||
* - peoParaPopEval : using to the parallel evaluation
|
* - peoParaPopEval : using to the parallel evaluation
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// For a parallel evaluation
|
// For a parallel evaluation
|
||||||
peoEvalFunc<Indi> plainEval(f);
|
peoEvalFunc<Indi> plainEval(f);
|
||||||
peoParaPopEval< Indi > eval(plainEval);
|
peoParaPopEval< Indi > eval(plainEval);
|
||||||
|
|
||||||
|
|
||||||
// Initialization
|
// Initialization
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
|
|
||||||
// Selection
|
// Selection
|
||||||
eoRankingSelect<Indi> selectionStrategy;
|
eoRankingSelect<Indi> selectionStrategy;
|
||||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||||
|
|
||||||
// Transformation
|
// Transformation
|
||||||
eoSegmentCrossover<Indi> crossover; // Crossover
|
eoSegmentCrossover<Indi> crossover; // Crossover
|
||||||
eoUniformMutation<Indi> mutation(EPSILON); // Mutation
|
eoUniformMutation<Indi> mutation(EPSILON); // Mutation
|
||||||
eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||||
peoSeqTransform<Indi> eaTransform(transform);
|
peoSeqTransform<Indi> eaTransform(transform);
|
||||||
|
|
||||||
// Replacement
|
// Replacement
|
||||||
eoPlusReplacement<Indi> replace;
|
eoPlusReplacement<Indi> replace;
|
||||||
|
|
||||||
// Creation of the population
|
// Creation of the population
|
||||||
eoPop < Indi > pop;
|
eoPop < Indi > pop;
|
||||||
pop.append (POP_SIZE, random);
|
pop.append (POP_SIZE, random);
|
||||||
|
|
||||||
//Parallel algorithm
|
//Parallel algorithm
|
||||||
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
||||||
Algo(pop);
|
Algo(pop);
|
||||||
|
|
||||||
peo :: run();
|
peo :: run();
|
||||||
peo :: finalize();
|
peo :: finalize();
|
||||||
if(getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
std::cout << "Final population :\n" << pop << std::endl;
|
std::cout << "Final population :\n" << pop << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <main.cpp>
|
* <main.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, INRIA, 2007
|
* (C) OPAC Team, INRIA, 2007
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
*
|
*
|
||||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <peo>
|
#include <peo>
|
||||||
|
|
@ -41,15 +41,15 @@ typedef eoRealParticle < double >Indi;
|
||||||
//Evaluation function
|
//Evaluation function
|
||||||
|
|
||||||
double f (const Indi & _indi)
|
double f (const Indi & _indi)
|
||||||
{
|
{
|
||||||
// Rosenbrock function f(x) = 100*(x[1]-x[0]^2)^2+(1-x[0])^2
|
// Rosenbrock function f(x) = 100*(x[1]-x[0]^2)^2+(1-x[0])^2
|
||||||
// => optimal : f* = 0 , with x* =(1,1)
|
// => optimal : f* = 0 , with x* =(1,1)
|
||||||
|
|
||||||
double sum;
|
double sum;
|
||||||
sum=_indi[1]-pow(_indi[0],2);
|
sum=_indi[1]-pow(_indi[0],2);
|
||||||
sum=100*pow(sum,2);
|
sum=100*pow(sum,2);
|
||||||
sum+=pow((1-_indi[0]),2);
|
sum+=pow((1-_indi[0]),2);
|
||||||
return (-sum);
|
return (-sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int __argc, char *__argv[])
|
int main (int __argc, char *__argv[])
|
||||||
|
|
@ -57,86 +57,86 @@ int main (int __argc, char *__argv[])
|
||||||
|
|
||||||
|
|
||||||
// Initialization of the parallel environment : thanks this instruction, ParadisEO-PEO can initialize himself
|
// Initialization of the parallel environment : thanks this instruction, ParadisEO-PEO can initialize himself
|
||||||
peo :: init( __argc, __argv );
|
peo :: init( __argc, __argv );
|
||||||
|
|
||||||
//Parameters
|
//Parameters
|
||||||
|
|
||||||
const unsigned int VEC_SIZE = 2; // Don't change this parameter when you are resolving the Rosenbrock function
|
const unsigned int VEC_SIZE = 2; // Don't change this parameter when you are resolving the Rosenbrock function
|
||||||
|
|
||||||
const unsigned int POP_SIZE = 20; // As with a sequential algorithm, you change the size of the population
|
const unsigned int POP_SIZE = 20; // As with a sequential algorithm, you change the size of the population
|
||||||
|
|
||||||
const unsigned int NEIGHBORHOOD_SIZE= 6; // This parameter define the neighborhoods in the PSO's topology
|
const unsigned int NEIGHBORHOOD_SIZE= 6; // This parameter define the neighborhoods in the PSO's topology
|
||||||
|
|
||||||
const unsigned int MAX_GEN = 150; // Define the number of maximal generation
|
const unsigned int MAX_GEN = 150; // Define the number of maximal generation
|
||||||
|
|
||||||
const double INIT_POSITION_MIN = -2.0; // For initialize x
|
const double INIT_POSITION_MIN = -2.0; // For initialize x
|
||||||
const double INIT_POSITION_MAX = 2.0; // In the case of the Rosenbrock function : -2 < x[i] < 2
|
const double INIT_POSITION_MAX = 2.0; // In the case of the Rosenbrock function : -2 < x[i] < 2
|
||||||
|
|
||||||
const double INIT_VELOCITY_MIN = -1.; // For initialize PSO's velocity
|
const double INIT_VELOCITY_MIN = -1.; // For initialize PSO's velocity
|
||||||
const double INIT_VELOCITY_MAX = 1.; // ie Lesson 6 of ParadisEO-EO
|
const double INIT_VELOCITY_MAX = 1.; // ie Lesson 6 of ParadisEO-EO
|
||||||
|
|
||||||
const double C1 = 0.5; // For calculate the velocity
|
const double C1 = 0.5; // For calculate the velocity
|
||||||
const double C2 = 2.; // ie Lesson 6 of ParadisEO-EO
|
const double C2 = 2.; // ie Lesson 6 of ParadisEO-EO
|
||||||
rng.reseed (time(0));
|
rng.reseed (time(0));
|
||||||
|
|
||||||
// Stopping
|
// Stopping
|
||||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* In this lesson, you should define a peoEvalFuncPSO witch will allow to initialize :
|
/* In this lesson, you should define a peoEvalFuncPSO witch will allow to initialize :
|
||||||
*
|
*
|
||||||
* - peoSeqPopEval : using to the sequential evaluation
|
* - peoSeqPopEval : using to the sequential evaluation
|
||||||
*
|
*
|
||||||
* OR
|
* OR
|
||||||
*
|
*
|
||||||
* - peoParaPopEval : using to the parallel evaluation
|
* - peoParaPopEval : using to the parallel evaluation
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// For a parallel evaluation
|
// For a parallel evaluation
|
||||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
||||||
peoParaPopEval< Indi > eval(plainEval);
|
peoParaPopEval< Indi > eval(plainEval);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Initialization
|
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
|
||||||
|
|
||||||
// Velocity (ie Lesson 6 of ParadisEO-PEO)
|
|
||||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
|
||||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
|
||||||
|
|
||||||
// Initializing the best (ie Lesson 6 of ParadisEO-PEO)
|
|
||||||
eoFirstIsBestInit < Indi > localInit;
|
|
||||||
|
|
||||||
// Flight (ie Lesson 6 of ParadisEO-PEO)
|
|
||||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
|
||||||
eoStandardFlight < Indi > flight(bndsFlight);
|
|
||||||
|
|
||||||
// Creation of the population
|
|
||||||
eoPop < Indi > pop;
|
|
||||||
pop.append (POP_SIZE, random);
|
|
||||||
|
|
||||||
// Initialization
|
// Initialization
|
||||||
peoInitializer <Indi> init(eval,veloRandom,localInit,pop);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
|
|
||||||
|
// Velocity (ie Lesson 6 of ParadisEO-PEO)
|
||||||
|
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
|
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||||
|
|
||||||
|
// Initializing the best (ie Lesson 6 of ParadisEO-PEO)
|
||||||
|
eoFirstIsBestInit < Indi > localInit;
|
||||||
|
|
||||||
|
// Flight (ie Lesson 6 of ParadisEO-PEO)
|
||||||
|
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
|
eoStandardFlight < Indi > flight(bndsFlight);
|
||||||
|
|
||||||
|
// Creation of the population
|
||||||
|
eoPop < Indi > pop;
|
||||||
|
pop.append (POP_SIZE, random);
|
||||||
|
|
||||||
|
// Initialization
|
||||||
|
peoInitializer <Indi> init(eval,veloRandom,localInit,pop);
|
||||||
|
|
||||||
// Topology (ie Lesson 6 of ParadisEO-PEO)
|
// Topology (ie Lesson 6 of ParadisEO-PEO)
|
||||||
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||||
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
||||||
|
|
||||||
//Parallel algorithm
|
//Parallel algorithm
|
||||||
peoPSO < Indi > psa(init,checkpoint, eval, velocity, flight);
|
peoPSO < Indi > psa(init,checkpoint, eval, velocity, flight);
|
||||||
psa(pop);
|
psa(pop);
|
||||||
peo :: run();
|
peo :: run();
|
||||||
peo :: finalize();
|
peo :: finalize();
|
||||||
if(getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
std::cout << "Final population :\n" << pop << std::endl;
|
std::cout << "Final population :\n" << pop << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <main.cpp>
|
* <main.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, INRIA, 2007
|
* (C) OPAC Team, INRIA, 2007
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
*
|
*
|
||||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <peo>
|
#include <peo>
|
||||||
|
|
@ -40,66 +40,66 @@
|
||||||
typedef eoReal<double> Indi;
|
typedef eoReal<double> Indi;
|
||||||
|
|
||||||
double f (const Indi & _indi)
|
double f (const Indi & _indi)
|
||||||
{
|
{
|
||||||
double sum;
|
double sum;
|
||||||
sum=_indi[1]-pow(_indi[0],2);
|
sum=_indi[1]-pow(_indi[0],2);
|
||||||
sum=100*pow(sum,2);
|
sum=100*pow(sum,2);
|
||||||
sum+=pow((1-_indi[0]),2);
|
sum+=pow((1-_indi[0]),2);
|
||||||
return (-sum);
|
return (-sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int __argc, char *__argv[])
|
int main (int __argc, char *__argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
peo :: init( __argc, __argv );
|
peo :: init( __argc, __argv );
|
||||||
const unsigned int VEC_SIZE = 2;
|
const unsigned int VEC_SIZE = 2;
|
||||||
const unsigned int POP_SIZE = 20;
|
const unsigned int POP_SIZE = 20;
|
||||||
const unsigned int MAX_GEN = 300;
|
const unsigned int MAX_GEN = 300;
|
||||||
const double INIT_POSITION_MIN = -2.0;
|
const double INIT_POSITION_MIN = -2.0;
|
||||||
const double INIT_POSITION_MAX = 2.0;
|
const double INIT_POSITION_MAX = 2.0;
|
||||||
const float CROSS_RATE = 0.8;
|
const float CROSS_RATE = 0.8;
|
||||||
const double EPSILON = 0.01;
|
const double EPSILON = 0.01;
|
||||||
const float MUT_RATE = 0.3;
|
const float MUT_RATE = 0.3;
|
||||||
rng.reseed (time(0));
|
rng.reseed (time(0));
|
||||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||||
peoEvalFunc<Indi> plainEval(f);
|
peoEvalFunc<Indi> plainEval(f);
|
||||||
peoSeqPopEval< Indi > eval(plainEval); // Here, the evaluation is sequential
|
peoSeqPopEval< Indi > eval(plainEval); // Here, the evaluation is sequential
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
eoRankingSelect<Indi> selectionStrategy;
|
eoRankingSelect<Indi> selectionStrategy;
|
||||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||||
eoSegmentCrossover<Indi> crossover;
|
eoSegmentCrossover<Indi> crossover;
|
||||||
eoUniformMutation<Indi> mutation(EPSILON);
|
eoUniformMutation<Indi> mutation(EPSILON);
|
||||||
|
|
||||||
/******************************************************************************************/
|
/******************************************************************************************/
|
||||||
|
|
||||||
/* In this lesson, you can choose between :
|
/* In this lesson, you can choose between :
|
||||||
*
|
*
|
||||||
* - A sequential transformation (crossover + mutation) : eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
* - A sequential transformation (crossover + mutation) : eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||||
* peoSeqTransform<Indi> eaTransform(transform);
|
* peoSeqTransform<Indi> eaTransform(transform);
|
||||||
*
|
*
|
||||||
* OR
|
* OR
|
||||||
*
|
*
|
||||||
* - A parallel transformation (crossover + mutation) : peoParaSGATransform <Indi> eaTransform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
* - A parallel transformation (crossover + mutation) : peoParaSGATransform <Indi> eaTransform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||||
*
|
*
|
||||||
* Unfortunately, if you don't use a crossover which creates two children with two parents,
|
* Unfortunately, if you don't use a crossover which creates two children with two parents,
|
||||||
* you can't use this operator.
|
* you can't use this operator.
|
||||||
* In this case, you should send a mail to : paradiseo-help@lists.gforge.inria.fr
|
* In this case, you should send a mail to : paradiseo-help@lists.gforge.inria.fr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
peoParaSGATransform <Indi> eaTransform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
peoParaSGATransform <Indi> eaTransform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||||
|
|
||||||
/******************************************************************************************/
|
/******************************************************************************************/
|
||||||
|
|
||||||
eoPlusReplacement<Indi> replace;
|
eoPlusReplacement<Indi> replace;
|
||||||
eoPop < Indi > pop;
|
eoPop < Indi > pop;
|
||||||
pop.append (POP_SIZE, random);
|
pop.append (POP_SIZE, random);
|
||||||
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
||||||
Algo(pop);
|
Algo(pop);
|
||||||
peo :: run();
|
peo :: run();
|
||||||
peo :: finalize();
|
peo :: finalize();
|
||||||
if(getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
std::cout << "Final population :\n" << pop << std::endl;
|
std::cout << "Final population :\n" << pop << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <main.cpp>
|
* <main.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, INRIA, 2007
|
* (C) OPAC Team, INRIA, 2007
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
*
|
*
|
||||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <peo>
|
#include <peo>
|
||||||
|
|
@ -40,109 +40,109 @@
|
||||||
typedef eoReal<double> Indi;
|
typedef eoReal<double> Indi;
|
||||||
|
|
||||||
double f (const Indi & _indi)
|
double f (const Indi & _indi)
|
||||||
{
|
{
|
||||||
double sum;
|
double sum;
|
||||||
sum=_indi[1]-pow(_indi[0],2);
|
sum=_indi[1]-pow(_indi[0],2);
|
||||||
sum=100*pow(sum,2);
|
sum=100*pow(sum,2);
|
||||||
sum+=pow((1-_indi[0]),2);
|
sum+=pow((1-_indi[0]),2);
|
||||||
return (-sum);
|
return (-sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int __argc, char *__argv[])
|
int main (int __argc, char *__argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
peo :: init( __argc, __argv );
|
peo :: init( __argc, __argv );
|
||||||
const unsigned int VEC_SIZE = 2;
|
const unsigned int VEC_SIZE = 2;
|
||||||
const unsigned int POP_SIZE = 20;
|
const unsigned int POP_SIZE = 20;
|
||||||
const unsigned int MAX_GEN = 300;
|
const unsigned int MAX_GEN = 300;
|
||||||
const double INIT_POSITION_MIN = -2.0;
|
const double INIT_POSITION_MIN = -2.0;
|
||||||
const double INIT_POSITION_MAX = 2.0;
|
const double INIT_POSITION_MAX = 2.0;
|
||||||
const float CROSS_RATE = 0.8;
|
const float CROSS_RATE = 0.8;
|
||||||
const double EPSILON = 0.01;
|
const double EPSILON = 0.01;
|
||||||
const float MUT_RATE = 0.3;
|
const float MUT_RATE = 0.3;
|
||||||
// MIG_FREQ define the frequency of the migration.
|
// MIG_FREQ define the frequency of the migration.
|
||||||
const unsigned int MIG_FREQ = 10;
|
const unsigned int MIG_FREQ = 10;
|
||||||
// MIG_SIZE define the size of each migration.
|
// MIG_SIZE define the size of each migration.
|
||||||
const unsigned int MIG_SIZE = 5;
|
const unsigned int MIG_SIZE = 5;
|
||||||
rng.reseed (time(0));
|
rng.reseed (time(0));
|
||||||
|
|
||||||
// Define the topology of your island model
|
|
||||||
RingTopology topology;
|
|
||||||
|
|
||||||
// First algorithm
|
|
||||||
/*****************************************************************************************/
|
|
||||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
|
||||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
|
||||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
|
||||||
peoEvalFunc<Indi> plainEval(f);
|
|
||||||
peoSeqPopEval< Indi > eval(plainEval); // Here, the evaluation is sequential
|
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
|
||||||
eoRankingSelect<Indi> selectionStrategy;
|
|
||||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
|
||||||
eoSegmentCrossover<Indi> crossover;
|
|
||||||
eoUniformMutation<Indi> mutation(EPSILON);
|
|
||||||
eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
|
||||||
peoSeqTransform<Indi> eaTransform(transform); // Here, the transformation is sequential
|
|
||||||
eoPlusReplacement<Indi> replace;
|
|
||||||
eoPop < Indi > pop;
|
|
||||||
pop.append (POP_SIZE, random);
|
|
||||||
|
|
||||||
eoPeriodicContinue <Indi> mig_cont( MIG_FREQ ); // Migration occurs periodically
|
|
||||||
eoRandomSelect<Indi> mig_select_one; // Emigrants are randomly selected
|
|
||||||
eoSelectNumber<Indi> mig_select (mig_select_one,MIG_SIZE);
|
|
||||||
eoPlusReplacement<Indi> mig_replace; // Immigrants replace the worse individuals
|
|
||||||
|
|
||||||
/*****************************************************************************************/
|
// Define the topology of your island model
|
||||||
|
RingTopology topology;
|
||||||
|
|
||||||
// Second algorithm (on the same model but with others names)
|
// First algorithm
|
||||||
/*****************************************************************************************/
|
/*****************************************************************************************/
|
||||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||||
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||||
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||||
peoEvalFunc<Indi> plainEval2(f);
|
peoEvalFunc<Indi> plainEval(f);
|
||||||
peoSeqPopEval< Indi > eval2(plainEval2);
|
peoSeqPopEval< Indi > eval(plainEval); // Here, the evaluation is sequential
|
||||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
eoRankingSelect<Indi> selectionStrategy2;
|
eoRankingSelect<Indi> selectionStrategy;
|
||||||
eoSelectNumber<Indi> select2(selectionStrategy2,POP_SIZE);
|
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||||
eoSegmentCrossover<Indi> crossover2;
|
eoSegmentCrossover<Indi> crossover;
|
||||||
eoUniformMutation<Indi> mutation2(EPSILON);
|
eoUniformMutation<Indi> mutation(EPSILON);
|
||||||
eoSGATransform<Indi> transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
|
eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||||
peoSeqTransform<Indi> eaTransform2(transform2);
|
peoSeqTransform<Indi> eaTransform(transform); // Here, the transformation is sequential
|
||||||
eoPlusReplacement<Indi> replace2;
|
eoPlusReplacement<Indi> replace;
|
||||||
eoPop < Indi > pop2;
|
eoPop < Indi > pop;
|
||||||
pop2.append (POP_SIZE, random2);
|
pop.append (POP_SIZE, random);
|
||||||
eoPeriodicContinue <Indi> mig_cont2( MIG_FREQ );
|
|
||||||
eoRandomSelect<Indi> mig_select_one2;
|
|
||||||
eoSelectNumber<Indi> mig_select2 (mig_select_one2,MIG_SIZE);
|
|
||||||
eoPlusReplacement<Indi> mig_replace2;
|
|
||||||
|
|
||||||
/*****************************************************************************************/
|
eoPeriodicContinue <Indi> mig_cont( MIG_FREQ ); // Migration occurs periodically
|
||||||
|
eoRandomSelect<Indi> mig_select_one; // Emigrants are randomly selected
|
||||||
|
eoSelectNumber<Indi> mig_select (mig_select_one,MIG_SIZE);
|
||||||
|
eoPlusReplacement<Indi> mig_replace; // Immigrants replace the worse individuals
|
||||||
|
|
||||||
|
/*****************************************************************************************/
|
||||||
|
|
||||||
|
// Second algorithm (on the same model but with others names)
|
||||||
|
/*****************************************************************************************/
|
||||||
|
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||||
|
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
||||||
|
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
||||||
|
peoEvalFunc<Indi> plainEval2(f);
|
||||||
|
peoSeqPopEval< Indi > eval2(plainEval2);
|
||||||
|
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
|
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||||
|
eoRankingSelect<Indi> selectionStrategy2;
|
||||||
|
eoSelectNumber<Indi> select2(selectionStrategy2,POP_SIZE);
|
||||||
|
eoSegmentCrossover<Indi> crossover2;
|
||||||
|
eoUniformMutation<Indi> mutation2(EPSILON);
|
||||||
|
eoSGATransform<Indi> transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
|
||||||
|
peoSeqTransform<Indi> eaTransform2(transform2);
|
||||||
|
eoPlusReplacement<Indi> replace2;
|
||||||
|
eoPop < Indi > pop2;
|
||||||
|
pop2.append (POP_SIZE, random2);
|
||||||
|
eoPeriodicContinue <Indi> mig_cont2( MIG_FREQ );
|
||||||
|
eoRandomSelect<Indi> mig_select_one2;
|
||||||
|
eoSelectNumber<Indi> mig_select2 (mig_select_one2,MIG_SIZE);
|
||||||
|
eoPlusReplacement<Indi> mig_replace2;
|
||||||
|
|
||||||
|
/*****************************************************************************************/
|
||||||
|
|
||||||
// You can choose between :
|
// You can choose between :
|
||||||
//
|
//
|
||||||
// - Synchronous communication : peoSyncIslandMig<Indi> mig(MIG_FREQ,mig_select,mig_replace,topology,pop,pop);
|
// - Synchronous communication : peoSyncIslandMig<Indi> mig(MIG_FREQ,mig_select,mig_replace,topology,pop,pop);
|
||||||
// - Asynchronous communication : peoAsyncIslandMig<Indi> mig(mig_cont,mig_select,mig_replace,topology,pop,pop);
|
// - Asynchronous communication : peoAsyncIslandMig<Indi> mig(mig_cont,mig_select,mig_replace,topology,pop,pop);
|
||||||
// With a grid, you should use an asynchronous communication
|
// With a grid, you should use an asynchronous communication
|
||||||
peoAsyncIslandMig<Indi> mig(mig_cont,mig_select,mig_replace,topology,pop,pop2);
|
peoAsyncIslandMig<Indi> mig(mig_cont,mig_select,mig_replace,topology,pop,pop2);
|
||||||
checkpoint.add(mig);
|
checkpoint.add(mig);
|
||||||
peoAsyncIslandMig<Indi> mig2(mig_cont2,mig_select2,mig_replace2,topology,pop2,pop);
|
peoAsyncIslandMig<Indi> mig2(mig_cont2,mig_select2,mig_replace2,topology,pop2,pop);
|
||||||
checkpoint2.add(mig2);
|
checkpoint2.add(mig2);
|
||||||
|
|
||||||
// Initialization of the algorithms
|
// Initialization of the algorithms
|
||||||
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
||||||
mig.setOwner(Algo);
|
mig.setOwner(Algo);
|
||||||
Algo(pop);
|
Algo(pop);
|
||||||
peoEA<Indi> Algo2(checkpoint2,eval2,select2,eaTransform2,replace2);
|
peoEA<Indi> Algo2(checkpoint2,eval2,select2,eaTransform2,replace2);
|
||||||
mig2.setOwner(Algo2);
|
mig2.setOwner(Algo2);
|
||||||
Algo2(pop2);
|
Algo2(pop2);
|
||||||
|
|
||||||
peo :: run();
|
peo :: run();
|
||||||
peo :: finalize();
|
peo :: finalize();
|
||||||
if(getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
std::cout << "Final population 1 :\n" << pop << std::endl;
|
std::cout << "Final population 1 :\n" << pop << std::endl;
|
||||||
std::cout << "Final population 2 :\n" << pop2 << std::endl;
|
std::cout << "Final population 2 :\n" << pop2 << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <main.cpp>
|
* <main.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, INRIA, 2007
|
* (C) OPAC Team, INRIA, 2007
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
*
|
*
|
||||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <peo>
|
#include <peo>
|
||||||
|
|
@ -39,114 +39,114 @@
|
||||||
typedef eoRealParticle < double >Indi;
|
typedef eoRealParticle < double >Indi;
|
||||||
|
|
||||||
double f (const Indi & _indi)
|
double f (const Indi & _indi)
|
||||||
{
|
{
|
||||||
double sum;
|
double sum;
|
||||||
sum=_indi[1]-pow(_indi[0],2);
|
sum=_indi[1]-pow(_indi[0],2);
|
||||||
sum=100*pow(sum,2);
|
sum=100*pow(sum,2);
|
||||||
sum+=pow((1-_indi[0]),2);
|
sum+=pow((1-_indi[0]),2);
|
||||||
return (-sum);
|
return (-sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int __argc, char *__argv[])
|
int main (int __argc, char *__argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
// In this lesson, we define two algorithms of the PSO witch represents two islands.
|
// In this lesson, we define two algorithms of the PSO witch represents two islands.
|
||||||
// Obviously, you can define more algorithms.
|
// Obviously, you can define more algorithms.
|
||||||
|
|
||||||
// The parameters are common between the two algorithms.
|
|
||||||
/*****************************************************************************************/
|
|
||||||
peo :: init( __argc, __argv );
|
|
||||||
const unsigned int VEC_SIZE = 2;
|
|
||||||
const unsigned int POP_SIZE = 20;
|
|
||||||
const unsigned int NEIGHBORHOOD_SIZE= 6;
|
|
||||||
const unsigned int MAX_GEN = 150;
|
|
||||||
const double INIT_POSITION_MIN = -2.0;
|
|
||||||
const double INIT_POSITION_MAX = 2.0;
|
|
||||||
const double INIT_VELOCITY_MIN = -1.;
|
|
||||||
const double INIT_VELOCITY_MAX = 1.;
|
|
||||||
const double C1 = 0.5;
|
|
||||||
const double C2 = 2.;
|
|
||||||
// C3 is used for the calculation of one of the strategies of the island model.
|
|
||||||
const double C3 = 2.;
|
|
||||||
// MIG_FREQ define the frequency of the migration.
|
|
||||||
const unsigned int MIG_FREQ = 10; // The optimal value is 1 or 2 for the component peoPSOVelocity.
|
|
||||||
rng.reseed (time(0));
|
|
||||||
/*****************************************************************************************/
|
|
||||||
|
|
||||||
// Define the topology of your island model
|
|
||||||
RingTopology topologyMig;
|
|
||||||
|
|
||||||
// First algorithm
|
|
||||||
/*****************************************************************************************/
|
|
||||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
|
||||||
peoSeqPopEval< Indi > eval(plainEval); // Here, the evaluation is sequential !
|
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
|
||||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
|
||||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
|
||||||
eoFirstIsBestInit < Indi > localInit;
|
|
||||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
|
||||||
eoStandardFlight < Indi > flight(bndsFlight);
|
|
||||||
eoPop < Indi > pop;
|
|
||||||
pop.append (POP_SIZE, random);
|
|
||||||
peoInitializer <Indi> init(eval,veloRandom,localInit,pop);
|
|
||||||
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
|
||||||
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
|
||||||
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
|
||||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
|
||||||
eoCheckPoint<Indi> checkpoint(genContPara);
|
|
||||||
// Specific implementation for the island model
|
|
||||||
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
|
||||||
peoPSOSelect<Indi> mig_selec(topology);
|
|
||||||
eoSelectNumber< Indi > mig_select(mig_selec);
|
|
||||||
// If you want to use a replacement stategy : peoPSOReplacement<Indi> mig_replace;
|
|
||||||
// If you want to use a consideration of the migration in the calculation of the velocity : peoPSOVelocity<Indi> mig_replace(C3,velocity);
|
|
||||||
peoPSOReplacement<Indi> mig_replace;
|
|
||||||
/*****************************************************************************************/
|
|
||||||
|
|
||||||
// Second algorithm (on the same model but with others names)
|
|
||||||
/*****************************************************************************************/
|
|
||||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval2(f);
|
|
||||||
peoSeqPopEval< Indi > eval2(plainEval2);
|
|
||||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
|
||||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
|
||||||
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
|
||||||
eoVelocityInitFixedLength < Indi > veloRandom2 (VEC_SIZE, sGen2);
|
|
||||||
eoFirstIsBestInit < Indi > localInit2;
|
|
||||||
eoRealVectorBounds bndsFlight2(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
|
||||||
eoStandardFlight < Indi > flight2(bndsFlight2);
|
|
||||||
eoPop < Indi > pop2;
|
|
||||||
pop2.append (POP_SIZE, random2);
|
|
||||||
peoInitializer <Indi> init2(eval2,veloRandom2,localInit2,pop2);
|
|
||||||
eoLinearTopology<Indi> topology2(NEIGHBORHOOD_SIZE);
|
|
||||||
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
|
||||||
eoStandardVelocity < Indi > velocity2 (topology2,C1,C2,bnds2);
|
|
||||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
|
||||||
eoCheckPoint<Indi> checkpoint2(genContPara2);
|
|
||||||
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
|
||||||
peoPSOSelect<Indi> mig_selec2(topology2);
|
|
||||||
eoSelectNumber< Indi > mig_select2(mig_selec2);
|
|
||||||
peoPSOReplacement<Indi> mig_replace2;
|
|
||||||
/*****************************************************************************************/
|
|
||||||
|
|
||||||
// Define the communication between the islands
|
// The parameters are common between the two algorithms.
|
||||||
peoAsyncIslandMig< Indi > mig( mig_cont, mig_select, mig_replace, topologyMig, pop, pop);
|
/*****************************************************************************************/
|
||||||
checkpoint.add( mig );
|
peo :: init( __argc, __argv );
|
||||||
peoAsyncIslandMig< Indi > mig2( mig_cont2, mig_select2, mig_replace2, topologyMig, pop2, pop2);
|
const unsigned int VEC_SIZE = 2;
|
||||||
checkpoint2.add( mig2 );
|
const unsigned int POP_SIZE = 20;
|
||||||
// Initialization of the algorithms
|
const unsigned int NEIGHBORHOOD_SIZE= 6;
|
||||||
peoPSO < Indi > psa(init,checkpoint, eval, velocity, flight);
|
const unsigned int MAX_GEN = 150;
|
||||||
mig.setOwner( psa );
|
const double INIT_POSITION_MIN = -2.0;
|
||||||
psa(pop);
|
const double INIT_POSITION_MAX = 2.0;
|
||||||
peoPSO < Indi > psa2(init2,checkpoint2, eval2, velocity2, flight2);
|
const double INIT_VELOCITY_MIN = -1.;
|
||||||
mig2.setOwner( psa2 );
|
const double INIT_VELOCITY_MAX = 1.;
|
||||||
psa2(pop2);
|
const double C1 = 0.5;
|
||||||
|
const double C2 = 2.;
|
||||||
peo :: run();
|
// C3 is used for the calculation of one of the strategies of the island model.
|
||||||
peo :: finalize();
|
const double C3 = 2.;
|
||||||
if(getNodeRank()==1)
|
// MIG_FREQ define the frequency of the migration.
|
||||||
|
const unsigned int MIG_FREQ = 10; // The optimal value is 1 or 2 for the component peoPSOVelocity.
|
||||||
|
rng.reseed (time(0));
|
||||||
|
/*****************************************************************************************/
|
||||||
|
|
||||||
|
// Define the topology of your island model
|
||||||
|
RingTopology topologyMig;
|
||||||
|
|
||||||
|
// First algorithm
|
||||||
|
/*****************************************************************************************/
|
||||||
|
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
||||||
|
peoSeqPopEval< Indi > eval(plainEval); // Here, the evaluation is sequential !
|
||||||
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
|
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
|
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||||
|
eoFirstIsBestInit < Indi > localInit;
|
||||||
|
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
|
eoStandardFlight < Indi > flight(bndsFlight);
|
||||||
|
eoPop < Indi > pop;
|
||||||
|
pop.append (POP_SIZE, random);
|
||||||
|
peoInitializer <Indi> init(eval,veloRandom,localInit,pop);
|
||||||
|
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||||
|
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
|
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
||||||
|
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||||
|
eoCheckPoint<Indi> checkpoint(genContPara);
|
||||||
|
// Specific implementation for the island model
|
||||||
|
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
||||||
|
peoPSOSelect<Indi> mig_selec(topology);
|
||||||
|
eoSelectNumber< Indi > mig_select(mig_selec);
|
||||||
|
// If you want to use a replacement stategy : peoPSOReplacement<Indi> mig_replace;
|
||||||
|
// If you want to use a consideration of the migration in the calculation of the velocity : peoPSOVelocity<Indi> mig_replace(C3,velocity);
|
||||||
|
peoPSOReplacement<Indi> mig_replace;
|
||||||
|
/*****************************************************************************************/
|
||||||
|
|
||||||
|
// Second algorithm (on the same model but with others names)
|
||||||
|
/*****************************************************************************************/
|
||||||
|
peoEvalFuncPSO<Indi, double, const Indi& > plainEval2(f);
|
||||||
|
peoSeqPopEval< Indi > eval2(plainEval2);
|
||||||
|
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
|
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||||
|
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
|
eoVelocityInitFixedLength < Indi > veloRandom2 (VEC_SIZE, sGen2);
|
||||||
|
eoFirstIsBestInit < Indi > localInit2;
|
||||||
|
eoRealVectorBounds bndsFlight2(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
|
eoStandardFlight < Indi > flight2(bndsFlight2);
|
||||||
|
eoPop < Indi > pop2;
|
||||||
|
pop2.append (POP_SIZE, random2);
|
||||||
|
peoInitializer <Indi> init2(eval2,veloRandom2,localInit2,pop2);
|
||||||
|
eoLinearTopology<Indi> topology2(NEIGHBORHOOD_SIZE);
|
||||||
|
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
|
eoStandardVelocity < Indi > velocity2 (topology2,C1,C2,bnds2);
|
||||||
|
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||||
|
eoCheckPoint<Indi> checkpoint2(genContPara2);
|
||||||
|
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
||||||
|
peoPSOSelect<Indi> mig_selec2(topology2);
|
||||||
|
eoSelectNumber< Indi > mig_select2(mig_selec2);
|
||||||
|
peoPSOReplacement<Indi> mig_replace2;
|
||||||
|
/*****************************************************************************************/
|
||||||
|
|
||||||
|
// Define the communication between the islands
|
||||||
|
peoAsyncIslandMig< Indi > mig( mig_cont, mig_select, mig_replace, topologyMig, pop, pop);
|
||||||
|
checkpoint.add( mig );
|
||||||
|
peoAsyncIslandMig< Indi > mig2( mig_cont2, mig_select2, mig_replace2, topologyMig, pop2, pop2);
|
||||||
|
checkpoint2.add( mig2 );
|
||||||
|
// Initialization of the algorithms
|
||||||
|
peoPSO < Indi > psa(init,checkpoint, eval, velocity, flight);
|
||||||
|
mig.setOwner( psa );
|
||||||
|
psa(pop);
|
||||||
|
peoPSO < Indi > psa2(init2,checkpoint2, eval2, velocity2, flight2);
|
||||||
|
mig2.setOwner( psa2 );
|
||||||
|
psa2(pop2);
|
||||||
|
|
||||||
|
peo :: run();
|
||||||
|
peo :: finalize();
|
||||||
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
std::cout << "Population 1 :\n" << pop << std::endl;
|
std::cout << "Population 1 :\n" << pop << std::endl;
|
||||||
std::cout << "Population 2 :\n" << pop2 << std::endl;
|
std::cout << "Population 2 :\n" << pop2 << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <main.cpp>
|
* <main.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, INRIA, 2007
|
* (C) OPAC Team, INRIA, 2007
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
*
|
*
|
||||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <peo>
|
#include <peo>
|
||||||
|
|
@ -40,12 +40,12 @@
|
||||||
typedef eoReal<double> Indi;
|
typedef eoReal<double> Indi;
|
||||||
|
|
||||||
double f (const Indi & _indi)
|
double f (const Indi & _indi)
|
||||||
{
|
{
|
||||||
double sum;
|
double sum;
|
||||||
sum=_indi[1]-pow(_indi[0],2);
|
sum=_indi[1]-pow(_indi[0],2);
|
||||||
sum=100*pow(sum,2);
|
sum=100*pow(sum,2);
|
||||||
sum+=pow((1-_indi[0]),2);
|
sum+=pow((1-_indi[0]),2);
|
||||||
return (-sum);
|
return (-sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int __argc, char *__argv[])
|
int main (int __argc, char *__argv[])
|
||||||
|
|
@ -55,98 +55,98 @@ int main (int __argc, char *__argv[])
|
||||||
// The evaluation is parallel.
|
// The evaluation is parallel.
|
||||||
// The transformation is parallel.
|
// The transformation is parallel.
|
||||||
|
|
||||||
peo :: init( __argc, __argv );
|
peo :: init( __argc, __argv );
|
||||||
const unsigned int VEC_SIZE = 2;
|
const unsigned int VEC_SIZE = 2;
|
||||||
const unsigned int POP_SIZE = 20;
|
const unsigned int POP_SIZE = 20;
|
||||||
const unsigned int MAX_GEN = 300;
|
const unsigned int MAX_GEN = 300;
|
||||||
const double INIT_POSITION_MIN = -2.0;
|
const double INIT_POSITION_MIN = -2.0;
|
||||||
const double INIT_POSITION_MAX = 2.0;
|
const double INIT_POSITION_MAX = 2.0;
|
||||||
const float CROSS_RATE = 0.8;
|
const float CROSS_RATE = 0.8;
|
||||||
const double EPSILON = 0.01;
|
const double EPSILON = 0.01;
|
||||||
const float MUT_RATE = 0.3;
|
const float MUT_RATE = 0.3;
|
||||||
const unsigned int MIG_FREQ = 10;
|
const unsigned int MIG_FREQ = 10;
|
||||||
const unsigned int MIG_SIZE = 5;
|
const unsigned int MIG_SIZE = 5;
|
||||||
rng.reseed (time(0));
|
rng.reseed (time(0));
|
||||||
RingTopology topology;
|
RingTopology topology;
|
||||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||||
peoEvalFunc<Indi> plainEval(f);
|
peoEvalFunc<Indi> plainEval(f);
|
||||||
peoParaPopEval< Indi > eval(plainEval);
|
peoParaPopEval< Indi > eval(plainEval);
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
eoRankingSelect<Indi> selectionStrategy;
|
eoRankingSelect<Indi> selectionStrategy;
|
||||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||||
eoSegmentCrossover<Indi> crossover;
|
eoSegmentCrossover<Indi> crossover;
|
||||||
eoUniformMutation<Indi> mutation(EPSILON);
|
eoUniformMutation<Indi> mutation(EPSILON);
|
||||||
peoParaSGATransform <Indi> eaTransform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
peoParaSGATransform <Indi> eaTransform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||||
eoPlusReplacement<Indi> replace;
|
eoPlusReplacement<Indi> replace;
|
||||||
eoPop < Indi > pop;
|
eoPop < Indi > pop;
|
||||||
pop.append (POP_SIZE, random);
|
pop.append (POP_SIZE, random);
|
||||||
eoPeriodicContinue <Indi> mig_cont( MIG_FREQ );
|
eoPeriodicContinue <Indi> mig_cont( MIG_FREQ );
|
||||||
eoRandomSelect<Indi> mig_select_one;
|
eoRandomSelect<Indi> mig_select_one;
|
||||||
eoSelectNumber<Indi> mig_select (mig_select_one,MIG_SIZE);
|
eoSelectNumber<Indi> mig_select (mig_select_one,MIG_SIZE);
|
||||||
eoPlusReplacement<Indi> mig_replace;
|
eoPlusReplacement<Indi> mig_replace;
|
||||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||||
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
||||||
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
||||||
peoEvalFunc<Indi> plainEval2(f);
|
peoEvalFunc<Indi> plainEval2(f);
|
||||||
peoParaPopEval< Indi > eval2(plainEval2);
|
peoParaPopEval< Indi > eval2(plainEval2);
|
||||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||||
eoRankingSelect<Indi> selectionStrategy2;
|
eoRankingSelect<Indi> selectionStrategy2;
|
||||||
eoSelectNumber<Indi> select2(selectionStrategy2,POP_SIZE);
|
eoSelectNumber<Indi> select2(selectionStrategy2,POP_SIZE);
|
||||||
eoSegmentCrossover<Indi> crossover2;
|
eoSegmentCrossover<Indi> crossover2;
|
||||||
eoUniformMutation<Indi> mutation2(EPSILON);
|
eoUniformMutation<Indi> mutation2(EPSILON);
|
||||||
peoParaSGATransform <Indi> eaTransform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
|
peoParaSGATransform <Indi> eaTransform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
|
||||||
eoPlusReplacement<Indi> replace2;
|
eoPlusReplacement<Indi> replace2;
|
||||||
eoPop < Indi > pop2;
|
eoPop < Indi > pop2;
|
||||||
pop2.append (POP_SIZE, random2);
|
pop2.append (POP_SIZE, random2);
|
||||||
eoPeriodicContinue <Indi> mig_cont2( MIG_FREQ );
|
eoPeriodicContinue <Indi> mig_cont2( MIG_FREQ );
|
||||||
eoRandomSelect<Indi> mig_select_one2;
|
eoRandomSelect<Indi> mig_select_one2;
|
||||||
eoSelectNumber<Indi> mig_select2 (mig_select_one2,MIG_SIZE);
|
eoSelectNumber<Indi> mig_select2 (mig_select_one2,MIG_SIZE);
|
||||||
eoPlusReplacement<Indi> mig_replace2;
|
eoPlusReplacement<Indi> mig_replace2;
|
||||||
eoGenContinue < Indi > genContPara3 (MAX_GEN);
|
eoGenContinue < Indi > genContPara3 (MAX_GEN);
|
||||||
eoCombinedContinue <Indi> continuatorPara3 (genContPara3);
|
eoCombinedContinue <Indi> continuatorPara3 (genContPara3);
|
||||||
eoCheckPoint<Indi> checkpoint3(continuatorPara3);
|
eoCheckPoint<Indi> checkpoint3(continuatorPara3);
|
||||||
peoEvalFunc<Indi> plainEval3(f);
|
peoEvalFunc<Indi> plainEval3(f);
|
||||||
peoParaPopEval< Indi > eval3(plainEval3);
|
peoParaPopEval< Indi > eval3(plainEval3);
|
||||||
eoUniformGenerator < double >uGen3 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen3 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random3 (VEC_SIZE, uGen3);
|
eoInitFixedLength < Indi > random3 (VEC_SIZE, uGen3);
|
||||||
eoRankingSelect<Indi> selectionStrategy3;
|
eoRankingSelect<Indi> selectionStrategy3;
|
||||||
eoSelectNumber<Indi> select3(selectionStrategy3,POP_SIZE);
|
eoSelectNumber<Indi> select3(selectionStrategy3,POP_SIZE);
|
||||||
eoSegmentCrossover<Indi> crossover3;
|
eoSegmentCrossover<Indi> crossover3;
|
||||||
eoUniformMutation<Indi> mutation3(EPSILON);
|
eoUniformMutation<Indi> mutation3(EPSILON);
|
||||||
peoParaSGATransform <Indi> eaTransform3(crossover3,CROSS_RATE,mutation3,MUT_RATE);
|
peoParaSGATransform <Indi> eaTransform3(crossover3,CROSS_RATE,mutation3,MUT_RATE);
|
||||||
eoPlusReplacement<Indi> replace3;
|
eoPlusReplacement<Indi> replace3;
|
||||||
eoPop < Indi > pop3;
|
eoPop < Indi > pop3;
|
||||||
pop3.append (POP_SIZE, random3);
|
pop3.append (POP_SIZE, random3);
|
||||||
eoPeriodicContinue <Indi> mig_cont3( MIG_FREQ );
|
eoPeriodicContinue <Indi> mig_cont3( MIG_FREQ );
|
||||||
eoRandomSelect<Indi> mig_select_one3;
|
eoRandomSelect<Indi> mig_select_one3;
|
||||||
eoSelectNumber<Indi> mig_select3 (mig_select_one3,MIG_SIZE);
|
eoSelectNumber<Indi> mig_select3 (mig_select_one3,MIG_SIZE);
|
||||||
eoPlusReplacement<Indi> mig_replace3;
|
eoPlusReplacement<Indi> mig_replace3;
|
||||||
peoAsyncIslandMig<Indi> mig(mig_cont,mig_select,mig_replace,topology,pop,pop2);
|
peoAsyncIslandMig<Indi> mig(mig_cont,mig_select,mig_replace,topology,pop,pop2);
|
||||||
checkpoint.add(mig);
|
checkpoint.add(mig);
|
||||||
peoAsyncIslandMig<Indi> mig2(mig_cont2,mig_select2,mig_replace2,topology,pop2,pop);
|
peoAsyncIslandMig<Indi> mig2(mig_cont2,mig_select2,mig_replace2,topology,pop2,pop);
|
||||||
checkpoint2.add(mig2);
|
checkpoint2.add(mig2);
|
||||||
peoAsyncIslandMig<Indi> mig3(mig_cont3,mig_select3,mig_replace3,topology,pop3,pop);
|
peoAsyncIslandMig<Indi> mig3(mig_cont3,mig_select3,mig_replace3,topology,pop3,pop);
|
||||||
checkpoint3.add(mig3);
|
checkpoint3.add(mig3);
|
||||||
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
peoEA<Indi> Algo(checkpoint,eval,select,eaTransform,replace);
|
||||||
mig.setOwner(Algo);
|
mig.setOwner(Algo);
|
||||||
Algo(pop);
|
Algo(pop);
|
||||||
peoEA<Indi> Algo2(checkpoint2,eval2,select2,eaTransform2,replace2);
|
peoEA<Indi> Algo2(checkpoint2,eval2,select2,eaTransform2,replace2);
|
||||||
mig2.setOwner(Algo2);
|
mig2.setOwner(Algo2);
|
||||||
Algo2(pop2);
|
Algo2(pop2);
|
||||||
peoEA<Indi> Algo3(checkpoint3,eval3,select3,eaTransform3,replace3);
|
peoEA<Indi> Algo3(checkpoint3,eval3,select3,eaTransform3,replace3);
|
||||||
mig3.setOwner(Algo3);
|
mig3.setOwner(Algo3);
|
||||||
Algo3(pop3);
|
Algo3(pop3);
|
||||||
|
|
||||||
peo :: run();
|
peo :: run();
|
||||||
peo :: finalize();
|
peo :: finalize();
|
||||||
if(getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
std::cout << "Final population 1 :\n" << pop << std::endl;
|
std::cout << "Final population 1 :\n" << pop << std::endl;
|
||||||
std::cout << "Final population 2 :\n" << pop2 << std::endl;
|
std::cout << "Final population 2 :\n" << pop2 << std::endl;
|
||||||
std::cout << "Final population 3 :\n" << pop3 << std::endl;
|
std::cout << "Final population 3 :\n" << pop3 << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <main.cpp>
|
* <main.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, INRIA, 2007
|
* (C) OPAC Team, INRIA, 2007
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
*
|
*
|
||||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <peo>
|
#include <peo>
|
||||||
|
|
@ -39,12 +39,12 @@
|
||||||
typedef eoRealParticle < double >Indi;
|
typedef eoRealParticle < double >Indi;
|
||||||
|
|
||||||
double f (const Indi & _indi)
|
double f (const Indi & _indi)
|
||||||
{
|
{
|
||||||
double sum;
|
double sum;
|
||||||
sum=_indi[1]-pow(_indi[0],2);
|
sum=_indi[1]-pow(_indi[0],2);
|
||||||
sum=100*pow(sum,2);
|
sum=100*pow(sum,2);
|
||||||
sum+=pow((1-_indi[0]),2);
|
sum+=pow((1-_indi[0]),2);
|
||||||
return (-sum);
|
return (-sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int __argc, char *__argv[])
|
int main (int __argc, char *__argv[])
|
||||||
|
|
@ -52,108 +52,108 @@ int main (int __argc, char *__argv[])
|
||||||
|
|
||||||
// In this lesson, we can see an example of a PSO with three islands.
|
// In this lesson, we can see an example of a PSO with three islands.
|
||||||
// The strategy of migration is the replacement.
|
// The strategy of migration is the replacement.
|
||||||
// The evaluation is parallel.
|
// The evaluation is parallel.
|
||||||
|
|
||||||
peo :: init( __argc, __argv );
|
peo :: init( __argc, __argv );
|
||||||
const unsigned int VEC_SIZE = 2;
|
const unsigned int VEC_SIZE = 2;
|
||||||
const unsigned int POP_SIZE = 20;
|
const unsigned int POP_SIZE = 20;
|
||||||
const unsigned int NEIGHBORHOOD_SIZE= 6;
|
const unsigned int NEIGHBORHOOD_SIZE= 6;
|
||||||
const unsigned int MAX_GEN = 150;
|
const unsigned int MAX_GEN = 150;
|
||||||
const double INIT_POSITION_MIN = -2.0;
|
const double INIT_POSITION_MIN = -2.0;
|
||||||
const double INIT_POSITION_MAX = 2.0;
|
const double INIT_POSITION_MAX = 2.0;
|
||||||
const double INIT_VELOCITY_MIN = -1.;
|
const double INIT_VELOCITY_MIN = -1.;
|
||||||
const double INIT_VELOCITY_MAX = 1.;
|
const double INIT_VELOCITY_MAX = 1.;
|
||||||
const double C1 = 0.5;
|
const double C1 = 0.5;
|
||||||
const double C2 = 2.;
|
const double C2 = 2.;
|
||||||
const double C3 = 2.;
|
const double C3 = 2.;
|
||||||
const unsigned int MIG_FREQ = 10;
|
const unsigned int MIG_FREQ = 10;
|
||||||
rng.reseed (time(0));
|
rng.reseed (time(0));
|
||||||
RingTopology topologyMig;
|
RingTopology topologyMig;
|
||||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
peoEvalFuncPSO<Indi, double, const Indi& > plainEval(f);
|
||||||
peoParaPopEval< Indi > eval(plainEval);
|
peoParaPopEval< Indi > eval(plainEval);
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||||
eoFirstIsBestInit < Indi > localInit;
|
eoFirstIsBestInit < Indi > localInit;
|
||||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
eoStandardFlight < Indi > flight(bndsFlight);
|
eoStandardFlight < Indi > flight(bndsFlight);
|
||||||
eoPop < Indi > pop;
|
eoPop < Indi > pop;
|
||||||
pop.append (POP_SIZE, random);
|
pop.append (POP_SIZE, random);
|
||||||
peoInitializer <Indi> init(eval,veloRandom,localInit,pop);
|
peoInitializer <Indi> init(eval,veloRandom,localInit,pop);
|
||||||
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||||
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds);
|
||||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||||
eoCheckPoint<Indi> checkpoint(genContPara);
|
eoCheckPoint<Indi> checkpoint(genContPara);
|
||||||
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
||||||
peoPSOSelect<Indi> mig_selec(topology);
|
peoPSOSelect<Indi> mig_selec(topology);
|
||||||
eoSelectNumber< Indi > mig_select(mig_selec);
|
eoSelectNumber< Indi > mig_select(mig_selec);
|
||||||
peoPSOReplacement<Indi> mig_replace;
|
peoPSOReplacement<Indi> mig_replace;
|
||||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval2(f);
|
peoEvalFuncPSO<Indi, double, const Indi& > plainEval2(f);
|
||||||
peoParaPopEval< Indi > eval2(plainEval2);
|
peoParaPopEval< Indi > eval2(plainEval2);
|
||||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||||
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
eoVelocityInitFixedLength < Indi > veloRandom2 (VEC_SIZE, sGen2);
|
eoVelocityInitFixedLength < Indi > veloRandom2 (VEC_SIZE, sGen2);
|
||||||
eoFirstIsBestInit < Indi > localInit2;
|
eoFirstIsBestInit < Indi > localInit2;
|
||||||
eoRealVectorBounds bndsFlight2(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
eoRealVectorBounds bndsFlight2(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
eoStandardFlight < Indi > flight2(bndsFlight2);
|
eoStandardFlight < Indi > flight2(bndsFlight2);
|
||||||
eoPop < Indi > pop2;
|
eoPop < Indi > pop2;
|
||||||
pop2.append (POP_SIZE, random2);
|
pop2.append (POP_SIZE, random2);
|
||||||
peoInitializer <Indi> init2(eval2,veloRandom2,localInit2,pop2);
|
peoInitializer <Indi> init2(eval2,veloRandom2,localInit2,pop2);
|
||||||
eoLinearTopology<Indi> topology2(NEIGHBORHOOD_SIZE);
|
eoLinearTopology<Indi> topology2(NEIGHBORHOOD_SIZE);
|
||||||
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
eoStandardVelocity < Indi > velocity2 (topology2,C1,C2,bnds2);
|
eoStandardVelocity < Indi > velocity2 (topology2,C1,C2,bnds2);
|
||||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||||
eoCheckPoint<Indi> checkpoint2(genContPara2);
|
eoCheckPoint<Indi> checkpoint2(genContPara2);
|
||||||
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
||||||
peoPSOSelect<Indi> mig_selec2(topology2);
|
peoPSOSelect<Indi> mig_selec2(topology2);
|
||||||
eoSelectNumber< Indi > mig_select2(mig_selec2);
|
eoSelectNumber< Indi > mig_select2(mig_selec2);
|
||||||
peoPSOReplacement<Indi> mig_replace2;
|
peoPSOReplacement<Indi> mig_replace2;
|
||||||
peoEvalFuncPSO<Indi, double, const Indi& > plainEval3(f);
|
peoEvalFuncPSO<Indi, double, const Indi& > plainEval3(f);
|
||||||
peoParaPopEval< Indi > eval3(plainEval3);
|
peoParaPopEval< Indi > eval3(plainEval3);
|
||||||
eoUniformGenerator < double >uGen3 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen3 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random3 (VEC_SIZE, uGen3);
|
eoInitFixedLength < Indi > random3 (VEC_SIZE, uGen3);
|
||||||
eoUniformGenerator < double >sGen3 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
eoUniformGenerator < double >sGen3 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
eoVelocityInitFixedLength < Indi > veloRandom3 (VEC_SIZE, sGen3);
|
eoVelocityInitFixedLength < Indi > veloRandom3 (VEC_SIZE, sGen3);
|
||||||
eoFirstIsBestInit < Indi > localInit3;
|
eoFirstIsBestInit < Indi > localInit3;
|
||||||
eoRealVectorBounds bndsFlight3(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
eoRealVectorBounds bndsFlight3(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
eoStandardFlight < Indi > flight3(bndsFlight3);
|
eoStandardFlight < Indi > flight3(bndsFlight3);
|
||||||
eoPop < Indi > pop3;
|
eoPop < Indi > pop3;
|
||||||
pop3.append (POP_SIZE, random3);
|
pop3.append (POP_SIZE, random3);
|
||||||
peoInitializer <Indi> init3(eval3,veloRandom3,localInit3,pop3);
|
peoInitializer <Indi> init3(eval3,veloRandom3,localInit3,pop3);
|
||||||
eoLinearTopology<Indi> topology3(NEIGHBORHOOD_SIZE);
|
eoLinearTopology<Indi> topology3(NEIGHBORHOOD_SIZE);
|
||||||
eoRealVectorBounds bnds3(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
eoRealVectorBounds bnds3(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
eoStandardVelocity < Indi > velocity3 (topology3,C1,C2,bnds3);
|
eoStandardVelocity < Indi > velocity3 (topology3,C1,C2,bnds3);
|
||||||
eoGenContinue < Indi > genContPara3 (MAX_GEN);
|
eoGenContinue < Indi > genContPara3 (MAX_GEN);
|
||||||
eoCheckPoint<Indi> checkpoint3(genContPara3);
|
eoCheckPoint<Indi> checkpoint3(genContPara3);
|
||||||
eoPeriodicContinue< Indi > mig_cont3( MIG_FREQ );
|
eoPeriodicContinue< Indi > mig_cont3( MIG_FREQ );
|
||||||
peoPSOSelect<Indi> mig_selec3(topology3);
|
peoPSOSelect<Indi> mig_selec3(topology3);
|
||||||
eoSelectNumber< Indi > mig_select3(mig_selec3);
|
eoSelectNumber< Indi > mig_select3(mig_selec3);
|
||||||
peoPSOReplacement<Indi> mig_replace3;
|
peoPSOReplacement<Indi> mig_replace3;
|
||||||
peoAsyncIslandMig< Indi > mig( mig_cont, mig_select, mig_replace, topologyMig, pop, pop2);
|
peoAsyncIslandMig< Indi > mig( mig_cont, mig_select, mig_replace, topologyMig, pop, pop2);
|
||||||
checkpoint.add( mig );
|
checkpoint.add( mig );
|
||||||
peoAsyncIslandMig< Indi > mig2( mig_cont2, mig_select2, mig_replace2, topologyMig, pop2, pop3);
|
peoAsyncIslandMig< Indi > mig2( mig_cont2, mig_select2, mig_replace2, topologyMig, pop2, pop3);
|
||||||
checkpoint2.add( mig2 );
|
checkpoint2.add( mig2 );
|
||||||
peoAsyncIslandMig< Indi > mig3( mig_cont3, mig_select3, mig_replace3, topologyMig, pop3, pop);
|
peoAsyncIslandMig< Indi > mig3( mig_cont3, mig_select3, mig_replace3, topologyMig, pop3, pop);
|
||||||
checkpoint3.add( mig3 );
|
checkpoint3.add( mig3 );
|
||||||
peoPSO < Indi > psa(init,checkpoint, eval, velocity, flight);
|
peoPSO < Indi > psa(init,checkpoint, eval, velocity, flight);
|
||||||
mig.setOwner( psa );
|
mig.setOwner( psa );
|
||||||
psa(pop);
|
psa(pop);
|
||||||
peoPSO < Indi > psa2(init2,checkpoint2, eval2, velocity2, flight2);
|
peoPSO < Indi > psa2(init2,checkpoint2, eval2, velocity2, flight2);
|
||||||
mig2.setOwner( psa2 );
|
mig2.setOwner( psa2 );
|
||||||
psa2(pop2);
|
psa2(pop2);
|
||||||
peoPSO < Indi > psa3(init3,checkpoint3, eval3, velocity3, flight3);
|
peoPSO < Indi > psa3(init3,checkpoint3, eval3, velocity3, flight3);
|
||||||
mig3.setOwner( psa3 );
|
mig3.setOwner( psa3 );
|
||||||
psa3(pop3);
|
psa3(pop3);
|
||||||
|
|
||||||
peo :: run();
|
peo :: run();
|
||||||
peo :: finalize();
|
peo :: finalize();
|
||||||
if(getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
std::cout << "Population 1 :\n" << pop << std::endl;
|
std::cout << "Population 1 :\n" << pop << std::endl;
|
||||||
std::cout << "Population 2 :\n" << pop2 << std::endl;
|
std::cout << "Population 2 :\n" << pop2 << std::endl;
|
||||||
std::cout << "Population 3 :\n" << pop3 << std::endl;
|
std::cout << "Population 3 :\n" << pop3 << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <example.cpp>
|
* <example.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -59,20 +59,21 @@
|
||||||
#define MUT_RATE 0.01
|
#define MUT_RATE 0.01
|
||||||
|
|
||||||
|
|
||||||
int main (int __argc, char * * __argv) {
|
int main (int __argc, char * * __argv)
|
||||||
|
{
|
||||||
// Example of a problem (TSP) with an hybridization
|
|
||||||
|
// Example of a problem (TSP) with an hybridization
|
||||||
|
|
||||||
peo :: init (__argc, __argv);
|
peo :: init (__argc, __argv);
|
||||||
|
|
||||||
|
|
||||||
loadParameters (__argc, __argv); /* Processing some parameters relative to the tackled
|
|
||||||
problem (TSP) */
|
|
||||||
|
|
||||||
RouteInit route_init; /* Its builds random routes */
|
loadParameters (__argc, __argv); /* Processing some parameters relative to the tackled
|
||||||
|
problem (TSP) */
|
||||||
|
|
||||||
|
RouteInit route_init; /* Its builds random routes */
|
||||||
RouteEval full_eval; /* Full route evaluator */
|
RouteEval full_eval; /* Full route evaluator */
|
||||||
|
|
||||||
|
|
||||||
OrderXover order_cross; /* Recombination */
|
OrderXover order_cross; /* Recombination */
|
||||||
PartialMappedXover pm_cross;
|
PartialMappedXover pm_cross;
|
||||||
EdgeXover edge_cross;
|
EdgeXover edge_cross;
|
||||||
|
|
@ -88,30 +89,30 @@ int main (int __argc, char * * __argv) {
|
||||||
|
|
||||||
/** The EA */
|
/** The EA */
|
||||||
eoPop <Route> ox_pop (POP_SIZE, route_init); /* Population */
|
eoPop <Route> ox_pop (POP_SIZE, route_init); /* Population */
|
||||||
|
|
||||||
eoGenContinue <Route> ox_cont (NUM_GEN); /* A fixed number of iterations */
|
eoGenContinue <Route> ox_cont (NUM_GEN); /* A fixed number of iterations */
|
||||||
eoCheckPoint <Route> ox_checkpoint (ox_cont); /* Checkpoint */
|
eoCheckPoint <Route> ox_checkpoint (ox_cont); /* Checkpoint */
|
||||||
peoSeqPopEval <Route> ox_pop_eval (full_eval);
|
peoSeqPopEval <Route> ox_pop_eval (full_eval);
|
||||||
eoStochTournamentSelect <Route> ox_select_one;
|
eoStochTournamentSelect <Route> ox_select_one;
|
||||||
eoSelectNumber <Route> ox_select (ox_select_one, POP_SIZE);
|
eoSelectNumber <Route> ox_select (ox_select_one, POP_SIZE);
|
||||||
eoSGATransform <Route> ox_transform (order_cross, CROSS_RATE, city_swap_mut, MUT_RATE);
|
eoSGATransform <Route> ox_transform (order_cross, CROSS_RATE, city_swap_mut, MUT_RATE);
|
||||||
peoSeqTransform <Route> ox_para_transform (ox_transform);
|
peoSeqTransform <Route> ox_para_transform (ox_transform);
|
||||||
eoEPReplacement <Route> ox_replace (2);
|
eoEPReplacement <Route> ox_replace (2);
|
||||||
|
|
||||||
peoEA <Route> ox_ea (ox_checkpoint, ox_pop_eval, ox_select, ox_para_transform, ox_replace);
|
peoEA <Route> ox_ea (ox_checkpoint, ox_pop_eval, ox_select, ox_para_transform, ox_replace);
|
||||||
|
|
||||||
ox_ea (ox_pop); /* Application to the given population */
|
ox_ea (ox_pop); /* Application to the given population */
|
||||||
|
|
||||||
|
|
||||||
peo :: run ();
|
peo :: run ();
|
||||||
peo :: finalize (); /* Termination */
|
peo :: finalize (); /* Termination */
|
||||||
|
|
||||||
if(getNodeRank()==1)
|
|
||||||
std :: cout << "\nResult : "<<ox_pop[ 0 ].fitness();
|
|
||||||
hc( ox_pop[ 0 ] );
|
|
||||||
if(getNodeRank()==1)
|
|
||||||
std :: cout << "\n\nAfter an hybridization : " << ox_pop[ 0 ].fitness() << std :: endl;
|
|
||||||
|
|
||||||
|
if (getNodeRank()==1)
|
||||||
|
std :: cout << "\nResult : "<<ox_pop[ 0 ].fitness();
|
||||||
|
hc( ox_pop[ 0 ] );
|
||||||
|
if (getNodeRank()==1)
|
||||||
|
std :: cout << "\n\nAfter an hybridization : " << ox_pop[ 0 ].fitness() << std :: endl;
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <main.cpp>
|
* <main.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, INRIA, 2007
|
* (C) OPAC Team, INRIA, 2007
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
*
|
*
|
||||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -50,56 +50,56 @@
|
||||||
|
|
||||||
int main( int __argc, char** __argv )
|
int main( int __argc, char** __argv )
|
||||||
{
|
{
|
||||||
|
|
||||||
/* In this lesson you will learn to use a multi-start.
|
/* In this lesson you will learn to use a multi-start.
|
||||||
*
|
*
|
||||||
* Thanks to this method, you can use several local searches together !!!
|
* Thanks to this method, you can use several local searches together !!!
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Parameter
|
// Parameter
|
||||||
const unsigned int POP_SIZE = 10;
|
const unsigned int POP_SIZE = 10;
|
||||||
srand( time(NULL) );
|
srand( time(NULL) );
|
||||||
|
|
||||||
// Initializing the ParadisEO-PEO environment
|
// Initializing the ParadisEO-PEO environment
|
||||||
peo :: init( __argc, __argv );
|
peo :: init( __argc, __argv );
|
||||||
// Processing the command line specified parameters
|
// Processing the command line specified parameters
|
||||||
loadParameters( __argc, __argv );
|
loadParameters( __argc, __argv );
|
||||||
|
|
||||||
// Define a Hill Climbing (you can choose an other local search)
|
// Define a Hill Climbing (you can choose an other local search)
|
||||||
// ie Lessons of ParadisEO - MO
|
// ie Lessons of ParadisEO - MO
|
||||||
Route route;
|
Route route;
|
||||||
RouteInit init;
|
RouteInit init;
|
||||||
init(route);
|
init(route);
|
||||||
RouteEval eval;
|
RouteEval eval;
|
||||||
eval(route);
|
eval(route);
|
||||||
TwoOptInit initHC;
|
TwoOptInit initHC;
|
||||||
TwoOptNext nextHC;
|
TwoOptNext nextHC;
|
||||||
TwoOptIncrEval incrHC;
|
TwoOptIncrEval incrHC;
|
||||||
moBestImprSelect< TwoOpt > selectHC;
|
moBestImprSelect< TwoOpt > selectHC;
|
||||||
moHC< TwoOpt > hc(initHC, nextHC, incrHC, selectHC, eval);
|
moHC< TwoOpt > hc(initHC, nextHC, incrHC, selectHC, eval);
|
||||||
|
|
||||||
// Define a population
|
// Define a population
|
||||||
RouteInit initPop; // Creates random Route objects
|
RouteInit initPop; // Creates random Route objects
|
||||||
RouteEval evalPop; // Offers a fitness value for a specified Route object
|
RouteEval evalPop; // Offers a fitness value for a specified Route object
|
||||||
eoPop < Route > pop(POP_SIZE, initPop);
|
eoPop < Route > pop(POP_SIZE, initPop);
|
||||||
for ( unsigned int index = 0; index < POP_SIZE; index++ )
|
for ( unsigned int index = 0; index < POP_SIZE; index++ )
|
||||||
evalPop( pop[ index ] );
|
evalPop( pop[ index ] );
|
||||||
|
|
||||||
// Setting up the parallel wrapper
|
// Setting up the parallel wrapper
|
||||||
peoSynchronousMultiStart< Route > parallelHC(hc);
|
peoSynchronousMultiStart< Route > parallelHC(hc);
|
||||||
peoParallelAlgorithmWrapper WrapHC (parallelHC, pop);
|
peoParallelAlgorithmWrapper WrapHC (parallelHC, pop);
|
||||||
parallelHC.setOwner( WrapHC );
|
parallelHC.setOwner( WrapHC );
|
||||||
|
|
||||||
peo :: run( );
|
peo :: run( );
|
||||||
peo :: finalize( );
|
peo :: finalize( );
|
||||||
if ( getNodeRank() == 1 )
|
if ( getNodeRank() == 1 )
|
||||||
{
|
{
|
||||||
|
|
||||||
std :: cout << "\n\nBefore : \n" << route;
|
std :: cout << "\n\nBefore : \n" << route;
|
||||||
std :: cout << "\n\nWith the synchronous Multi-Start HCs:";
|
std :: cout << "\n\nWith the synchronous Multi-Start HCs:";
|
||||||
for ( unsigned int index = 0; index < POP_SIZE; index++ )
|
for ( unsigned int index = 0; index < POP_SIZE; index++ )
|
||||||
std::cout <<"\n"<< pop[ index ];
|
std::cout <<"\n"<< pop[ index ];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <city_swap.cpp>
|
* <city_swap.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -38,12 +38,13 @@
|
||||||
|
|
||||||
#include "city_swap.h"
|
#include "city_swap.h"
|
||||||
|
|
||||||
bool CitySwap :: operator () (Route & __route) {
|
bool CitySwap :: operator () (Route & __route)
|
||||||
|
{
|
||||||
|
|
||||||
std :: swap (__route [rng.random (__route.size ())],
|
std :: swap (__route [rng.random (__route.size ())],
|
||||||
__route [rng.random (__route.size ())]) ;
|
__route [rng.random (__route.size ())]) ;
|
||||||
|
|
||||||
__route.invalidate () ;
|
__route.invalidate () ;
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <city_swap.h>
|
* <city_swap.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -43,12 +43,13 @@
|
||||||
|
|
||||||
/** Its swaps two vertices
|
/** Its swaps two vertices
|
||||||
randomly choosen */
|
randomly choosen */
|
||||||
class CitySwap : public eoMonOp <Route> {
|
class CitySwap : public eoMonOp <Route>
|
||||||
|
{
|
||||||
public :
|
|
||||||
|
public :
|
||||||
bool operator () (Route & __route) ;
|
|
||||||
|
bool operator () (Route & __route) ;
|
||||||
} ;
|
|
||||||
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <data.cpp>
|
* <data.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -48,78 +48,84 @@
|
||||||
#define MAX_FIELD_LENGTH 1000
|
#define MAX_FIELD_LENGTH 1000
|
||||||
#define MAX_LINE_LENGTH 1000
|
#define MAX_LINE_LENGTH 1000
|
||||||
|
|
||||||
static void getNextField (FILE * __f, char * __buff) {
|
static void getNextField (FILE * __f, char * __buff)
|
||||||
|
{
|
||||||
char trash [MAX_TRASH_LENGTH];
|
|
||||||
|
|
||||||
fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
|
char trash [MAX_TRASH_LENGTH];
|
||||||
|
|
||||||
|
fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
|
||||||
fscanf (__f, "%[^:\n]", __buff); /* Reading the field */
|
fscanf (__f, "%[^:\n]", __buff); /* Reading the field */
|
||||||
fgetc (__f);
|
fgetc (__f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getLine (FILE * __f, char * __buff) {
|
static void getLine (FILE * __f, char * __buff)
|
||||||
|
{
|
||||||
|
|
||||||
char trash [MAX_TRASH_LENGTH];
|
char trash [MAX_TRASH_LENGTH];
|
||||||
|
|
||||||
fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
|
fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
|
||||||
fscanf (__f, "%[^\n]", __buff); /* Reading the line */
|
fscanf (__f, "%[^\n]", __buff); /* Reading the line */
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadData (const char * __filename) {
|
void loadData (const char * __filename)
|
||||||
|
{
|
||||||
|
|
||||||
FILE * f = fopen (__filename, "r");
|
FILE * f = fopen (__filename, "r");
|
||||||
|
|
||||||
if (f) {
|
if (f)
|
||||||
|
{
|
||||||
|
|
||||||
printf ("Loading '%s'.\n", __filename);
|
printf ("Loading '%s'.\n", __filename);
|
||||||
|
|
||||||
char field [MAX_FIELD_LENGTH];
|
|
||||||
|
|
||||||
getNextField (f, field); /* Name */
|
|
||||||
assert (strstr (field, "NAME"));
|
|
||||||
getNextField (f, field);
|
|
||||||
printf ("NAME: %s.\n", field);
|
|
||||||
|
|
||||||
getNextField (f, field); /* Comment */
|
|
||||||
assert (strstr (field, "COMMENT"));
|
|
||||||
getLine (f, field);
|
|
||||||
printf ("COMMENT: %s.\n", field);
|
|
||||||
|
|
||||||
getNextField (f, field); /* Type */
|
|
||||||
assert (strstr (field, "TYPE"));
|
|
||||||
getNextField (f, field);
|
|
||||||
printf ("TYPE: %s.\n", field);
|
|
||||||
|
|
||||||
getNextField (f, field); /* Dimension */
|
char field [MAX_FIELD_LENGTH];
|
||||||
assert (strstr (field, "DIMENSION"));
|
|
||||||
getNextField (f, field);
|
|
||||||
printf ("DIMENSION: %s.\n", field);
|
|
||||||
numNodes = atoi (field);
|
|
||||||
|
|
||||||
getNextField (f, field); /* Edge weight type */
|
getNextField (f, field); /* Name */
|
||||||
assert (strstr (field, "EDGE_WEIGHT_TYPE"));
|
assert (strstr (field, "NAME"));
|
||||||
getNextField (f, field);
|
getNextField (f, field);
|
||||||
printf ("EDGE_WEIGHT_TYPE: %s.\n", field);
|
printf ("NAME: %s.\n", field);
|
||||||
|
|
||||||
getNextField (f, field); /* Node coord section */
|
getNextField (f, field); /* Comment */
|
||||||
assert (strstr (field, "NODE_COORD_SECTION"));
|
assert (strstr (field, "COMMENT"));
|
||||||
loadNodes (f);
|
getLine (f, field);
|
||||||
|
printf ("COMMENT: %s.\n", field);
|
||||||
getNextField (f, field); /* End of file */
|
|
||||||
assert (strstr (field, "EOF"));
|
getNextField (f, field); /* Type */
|
||||||
printf ("EOF.\n");
|
assert (strstr (field, "TYPE"));
|
||||||
}
|
getNextField (f, field);
|
||||||
else {
|
printf ("TYPE: %s.\n", field);
|
||||||
|
|
||||||
fprintf (stderr, "Can't open '%s'.\n", __filename);
|
getNextField (f, field); /* Dimension */
|
||||||
exit (1);
|
assert (strstr (field, "DIMENSION"));
|
||||||
}
|
getNextField (f, field);
|
||||||
|
printf ("DIMENSION: %s.\n", field);
|
||||||
|
numNodes = atoi (field);
|
||||||
|
|
||||||
|
getNextField (f, field); /* Edge weight type */
|
||||||
|
assert (strstr (field, "EDGE_WEIGHT_TYPE"));
|
||||||
|
getNextField (f, field);
|
||||||
|
printf ("EDGE_WEIGHT_TYPE: %s.\n", field);
|
||||||
|
|
||||||
|
getNextField (f, field); /* Node coord section */
|
||||||
|
assert (strstr (field, "NODE_COORD_SECTION"));
|
||||||
|
loadNodes (f);
|
||||||
|
|
||||||
|
getNextField (f, field); /* End of file */
|
||||||
|
assert (strstr (field, "EOF"));
|
||||||
|
printf ("EOF.\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
fprintf (stderr, "Can't open '%s'.\n", __filename);
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadData (eoParser & __parser) {
|
void loadData (eoParser & __parser)
|
||||||
|
{
|
||||||
|
|
||||||
/* Getting the path of the instance */
|
/* Getting the path of the instance */
|
||||||
|
|
||||||
eoValueParam <std :: string> param ("", "inst", "Path of the instance") ;
|
eoValueParam <std :: string> param ("", "inst", "Path of the instance") ;
|
||||||
__parser.processParam (param) ;
|
__parser.processParam (param) ;
|
||||||
loadData (param.value ().c_str ());
|
loadData (param.value ().c_str ());
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <data.h>
|
* <data.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <display.cpp>
|
* <display.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -56,7 +56,7 @@ static unsigned * X_new_coord, * Y_new_coord ;
|
||||||
|
|
||||||
/* this variable will contain the handle to the returned graphics context. */
|
/* this variable will contain the handle to the returned graphics context. */
|
||||||
static GC gc;
|
static GC gc;
|
||||||
|
|
||||||
/* this variable will contain the pointer to the Display structure */
|
/* this variable will contain the pointer to the Display structure */
|
||||||
static Display* disp;
|
static Display* disp;
|
||||||
|
|
||||||
|
|
@ -67,23 +67,24 @@ static int screen;
|
||||||
|
|
||||||
/* Create a new backing pixmap of the appropriate size */
|
/* Create a new backing pixmap of the appropriate size */
|
||||||
|
|
||||||
/* Best tour */
|
/* Best tour */
|
||||||
/*
|
/*
|
||||||
gdk_gc_set_line_attributes (gc, 2, GDK_LINE_ON_OFF_DASH, GDK_CAP_NOT_LAST, GDK_JOIN_MITER) ;
|
gdk_gc_set_line_attributes (gc, 2, GDK_LINE_ON_OFF_DASH, GDK_CAP_NOT_LAST, GDK_JOIN_MITER) ;
|
||||||
|
|
||||||
gdk_gc_set_foreground (gc, & color_green) ;
|
gdk_gc_set_foreground (gc, & color_green) ;
|
||||||
|
|
||||||
for (int i = 0 ; i < (int) numNodes ; i ++) {
|
for (int i = 0 ; i < (int) numNodes ; i ++) {
|
||||||
|
|
||||||
gdk_draw_line (pixmap, gc,
|
gdk_draw_line (pixmap, gc,
|
||||||
X_new_coord [opt_route [i]],
|
X_new_coord [opt_route [i]],
|
||||||
Y_new_coord [opt_route [i]],
|
Y_new_coord [opt_route [i]],
|
||||||
X_new_coord [opt_route [(i + 1) % numNodes]],
|
X_new_coord [opt_route [(i + 1) % numNodes]],
|
||||||
Y_new_coord [opt_route [(i + 1) % numNodes]]);
|
Y_new_coord [opt_route [(i + 1) % numNodes]]);
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
void openMainWindow (const char * __filename) {
|
void openMainWindow (const char * __filename)
|
||||||
|
{
|
||||||
|
|
||||||
filename = __filename;
|
filename = __filename;
|
||||||
|
|
||||||
|
|
@ -91,7 +92,7 @@ void openMainWindow (const char * __filename) {
|
||||||
int map_width = (int) (X_max - X_min);
|
int map_width = (int) (X_max - X_min);
|
||||||
int map_height = (int) (Y_max - Y_min);
|
int map_height = (int) (Y_max - Y_min);
|
||||||
int map_side = std :: max (map_width, map_height);
|
int map_side = std :: max (map_width, map_height);
|
||||||
|
|
||||||
/* Calculate the window's width and height. */
|
/* Calculate the window's width and height. */
|
||||||
int win_width = (int) (screen_width * RATIO * map_width / map_side);
|
int win_width = (int) (screen_width * RATIO * map_width / map_side);
|
||||||
int win_height = (int) (screen_height * RATIO * map_height / map_side);
|
int win_height = (int) (screen_height * RATIO * map_height / map_side);
|
||||||
|
|
@ -100,46 +101,49 @@ void openMainWindow (const char * __filename) {
|
||||||
X_new_coord = new unsigned [numNodes];
|
X_new_coord = new unsigned [numNodes];
|
||||||
Y_new_coord = new unsigned [numNodes];
|
Y_new_coord = new unsigned [numNodes];
|
||||||
|
|
||||||
for (unsigned i = 0; i < numNodes; i ++) {
|
for (unsigned i = 0; i < numNodes; i ++)
|
||||||
X_new_coord [i] = (unsigned) (win_width * (1.0 - (X_coord [i] - X_min) / map_width) + BORDER);
|
{
|
||||||
Y_new_coord [i] = (unsigned) (win_height * (1.0 - (Y_coord [i] - Y_min) / map_height) + BORDER);
|
X_new_coord [i] = (unsigned) (win_width * (1.0 - (X_coord [i] - X_min) / map_width) + BORDER);
|
||||||
}
|
Y_new_coord [i] = (unsigned) (win_height * (1.0 - (Y_coord [i] - Y_min) / map_height) + BORDER);
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialisation */
|
/* Initialisation */
|
||||||
XGCValues val ;
|
XGCValues val ;
|
||||||
|
|
||||||
disp = XOpenDisplay (NULL) ;
|
disp = XOpenDisplay (NULL) ;
|
||||||
screen = DefaultScreen (disp) ;
|
screen = DefaultScreen (disp) ;
|
||||||
win = XCreateSimpleWindow (disp, RootWindow (disp, screen), 0, 0, win_width + 2 * BORDER, win_height + 2 * BORDER, 2, BlackPixel (disp, screen), WhitePixel (disp, screen)) ;
|
win = XCreateSimpleWindow (disp, RootWindow (disp, screen), 0, 0, win_width + 2 * BORDER, win_height + 2 * BORDER, 2, BlackPixel (disp, screen), WhitePixel (disp, screen)) ;
|
||||||
val.foreground = BlackPixel(disp, screen) ;
|
val.foreground = BlackPixel(disp, screen) ;
|
||||||
val.background = WhitePixel(disp, screen) ;
|
val.background = WhitePixel(disp, screen) ;
|
||||||
gc = XCreateGC (disp, win, GCForeground | GCBackground, & val) ;
|
gc = XCreateGC (disp, win, GCForeground | GCBackground, & val) ;
|
||||||
|
|
||||||
XMapWindow (disp, win) ;
|
XMapWindow (disp, win) ;
|
||||||
XFlush (disp) ;
|
XFlush (disp) ;
|
||||||
|
|
||||||
while (true) {
|
while (true)
|
||||||
XClearWindow (disp, win) ;
|
{
|
||||||
|
XClearWindow (disp, win) ;
|
||||||
|
|
||||||
/* Vertices as circles */
|
/* Vertices as circles */
|
||||||
for (unsigned i = 1 ; i < numNodes ; i ++)
|
for (unsigned i = 1 ; i < numNodes ; i ++)
|
||||||
XDrawArc (disp, win, gc, X_new_coord [i] - 1, Y_new_coord [i] - 1, 3, 3, 0, 364 * 64) ;
|
XDrawArc (disp, win, gc, X_new_coord [i] - 1, Y_new_coord [i] - 1, 3, 3, 0, 364 * 64) ;
|
||||||
|
|
||||||
/* New tour */
|
/* New tour */
|
||||||
std :: ifstream f (filename);
|
std :: ifstream f (filename);
|
||||||
if (f) {
|
if (f)
|
||||||
Route route;
|
{
|
||||||
f >> route;
|
Route route;
|
||||||
f.close ();
|
f >> route;
|
||||||
|
f.close ();
|
||||||
for (int i = 0; i < (int) numNodes; i ++)
|
|
||||||
XDrawLine (disp, win, gc,
|
for (int i = 0; i < (int) numNodes; i ++)
|
||||||
X_new_coord [route [i]],
|
XDrawLine (disp, win, gc,
|
||||||
Y_new_coord [route [i]],
|
X_new_coord [route [i]],
|
||||||
X_new_coord [route [(i + 1) % numNodes]],
|
Y_new_coord [route [i]],
|
||||||
Y_new_coord [route [(i + 1) % numNodes]]);
|
X_new_coord [route [(i + 1) % numNodes]],
|
||||||
|
Y_new_coord [route [(i + 1) % numNodes]]);
|
||||||
|
}
|
||||||
|
XFlush (disp) ;
|
||||||
|
sleep (1) ;
|
||||||
}
|
}
|
||||||
XFlush (disp) ;
|
|
||||||
sleep (1) ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <display.h>
|
* <display.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <display_best_route.cpp>
|
* <display_best_route.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -38,13 +38,14 @@
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
DisplayBestRoute :: DisplayBestRoute (eoPop <Route> & __pop
|
DisplayBestRoute :: DisplayBestRoute (eoPop <Route> & __pop
|
||||||
) : pop (__pop) {
|
) : pop (__pop)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayBestRoute :: operator () () {
|
void DisplayBestRoute :: operator () ()
|
||||||
|
{
|
||||||
|
|
||||||
displayRoute (pop.best_element ());
|
displayRoute (pop.best_element ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <display_best_route.h>
|
* <display_best_route.h>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -43,18 +43,19 @@
|
||||||
|
|
||||||
#include "route.h"
|
#include "route.h"
|
||||||
|
|
||||||
class DisplayBestRoute : public eoUpdater {
|
class DisplayBestRoute : public eoUpdater
|
||||||
|
{
|
||||||
public :
|
|
||||||
|
|
||||||
DisplayBestRoute (eoPop <Route> & __pop);
|
public :
|
||||||
|
|
||||||
void operator () ();
|
|
||||||
|
|
||||||
private :
|
DisplayBestRoute (eoPop <Route> & __pop);
|
||||||
|
|
||||||
eoPop <Route> & pop;
|
|
||||||
|
|
||||||
};
|
void operator () ();
|
||||||
|
|
||||||
|
private :
|
||||||
|
|
||||||
|
eoPop <Route> & pop;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* <edge_xover.cpp>
|
* <edge_xover.cpp>
|
||||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
* (C) OPAC Team, LIFL, 2002-2007
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
|
@ -41,104 +41,114 @@
|
||||||
|
|
||||||
#include "edge_xover.h"
|
#include "edge_xover.h"
|
||||||
|
|
||||||
void EdgeXover :: build_map (const Route & __par1, const Route & __par2) {
|
void EdgeXover :: build_map (const Route & __par1, const Route & __par2)
|
||||||
|
{
|
||||||
|
|
||||||
unsigned len = __par1.size () ;
|
unsigned len = __par1.size () ;
|
||||||
|
|
||||||
/* Initialization */
|
/* Initialization */
|
||||||
_map.clear () ;
|
_map.clear () ;
|
||||||
_map.resize (len) ;
|
_map.resize (len) ;
|
||||||
|
|
||||||
for (unsigned i = 0 ; i < len ; i ++) {
|
for (unsigned i = 0 ; i < len ; i ++)
|
||||||
_map [__par1 [i]].insert (__par1 [(i + 1) % len]) ;
|
{
|
||||||
_map [__par2 [i]].insert (__par2 [(i + 1) % len]) ;
|
_map [__par1 [i]].insert (__par1 [(i + 1) % len]) ;
|
||||||
_map [__par1 [i]].insert (__par1 [(i - 1 + len) % len]) ;
|
_map [__par2 [i]].insert (__par2 [(i + 1) % len]) ;
|
||||||
_map [__par2 [i]].insert (__par2 [(i - 1 + len) % len]) ;
|
_map [__par1 [i]].insert (__par1 [(i - 1 + len) % len]) ;
|
||||||
}
|
_map [__par2 [i]].insert (__par2 [(i - 1 + len) % len]) ;
|
||||||
|
}
|
||||||
|
|
||||||
visited.clear () ;
|
visited.clear () ;
|
||||||
visited.resize (len, false) ;
|
visited.resize (len, false) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EdgeXover :: remove_entry (unsigned __vertex, std :: vector <std :: set <unsigned> > & __map) {
|
void EdgeXover :: remove_entry (unsigned __vertex, std :: vector <std :: set <unsigned> > & __map)
|
||||||
|
{
|
||||||
std :: set <unsigned> & neigh = __map [__vertex] ;
|
|
||||||
|
|
||||||
for (std :: set <unsigned> :: iterator it = neigh.begin () ;
|
std :: set <unsigned> & neigh = __map [__vertex] ;
|
||||||
it != neigh.end () ;
|
|
||||||
it ++)
|
for (std :: set <unsigned> :: iterator it = neigh.begin () ;
|
||||||
__map [* it].erase (__vertex) ;
|
it != neigh.end () ;
|
||||||
|
it ++)
|
||||||
}
|
__map [* it].erase (__vertex) ;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void EdgeXover :: add_vertex (unsigned __vertex, Route & __child)
|
||||||
|
{
|
||||||
|
|
||||||
void EdgeXover :: add_vertex (unsigned __vertex, Route & __child) {
|
|
||||||
|
|
||||||
visited [__vertex] = true ;
|
visited [__vertex] = true ;
|
||||||
__child.push_back (__vertex) ;
|
__child.push_back (__vertex) ;
|
||||||
remove_entry (__vertex, _map) ; /* Removing entries */
|
remove_entry (__vertex, _map) ; /* Removing entries */
|
||||||
}
|
}
|
||||||
|
|
||||||
void EdgeXover :: cross (const Route & __par1, const Route & __par2, Route & __child) {
|
void EdgeXover :: cross (const Route & __par1, const Route & __par2, Route & __child)
|
||||||
|
{
|
||||||
|
|
||||||
build_map (__par1, __par2) ;
|
build_map (__par1, __par2) ;
|
||||||
|
|
||||||
unsigned len = __par1.size () ;
|
unsigned len = __par1.size () ;
|
||||||
|
|
||||||
/* Go ! */
|
/* Go ! */
|
||||||
__child.clear () ;
|
__child.clear () ;
|
||||||
|
|
||||||
unsigned cur_vertex = rng.random (len) ;
|
unsigned cur_vertex = rng.random (len) ;
|
||||||
|
|
||||||
add_vertex (cur_vertex, __child) ;
|
add_vertex (cur_vertex, __child) ;
|
||||||
|
|
||||||
for (unsigned i = 1 ; i < len ; i ++) {
|
for (unsigned i = 1 ; i < len ; i ++)
|
||||||
|
{
|
||||||
unsigned len_min_entry = MAXINT ;
|
|
||||||
|
|
||||||
std :: set <unsigned> & neigh = _map [cur_vertex] ;
|
|
||||||
|
|
||||||
for (std :: set <unsigned> :: iterator it = neigh.begin () ;
|
|
||||||
it != neigh.end () ;
|
|
||||||
it ++) {
|
|
||||||
unsigned l = _map [* it].size () ;
|
|
||||||
if (len_min_entry > l)
|
|
||||||
len_min_entry = l ;
|
|
||||||
}
|
|
||||||
|
|
||||||
std :: vector <unsigned> cand ; /* Candidates */
|
|
||||||
|
|
||||||
for (std :: set <unsigned> :: iterator it = neigh.begin () ;
|
|
||||||
it != neigh.end () ;
|
|
||||||
it ++) {
|
|
||||||
unsigned l = _map [* it].size () ;
|
|
||||||
if (len_min_entry == l)
|
|
||||||
cand.push_back (* it) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! cand.size ()) {
|
|
||||||
|
|
||||||
/* Oh no ! Implicit mutation */
|
|
||||||
for (unsigned j = 0 ; j < len ; j ++)
|
|
||||||
if (! visited [j])
|
|
||||||
cand.push_back (j) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_vertex = cand [rng.random (cand.size ())] ;
|
unsigned len_min_entry = MAXINT ;
|
||||||
|
|
||||||
add_vertex (cur_vertex, __child) ;
|
std :: set <unsigned> & neigh = _map [cur_vertex] ;
|
||||||
}
|
|
||||||
|
for (std :: set <unsigned> :: iterator it = neigh.begin () ;
|
||||||
|
it != neigh.end () ;
|
||||||
|
it ++)
|
||||||
|
{
|
||||||
|
unsigned l = _map [* it].size () ;
|
||||||
|
if (len_min_entry > l)
|
||||||
|
len_min_entry = l ;
|
||||||
|
}
|
||||||
|
|
||||||
|
std :: vector <unsigned> cand ; /* Candidates */
|
||||||
|
|
||||||
|
for (std :: set <unsigned> :: iterator it = neigh.begin () ;
|
||||||
|
it != neigh.end () ;
|
||||||
|
it ++)
|
||||||
|
{
|
||||||
|
unsigned l = _map [* it].size () ;
|
||||||
|
if (len_min_entry == l)
|
||||||
|
cand.push_back (* it) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! cand.size ())
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Oh no ! Implicit mutation */
|
||||||
|
for (unsigned j = 0 ; j < len ; j ++)
|
||||||
|
if (! visited [j])
|
||||||
|
cand.push_back (j) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
cur_vertex = cand [rng.random (cand.size ())] ;
|
||||||
|
|
||||||
|
add_vertex (cur_vertex, __child) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EdgeXover :: operator () (Route & __route1, Route & __route2) {
|
bool EdgeXover :: operator () (Route & __route1, Route & __route2)
|
||||||
|
{
|
||||||
|
|
||||||
// Init. copy
|
// Init. copy
|
||||||
Route par [2] ;
|
Route par [2] ;
|
||||||
par [0] = __route1 ;
|
par [0] = __route1 ;
|
||||||
par [1] = __route2 ;
|
par [1] = __route2 ;
|
||||||
|
|
||||||
cross (par [0], par [1], __route1) ;
|
cross (par [0], par [1], __route1) ;
|
||||||
cross (par [1], par [0], __route2) ;
|
cross (par [1], par [0], __route2) ;
|
||||||
|
|
||||||
__route1.invalidate () ;
|
__route1.invalidate () ;
|
||||||
__route2.invalidate () ;
|
__route2.invalidate () ;
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue