#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<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;
}
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;
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();
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();
+ 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);
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