]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
Merge branch 'refact_meth_progress_calculation'
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Tue, 15 Sep 2015 16:02:31 +0000 (18:02 +0200)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Tue, 15 Sep 2015 16:02:31 +0000 (18:02 +0200)
16 files changed:
src/engine/AnyInputPort.hxx
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
src/yacsloader_swig/Test/testProgress.py [new file with mode: 0755]

index 7978410c5a20b65f2c2eaeda9ea394101d3e82bf..d329635c8e15f8831ab3a0691f456662958266c2 100644 (file)
@@ -39,7 +39,7 @@ namespace YACS
       void exSaveInit();
       void exRestoreInit();
       Any *getValue() const { return _value; }
-      int getIntValue() const { return _value->getIntValue(); }
+      int getIntValue() const { return _value ? _value->getIntValue():0; }
       void put(Any *data);
       void *get() const;
       virtual std::string getAsString();
index 31424ad25dfd8c0aaa9c15c82ee4877a899bb8ad..69870fa47361573d05655d249615ade665cdeb68 100644 (file)
@@ -28,7 +28,6 @@
 #include "DataStreamPort.hxx"
 #include "ElementaryNode.hxx"
 #include "ComponentInstance.hxx"
-#include "ForEachLoop.hxx"
 
 #include <iostream>
 #include <set>
