]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/OptimizerLoop.hxx
Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / engine / OptimizerLoop.hxx
1 #ifndef __OPTIMIZERLOOP_HXX__
2 #define __OPTIMIZERLOOP_HXX__
3
4 #include "Pool.hxx"
5 #include "Thread.hxx"
6 #include "DynParaLoop.hxx"
7 #include "DynLibLoader.hxx"
8 #include "OptimizerAlg.hxx"
9 #include "ElementaryNode.hxx"
10 #include "DrivenCondition.hxx"
11
12 namespace YACS
13 {
14   namespace ENGINE
15   {
16     class OptimizerAlgStandardized : public OptimizerAlgSync
17     {
18     private:
19       ::YACS::BASES::Thread *_threadInCaseOfNotEvent;
20       ::YACS::BASES::DrivenCondition _condition;
21       OptimizerAlgBase *_algBehind;
22     public:
23       OptimizerAlgStandardized(Pool *pool, OptimizerAlgBase *alg);
24       ~OptimizerAlgStandardized();
25       TypeCode *getTCForIn() const;
26       TypeCode *getTCForOut() const;
27       void setAlgPointer(OptimizerAlgBaseFactory algFactory);
28       void parseFileToInit(const std::string& fileName);
29       void initialize(const Any *input) throw (Exception);
30       void takeDecision();
31       void finish();
32       void start();
33     private:
34       static void *threadFctForAsync(void* ownStack);
35     };
36
37     class OptimizerLoop;
38
39     class FakeNodeForOptimizerLoop : public ElementaryNode
40     {
41       friend class OptimizerLoop;
42     private:
43       OptimizerLoop *_loop;
44       unsigned _reason;
45       bool _normal;
46     private:
47       FakeNodeForOptimizerLoop(OptimizerLoop *loop, bool normal, unsigned reason);
48       FakeNodeForOptimizerLoop(const FakeNodeForOptimizerLoop& other);
49       Node *simpleClone(ComposedNode *father, bool editionOnly) const;
50       void exForwardFailed();
51       void exForwardFinished();
52       void execute();
53       void aborted();
54       void finished();
55     private:
56       static const char NAME[];
57       static const unsigned char ALG_WITHOUT_START_CASES = 52;
58       static const unsigned char NO_BRANCHES = 53;
59       static const unsigned char NO_ALG_INITIALIZATION = 54;
60     };
61
62     class OptimizerLoop : public DynParaLoop
63     {
64       friend class FakeNodeForOptimizerLoop;
65       
66     protected:
67       Pool _myPool;
68       bool _algInitOnFile;
69       std::string _symbol;
70       AnyInputPort _portForInitFile;
71       ::YACS::BASES::DynLibLoader _loader;
72       OptimizerAlgStandardized *_alg;
73       AnyInputPort _retPortForOutPool;
74       std::vector<bool> _initNodeUpdated;
75       bool _convergenceReachedWithOtherCalc;
76       FakeNodeForOptimizerLoop *_nodeForSpecialCases;
77       std::vector<AnyInputPort *> _interceptorsForOutPool;
78       ::YACS::BASES::DrivenCondition _condForCompletenessB4Relaunch;
79       //! outputports interceptors leaving current scope.
80       std::map<InputPort *, std::vector<InputPort *> > _interceptors;
81     public:
82       OptimizerLoop(const std::string& name, const std::string& algLibWthOutExt,
83                     const std::string& symbolNameToOptimizerAlgBaseInstanceFactory,
84                     bool algInitOnFile) throw(Exception);
85       OptimizerLoop(const OptimizerLoop& other, ComposedNode *father, bool editionOnly);
86       ~OptimizerLoop();
87       void init(bool start=true);
88       void exUpdateState();
89       int getNumberOfInputPorts() const;
90       InputPort *edGetPortForOutPool() { return &_retPortForOutPool; }
91       InputPort *edGetPortForInitFile() { return &_portForInitFile; }
92       InputPort *getInputPort(const std::string& name) const throw(Exception);
93       std::list<InputPort *> getSetOfInputPort() const;
94       void selectRunnableTasks(std::vector<Task *>& tasks);
95       void getReadyTasks(std::vector<Task *>& tasks);
96       YACS::Event updateStateOnFinishedEventFrom(Node *node);
97       void checkNoCyclePassingThrough(Node *node) throw(Exception);
98       void checkConsistency(ComposedNode *pointOfView) const throw(Exception);
99     protected:
100       void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::set<ComposedNode *>& pointsOfView);
101       void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::set<ComposedNode *>& pointsOfView);
102     protected:
103       void cleanInterceptors();
104       void launchMaxOfSamples(bool first);
105       bool isFullyLazy() const;
106       bool isFullyBusy(unsigned& branchId) const;
107       void initInterceptors(unsigned nbOfBr);
108       void pushValueOutOfScopeForCase(unsigned branchId);
109       Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
110     protected:
111       static const int NOT_RUNNING_BRANCH_ID;
112       static const char NAME_OF_FILENAME_INPUT[];
113       static const char NAME_OF_OUT_POOL_INPUT[];
114     };
115   }
116 }
117
118 #endif