Version: 9.15.0
OptimizerLoop.hxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2025 CEA, EDF
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 ;
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) ;
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 ;
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 ;
106  OutputPort *getOutputPort(const std::string& name) const ;
107  YACS::Event finalize();
108  protected:
109  virtual YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);
110  void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
111  void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
112  void checkControlDependancy(OutPort *start, InPort *end, bool cross,
113  std::map < ComposedNode *, std::list < OutPort * >, SortHierarc >& fw,
114  std::vector<OutPort *>& fwCross,
115  std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
116  LinkInfo& info) const;
117  void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
118  void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
119  InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) ;
120  protected:
121  void cleanInterceptors();
122  void launchMaxOfSamples(bool first);
123  bool isFullyLazy() const;
124  bool isFullyBusy(unsigned& branchId) const;
125  void initInterceptors(unsigned nbOfBr);
126  void pushValueOutOfScopeForCase(unsigned branchId);
127  Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
128  virtual void loadAlgorithm();
129 
130  private:
131  TypeCode * checkTypeCode(TypeCode * tc, const char * portName);
132 
133  protected:
134  static const int NOT_RUNNING_BRANCH_ID;
135  static const int NOT_INITIALIZED_BRANCH_ID;
136  static const char NAME_OF_ALGO_INIT_PORT[];
137  static const char NAME_OF_OUT_POOL_INPUT[];
138  static const char NAME_OF_ALGO_RESULT_PORT[];
139  };
140  }
141 }
142 
143 #endif
#define YACSLIBENGINE_EXPORT
Base class for all composed nodes.
Base class for dynamically (fully or semifully) built graphs.
Definition: DynParaLoop.hxx:41
Base class for all calculation nodes.
Threaded Executor.
Definition: Executor.hxx:63
Node * simpleClone(ComposedNode *father, bool editionOnly) const
FakeNodeForOptimizerLoop(OptimizerLoop *loop, bool normal, std::string message)
Base class for Input Ports.
Definition: InputPort.hxx:44
Class that deal with list of semantics links for high level analysis.
Definition: LinkInfo.hxx:83
Base class for all nodes.
Definition: Node.hxx:70
Base class factorizing common methods for all algorithms interfaces.
class to build optimization loops
OutputPort * edGetAlgoResultPort()
virtual std::string getSymbol() const
virtual std::string typeName()
std::map< InputPort *, std::vector< InputPort * > > _interceptors
outputports interceptors leaving current scope.
static const int NOT_RUNNING_BRANCH_ID
FakeNodeForOptimizerLoop * _nodeForSpecialCases
static const int NOT_INITIALIZED_BRANCH_ID
::YACS::BASES::DynLibLoader * _loader
std::vector< AnyInputPort * > _interceptorsForOutPool
std::vector< bool > _initNodeUpdated
Pool used to manage the samples of the optimizer loop plugin.
Definition: Pool.hxx:42
Base class for all schema objects.
Definition: Proc.hxx:44
Base class for all type objects.
Definition: TypeCode.hxx:68
Event
Definition: define.hxx:56