From b6dcf911b72a3f0e1b5c0c5e724f8eba23fda3c4 Mon Sep 17 00:00:00 2001 From: cahon Date: Fri, 29 Mar 2002 14:38:36 +0000 Subject: [PATCH] A tool to apply a process to any incoming EO ... --- eo/src/paradisEO/eoSolAgent.h | 91 +++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 eo/src/paradisEO/eoSolAgent.h diff --git a/eo/src/paradisEO/eoSolAgent.h b/eo/src/paradisEO/eoSolAgent.h new file mode 100644 index 00000000..722e8bef --- /dev/null +++ b/eo/src/paradisEO/eoSolAgent.h @@ -0,0 +1,91 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +// "eoSolAgent.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 + + Contact: cahon@lifl.fr +*/ + +#ifndef eoSolAgent_h +#define eoSolAgent_h + +#include +#include +#include + +#include + +/** + A solAgent is waiting for any solutions that are queued. + For each one, a processing is performed. +*/ + +template class eoSolAgent { + +public : + + /** + Constructor + */ + + eoSolAgent (string _label, + eoListener & _listen, + eoSolAlgo & _algo + ) : + label (_label), + listen (_listen), + algo (_algo) { + + } + + // Waiting for eoPop reception and then ... + + void operator () () { + + listen.publish (label) ; // To be known by everyone ... + + while (true) { + + listen.wait () ; // While no neighbour sends any eoPop ... + + for (int i = 0 ; i < listen.size () ; i ++) { + + while (! listen [i].empty ()) { + + EOT & sol = listen [i].front () ; + cout << "Agent [" << label << "] on " << listen.here ().host_name << " : Receiving one individual ..." << endl ; + algo (sol) ; + eoPop pop ; + pop.push_back (sol) ; + eoEOSendMessTo mess (pop) ; + mess (listen [i]) ; // Coming back ... + listen [i].pop () ; + } + } + } + } + +private : + + string label ; // string identifier + eoListener & listen ; // EO's listener + eoSolAlgo & algo ; // Local supplied algo + +} ; + +#endif