]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/OptimizerAlg.hxx
Salome HOME
a9a2dde9e348f47c2386eb1f048f018423f568a0
[modules/yacs.git] / src / engine / OptimizerAlg.hxx
1 #ifndef __OPTIMIZERALG_HXX__
2 #define __OPTIMIZERALG_HXX__
3
4 #include "RefCounter.hxx"
5 #include "Exception.hxx"
6 #include "DrivenCondition.hxx"
7
8 #include <string>
9
10 namespace YACS
11 {
12   namespace ENGINE
13   {
14     class Any;
15     class Pool;
16     class TypeCode;
17
18     typedef enum
19       {
20         EVENT_ORIENTED = 26,
21         NOT_EVENT_ORIENTED = 28
22       } TypeOfAlgInterface;
23
24     /*!
25      *  \brief Base class factorizing common methods for all algorithms interfaces.
26      */
27     class OptimizerAlgBase : public RefCounter
28     {
29     protected:
30       Pool *_pool;
31     protected:
32       OptimizerAlgBase(Pool *pool);
33       virtual ~OptimizerAlgBase();
34     public:
35       //! returns typecode of type expected as Input. OwnerShip of returned pointer is held by this.
36       virtual TypeCode *getTCForIn() const = 0;
37       //! returns typecode of type expected as Output. OwnerShip of returned pointer is held by this.
38       virtual TypeCode *getTCForOut() const = 0;
39       virtual void parseFileToInit(const std::string& fileName) = 0;
40       virtual TypeOfAlgInterface getType() const = 0;
41       virtual void initialize(const Any *input) throw (Exception) = 0;
42       virtual void finish() = 0;//! Called when optimization has succeed.
43     };
44
45     /*!
46      *  \brief Base class to implement in external dynamic lib in case of optimizer event oriented.
47      */
48     class OptimizerAlgSync : public OptimizerAlgBase
49     {
50     protected:
51       OptimizerAlgSync(Pool *pool);
52     public:
53       TypeOfAlgInterface getType() const;
54       virtual ~OptimizerAlgSync();
55       virtual void start() = 0;//! Update _pool attribute before performing anything.
56       virtual void takeDecision() = 0;//! _pool->getCurrentId gives the \b id at the origin of this call.
57                                       //! Perform the job of analysing to know what new jobs to do (_pool->pushInSample)
58                                       //! or in case of convergence _pool->destroyAll
59     };
60
61     /*!
62      *  \brief Base class to implement in external dynamic lib in case of optimizer non event oriented.
63      */
64     class OptimizerAlgASync : public OptimizerAlgBase
65     {
66     protected:
67       OptimizerAlgASync(Pool *pool);
68     public:
69       TypeOfAlgInterface getType() const;
70       virtual ~OptimizerAlgASync();
71       virtual void startToTakeDecision(::YACS::BASES::DrivenCondition *condition) = 0;//! _pool->getCurrentId gives the \b id at the origin of this call.
72       //! Perform the job between 2 'condition->wait()' of analysing to know what new jobs to do
73       //! (_pool->pushInSample) or in case of convergence _pool->destroyAll
74       //! WARNING ! 'condition->wait()' must be called before any analyse of Pool.
75     };
76
77     typedef OptimizerAlgBase *(*OptimizerAlgBaseFactory)(Pool *pool);
78   }
79 }
80
81 #endif