Salome HOME
refactoring calculation progress meth
authorLauffenburger Thomas <thomas.lauffenburger@edf.fr>
Wed, 9 Sep 2015 11:29:14 +0000 (13:29 +0200)
committerLauffenburger Thomas <thomas.lauffenburger@edf.fr>
Wed, 9 Sep 2015 11:29:14 +0000 (13:29 +0200)
14 files changed:
src/engine/ComposedNode.cxx
src/engine/ComposedNode.hxx
src/engine/ElementaryNode.cxx
src/engine/ElementaryNode.hxx
src/engine/ForEachLoop.cxx
src/engine/ForEachLoop.hxx
src/engine/ForLoop.cxx
src/engine/ForLoop.hxx
src/engine/Node.hxx
src/engine/Proc.cxx
src/engine/Switch.cxx
src/engine/Switch.hxx
src/yacsloader_swig/Test/CMakeLists.txt
src/yacsloader_swig/Test/YacsLoaderInSessionTest.sh.in

index 31424ad25dfd8c0aaa9c15c82ee4877a899bb8ad..6475ef03b25d7aa89d957adf72965ecc6b34531e 100644 (file)
@@ -28,7 +28,6 @@
 #include "DataStreamPort.hxx"
 #include "ElementaryNode.hxx"
 #include "ComponentInstance.hxx"
-#include "ForEachLoop.hxx"
 
 #include <iostream>
 #include <set>
@@ -1135,42 +1134,17 @@ list<Node *> ComposedNode::getAllRecursiveNodes()
 
 //! Get the progress weight for all elementary nodes
 /*!
- * Only elementary nodes have weight. If a node is in a for each loop, his weight is modified by the size of the loop
- *
+ * Only elementary nodes have weight. A simple composed node only sum up weight of all his descendants
+ * (working is different for loop or switch nodes)
  */
-list<pair<int,int> > ComposedNode::getProgressWeight()
+list<ProgressWeight> ComposedNode::getProgressWeight() const
 {
-       list<pair<int,int> > ret;
+       list<ProgressWeight> ret;
        list<Node *> setOfNode=edGetDirectDescendants();
-       int elemDone, elemTotal;
        for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
                {
-                       if ( dynamic_cast<ForEachLoop*> (*iter) )
-                               {
-                                       elemDone=((ForEachLoop*)(*iter))->getCurrentIndex();
-                                       elemTotal=((ForEachLoop*)(*iter))->getNbOfElementsToBeProcessed();
-                                       list<pair<int,int> > myCurrentSet=((ComposedNode*)(*iter))->getProgressWeight();
-                                       myCurrentSet.pop_front();
-                                       myCurrentSet.pop_back();
-                                       for(list<pair<int,int> >::iterator iter=myCurrentSet.begin();iter!=myCurrentSet.end();iter++)
-                                               {
-                                                       (*iter).first=(*iter).second*elemDone;
-                                                       (*iter).second*=elemTotal;
-                                               }
-                                       ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
-                               }
-                       else if ( dynamic_cast<ComposedNode*> (*iter) )
-                               {
-                                 list<pair<int,int> > myCurrentSet=((ComposedNode*)(*iter))->getProgressWeight();
-                                       ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
-                               }
-                       else
-                               {
-                                 if ((*iter)->getState() == YACS::DONE)
-                                         ret.push_back(pair<int,int>(1,1));
-                                       else
-                                               ret.push_back(pair<int,int>(0,1));
-                               }
+                 list<ProgressWeight> myCurrentSet=((ComposedNode*)(*iter))->getProgressWeight();
+                       ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
                }
   return ret;
 }
index 84e4d5555520c32a56ac5c9a78ec29095ffe5260..aadd2804c3343c074776d9a22425e8517c681533 100644 (file)
@@ -80,7 +80,7 @@ namespace YACS
       std::list<ElementaryNode *> getRecursiveConstituents() const;
       std::list<Node *> getAllRecursiveNodes();
       virtual std::list<Node *> getAllRecursiveConstituents(); // first implementation
