1 #ifndef __OPTIMIZERLOOP_HXX__
2 #define __OPTIMIZERLOOP_HXX__
6 #include "DynParaLoop.hxx"
7 #include "DynLibLoader.hxx"
8 #include "OptimizerAlg.hxx"
9 #include "ElementaryNode.hxx"
10 #include "DrivenCondition.hxx"
16 class OptimizerAlgStandardized : public OptimizerAlgSync
19 ::YACS::BASES::Thread *_threadInCaseOfNotEvent;
20 ::YACS::BASES::DrivenCondition _condition;
21 OptimizerAlgBase *_algBehind;
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);
34 static void *threadFctForAsync(void* ownStack);
39 class FakeNodeForOptimizerLoop : public ElementaryNode
41 friend class OptimizerLoop;
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();
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;
62 class OptimizerLoop : public DynParaLoop
64 friend class FakeNodeForOptimizerLoop;
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;
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);
87 void init(bool start=true);
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);
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);
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;
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[];