Salome HOME
Merge branch 'V7_dev'
[modules/yacs.git] / src / engine / Bloc.hxx
index cdf5daee69dd773a66851600dcf50ebe86c13097..3cfec917263b5eab4445c9a4d2530a135dca5d40 100644 (file)
@@ -1,23 +1,36 @@
+// Copyright (C) 2006-2016  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #ifndef __BLOC_HXX__
 #define __BLOC_HXX__
 
+#include "YACSlibEngineExport.hxx"
 #include "StaticDefinedComposedNode.hxx"
 
 namespace YACS
 {
   namespace ENGINE
   {
-/*! \brief Class for bloc node
- *
- * \ingroup Nodes
- *
- *
- * \see ComposedNode
- */
-    class Bloc : public StaticDefinedComposedNode
+    class YACSLIBENGINE_EXPORT Bloc : public StaticDefinedComposedNode
     {
     protected:
-      std::set<Node *> _setOfNode;//OWNERSHIP OF ALL NODES
+      std::list<Node *> _setOfNode;//OWNERSHIP OF ALL NODES
       //! For internal calculations
       mutable std::map<Node *,std::set<Node *> > *_fwLinks;
       //! For internal calculations
@@ -33,18 +46,22 @@ namespace YACS
       void init(bool start=true);
       void getReadyTasks(std::vector<Task *>& tasks);
       void exUpdateState();
-      bool edAddChild(Node *node) throw(Exception);
+      //Node* DISOWNnode is a SWIG notation to indicate that the ownership of the node is transfered to C++
+      bool edAddChild(Node *DISOWNnode) throw(Exception);
       void edRemoveChild(Node *node) throw(Exception);
-      std::set<Node *> getChildren() { return _setOfNode; }
-      std::set<Node *> edGetDirectDescendants() const;
+      std::list<Node *> getChildren() const { return _setOfNode; }
+      std::list<Node *> edGetDirectDescendants() const { return _setOfNode; }
+      std::vector< std::list<Node *> > splitIntoIndependantGraph() const;
       Node *getChildByShortName(const std::string& name) const throw(Exception);
-      void selectRunnableTasks(std::vector<Task *>& tasks);
-      virtual void writeDot(std::ostream &os);
+      virtual void writeDot(std::ostream &os) const;
       void accept(Visitor *visitor);
       template<bool direction>
       void findAllPathsStartingFrom(Node *start, std::list< std::vector<Node *> >& vec, std::map<Node *, std::set<Node *> >& accelStr) const;
       template<bool direction>
       void findAllNodesStartingFrom(Node *start, std::set<Node *>& result, std::map<Node *, std::set<Node *> >& accelStr, LinkInfo& info) const;
+      virtual std::string typeName() { return "YACS__ENGINE__Bloc"; }
+      int getMaxLevelOfParallelism() const;
+      void removeRecursivelyRedundantCL();
     protected:
       bool areAllSubNodesFinished() const;
       bool areAllSubNodesDone() const;
@@ -52,18 +69,19 @@ namespace YACS
       void checkNoCyclePassingThrough(Node *node) throw(Exception);
       std::vector< std::pair<OutGate *, InGate *> > getSetOfInternalCFLinks() const;
       YACS::Event updateStateOnFinishedEventFrom(Node *node);
-      YACS::Event updateStateOnFailedEventFrom(Node *node);
+      YACS::Event updateStateOnFailedEventFrom(Node *node, const Executor *execInst);
       void initComputation() const;
+      void performCFComputationsOnlyOneLevel(LinkInfo& info) const;
       void performCFComputations(LinkInfo& info) const;
       void destructCFComputations(LinkInfo& info) const;
       void checkControlDependancy(OutPort *start, InPort *end, bool cross,
-                                  std::map < ComposedNode *,  std::list < OutPort * > >& fw,
+                                  std::map < ComposedNode *,  std::list < OutPort * >, SortHierarc >& fw,
                                   std::vector<OutPort *>& fwCross,
-                                  std::map< ComposedNode *, std::list < OutPort *> >& bw,
+                                  std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
                                   LinkInfo& info) const;
       bool areLinked(Node *start, Node *end, bool fw) const;
       bool arePossiblyRunnableAtSameTime(Node *start, Node *end) const;
-      void checkCFLinks(const std::list< OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
+      void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
       static void verdictForOkAndUseless1(const std::map<Node *,std::list <OutPort *> >& pool, InputPort *end, const std::vector<Node *>& candidates,
                                           unsigned char& alreadyFed, bool direction, LinkInfo& info);
       static void verdictForCollapses(const std::map<Node *,std::list <OutPort *> >& pool, InputPort *end, const std::set<Node *>& candidates,
@@ -85,8 +103,8 @@ namespace YACS
     template<>
     struct CFDirectionVisTraits<true>
     {
-      typedef std::map<InGate *,bool>::iterator Iterator;
-      typedef std::map<InGate *,bool>& Nexts;
+      typedef std::list< std::pair<InGate *,bool> >::iterator Iterator;
+      typedef std::list< std::pair<InGate *,bool> >& Nexts;
       static Nexts getNexts(Node *node) { return node->getOutGate()->edMapInGate(); }
     };
 
@@ -94,8 +112,8 @@ namespace YACS
     template<>
     struct CFDirectionVisTraits<false>
     {
-      typedef std::map<OutGate *,bool>::iterator Iterator;
-      typedef std::map<OutGate *,bool>& Nexts;
+      typedef std::list< std::pair<OutGate *,bool> >::iterator Iterator;
+      typedef std::list< std::pair<OutGate *,bool> >& Nexts;
       static Nexts getNexts(Node *node) { return node->getInGate()->edMapOutGate(); }
     };
 
@@ -106,12 +124,13 @@ namespace YACS
     template<bool direction>
     unsigned Bloc::appendIfAlreadyFound(std::list< std::vector<Node *> >& res, const std::vector<Node *>& startRes, Node *node, std::map<Node *, std::set<Node *> >& fastFinder)
     {
-      std::map<Node *, std::set<Node *> >::const_iterator iter=fastFinder.find(node);
+      std::map<Node *, std::set<Node *> >::iterator iter=fastFinder.find(node);
       if(iter==fastFinder.end())
         return 0;
       unsigned ret=0;
       std::vector<std::pair<std::set<Node *>::iterator, std::set<Node *>::iterator > > li;
-      li.push_back(std::pair<std::set<Node *>::iterator, std::set<Node *>::iterator>(((*iter).second).begin(),((*iter).second).end()));
+      std::pair<std::set<Node *>::iterator, std::set<Node *>::iterator> ipr(((*iter).second).begin(),((*iter).second).end());
+      li.push_back(ipr);
       std::vector<Node *> work(startRes);
       std::list< std::vector<Node *> >::iterator where=res.end(); where--;
       std::list< std::vector<Node *> >::iterator updates=where;
@@ -129,8 +148,9 @@ namespace YACS
                 }
               else
                 {
-                  const std::set<Node *>& s=fastFinder[*(li.back().first)];
-                  li.push_back(std::pair<std::set<Node *>::iterator, std::set<Node *>::iterator>(s.begin(),s.end()));
+                  std::set<Node *>& s=fastFinder[*(li.back().first)];
+                  std::pair<std::set<Node *>::iterator, std::set<Node *>::iterator> pr(s.begin(),s.end());
+                  li.push_back(pr);
                 }
             }
           else
@@ -148,7 +168,8 @@ namespace YACS
     }
 
     template<bool direction>
-    void Bloc::findAllNodesStartingFrom(Node *start, std::set<Node *>& result, std::map<Node *, std::set<Node *> >& accelStr, LinkInfo& info) const
+    void Bloc::findAllNodesStartingFrom(Node *start, std::set<Node *>& result, 
+                                        std::map<Node *, std::set<Node *> >& accelStr, LinkInfo& info) const
     {
       std::list< std::vector<Node *> > li;
       findAllPathsStartingFrom<direction>(start,li,accelStr);
@@ -161,11 +182,14 @@ namespace YACS
 
     /*!
      * Method for CF computation.DFS visitor is used.
+     * if direction is true forward visiting is performed, if false backward is performed.
      * \param start \b must be a direct descendant of 'this'.
-     * \param direction if true forward visiting is perform, false backward is used.
+     * \param vec :
+     * \param accelStr
      */
     template<bool direction>
-    void Bloc::findAllPathsStartingFrom(Node *start, std::list< std::vector<Node *> >& vec, std::map<Node *, std::set<Node *> >& accelStr) const
+    void Bloc::findAllPathsStartingFrom(Node *start, std::list< std::vector<Node *> >& vec, 
+                                        std::map<Node *, std::set<Node *> >& accelStr) const
     {
       initComputation();
       Node *current=start;