-      std::list<std::pair<int,int> > getProgressWeight();
+      std::list<ProgressWeight> getProgressWeight() const;
       std::string getInPortName(const InPort *) const throw (Exception);
       std::string getOutPortName(const OutPort *) const throw (Exception);
       //
index 52b4e6eeeee63760c0095197b685fea6047aa875..e628ae6369d6b5b35cbd6e7f85b3fc1ce4a1d148 100644 (file)
@@ -547,6 +547,24 @@ list<ElementaryNode *> ElementaryNode::getRecursiveConstituents() const
   return ret;
 }
 
+//! Get the progress weight for all elementary nodes
+/*!
+ * Only elementary nodes have weight. At this stage weight is 0 or 1 (it can be modified later following
+ * the kind of father)
+ */
+list<ProgressWeight> ElementaryNode::getProgressWeight() const
+{
+       list<ProgressWeight> ret;
+       ProgressWeight myWeight;
+       myWeight.weightTotal=1;
+       if (getState() == YACS::DONE)
+         myWeight.weightDone=1;
+       else
+               myWeight.weightDone=0;
+       ret.push_back(myWeight);
+  return ret;
+}
+
 Node *ElementaryNode::getChildByName(const std::string& name) const throw(YACS::Exception)
 {
   string what("ElementaryNode does not agregate any nodes particullary node with name "); what+=name;
index 843de41e12e8140931381c11ebe46ccb15dc8c77..07fe8a485a740b4fbe629e20246b23168bab3e05 100644 (file)
@@ -69,6 +69,7 @@ namespace YACS
       void getReadyTasks(std::vector<Task *>& tasks);
       void edRemovePort(Port *port) throw(Exception);
       std::list<ElementaryNode *> getRecursiveConstituents() const;
+      std::list<ProgressWeight> getProgressWeight() const;
       Node *getChildByName(const std::string& name) const throw(Exception);
       virtual void checkBasicConsistency() const throw(Exception);
       ComposedNode *getDynClonerIfExists(const ComposedNode *levelToStop) const;
index b753f22e67e7b54ea3006f3194433a50962cf375..371bb8de3c272b99c9e6d2a4f5b33e274fa84d0d 100644 (file)
@@ -1103,6 +1103,31 @@ std::string ForEachLoop::getProgress() const
   return aProgress.str();
 }
 
+//! Get the progress weight for all elementary nodes
+/*!
+ * Only elementary nodes have weight. For each node in the loop, the weight done is multiplied
+ * by the number of elements done and the weight total by the number total of elements
+ */
+list<ProgressWeight> ForEachLoop::getProgressWeight() const
+{
+       list<ProgressWeight> ret;
+       list<Node *> setOfNode=edGetDirectDescendants();
+       int elemDone=getCurrentIndex();
+       int elemTotal=getNbOfElementsToBeProcessed();
+       for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
+         {
+                 list<ProgressWeight> myCurrentSet=(*iter)->getProgressWeight();
+                       for(list<ProgressWeight>::iterator iter=myCurrentSet.begin();iter!=myCurrentSet.end();iter++)
+                               {
+                                       (*iter).weightDone=((*iter).weightTotal) * elemDone;
+                                       (*iter).weightTotal*=elemTotal;
+                               }
+                       ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
+
+         }
+       return ret;
+}
+
 int ForEachLoop::getNbOfElementsToBeProcessed() const
 {
   return _splitterNode.getNumberOfElements();
index 1e06554097687634b8804db652635ed165fe6ef2..d70259618bfaf919f7f1e815785d6437d271f25a 100644 (file)
@@ -192,6 +192,7 @@ namespace YACS
       virtual std::string typeName() {return "YACS__ENGINE__ForEachLoop";}
       virtual void resetState(int level);
       std::string getProgress() const;
+      std::list<ProgressWeight> getProgressWeight() const;
       int getCurrentIndex() const { return _currentIndex; }
       int getNbOfElementsToBeProcessed() const;
 #ifndef SWIG
index fe45644902b2b702c65c1d28ca54aba06ed1a733..94e3167b22e52d95e6bafabe67736b5442652a8f 100644 (file)
@@ -265,17 +265,52 @@ std::list<OutputPort *> ForLoop::getSetOfOutputPort() const
   return ret;
 }
 
