1 // Copyright (C) 2006-2012 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
23 #include "OptimizerAlg.hxx"
25 using namespace YACS::ENGINE;
29 OptimizerAlgBase * createOptimizerAlgSyncExample(Pool * pool);
32 class OptimizerAlgSyncExample : public OptimizerAlgSync
39 OptimizerAlgSyncExample(Pool *pool);
40 virtual ~OptimizerAlgSyncExample();
41 TypeCode *getTCForIn() const;
42 TypeCode *getTCForOut() const;
45 void initialize(const Any *input) throw(YACS::Exception);
49 OptimizerAlgSyncExample::OptimizerAlgSyncExample(Pool *pool) : OptimizerAlgSync(pool),
53 _tcIn=new TypeCode(Double);
54 _tcOut=new TypeCode(Int);
57 OptimizerAlgSyncExample::~OptimizerAlgSyncExample()
59 std::cout << "Destroying OptimizerAlgSyncExample" << std::endl;
62 std::cout << "Destroyed OptimizerAlgSyncExample" << std::endl;
65 //! Return the typecode of the expected input type
66 TypeCode * OptimizerAlgSyncExample::getTCForIn() const
71 //! Return the typecode of the expected output type
72 TypeCode * OptimizerAlgSyncExample::getTCForOut() const
77 //! Start to fill the pool with samples to evaluate
78 void OptimizerAlgSyncExample::start()
81 Any *val=AtomAny::New(1.2);
82 _pool->pushInSample(4,val);
83 val=AtomAny::New(3.4);
84 _pool->pushInSample(9,val);
87 //! This method is called each time a sample has been evaluated.
89 * It can either add new samples to evaluate in the pool, do nothing (wait for more
90 * samples), or empty the pool to finish the evaluation.
92 void OptimizerAlgSyncExample::takeDecision()
96 Any *val=AtomAny::New(5.6);
97 _pool->pushInSample(16,val);
98 val=AtomAny::New(7.8);
99 _pool->pushInSample(25,val);
100 val=AtomAny::New(9. );
101 _pool->pushInSample(36,val);
102 val=AtomAny::New(12.3);
103 _pool->pushInSample(49,val);
107 Any *val=AtomAny::New(45.6);
108 _pool->pushInSample(64,val);
109 val=AtomAny::New(78.9);
110 _pool->pushInSample(81,val);
114 Any *tmp= _pool->getCurrentInSample();
115 if(fabs(tmp->getDoubleValue()-45.6)<1.e-12)
121 //! Optional method to initialize the algorithm.
123 * For now, the parameter input is always NULL. It might be used in the future to
124 * initialize an algorithm with custom data.
126 void OptimizerAlgSyncExample::initialize(const Any *input) throw (YACS::Exception)
131 * Optional method called when the algorithm has finished, successfully or not, to
132 * perform any necessary clean up.
134 void OptimizerAlgSyncExample::finish()
138 //! Factory method to create the algorithm.
139 OptimizerAlgBase * createOptimizerAlgSyncExample(Pool *pool)
141 return new OptimizerAlgSyncExample(pool);