1 // Copyright (C) 2006-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "LinkInfo.hxx"
22 #include "InputPort.hxx"
23 #include "InputDataStreamPort.hxx"
24 #include "OutputPort.hxx"
25 #include "OutputDataStreamPort.hxx"
26 #include "ElementaryNode.hxx"
27 #include "Visitor.hxx"
32 #include "YacsTrace.hxx"
34 using namespace YACS::ENGINE;
37 /*! \class YACS::ENGINE::Bloc
38 * \brief Composed node to group elementary and composed nodes
43 Bloc::Bloc(const Bloc& other, ComposedNode *father, bool editionOnly):StaticDefinedComposedNode(other,father),_fwLinks(0),_bwLinks(0)
45 for(list<Node *>::const_iterator iter=other._setOfNode.begin();iter!=other._setOfNode.end();iter++)
46 _setOfNode.push_back((*iter)->simpleClone(this,editionOnly));
49 vector< pair<OutGate *, InGate *> > cfLinksToReproduce=other.getSetOfInternalCFLinks();
50 vector< pair<OutGate *, InGate *> >::iterator iter1=cfLinksToReproduce.begin();
51 for(;iter1!=cfLinksToReproduce.end();iter1++)
52 edAddCFLink(getChildByName(other.getChildName((*iter1).first->getNode())),getChildByName(other.getChildName((*iter1).second->getNode())));
54 //Data + DataStream linking
55 vector< pair<OutPort *, InPort *> > linksToReproduce=other.getSetOfInternalLinks();
56 vector< pair<OutPort *, InPort *> >::iterator iter2=linksToReproduce.begin();
57 for(;iter2!=linksToReproduce.end();iter2++)
59 OutPort* pout = iter2->first;
60 InPort* pin = iter2->second;
61 edAddLink(getOutPort(other.getPortName(pout)),getInPort(other.getPortName(pin)));
65 //! Create a Bloc node with a given name
67 * \param name : the given name
69 Bloc::Bloc(const std::string& name):StaticDefinedComposedNode(name),_fwLinks(0),_bwLinks(0)
75 for(list<Node *>::iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++)
81 //! Initialize the bloc
83 * \param start : a boolean flag indicating the kind of initialization
84 * If start is true, it's a complete initialization with reinitialization of port values
85 * If start is false, there is no initialization of port values
87 void Bloc::init(bool start)
90 for(list<Node *>::iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++)
94 //! Indicate if the bloc execution is finished
96 * The execution bloc is finished if all its child nodes
97 * are finished with or without error or if it is disabled (not to execute)
99 bool Bloc::isFinished()
101 if(_state==YACS::DONE)return true;
102 if(_state==YACS::ERROR)return true;
103 if(_state==YACS::FAILED)return true;
104 if(_state==YACS::DISABLED)return true;
108 int Bloc::getNumberOfCFLinks() const
111 for(list<Node *>::const_iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++)
112 ret+=(*iter)->getOutGate()->getNbOfInGatesConnected();
116 Node *Bloc::simpleClone(ComposedNode *father, bool editionOnly) const
118 return new Bloc(*this,father,editionOnly);
121 //! Collect all nodes that are ready to execute
123 * \param tasks : vector of tasks to collect ready nodes
125 void Bloc::getReadyTasks(std::vector<Task *>& tasks)
128 * ComposedNode state goes to ACTIVATED when one of its child has been ACTIVATED
129 * To change this uncomment the following line
130 * Then the father node will go to ACTIVATED state before its child node
132 if(_state==YACS::TOACTIVATE ) setState(YACS::ACTIVATED);
133 if(_state==YACS::TOACTIVATE || _state==YACS::ACTIVATED)
134 for(list<Node *>::iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++)
135 (*iter)->getReadyTasks(tasks);
138 //! Update the bloc state
140 * Update the '_state' attribute.
141 * Typically called by 'this->_inGate' when 'this->_inGate' is ready.
142 * Contrary to Node::exUpdateState no check done on inputs
143 * because internal linked DF inputports are not valid yet.
145 void Bloc::exUpdateState()
147 if(_state == YACS::DISABLED)return;
148 if(_state == YACS::DONE)return;
149 if(_inGate.exIsReady())
151 setState(YACS::ACTIVATED);
152 for(list<Node *>::iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++)
153 if((*iter)->exIsControlReady())
154 (*iter)->exUpdateState();
158 //! Add a child node to the bloc
160 * \param node: the node to add to the bloc
161 * \return a boolean flag indicating if the node has been added
163 * If node is already a direct child of current bloc, do nothing.
164 * If node is a child of another bloc, throw exception.
165 * If node name already used in bloc, throw exception.
166 * Publish inputPorts in current bloc and ancestors.
168 bool Bloc::edAddChild(Node *node) throw(YACS::Exception)
170 if(isNodeAlreadyAggregated(node))
172 if(node->_father==this)
176 string what = "Bloc::edAddChild : node "; what += node->getName();
177 what += " is already grand children of node";
178 throw Exception(what);
184 string what = "Bloc::edAddChild: node is not orphan: "; what += node->getName();
185 throw Exception(what);
188 checkNoCrossHierachyWith(node);
190 if(isNameAlreadyUsed(node->getName()))
192 string what("Bloc::edAddChild : name "); what+=node->getName();
193 what+=" already exists in the scope of "; what+=_name;
194 throw Exception(what);
198 _setOfNode.push_back(node);
199 //should we also set _modified flag for node ??
200 ComposedNode *iter=node->_father;
201 //set the _modified flag so that latter on edUpdateState (eventually called by isValid) refresh state
202 //better call it at end
208 * Remove 'node' from the set of direct children.
209 * @exception If 'node' is NOT the son of 'this'.
212 void Bloc::edRemoveChild(Node *node) throw(YACS::Exception)
214 StaticDefinedComposedNode::edRemoveChild(node);
215 list<Node *>::iterator iter=find(_setOfNode.begin(),_setOfNode.end(),node);
216 if(iter!=_setOfNode.end())
218 _setOfNode.erase(iter);
223 Node *Bloc::getChildByShortName(const std::string& name) const throw(YACS::Exception)
225 for (list<Node *>::const_iterator iter = _setOfNode.begin(); iter != _setOfNode.end(); iter++)
226 if ((*iter)->getName() == name)
228 string what("node "); what+= name ; what+=" is not a child of Bloc "; what += getName();
229 throw Exception(what);
232 bool Bloc::areAllSubNodesDone() const
234 for(list<Node *>::const_iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++)
236 if((*iter)->_state == YACS::DONE)continue;
237 if((*iter)->_state == YACS::DISABLED)continue;
243 bool Bloc::areAllSubNodesFinished() const
245 for(list<Node *>::const_iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++)
247 if((*iter)->_state == YACS::DONE)continue;
248 if((*iter)->_state == YACS::FAILED)continue;
249 if((*iter)->_state == YACS::DISABLED)continue;
250 if((*iter)->_state == YACS::ERROR)continue;
251 if((*iter)->_state == YACS::INTERNALERR)continue;
257 bool Bloc::isNameAlreadyUsed(const std::string& name) const
259 for(list<Node *>::const_iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++)
260 if((*iter)->getName()==name)
265 bool insertNodeChildrenInSet(Node *node, std::set<Node *>& nodeSet)
268 set<Node *> outNodes=node->getOutNodes();
269 for (set<Node *>::iterator iter=outNodes.begin();iter!=outNodes.end(); iter++)
271 verdict=(nodeSet.insert(*iter)).second;
272 if (verdict) verdict = insertNodeChildrenInSet((*iter),nodeSet);
278 * \note Checks that in the forest from 'node' there are NO back-edges.
279 * \b WARNING : When using this method 'node' has to be checked in order to be part of direct children of 'this'.
282 void Bloc::checkNoCyclePassingThrough(Node *node) throw(YACS::Exception)
284 set<Node *> currentNodesToTest;
285 //don't insert node to test in set.
286 //If it is present after insertion of connected nodes we have a loop
287 //collect all connected nodes
288 insertNodeChildrenInSet(node,currentNodesToTest);
290 if(!(currentNodesToTest.insert(node)).second)
291 throw Exception("Cycle has been detected",1);
294 std::vector< std::pair<OutGate *, InGate *> > Bloc::getSetOfInternalCFLinks() const
296 vector< pair<OutGate *, InGate *> > ret;
297 for(list<Node *>::const_iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++)
299 set<InGate *> outCFLinksOfCurNode=(*iter)->_outGate.edSetInGate();
300 for(set<InGate *>::iterator iter2=outCFLinksOfCurNode.begin();iter2!=outCFLinksOfCurNode.end();iter2++)
301 ret.push_back(pair<OutGate *, InGate *>(&(*iter)->_outGate,*iter2));
308 * @note : Runtime called method. Indirectly called by StaticDefinedComposedNode::updateStateFrom which has dispatch to this method
309 * 'when event == FINISH'.
310 * WARNING Precondition : '_state == Running' and 'node->_father==this'(garanteed by StaticDefinedComposedNode::notifyFrom)
312 * Calls the node's outgate OutGate::exNotifyDone if all nodes are not finished
314 YACS::Event Bloc::updateStateOnFinishedEventFrom(Node *node)
316 DEBTRACE("Bloc::updateStateOnFinishedEventFrom: " << node->getName());
317 //ASSERT(node->_father==this)
318 if(areAllSubNodesFinished())
320 setState(YACS::DONE);
321 if(!areAllSubNodesDone())
323 setState(YACS::FAILED);
326 return YACS::FINISH;//notify to father node that 'this' has becomed finished.
328 //more job to do in 'this' bloc
329 //Conversion exceptions can be thrown so catch them to control errors
332 //notify the finished node to propagate to its following nodes
333 node->exForwardFinished();
335 catch(YACS::Exception& ex)
337 //The node has failed to propagate. It must be put in error
338 DEBTRACE("Bloc::updateStateOnFinishedEventFrom: " << ex.what());
339 // notify the node it has failed
340 node->exForwardFailed();
341 setState(YACS::FAILED);
344 return YACS::NOEVENT;//no notification to father needed because from father point of view nothing happened.
347 //! Notify this bloc that a node has failed
349 * \param node : node that has emitted the event
350 * \return the event to notify to bloc's father
352 YACS::Event Bloc::updateStateOnFailedEventFrom(Node *node)
354 node->exForwardFailed();
355 if(areAllSubNodesFinished())
357 setState(YACS::DONE);
358 if(!areAllSubNodesDone()){
359 setState(YACS::FAILED);
362 return YACS::FINISH;//notify to father node that 'this' has becomed finished.
364 return YACS::NOEVENT;
367 void Bloc::writeDot(std::ostream &os) const
369 os << " subgraph cluster_" << getId() << " {\n" ;
370 list<Node *>nodes=getChildren();
371 for(list<Node *>::const_iterator iter=nodes.begin();iter!=nodes.end();iter++)
373 (*iter)->writeDot(os);
374 string p=(*iter)->getId();
376 if((*iter)->_inGate._backLinks.size() == 0) os << getId() << " -> " << p << ";\n";
377 set<Node *>outnodes = (*iter)->getOutNodes();
378 for(set<Node *>::const_iterator itout=outnodes.begin();itout!=outnodes.end();itout++)
380 os << p << " -> " << (*itout)->getId() << ";\n";
384 os << getId() << "[fillcolor=\"" ;
385 YACS::StatesForNode state=getEffectiveState();
386 os << getColorState(state);
387 os << "\" label=\"" << "Bloc:" ;
388 os << getQualifiedName() <<"\"];\n";
391 void Bloc::accept(Visitor* visitor)
393 visitor->visitBloc(this);
397 * Updates mutable structures _fwLinks and _bwLinks with the result of computation (CPU consuming method).
398 * _fwLinks is a map with a Node* as key and a set<Node*> as value. The set gives
399 * all nodes that are forwardly connected to the key node
400 * _bwLinks is a map for backward dependencies
401 * The method is : for all CF link (n1->n2)
402 * add n2 and _fwLinks[n2] in forward dependencies of n1 and _bwLinks[n1]
403 * add n1 and _bwLinks[n1] in backward dependencies of n2 and _fwLinks[n2]
405 * If a node is already in a forward dependency when adding and the direct link
406 * already exists so it's a useless link (see the code !)
408 void Bloc::performCFComputations(LinkInfo& info) const
410 StaticDefinedComposedNode::performCFComputations(info);
411 delete _fwLinks;//Normally useless
412 delete _bwLinks;//Normally useless
413 _fwLinks=new map<Node *,set<Node *> >;
414 _bwLinks=new map<Node *,set<Node *> >;
416 //a set to store all CF links : used to find fastly if two nodes are connected
417 std::set< std::pair< Node*, Node* > > links;
419 for(list<Node *>::const_iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++)
422 std::set<InGate *> ingates=n1->getOutGate()->edSetInGate();
423 for(std::set<InGate *>::const_iterator it2=ingates.begin();it2!=ingates.end();it2++)
425 //CF link : n1 -> (*it2)->getNode()
426 Node* n2=(*it2)->getNode();
427 links.insert(std::pair< Node*, Node* >(n1,n2));
428 std::set<Node *> bwn1=(*_bwLinks)[n1];
429 std::set<Node *> fwn1=(*_fwLinks)[n1];
430 std::set<Node *> fwn2=(*_fwLinks)[n2];
431 std::set<Node *> bwn2=(*_bwLinks)[n2];
432 std::pair<std::set<Node*>::iterator,bool> ret;
433 for(std::set<Node *>::const_iterator iter2=bwn1.begin();iter2!=bwn1.end();iter2++)
435 for(std::set<Node *>::const_iterator it3=fwn2.begin();it3!=fwn2.end();it3++)
437 ret=(*_fwLinks)[*iter2].insert(*it3);
438 if(ret.second==false)
440 //dependency already exists (*iter2) -> (*it3) : if a direct link exists it's a useless one
441 if(links.find(std::pair< Node*, Node* >(*iter2,*it3)) != links.end())
442 info.pushUselessCFLink(*iter2,*it3);
445 ret=(*_fwLinks)[*iter2].insert(n2);
446 if(ret.second==false)
448 //dependency already exists (*iter2) -> n2 : if a direct link exists it's a useless one
449 if(links.find(std::pair< Node*, Node* >(*iter2,n2)) != links.end())
450 info.pushUselessCFLink(*iter2,n2);
453 for(std::set<Node *>::const_iterator it3=fwn2.begin();it3!=fwn2.end();it3++)
455 ret=(*_fwLinks)[n1].insert(*it3);
456 if(ret.second==false)
458 //dependency already exists n1 -> *it3 : if a direct link exists it's a useless one
459 if(links.find(std::pair< Node*, Node* >(n1,*it3)) != links.end())
460 info.pushUselessCFLink(n1,*it3);
463 ret=(*_fwLinks)[n1].insert(n2);
464 if(ret.second==false)
466 //dependency already exists n1 -> n2 : it's a useless link
467 info.pushUselessCFLink(n1,n2);
470 for(std::set<Node *>::const_iterator iter2=fwn2.begin();iter2!=fwn2.end();iter2++)
472 (*_bwLinks)[*iter2].insert(bwn1.begin(),bwn1.end());
473 (*_bwLinks)[*iter2].insert(n1);
475 (*_bwLinks)[n2].insert(bwn1.begin(),bwn1.end());
476 (*_bwLinks)[n2].insert(n1);
481 void Bloc::destructCFComputations(LinkInfo& info) const
483 StaticDefinedComposedNode::destructCFComputations(info);
484 delete _fwLinks; _fwLinks=0;
485 delete _bwLinks; _bwLinks=0;
489 * \b WARNING \b Needs call of performCFComputations before beeing called.
490 * Perform updates of containers regarding attributes of link 'start' -> 'end' and check the correct linking.
491 * The output is in info struct.
493 * \param start : start port
494 * \param end : end port
496 * \param fw out parameter being append if start -> end link is a forward link \b without cross type DF/DS.
497 * \param fwCross out parameter being append if start -> end link is a forward link \b with cross type DF/DS.
498 * \param bw out parameter being append if start -> end link is a backward link.
499 * \param info out parameter being informed about eventual errors.
501 void Bloc::checkControlDependancy(OutPort *start, InPort *end, bool cross,
502 std::map < ComposedNode *, std::list < OutPort * >, SortHierarc >& fw,
503 std::vector<OutPort *>& fwCross,
504 std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
505 LinkInfo& info) const
509 Node *startN=isInMyDescendance(start->getNode());
510 Node *endN=isInMyDescendance(end->getNode());
512 bw[(ComposedNode *)this].push_back(start);
513 else if(areLinked(startN,endN,true))
514 fw[(ComposedNode *)this].push_back(start);
516 if(areLinked(startN,endN,false))
517 bw[(ComposedNode *)this].push_back(start);
519 info.pushErrLink(start,end,E_UNPREDICTABLE_FED);
522 if(arePossiblyRunnableAtSameTime(isInMyDescendance(start->getNode()),isInMyDescendance(end->getNode())))
523 fwCross.push_back(start);
525 info.pushErrLink(start,end,E_DS_LINK_UNESTABLISHABLE);
528 //! Check if two nodes are linked
530 * 'start' and 'end' \b must be direct son of 'this'.
531 * Typically used for data link.
532 * \param start : start node
533 * \param end : end node
534 * \param fw indicates if it is a forward link searched (true : default value) or a backward link serach.
535 * \return if true or false
537 bool Bloc::areLinked(Node *start, Node *end, bool fw) const
539 set<Node *>& nexts=fw ? (*_fwLinks)[start] : (*_bwLinks)[start];
540 return nexts.find(end)!=nexts.end();
543 //! Check if two nodes can run in parallel
545 * Typically used for stream link.
546 * 'start' and 'end' \b must be direct son of 'this'.
547 * \param start : start node
548 * \param end : end node
549 * \return true or false
551 bool Bloc::arePossiblyRunnableAtSameTime(Node *start, Node *end) const
553 set<Node *>& nexts=(*_fwLinks)[start];
554 set<Node *>& preds=(*_bwLinks)[start];
555 return nexts.find(end)==nexts.end() && preds.find(end)==preds.end();
558 //! Check control flow links
560 * \param starts If different of 0, must aggregate at leat \b 1 element.
561 * \param end : end port
562 * \param alreadyFed in/out parameter. Indicates if 'end' ports is already and surely set or fed by an another port.
563 * \param direction If true : forward direction else backward direction.
564 * \param info : collected information
566 void Bloc::checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const
568 if(alreadyFed==FREE_ST || alreadyFed==FED_ST)
570 map<Node *,list <OutPort *> > classPerNodes;
571 for(list< OutPort *>::const_iterator iter1=starts.begin();iter1!=starts.end();iter1++)
572 classPerNodes[isInMyDescendance((*iter1)->getNode())].push_back(*iter1);
573 set<Node *> allNodes;
574 for(map<Node *,list <OutPort *> >::iterator iter2=classPerNodes.begin();iter2!=classPerNodes.end();iter2++)
575 allNodes.insert((*iter2).first);
576 vector<Node *> okAndUseless1,useless2;
577 seekOkAndUseless1(okAndUseless1,allNodes);
578 seekUseless2(useless2,allNodes);//after this point allNodes contains collapses
579 verdictForOkAndUseless1(classPerNodes,end,okAndUseless1,alreadyFed,direction,info);
580 verdictForCollapses(classPerNodes,end,allNodes,alreadyFed,direction,info);
581 verdictForOkAndUseless1(classPerNodes,end,useless2,alreadyFed,direction,info);
583 else if(alreadyFed==FED_DS_ST)
584 for(list< OutPort *>::const_iterator iter1=starts.begin();iter1!=starts.end();iter1++)
585 info.pushErrLink(*iter1,end,E_COLLAPSE_DFDS);
588 void Bloc::initComputation() const
590 for(list<Node *>::const_iterator iter=_setOfNode.begin();iter!=_setOfNode.end();iter++)
592 (*iter)->_colour=White;
593 (*iter)->getInGate()->exReset();
594 (*iter)->getOutGate()->exReset();
599 * Part of final step for CF graph anylizing. This is the part of non collapse nodes.
602 * \param candidates :
603 * \param alreadyFed in/out parameter. Indicates if 'end' ports is already and surely set or fed by an another port.
605 * \param info : collected information
607 void Bloc::verdictForOkAndUseless1(const std::map<Node *,std::list <OutPort *> >& pool, InputPort *end,
608 const std::vector<Node *>& candidates, unsigned char& alreadyFed,
609 bool direction, LinkInfo& info)
611 for(vector<Node *>::const_iterator iter=candidates.begin();iter!=candidates.end();iter++)
613 const list<OutPort *>& mySet=(*pool.find(*iter)).second;
616 if(alreadyFed==FREE_ST)
618 alreadyFed=FED_ST;//This the final choice. General case !
620 info.pushInfoLink(*(mySet.begin()),end,I_BACK);
622 else if(alreadyFed==FED_ST)
623 info.pushInfoLink(*(mySet.begin()),end,direction ? I_USELESS : I_BACK_USELESS);//Second or more turn in case of alreadyFed==FREE_ST before call of this method
627 if(dynamic_cast<ElementaryNode *>(*iter))
630 if(alreadyFed==FREE_ST)
631 reason=direction ? W_COLLAPSE_EL : W_BACK_COLLAPSE_EL;
632 else if(alreadyFed==FED_ST)
633 reason=direction ? W_COLLAPSE_EL_AND_USELESS : W_BACK_COLLAPSE_EL_AND_USELESS;
634 for(list<OutPort *>::const_iterator iter2=mySet.begin();iter2!=mySet.end();iter2++)
635 info.pushWarnLink(*iter2,end,reason);
638 ((ComposedNode *)(*iter))->checkCFLinks(mySet,end,alreadyFed,direction,info);//Thanks to recursive model!
644 * Part of final step for CF graph anylizing. This is the part of collapses nodes.
647 * \param candidates :
648 * \param alreadyFed in/out parameter. Indicates if 'end' ports is already and surely set or fed by an another port.
650 * \param info : collected information
652 void Bloc::verdictForCollapses(const std::map<Node *,std::list <OutPort *> >& pool, InputPort *end,
653 const std::set<Node *>& candidates, unsigned char& alreadyFed,
654 bool direction, LinkInfo& info)
656 info.startCollapseTransac();
657 for(set<Node *>::const_iterator iter=candidates.begin();iter!=candidates.end();iter++)
659 const list<OutPort *>& mySet=(*pool.find(*iter)).second;
662 if(alreadyFed==FREE_ST)
663 info.pushWarnLink(*(mySet.begin()),end,direction ? W_COLLAPSE : W_BACK_COLLAPSE);
664 else if(alreadyFed==FED_ST)
665 info.pushWarnLink(*(mySet.begin()),end,direction ? W_COLLAPSE_AND_USELESS : W_BACK_COLLAPSE_EL_AND_USELESS);
669 if(dynamic_cast<ElementaryNode *>(*iter))
672 if(alreadyFed==FREE_ST)
673 reason=direction ? W_COLLAPSE_EL : W_BACK_COLLAPSE_EL;
674 else if(alreadyFed==FED_ST)
675 reason=direction ? W_COLLAPSE_EL_AND_USELESS : W_BACK_COLLAPSE_EL_AND_USELESS;
676 for(list<OutPort *>::const_iterator iter2=mySet.begin();iter2!=mySet.end();iter2++)
677 info.pushWarnLink(*iter2,end,reason);
681 ((ComposedNode *)(*iter))->checkCFLinks(mySet,end,alreadyFed,direction,info);//Thanks to recursive model!
683 if(alreadyFed==FREE_ST)
684 reason=direction ? W_COLLAPSE : W_BACK_COLLAPSE;
685 else if(alreadyFed==FED_ST)
686 reason=direction ? W_COLLAPSE_AND_USELESS : W_BACK_COLLAPSE_AND_USELESS;
687 for(list<OutPort *>::const_iterator iter2=mySet.begin();iter2!=mySet.end();iter2++)
688 info.pushWarnLink(*iter2,end,reason);
692 if(!candidates.empty())
693 if(alreadyFed==FREE_ST)
695 info.endCollapseTransac();
699 * \b WARNING use this method only after having called Bloc::performCFComputations method.
700 * \param okAndUseless1 out param contains at the end, the nodes without any collapse.
701 * \param allNodes in/out param. At the end, all the nodes in 'okAndUseless1' are deleted from 'allNodes'.
703 void Bloc::seekOkAndUseless1(std::vector<Node *>& okAndUseless1, std::set<Node *>& allNodes) const
705 set<Node *>::iterator iter=allNodes.begin();
706 while(iter!=allNodes.end())
708 set<Node *>& whereToFind=(*_bwLinks)[*iter];
709 std::set<Node *>::iterator iter2;
710 for(iter2=allNodes.begin();iter2!=allNodes.end();iter2++)
711 if((*iter)!=(*iter2))
712 if(whereToFind.find(*iter2)==whereToFind.end())
714 if(iter2!=allNodes.end())
718 okAndUseless1.push_back((*iter));
719 allNodes.erase(iter);
720 iter=allNodes.begin();
726 * \b WARNING use this method only after having called Bloc::performCFComputations method.
727 * For params see Bloc::seekOkAndUseless1.
729 void Bloc::seekUseless2(std::vector<Node *>& useless2, std::set<Node *>& allNodes) const
731 set<Node *>::iterator iter=allNodes.begin();
732 while(iter!=allNodes.end())
734 set<Node *>& whereToFind=(*_fwLinks)[*iter];
735 std::set<Node *>::iterator iter2;
736 for(iter2=allNodes.begin();iter2!=allNodes.end();iter2++)
737 if((*iter)!=(*iter2))
738 if(whereToFind.find(*iter2)==whereToFind.end())
740 if(iter2!=allNodes.end())
746 useless2.push_back((*iter));
747 allNodes.erase(iter);
748 iter=allNodes.begin();
754 * Internal method : Given a succeful path : updates 'fastFinder'
756 void Bloc::updateWithNewFind(const std::vector<Node *>& path, std::map<Node *, std::set<Node *> >& fastFinder)
760 vector<Node *>::const_iterator iter=path.begin(); iter++;
761 vector<Node *>::const_iterator iter2=path.end(); iter2-=1;
762 for(;iter!=iter2;iter++)
763 fastFinder[*iter].insert(*(iter+1));
768 * Internal method : After all paths have been found, useless CF links are searched
770 void Bloc::findUselessLinksIn(const std::list< std::vector<Node *> >& res , LinkInfo& info)
773 list< vector<Node *> >::const_iterator whereToPeerAt;
774 for(list< vector<Node *> >::const_iterator iter=res.begin();iter!=res.end();iter++)
775 if((*iter).size()>maxSize)
777 maxSize=(*iter).size();
783 vector<Node *>::const_iterator iter2=(*whereToPeerAt).begin();
784 map<Node *,bool>::iterator iter4;
785 set<Node *> searcher(iter2+1,(*whereToPeerAt).end());//to boost research
786 for(;iter2!=((*whereToPeerAt).end()-2);iter2++)
788 map<InGate *,bool>::iterator iter4;
789 map<InGate *,bool>& nexts=(*iter2)->getOutGate()->edMapInGate();
790 for(iter4=nexts.begin();iter4!=nexts.end();iter4++)
791 if((*iter4).first->getNode()!=*(iter2+1))
792 if(searcher.find((*iter4).first->getNode())!=searcher.end())
793 info.pushUselessCFLink(*iter2,(*iter4).first->getNode());
794 searcher.erase(*iter2);