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();
#include "DataStreamPort.hxx"
#include "ElementaryNode.hxx"
#include "ComponentInstance.hxx"
-#include "ForEachLoop.hxx"
#include <iostream>
#include <set>
//! 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;
}
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);
//
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;
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;
_execNodes[id]->exUpdateState();
_nbOfEltConsumed++;
_initializingCounter--;
+ _currentIndex++;
if (_initializingCounter == 0)
_initNode->setState(DONE);
return YACS::NOEVENT;
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) ;
}
/*!
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
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;
+}
+
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,
class OutputDataStreamPort;
class Visitor;
+ struct ProgressWeight
+ {
+ int weightDone;
+ int weightTotal;
+ };
+
class YACSLIBENGINE_EXPORT NodeStateNameMap : public std::map<YACS::StatesForNode, std::string>
{
public:
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;
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;
}
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;
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;
testSaveLoadRun.py
optim_plugin.py
testValidationChecks.py
+ testProgress.py
)
INSTALL(FILES ${LOCAL_TEST_FILES}
DESTINATION ${LOCAL_TEST_DIR})
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
--- /dev/null
+# 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())