1 // Copyright (C) 2006-2016 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, or (at your option) any later version.
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;
50 OptimizerAlgBase(Pool *pool);
51 virtual ~OptimizerAlgBase();
53 // Methods to implement in real algorithm classes. These methods shall be called
54 // only through proxy methods.
55 //! returns typecode of type expected as Input. OwnerShip of returned pointer is held by this.
56 virtual TypeCode *getTCForIn() const = 0;
57 //! returns typecode of type expected as Output. OwnerShip of returned pointer is held by this.
58 virtual TypeCode *getTCForOut() const = 0;
59 //! returns typecode of type expected for algo initialization. OwnerShip of returned pointer is held by this.
60 virtual TypeCode *getTCForAlgoInit() const;
61 //! returns typecode of type expected as algo result. OwnerShip of returned pointer is held by this.
62 virtual TypeCode *getTCForAlgoResult() const;
63 virtual void initialize(const Any *input) throw (Exception);
64 virtual void start() = 0;//! Update _pool attribute before performing anything.
65 virtual void takeDecision() = 0;//! _pool->getCurrentId gives the \b id at the origin of this call.
66 //! Perform the job of analysing to know what new jobs to do (_pool->pushInSample)
67 //! or in case of convergence _pool->destroyAll
68 virtual void finish();//! Called when optimization has succeed.
69 virtual Any * getAlgoResult();
72 // Proxy methods to encapsulate the call to real methods
73 virtual TypeCode *getTCForInProxy() const;
74 virtual TypeCode *getTCForOutProxy() const;
75 virtual TypeCode *getTCForAlgoInitProxy() const;
76 virtual TypeCode *getTCForAlgoResultProxy() const;
77 virtual void initializeProxy(const Any *input) throw (Exception);
78 virtual void startProxy();
79 virtual void takeDecisionProxy();
80 virtual void finishProxy();
81 virtual Any * getAlgoResultProxy();
84 virtual void setPool(Pool *pool);
85 virtual void setProc(Proc * proc);
86 virtual Proc * getProc();
87 virtual bool hasError() const;
88 virtual const std::string & getError() const;
89 virtual void setError(const std::string & message);
90 void setNbOfBranches(int nbOfBranches);
91 int getNbOfBranches() const;
94 typedef OptimizerAlgBase OptimizerAlgSync;
97 * \brief Base class to implement in external dynamic lib in case of optimizer non event oriented.
99 class YACSLIBENGINE_EXPORT OptimizerAlgASync : public OptimizerAlgBase,
100 public YACS::BASES::AlternateThread
103 OptimizerAlgASync(Pool *pool);
105 virtual ~OptimizerAlgASync();
106 virtual void finishProxy();//! Called when optimization has succeed.
109 virtual void start();//! Update _pool attribute before performing anything.
110 virtual void takeDecision();//! _pool->getCurrentId gives the \b id at the origin of this call.
111 //! Perform the job of analysing to know what new jobs to do (_pool->pushInSample)
112 //! or in case of convergence _pool->destroyAll
115 //! _pool->getCurrentId gives the \b id at the origin of this call.
116 //! Perform the job between 2 'condition->wait()' of analysing to know what new jobs to do
117 //! (_pool->pushInSample) or in case of convergence _pool->destroyAll
118 //! WARNING ! 'condition->wait()' must be called before any analyse of Pool.
119 virtual void startToTakeDecision()=0;
122 typedef OptimizerAlgBase *(*OptimizerAlgBaseFactory)(Pool *pool);