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 #ifndef __OPTIMIZERALG_HXX__
21 #define __OPTIMIZERALG_HXX__
25 #include "YACSlibEngineExport.hxx"
26 #include "RefCounter.hxx"
27 #include "Exception.hxx"
28 #include "AlternateThread.hxx"
30 #include "TypeCode.hxx"
39 * \brief Base class factorizing common methods for all algorithms interfaces.
41 class YACSLIBENGINE_EXPORT OptimizerAlgBase : public RefCounter
46 std::string _errorMessage;
49 OptimizerAlgBase(Pool *pool);
50 virtual ~OptimizerAlgBase();
52 // Methods to implement in real algorithm classes. These methods shall be called
53 // only through proxy methods.
54 //! returns typecode of type expected as Input. OwnerShip of returned pointer is held by this.
55 virtual TypeCode *getTCForIn() const = 0;
56 //! returns typecode of type expected as Output. OwnerShip of returned pointer is held by this.
57 virtual TypeCode *getTCForOut() const = 0;
58 //! returns typecode of type expected for algo initialization. OwnerShip of returned pointer is held by this.
59 virtual TypeCode *getTCForAlgoInit() const;
60 //! returns typecode of type expected as algo result. OwnerShip of returned pointer is held by this.
61 virtual TypeCode *getTCForAlgoResult() const;
62 virtual void initialize(const Any *input) throw (Exception);
63 virtual void start() = 0;//! Update _pool attribute before performing anything.
64 virtual void takeDecision() = 0;//! _pool->getCurrentId gives the \b id at the origin of this call.
65 //! Perform the job of analysing to know what new jobs to do (_pool->pushInSample)
66 //! or in case of convergence _pool->destroyAll
67 virtual void finish();//! Called when optimization has succeed.
68 virtual Any * getAlgoResult();
71 // Proxy methods to encapsulate the call to real methods
72 virtual TypeCode *getTCForInProxy() const;
73 virtual TypeCode *getTCForOutProxy() const;
74 virtual TypeCode *getTCForAlgoInitProxy() const;
75 virtual TypeCode *getTCForAlgoResultProxy() const;
76 virtual void initializeProxy(const Any *input) throw (Exception);
77 virtual void startProxy();
78 virtual void takeDecisionProxy();
79 virtual void finishProxy();
80 virtual Any * getAlgoResultProxy();
83 virtual void setPool(Pool *pool);
84 virtual void setProc(Proc * proc);
85 virtual Proc * getProc();
86 virtual bool hasError() const;
87 virtual const std::string & getError() const;
88 virtual void setError(const std::string & message);
92 typedef OptimizerAlgBase OptimizerAlgSync;
95 * \brief Base class to implement in external dynamic lib in case of optimizer non event oriented.
97 class YACSLIBENGINE_EXPORT OptimizerAlgASync : public OptimizerAlgBase,
98 public YACS::BASES::AlternateThread
101 OptimizerAlgASync(Pool *pool);
103 virtual ~OptimizerAlgASync();
104 virtual void finishProxy();//! Called when optimization has succeed.
107 virtual void start();//! Update _pool attribute before performing anything.
108 virtual void takeDecision();//! _pool->getCurrentId gives the \b id at the origin of this call.
109 //! Perform the job of analysing to know what new jobs to do (_pool->pushInSample)
110 //! or in case of convergence _pool->destroyAll
113 //! _pool->getCurrentId gives the \b id at the origin of this call.
114 //! Perform the job between 2 'condition->wait()' of analysing to know what new jobs to do
115 //! (_pool->pushInSample) or in case of convergence _pool->destroyAll
116 //! WARNING ! 'condition->wait()' must be called before any analyse of Pool.
117 virtual void startToTakeDecision()=0;
120 typedef OptimizerAlgBase *(*OptimizerAlgBaseFactory)(Pool *pool);