@@ -1135,43 +1134,18 @@ 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<pair<int,int> > 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> ComposedNode::getProgressWeight() const
+{
+  list<ProgressWeight> ret;
+  list<Node *> setOfNode=edGetDirectDescendants();
+  for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
+    {
+      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..a2dd127df25324571d0b3591038c75fd6c90e9a0 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..3b9dec62cb8baa4e7fe63f4971cda31e067cb6ab 100644 (file)
@@ -741,6 +741,7 @@ YACS::Event ForEachLoop::updateStateForInitNodeOnFinishedEventFrom(Node *node, u
   _execNodes[id]->exUpdateState();
   _nbOfEltConsumed++;
   _initializingCounter--;
+  _currentIndex++;
   if (_initializingCounter == 0)
     _initNode->setState(DONE);
   return YACS::NOEVENT;
@@ -1103,9 +1104,36 @@ 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();
+  int nbBranches = _nbOfBranches.getIntValue();
+  return _splitterNode.getNumberOfElements()
+         + (_initNode ? nbBranches:0)
+         + (_finalizeNode ? nbBranches:0) ;
 }
 
 /*!
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..140a949828c5c75c5e11deefbbf7797294a1b09c 100644 (file)
@@ -265,17 +265,51 @@ 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..2eaaddaebe1799ec09b25fb53ee6be51f3f25c23 100644 (file)
@@ -232,17 +232,17 @@ std::string Proc::getNodeProgress(int numId)
 
 int Proc::getGlobalProgressPercent()
 {
-       list<pair <int,int> > 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++)
-         {
-                 weightDone += (*iter).first;
-                       weightTotal += (*iter).second;
-         }
+  list<ProgressWeight> weightList = getProgressWeight();
+  int weightDone = 0;
+  int weightTotal = 0;
+  int progressPercent = 0;
+  for(list<ProgressWeight>::const_iterator iter=weightList.begin();iter!=weightList.end();iter++)
+    {
+      weightDone += (*iter).weightDone;
+      weightTotal += (*iter).weightTotal;
+    }
   if (weightTotal > 0)
-       progressPercent = int(float(weightDone) / float(weightTotal) * 100);
+    progressPercent = int(float(weightDone) / float(weightTotal) * 100);
   return progressPercent;
 }
 
index f06d6d86b02a18677bcbbbc0c1cdb5dbf5790cc9..571d6a1266bde6a79f187b0e48c806fa30c03be1 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
 
diff --git a/src/yacsloader_swig/Test/testProgress.py b/src/yacsloader_swig/Test/testProgress.py
new file mode 100755 (executable)
index 0000000..ca8cee5
--- /dev/null
@@ -0,0 +1,141 @@
+# Copyright (C) 2006-2015  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
+#
+
+import sys
+import pilot
+import SALOMERuntime
+import loader
+import unittest
+
+class TestEdit(unittest.TestCase):
+
+    def setUp(self):
+        SALOMERuntime.RuntimeSALOME_setRuntime()
+        self.r = pilot.getRuntime()
+        self.l = loader.YACSLoader()
+        self.e = pilot.ExecutorSwig()
+        pass
+
+    def test_progress(self):
+  
+        p=self.r.createProc("pr")
+        ti=p.getTypeCode("int")
+        td=p.getTypeCode("double")
+        ts=p.getTypeCode("string")
+
+        #BLOC
+        b=self.r.createBloc("b1")
+        p.edAddChild(b)
+        n1=self.r.createScriptNode("","node1")
+        b.edAddChild(n1)
+        n1.setScript("p1=p1+10")
+        n1.edAddInputPort("p1",ti)
+        n1.edAddOutputPort("p1",ti)
+        n2=self.r.createScriptNode("","node2")
+        b.edAddChild(n2)
+        n2.setScript("p1=2*p1")
+        n2.edAddInputPort("p1",ti)
+        n2.edAddOutputPort("p1",ti)
+        b.edAddDFLink(n1.getOutputPort("p1"),n2.getInputPort("p1"))
+        #initialisation ports
+        n1.getInputPort("p1").edInitPy(5)
+
+        #FOR LOOP
+        loop=self.r.createForLoop("l1")
+        p.edAddChild(loop)
+        ip=loop.getInputPort("nsteps")
+        ip.edInitPy(3)
+        n10=self.r.createScriptNode("","node10")
+        loop.edSetNode(n10)
+        n10.setScript("p1=p1+10")
+        n10.edAddInputPort("p1",ti)
+        n10.edAddOutputPort("p1",ti)
+        n10.getInputPort("p1").edInitPy(5)
+        
+
+        #WHILE LOOP
+        wh=self.r.createWhileLoop("w1")
+        p.edAddChild(wh)
+        n20=self.r.createScriptNode("","node3")
+        n20.setScript("p1=0")
+        n20.edAddOutputPort("p1",ti)
+        wh.edSetNode(n20)
+        cport=wh.getInputPort("condition")
+        cport.edInitBool(True)
+        p.edAddLink(n20.getOutputPort("p1"),cport)
+
+
+        #FOR EACH LOOP
+        fe=self.r.createForEachLoop("fe1",td)
+        p.edAddChild(fe)
+        n30=self.r.createScriptNode("","node3")
+        n30.setScript("import time \ntime.sleep(1) \np1=p1+3.\n")
+        n30.edAddInputPort("p1",td)
+        n30.edAddOutputPort("p1",td)
+        fe.edSetNode(n30)
+        p.edAddLink(fe.getOutputPort("evalSamples"),n30.getInputPort("p1"))
+        fe.getInputPort("nbBranches").edInitPy(2)
+        fe.getInputPort("SmplsCollection").edInitPy([1.,2.,3.,4.,5.,6.])
+
+        #SWITCH
+        n40=self.r.createScriptNode("","node3")
+        n40.setScript("p1=3.5")
+        n40.edAddOutputPort("p1",td)
+        p.edAddChild(n40)
+        #switch
+        sw=self.r.createSwitch("sw1")
+        p.edAddChild(sw)
+        nk1=self.r.createScriptNode("","ncas1")
+        nk1.setScript("p1=p1+3.")
+        nk1.edAddInputPort("p1",td)
+        nk1.edAddOutputPort("p1",td)
+        sw.edSetNode(1,nk1)
+        ndef=self.r.createScriptNode("","ndefault")
+        ndef.setScript("p1=p1+5.")
+        ndef.edAddInputPort("p1",td)
+        ndef.edAddOutputPort("p1",td)
+        sw.edSetDefaultNode(ndef)
+        #initialise the select port
+        sw.getInputPort("select").edInitPy(1)
+        #connection of internal nodes
+        p.edAddDFLink(n40.getOutputPort("p1"),nk1.getInputPort("p1"))
+        p.edAddDFLink(n40.getOutputPort("p1"),ndef.getInputPort("p1"))
+
+        import time
+        import threading
+        self.assertEqual(p.getGlobalProgressPercent(),0)
+        self.assertEqual(p.getState(),pilot.READY)
+        myRun = threading.Thread(None, self.e.RunW, None, (p,0))
+        myRun.start()
+        time.sleep(1.5)
+        self.assertGreater(p.getGlobalProgressPercent(),0)
+        self.assertLess(p.getGlobalProgressPercent(),100)
+        myRun.join()
+        self.assertEqual(p.getState(),pilot.DONE)
+        self.assertEqual(p.getGlobalProgressPercent(),100)
+         
+if __name__ == '__main__':
+  import os
+  U = os.getenv('USER')
+  f=open("/tmp/" + U + "/UnitTestsResult", 'a')
+  f.write("  --- TEST src/yacsloader: testProgress.py\n")
+  suite = unittest.makeSuite(TestEdit)
+  result=unittest.TextTestRunner(f, descriptions=1, verbosity=3).run(suite)
+  f.close()
+  sys.exit(not result.wasSuccessful())