diff --git a/eo/src/paradisEO/island/eoMigUpdater.h b/eo/src/paradisEO/island/eoMigUpdater.h new file mode 100644 index 00000000..d15cdb92 --- /dev/null +++ b/eo/src/paradisEO/island/eoMigUpdater.h @@ -0,0 +1,141 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +// "eoMigUpdater.h" + +// (c) OPAC Team, LIFL, 2002 + +/* This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Cont act: cahon@lifl.fr +*/ + +#ifndef eoMigUpdater_h +#define eoMigUpdater_h + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + An updater. After any evolution of an evolutionnary algorithm, it + moves some EO from/into the current population from/to a subset + of the neighbouring algos. +*/ + +template class eoMigUpdater : public eoUpdater { + +public : + + /** + Constructor. Some features which should be specified. + - The neighbouring interface, + - The communication topology, + - Which EO instancies from the given population should be sent ? + - How integrate new immigrants ? + - Then, an event to determine the time to ask neighbouring sources + for sending sets of EO. + */ + + eoMigUpdater (eoListener & _listen, + eoConnectivity & _conn, + eoContinue & _cont, + eoSelect & _select, + eoReplacement & _replace) : + listen (_listen), + conn (_conn), + cont (_cont), + select (_select), + replace (_replace) { + + } + + /** + Sets the given population to be the one to receive and/or send EO + */ + + void operator () (eoPop & _pop) { + + pop = & _pop ; + } + + /** + Should be often called. (after each local evolution ?) + */ + + virtual void operator () () { + + listen.update () ; + // listen.display () ; + + vector *> src = conn.from (), dest = conn.to () ; + + // Any coming immigrants ? + for (int i = 0 ; i < src.size () ; i ++) { + src [i] -> update () ; + while (! src [i] -> empty ()) { + replace (* pop, src [i] -> front ()) ; + cout << "[" << listen.here ().host_name << "] Arrival of " << src [i] -> front ().size () << " individuals ..." << endl ; + src [i] -> pop () ; + } + } + + // Any request ? + for (int i = 0 ; i < dest.size () ; i ++) + if (dest [i] -> need_immigration ()) { + eoPop emm ; // Emmigrants + select (* pop, emm) ; + eoEOSendMessTo mess (emm) ; + mess (* (dest [i])) ; + } + + // Any request to submit ? + if (! cont (* pop)) + for (int i = 0 ; i < src.size () ; i ++) { + eoEOReceiveMessTo mess ; + mess (* (src [i])) ; + } + } + +private : + + eoConnectivity & conn ; // The used topology + + eoContinue & cont ; /* The 'event' which determines + need of immigration */ + + eoSelect & select ; /* In order to select emmigrants + from the current population */ + + eoReplacement & replace ; // The replacement procedure + + eoPop * pop ; // The population considered + + eoListener & listen ; // A reference to the neighbouring + +} ; + +#endif + + + + + +