Version: 8.3.0
OptimizerLoop.hxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef __OPTIMIZERLOOP_HXX__
21 #define __OPTIMIZERLOOP_HXX__
22 
23 #include "YACSlibEngineExport.hxx"
24 #include "Pool.hxx"
25 #include "DynParaLoop.hxx"
26 #include "DynLibLoader.hxx"
27 #include "OptimizerAlg.hxx"
28 #include "ElementaryNode.hxx"
29 
30 namespace YACS
31 {
32  namespace ENGINE
33  {
34  class OptimizerLoop;
35 
37  {
38  friend class OptimizerLoop;
39  private:
41  std::string _message;
42  bool _normal;
43  private:
44  FakeNodeForOptimizerLoop(OptimizerLoop *loop, bool normal, std::string message);
46  Node *simpleClone(ComposedNode *father, bool editionOnly) const;
47  void exForwardFailed();
48  void exForwardFinished();
49  void execute();
50  void aborted();
51  void finished();
52  private:
53  static const char NAME[];
54  };
55 
57  {
59 
60  protected:
63  std::string _symbol;
64  std::string _alglib;
66  ::YACS::BASES::DynLibLoader * _loader;
69  std::vector<bool> _initNodeUpdated;
72  std::vector<AnyInputPort *> _interceptorsForOutPool;
74  std::map<InputPort *, std::vector<InputPort *> > _interceptors;
76  public:
77  OptimizerLoop(const std::string& name, const std::string& algLibWthOutExt,
78  const std::string& symbolNameToOptimizerAlgBaseInstanceFactory,
79  bool algInitOnFile,bool initAlgo=true, Proc * procForTypes = NULL);
80  OptimizerLoop(const OptimizerLoop& other, ComposedNode *father, bool editionOnly);
81  ~OptimizerLoop();
82  void init(bool start=true);
83  void exUpdateState();
84  int getNumberOfInputPorts() const;
85  InputPort *edGetPortForOutPool() { return &_retPortForOutPool; }
86  InputPort *edGetAlgoInitPort() { return &_algoInitPort; }
87  OutputPort *edGetAlgoResultPort() { return &_algoResultPort; }
88  InputPort *getInputPort(const std::string& name) const throw(Exception);
89  std::list<InputPort *> getSetOfInputPort() const;
90  std::list<InputPort *> getLocalInputPorts() const;
91  void selectRunnableTasks(std::vector<Task *>& tasks);
92  void getReadyTasks(std::vector<Task *>& tasks);
93  YACS::Event updateStateOnFinishedEventFrom(Node *node);
94  void checkNoCyclePassingThrough(Node *node) throw(Exception);
95  virtual void accept(Visitor *visitor);
96  virtual std::string getSymbol() const { return _symbol; }
97  virtual std::string getAlgLib() const ;
98  virtual void setAlgorithm(const std::string& alglib,const std::string& symbol,
99  bool checkLinks=true, Proc * procForTypes = NULL);
100  virtual void checkBasicConsistency() const throw(Exception);
101  virtual std::string typeName() {return "YACS__ENGINE__OptimizerLoop";}
102  int getNumberOfOutputPorts() const;
103  std::list<OutputPort *> getSetOfOutputPort() const;
104  std::list<OutputPort *> getLocalOutputPorts() const;
105  OutPort *getOutPort(const std::string& name) const throw(Exception);
106  OutputPort *getOutputPort(const std::string& name) const throw(Exception);
107  YACS::Event finalize();
108 
109  protected:
110  virtual YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);
111  void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
112  void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
113  void checkControlDependancy(OutPort *start, InPort *end, bool cross,
114  std::map < ComposedNode *, std::list < OutPort * >, SortHierarc >& fw,
115  std::vector<OutPort *>& fwCross,
116  std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
117  LinkInfo& info) const;
118  void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
119  void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
120  InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception);
121  protected:
122  void cleanInterceptors();
123  void launchMaxOfSamples(bool first);
124  bool isFullyLazy() const;
125  bool isFullyBusy(unsigned& branchId) const;
126  void initInterceptors(unsigned nbOfBr);
127  void pushValueOutOfScopeForCase(unsigned branchId);
128  Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
129  virtual void loadAlgorithm();
130 
131  private:
132  TypeCode * checkTypeCode(TypeCode * tc, const char * portName);
133 
134  protected:
135  static const int NOT_RUNNING_BRANCH_ID;
136  static const int NOT_INITIALIZED_BRANCH_ID;
137  static const char NAME_OF_ALGO_INIT_PORT[];
138  static const char NAME_OF_OUT_POOL_INPUT[];
139  static const char NAME_OF_ALGO_RESULT_PORT[];
140  };
141  }
142 }
143 
144 #endif