From da3dd7789921cfccb7a2845bffe4ecb2f5c28f5e Mon Sep 17 00:00:00 2001 From: Lauffenburger Thomas Date: Wed, 9 Sep 2015 13:29:14 +0200 Subject: [PATCH] refactoring calculation progress meth --- src/engine/ComposedNode.cxx | 38 +++------------- src/engine/ComposedNode.hxx | 2 +- src/engine/ElementaryNode.cxx | 18 ++++++++ src/engine/ElementaryNode.hxx | 1 + src/engine/ForEachLoop.cxx | 25 +++++++++++ src/engine/ForEachLoop.hxx | 1 + src/engine/ForLoop.cxx | 45 ++++++++++++++++--- src/engine/ForLoop.hxx | 3 ++ src/engine/Node.hxx | 7 +++ src/engine/Proc.cxx | 8 ++-- src/engine/Switch.cxx | 28 ++++++++++++ src/engine/Switch.hxx | 1 + src/yacsloader_swig/Test/CMakeLists.txt | 1 + .../Test/YacsLoaderInSessionTest.sh.in | 9 +++- 14 files changed, 144 insertions(+), 43 deletions(-) diff --git a/src/engine/ComposedNode.cxx b/src/engine/ComposedNode.cxx index 31424ad25..6475ef03b 100644 --- a/src/engine/ComposedNode.cxx +++ b/src/engine/ComposedNode.cxx @@ -28,7 +28,6 @@ #include "DataStreamPort.hxx" #include "ElementaryNode.hxx" #include "ComponentInstance.hxx" -#include "ForEachLoop.hxx" #include #include @@ -1135,42 +1134,17 @@ list 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 > ComposedNode::getProgressWeight() +list ComposedNode::getProgressWeight() const { - list > ret; + list ret; list setOfNode=edGetDirectDescendants(); - int elemDone, elemTotal; for(list::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++) { - if ( dynamic_cast (*iter) ) - { - elemDone=((ForEachLoop*)(*iter))->getCurrentIndex(); - elemTotal=((ForEachLoop*)(*iter))->getNbOfElementsToBeProcessed(); - list > myCurrentSet=((ComposedNode*)(*iter))->getProgressWeight(); - myCurrentSet.pop_front(); - myCurrentSet.pop_back(); - for(list >::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 (*iter) ) - { - list > myCurrentSet=((ComposedNode*)(*iter))->getProgressWeight(); - ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end()); - } - else - { - if ((*iter)->getState() == YACS::DONE) - ret.push_back(pair(1,1)); - else - ret.push_back(pair(0,1)); - } + list myCurrentSet=((ComposedNode*)(*iter))->getProgressWeight(); + ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end()); } return ret; } diff --git a/src/engine/ComposedNode.hxx b/src/engine/ComposedNode.hxx index 84e4d5555..aadd2804c 100644 --- a/src/engine/ComposedNode.hxx +++ b/src/engine/ComposedNode.hxx @@ -80,7 +80,7 @@ namespace YACS std::list getRecursiveConstituents() const; std::list getAllRecursiveNodes(); virtual std::list getAllRecursiveConstituents(); // first implementation - std::list > getProgressWeight(); + std::list getProgressWeight() const; std::string getInPortName(const InPort *) const throw (Exception); std::string getOutPortName(const OutPort *) const throw (Exception); // diff --git a/src/engine/ElementaryNode.cxx b/src/engine/ElementaryNode.cxx index 52b4e6eee..e628ae636 100644 --- a/src/engine/ElementaryNode.cxx +++ b/src/engine/ElementaryNode.cxx @@ -547,6 +547,24 @@ list 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 ElementaryNode::getProgressWeight() const +{ + list 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; diff --git a/src/engine/ElementaryNode.hxx b/src/engine/ElementaryNode.hxx index 843de41e1..07fe8a485 100644 --- a/src/engine/ElementaryNode.hxx +++ b/src/engine/ElementaryNode.hxx @@ -69,6 +69,7 @@ namespace YACS void getReadyTasks(std::vector& tasks); void edRemovePort(Port *port) throw(Exception); std::list getRecursiveConstituents() const; + std::list getProgressWeight() const; Node *getChildByName(const std::string& name) const throw(Exception); virtual void checkBasicConsistency() const throw(Exception); ComposedNode *getDynClonerIfExists(const ComposedNode *levelToStop) const; diff --git a/src/engine/ForEachLoop.cxx b/src/engine/ForEachLoop.cxx index b753f22e6..371bb8de3 100644 --- a/src/engine/ForEachLoop.cxx +++ b/src/engine/ForEachLoop.cxx @@ -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 ForEachLoop::getProgressWeight() const +{ + list ret; + list setOfNode=edGetDirectDescendants(); + int elemDone=getCurrentIndex(); + int elemTotal=getNbOfElementsToBeProcessed(); + for(list::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++) + { + list myCurrentSet=(*iter)->getProgressWeight(); + for(list::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(); diff --git a/src/engine/ForEachLoop.hxx b/src/engine/ForEachLoop.hxx index 1e0655409..d70259618 100644 --- a/src/engine/ForEachLoop.hxx +++ b/src/engine/ForEachLoop.hxx @@ -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 getProgressWeight() const; int getCurrentIndex() const { return _currentIndex; } int getNbOfElementsToBeProcessed() const; #ifndef SWIG diff --git a/src/engine/ForLoop.cxx b/src/engine/ForLoop.cxx index fe4564490..94e3167b2 100644 --- a/src/engine/ForLoop.cxx +++ b/src/engine/ForLoop.cxx @@ -265,17 +265,52 @@ std::list 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 ForLoop::getProgressWeight() const +{ + list ret; + list setOfNode=edGetDirectDescendants(); + int nbStepsDone=getNbOfTurns(); + int nbStepsTotal=getNbSteps(); + for(list::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++) + { + list myCurrentSet=(*iter)->getProgressWeight(); + for(list::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; +} + diff --git a/src/engine/ForLoop.hxx b/src/engine/ForLoop.hxx index e00c271ba..3d33e0626 100644 --- a/src/engine/ForLoop.hxx +++ b/src/engine/ForLoop.hxx @@ -55,6 +55,9 @@ namespace YACS OutputPort *edGetIndexPort() { return &_indexPort; } virtual std::string typeName() {return "YACS__ENGINE__ForLoop";} std::string getProgress() const; + std::list getProgressWeight() const; + int getNbSteps() const; + protected: YACS::Event updateStateOnFinishedEventFrom(Node *node); void checkCFLinks(const std::list& starts, InputPort *end, unsigned char& alreadyFed, diff --git a/src/engine/Node.hxx b/src/engine/Node.hxx index c724fb605..e94b0a4ad 100644 --- a/src/engine/Node.hxx +++ b/src/engine/Node.hxx @@ -52,6 +52,12 @@ namespace YACS class OutputDataStreamPort; class Visitor; + struct ProgressWeight + { + int weightDone; + int weightTotal; + }; + class YACSLIBENGINE_EXPORT NodeStateNameMap : public std::map { public: @@ -125,6 +131,7 @@ namespace YACS virtual void exDisabledState(); virtual void getReadyTasks(std::vector& tasks) = 0; virtual std::list getRecursiveConstituents() const = 0; + virtual std::list getProgressWeight() const = 0; virtual int getNumberOfInputPorts() const = 0; virtual int getNumberOfOutputPorts() const = 0; std::list getSetOfInPort() const; diff --git a/src/engine/Proc.cxx b/src/engine/Proc.cxx index 4cb742955..7e777d22f 100644 --- a/src/engine/Proc.cxx +++ b/src/engine/Proc.cxx @@ -232,14 +232,14 @@ std::string Proc::getNodeProgress(int numId) int Proc::getGlobalProgressPercent() { - list > weightList = getProgressWeight(); + list weightList = getProgressWeight(); int weightDone = 0; int weightTotal = 0; int progressPercent = 0; - for(list >::const_iterator iter=weightList.begin();iter!=weightList.end();iter++) + for(list::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); diff --git a/src/engine/Switch.cxx b/src/engine/Switch.cxx index f06d6d86b..c196cc2db 100644 --- a/src/engine/Switch.cxx +++ b/src/engine/Switch.cxx @@ -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 Switch::getProgressWeight() const +{ + list ret; + list setOfNode=edGetDirectDescendants(); + if (getState() == YACS::DONE) + { + for(list::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++) + { + if (getEffectiveState(*iter) == YACS::DONE) + ret=(*iter)->getProgressWeight(); + } + } + else + { + for(list::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++) + { + list 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; diff --git a/src/engine/Switch.hxx b/src/engine/Switch.hxx index 4d6670d13..cc1471309 100644 --- a/src/engine/Switch.hxx +++ b/src/engine/Switch.hxx @@ -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 getProgressWeight() const; protected: YACS::Event updateStateOnFinishedEventFrom(Node *node); Node *simpleClone(ComposedNode *father, bool editionOnly=true) const; diff --git a/src/yacsloader_swig/Test/CMakeLists.txt b/src/yacsloader_swig/Test/CMakeLists.txt index 4af457d6f..2b7aefabc 100644 --- a/src/yacsloader_swig/Test/CMakeLists.txt +++ b/src/yacsloader_swig/Test/CMakeLists.txt @@ -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}) diff --git a/src/yacsloader_swig/Test/YacsLoaderInSessionTest.sh.in b/src/yacsloader_swig/Test/YacsLoaderInSessionTest.sh.in index 0229f6d41..edaad8e53 100644 --- a/src/yacsloader_swig/Test/YacsLoaderInSessionTest.sh.in +++ b/src/yacsloader_swig/Test/YacsLoaderInSessionTest.sh.in @@ -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 -- 2.30.2