+
+int ForLoop::getNbSteps() const
+{
+  AnyInputPort* aNbStepsPort = (AnyInputPort*)&_nbOfTimesPort;
+  int nbSteps = 0;
+  if (aNbStepsPort && !aNbStepsPort->isEmpty())
+    nbSteps = aNbStepsPort->getIntValue();
+  return nbSteps;
+}
+
 std::string ForLoop::getProgress() const
 {
   std::stringstream aProgress;
   aProgress << "0";
-  AnyInputPort* aNbStepsPort = (AnyInputPort*)&_nbOfTimesPort;
-  if (aNbStepsPort && !aNbStepsPort->isEmpty()) {
-    int nbSteps = aNbStepsPort->getIntValue();
-    if (nbSteps > 0 && _nbOfTurns >= 0) {
+  int nbSteps = getNbSteps();
+  if (nbSteps > 0 && _nbOfTurns >= 0)
+    {
       aProgress.str("");
       aProgress << _nbOfTurns << "/" << nbSteps;
     }
-  }
   return aProgress.str();
 }
+
+//! Get the progress weight for all elementary nodes
+/*!
+ * Only elementary nodes have weight. For each node in the loop, the weight done is multiplied
+ * by the number of steps done and the weight total by the number total of steps
+ *
+ */
+list<ProgressWeight> ForLoop::getProgressWeight() const
+{
+       list<ProgressWeight> ret;
+       list<Node *> setOfNode=edGetDirectDescendants();
+       int nbStepsDone=getNbOfTurns();
+       int nbStepsTotal=getNbSteps();
+       for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
+         {
+                 list<ProgressWeight> myCurrentSet=(*iter)->getProgressWeight();
+                       for(list<ProgressWeight>::iterator iter=myCurrentSet.begin();iter!=myCurrentSet.end();iter++)
+                               {
+                                       (*iter).weightDone=((*iter).weightTotal) * nbStepsDone;
+                                       (*iter).weightTotal*=nbStepsTotal;
+                               }
+                       ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
+
+         }
+       return ret;
+}
+
index e00c271bab7097b1f0309237137df7c974a7c3fc..3d33e0626880645224b34befb616472c3c2e203c 100644 (file)
@@ -55,6 +55,9 @@ namespace YACS
       OutputPort *edGetIndexPort() { return &_indexPort; }
       virtual std::string typeName() {return "YACS__ENGINE__ForLoop";}
       std::string getProgress() const;
+      std::list<ProgressWeight> getProgressWeight() const;
+      int getNbSteps() const;
+
     protected:
       YACS::Event updateStateOnFinishedEventFrom(Node *node);
       void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed,
index c724fb605226b88b0a7d0867646fa87afd587600..e94b0a4add2ccfe21a48b12abed54cdf1a6a4807 100644 (file)
@@ -52,6 +52,12 @@ namespace YACS
     class OutputDataStreamPort;
     class Visitor;
 
+    struct ProgressWeight
+    {
+       int weightDone;
+       int weightTotal;
+    };
+
     class YACSLIBENGINE_EXPORT NodeStateNameMap : public std::map<YACS::StatesForNode, std::string>
     {
     public:
@@ -125,6 +131,7 @@ namespace YACS
       virtual void exDisabledState();
       virtual void getReadyTasks(std::vector<Task *>& tasks) = 0;
       virtual std::list<ElementaryNode *> getRecursiveConstituents() const = 0;
+      virtual std::list<ProgressWeight> getProgressWeight() const = 0;
       virtual int getNumberOfInputPorts() const = 0;
       virtual int getNumberOfOutputPorts() const = 0;
       std::list<InPort *> getSetOfInPort() const;
index 4cb7429557d682721059287de61881aa0e0fe619..7e777d22f99b8e5783a102408f51ac679bae57f7 100644 (file)
@@ -232,14 +232,14 @@ std::string Proc::getNodeProgress(int numId)
 
 int Proc::getGlobalProgressPercent()
 {
-       list<pair <int,int> > weightList = getProgressWeight();
+       list<ProgressWeight> weightList = getProgressWeight();
        int weightDone = 0;
        int weightTotal = 0;
        int progressPercent = 0;
-       for(list<pair <int,int> >::const_iterator iter=weightList.begin();iter!=weightList.end();iter++)
+       for(list<ProgressWeight>::const_iterator iter=weightList.begin();iter!=weightList.end();iter++)
          {
-                 weightDone += (*iter).first;
-                       weightTotal += (*iter).second;
+                 weightDone += (*iter).weightDone;
+                       weightTotal += (*iter).weightTotal;
          }
   if (weightTotal > 0)
        progressPercent = int(float(weightDone) / float(weightTotal) * 100);
index f06d6d86b02a18677bcbbbc0c1cdb5dbf5790cc9..c196cc2db6c788f1784f9b100ce9d82aa5bb8178 100644 (file)
@@ -580,6 +580,34 @@ int Switch::getMaxCase()
   return aCase;
 }
 
+//! Get the progress weight of the graph
+/*!
+ * Only elementary nodes have weight. If the switch node is not done, we add the weight of all his descendants,
+ * otherwise only the weight of the used case count.
+ */
+list<ProgressWeight> Switch::getProgressWeight() const
+{
+       list<ProgressWeight> ret;
+       list<Node *> setOfNode=edGetDirectDescendants();
+       if (getState() == YACS::DONE)
+         {
+                 for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
+             {
+                     if (getEffectiveState(*iter) == YACS::DONE)
+                         ret=(*iter)->getProgressWeight();
+             }
+         }
+       else
+         {
+           for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
+        {
+                 list<ProgressWeight> myCurrentSet=(*iter)->getProgressWeight();
+                 ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
+        }
+         }
+       return ret;
+}
+
 bool Switch::edAddChild(Node *node) throw(YACS::Exception)
 {
   int aCase = getMaxCase() + 1;
index 4d6670d131dba2134f34380df6b9e83e4545796a..cc1471309f614678a095dbcbc906f44036551fcd 100644 (file)
@@ -129,6 +129,7 @@ namespace YACS
       virtual void accept(Visitor *visitor);
       int getRankOfNode(Node *node) const;
       virtual std::string typeName() {return "YACS__ENGINE__Switch";}
+      std::list<ProgressWeight> getProgressWeight() const;
     protected:
       YACS::Event updateStateOnFinishedEventFrom(Node *node);
       Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
index 4af457d6fdf1dcec8964222d894cca30be715f35..2b7aefabc1bcadfc6f46c8254c72c923918aa680 100644 (file)
@@ -43,6 +43,7 @@ IF(NOT WIN32)
     testSaveLoadRun.py
     optim_plugin.py
     testValidationChecks.py
+    testProgress.py
    )
   INSTALL(FILES ${LOCAL_TEST_FILES}
         DESTINATION ${LOCAL_TEST_DIR})
index 0229f6d41d67537f78dcd8833b7e60e45c985b2b..edaad8e53e400fb9b53df08475d1de4b8375bb45 100644 (file)
@@ -88,7 +88,14 @@ if [ $ret6 -gt 0 ]; then
   exit $ret6
 fi
 
-let ret=$ret0+$ret1+$ret2+$ret3+$ret4+$ret5+$ret6
+python  @CMAKE_CURRENT_SOURCE_DIR@/testProgress.py
+ret7=$?
+if [ $ret7 -gt 0 ]; then
+  echo "exec status testProgress : " $ret7
+  exit $ret7
+fi
+
+let ret=$ret0+$ret1+$ret2+$ret3+$ret4+$ret5+$ret6+$ret7
 
 # --- return unit tests status