1 // Copyright (C) 2006-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "OptimizerAlg.hxx"
22 using namespace YACS::ENGINE;
26 OptimizerAlgBase * createOptimizerAlgASyncExample(Pool * pool);
29 class OptimizerAlgASyncExample : public OptimizerAlgASync
35 OptimizerAlgASyncExample(Pool * pool);
36 virtual ~OptimizerAlgASyncExample();
37 TypeCode * getTCForIn() const;
38 TypeCode * getTCForOut() const;
39 void startToTakeDecision();
42 OptimizerAlgASyncExample::OptimizerAlgASyncExample(Pool * pool) : OptimizerAlgASync(pool),
45 _tcIn = new TypeCode(Double);
46 _tcOut = new TypeCode(Int);
49 OptimizerAlgASyncExample::~OptimizerAlgASyncExample()
55 //! Return the typecode of the expected input type
56 TypeCode *OptimizerAlgASyncExample::getTCForIn() const
61 //! Return the typecode of the expected output type
62 TypeCode *OptimizerAlgASyncExample::getTCForOut() const
67 //! This method is called only once to launch the algorithm.
69 * It must first fill the pool with samples to evaluate and call signalMasterAndWait()
70 * to block until a sample has been evaluated. When returning from this method, it MUST
71 * check for an eventual termination request (with the method isTerminationRequested()).
72 * If the termination is requested, the method must perform any necessary cleanup and
73 * return as soon as possible. Otherwise it can either add new samples to evaluate in
74 * the pool, do nothing (wait for more samples), or empty the pool and return to finish
77 void OptimizerAlgASyncExample::startToTakeDecision()
80 for (int i=0 ; i<5 ; i++) {
81 // push a sample in the input of the slave node
82 _pool->pushInSample(i, AtomAny::New(val));
83 // wait until next sample is ready
84 signalMasterAndWait();
85 // check error notification
86 if (isTerminationRequested()) {
91 // get a sample from the output of the slave node
92 Any * v = _pool->getCurrentOutSample();
93 val += v->getIntValue();
96 // in the end destroy the pool content
100 //! Factory method to create the algorithm.
101 OptimizerAlgBase * createOptimizerAlgASyncExample(Pool * pool)
103 return new OptimizerAlgASyncExample(pool);