From fce58f67dc012ff397c9cdecd480490b7bd48492 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 18 Aug 2015 18:10:26 +0200 Subject: [PATCH] First version of alg for max level of parallelism computation. --- src/engine/AbstractPoint.cxx | 335 +++++++++++++++++++++++++++++++++ src/engine/AbstractPoint.hxx | 90 +++++++++ src/engine/BagPoint.cxx | 149 +++++++++++++++ src/engine/BagPoint.hxx | 53 ++++++ src/engine/Bloc.cxx | 49 +++++ src/engine/Bloc.hxx | 1 + src/engine/BlocPoint.cxx | 92 +++++++++ src/engine/BlocPoint.hxx | 50 +++++ src/engine/CMakeLists.txt | 14 ++ src/engine/DataPort.cxx | 9 +- src/engine/ElementaryPoint.cxx | 65 +++++++ src/engine/ElementaryPoint.hxx | 53 ++++++ src/engine/ForkBlocPoint.cxx | 74 ++++++++ src/engine/ForkBlocPoint.hxx | 44 +++++ src/engine/LinkedBlocPoint.cxx | 67 +++++++ src/engine/LinkedBlocPoint.hxx | 46 +++++ src/engine/SetOfPoints.cxx | 88 +++++++++ src/engine/SetOfPoints.hxx | 53 ++++++ src/engine/Test/engineTest.cxx | 153 +++++++++++++++ src/engine/Test/engineTest.hxx | 9 +- 20 files changed, 1490 insertions(+), 4 deletions(-) create mode 100644 src/engine/AbstractPoint.cxx create mode 100644 src/engine/AbstractPoint.hxx create mode 100644 src/engine/BagPoint.cxx create mode 100644 src/engine/BagPoint.hxx create mode 100644 src/engine/BlocPoint.cxx create mode 100644 src/engine/BlocPoint.hxx create mode 100644 src/engine/ElementaryPoint.cxx create mode 100644 src/engine/ElementaryPoint.hxx create mode 100644 src/engine/ForkBlocPoint.cxx create mode 100644 src/engine/ForkBlocPoint.hxx create mode 100644 src/engine/LinkedBlocPoint.cxx create mode 100644 src/engine/LinkedBlocPoint.hxx create mode 100644 src/engine/SetOfPoints.cxx create mode 100644 src/engine/SetOfPoints.hxx diff --git a/src/engine/AbstractPoint.cxx b/src/engine/AbstractPoint.cxx new file mode 100644 index 000000000..2a9f98e64 --- /dev/null +++ b/src/engine/AbstractPoint.cxx @@ -0,0 +1,335 @@ +// Copyright (C) 2015 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 +// + +#include "AbstractPoint.hxx" +#include "LinkedBlocPoint.hxx" +#include "ForkBlocPoint.hxx" +#include "SetOfPoints.hxx" +#include "Node.hxx" + +using namespace YACS::ENGINE; + +AbstractPoint::~AbstractPoint() +{ +} + +AbstractPoint *AbstractPoint::getGodFather() +{ + if(_father==0) + return this; + else + return _father->getGodFather(); +} + +bool AbstractPoint::isBegin() +{ + Node *beg(getFirstNode()); + InGate *ing(beg->getInGate()); + return ing->getBackLinks().empty(); +} + +bool AbstractPoint::isLast() +{ + Node *endd(getLastNode()); + OutGate *oug(endd->getOutGate()); + return oug->edSetInGate().empty(); +} + +bool AbstractPoint::isSimplyLinkedBeforeAfter(BlocPoint *sop) +{ + Node *beg(getFirstNode()),*endd(getLastNode()); + return isSimplyLinkedBefore(sop,beg) && isSimplyLinkedAfter(sop,endd); +} + +bool AbstractPoint::isSimplyLinkedAfterNullBefore(BlocPoint *sop) +{ + Node *beg(getFirstNode()),*endd(getLastNode()); + return IsNoLinksBefore(beg) && isSimplyLinkedAfter(sop,endd); +} + +bool AbstractPoint::isSimplyLinkedBeforeNullAfter(BlocPoint *sop) +{ + Node *beg(getFirstNode()),*endd(getLastNode()); + return IsNoLinksAfter(endd) && isSimplyLinkedBefore(sop,beg); +} + +/*! + * precondition : isSimplyLinkedBeforeAfter must return true on \a this. + */ +LinkedBlocPoint *AbstractPoint::tryAsLink(BlocPoint *sop) +{ + Node *bb(getFirstNode()),*ee(getLastNode()); + std::list l; l.push_back(this); + AbstractPoint *cur2(0); + // + cur2=sop->getNodeB4(bb); + while(cur2) + { + Node *cur3(cur2->getFirstNode()); + if(cur2->isSimplyLinkedBeforeAfter(sop)) + { + l.push_front(cur2); + cur2=sop->getNodeB4(cur3); + continue; + } + else if(IsGatherB4Ext(cur3) && isSimplyLinkedAfter(sop,cur2->getLastNode())) + { + l.push_front(cur2); + break; + } + else + break; + } + // + cur2=sop->getNodeAfter(ee); + while(cur2) + { + Node *cur3(cur2->getLastNode()); + if(cur2->isSimplyLinkedBeforeAfter(sop)) + { + l.push_back(cur2); + cur2=sop->getNodeAfter(cur3); + continue; + } + else if(IsScatterAfterExt(cur3) && isSimplyLinkedBefore(sop,cur2->getFirstNode())) + { + l.push_back(cur2); + break; + } + else + break; + } + if(l.size()>1) + { + return new LinkedBlocPoint(l,getFather()); + } + else + return 0; +} + +/*! + * precondition : isSimplyLinkedBeforeAfter must return true on \a this. + */ +ForkBlocPoint *AbstractPoint::tryAsFork(BlocPoint *sop) +{ + Node *bb(GetNodeB4(getFirstNode())),*ee(GetNodeAfter(getLastNode())); + AbstractPoint *bb2(sop->findPointWithNode(bb)),*ee2(sop->findPointWithNode(ee)); + // + const std::list& lp(sop->getListOfPoints()); + std::list l; l.push_back(this); + for(std::list::const_iterator it=lp.begin();it!=lp.end();it++) + { + if(*it==this) + continue; + Node *curFirst((*it)->getFirstNode()),*curEnd((*it)->getLastNode()); + if(!IsSimplyLinkedBeforeExt(curFirst) || !IsSimplyLinkedAfterExt(curEnd)) + continue; + Node *curbb(GetNodeB4(curFirst)),*curee(GetNodeAfter(curEnd)); + AbstractPoint *bb3(sop->findPointWithNode(curbb)),*ee3(sop->findPointWithNode(curee)); + if(bb2==bb3 && ee2==ee3) + l.push_back(*it); + } + if(l.size()>1) + { + return new ForkBlocPoint(l,getFather()); + } + else + return 0; +} + +ForkBlocPoint *AbstractPoint::tryAsForkBis(BlocPoint *sop) +{ + Node *bb(GetNodeB4(getFirstNode())),*ee(GetNodeAfter(getLastNode())); + AbstractPoint *ee2(sop->findPointWithNode(ee)); + // + const std::list& lp(sop->getListOfPoints()); + std::list l; l.push_back(this); + for(std::list::const_iterator it=lp.begin();it!=lp.end();it++) + { + if(*it==this) + continue; + Node *curFirst((*it)->getFirstNode()),*curEnd((*it)->getLastNode()); + if(!IsNoLinksBefore(curFirst) || !IsSimplyLinkedAfterExt(curEnd)) + continue; + Node *curee(GetNodeAfter(curEnd)); + AbstractPoint *ee3(sop->findPointWithNode(curee)); + if(ee2==ee3) + l.push_back(*it); + } + if(l.size()>1) + { + return new ForkBlocPoint(l,getFather()); + } + else + return 0; +} + +ForkBlocPoint *AbstractPoint::tryAsForkTer(BlocPoint *sop) +{ + Node *bb(GetNodeB4(getFirstNode())),*ee(GetNodeAfter(getLastNode())); + AbstractPoint *bb2(sop->findPointWithNode(bb)); + // + const std::list& lp(sop->getListOfPoints()); + std::list l; l.push_back(this); + for(std::list::const_iterator it=lp.begin();it!=lp.end();it++) + { + if(*it==this) + continue; + Node *curFirst((*it)->getFirstNode()),*curEnd((*it)->getLastNode()); + if(!IsSimplyLinkedBeforeExt(curFirst) || !IsNoLinksAfter(curEnd)) + continue; + Node *curbb(GetNodeB4(curFirst)); + AbstractPoint *bb3(sop->findPointWithNode(curbb)); + if(bb2==bb3) + l.push_back(*it); + } + if(l.size()>1) + { + return new ForkBlocPoint(l,getFather()); + } + else + return 0; +} + +bool AbstractPoint::IsGatherB4Ext(Node *node) +{ + InGate *ing(node->getInGate()); + return ing->getBackLinks().size()!=1; +} + +bool AbstractPoint::isSimplyLinkedAfter(BlocPoint *sop, Node *node) +{ + OutGate *oug(node->getOutGate()); + std::set ings(oug->edSetInGate()); + if(ings.size()==1) + return true; + if(ings.size()==0) + return false; + AbstractPoint *dummy=0; + return IsCommonDirectSonOf(sop,ings,dummy); +} + +bool AbstractPoint::IsSimplyLinkedAfterExt(Node *node) +{ + OutGate *oug(node->getOutGate()); + return oug->edSetInGate().size()<=1; +} + +bool AbstractPoint::IsScatterAfterExt(Node *node) +{ + OutGate *oug(node->getOutGate()); + return oug->edSetInGate().size()!=1; +} + +bool AbstractPoint::isSimplyLinkedBefore(BlocPoint *sop, Node *node) +{ + InGate *ing(node->getInGate()); + std::list outgs(ing->getBackLinks()); + if(outgs.size()==1) + return true; + if(outgs.size()==0) + return false; + AbstractPoint *dummy=0; + return IsCommonDirectSonOf(sop,outgs,dummy); +} + +bool AbstractPoint::IsSimplyLinkedBeforeExt(Node *node) +{ + InGate *ing(node->getInGate()); + return ing->getBackLinks().size()<=1; +} + +bool AbstractPoint::IsNoLinksBefore(Node *node) +{ + InGate *ing(node->getInGate()); + return ing->getBackLinks().size()==0; +} + +bool AbstractPoint::IsNoLinksAfter(Node *node) +{ + OutGate *oug(node->getOutGate()); + return oug->edSetInGate().size()==0; +} + +Node *AbstractPoint::GetNodeB4(Node *node) +{ + InGate *ing(node->getInGate()); + std::list bl(ing->getBackLinks()); + if(bl.size()>1) + throw Exception("AbstractPoint::GetNodeB4 : precond not OK !"); + if(bl.size()==0) + return 0; + return bl.front()->getNode(); +} + +Node *AbstractPoint::GetNodeAfter(Node *node) +{ + OutGate *oug(node->getOutGate()); + std::set fl(oug->edSetInGate()); + if(fl.size()>1) + throw Exception("AbstractPoint::GetNodeAfter : precond not OK !"); + if(fl.size()==0) + return 0; + return (*fl.begin())->getNode(); +} + +AbstractPoint *AbstractPoint::GetDirectSonOf(AbstractPoint *refFather, AbstractPoint *sonOrLittleSon) +{ + AbstractPoint *curFath(sonOrLittleSon->getFather()),*cur(sonOrLittleSon); + while(curFath && curFath!=refFather) + { + cur=curFath; + curFath=cur->getFather(); + } + if(!curFath) + throw YACS::Exception("AbstractPoint::GetDirectSonOf : not in the same family !"); + return cur; +} + +bool AbstractPoint::IsCommonDirectSonOf(AbstractPoint *refFather, const std::list& outgs, AbstractPoint *&ret) +{ + if(outgs.size()<1) + throw YACS::Exception("AbstractPoint::GetCommonDirectSonOf1 : not enough !"); + std::list::const_iterator it(outgs.begin()); + OutGate *ref(*(it++)); + AbstractPoint *ref2(GetDirectSonOf(refFather,refFather->findPointWithNode(ref->getNode()))); + for(;it!=outgs.end();it++) + { + if(!ref2->contains((*it)->getNode())) + return false; + } + ret=ref2; + return true; +} + +bool AbstractPoint::IsCommonDirectSonOf(AbstractPoint *refFather, const std::set& ings, AbstractPoint *&ret) +{ + if(ings.size()<1) + throw YACS::Exception("AbstractPoint::GetCommonDirectSonOf2 : not enough !"); + std::set::const_iterator it(ings.begin()); + InGate *ref(*(it++)); + AbstractPoint *ref2(GetDirectSonOf(refFather,refFather->findPointWithNode(ref->getNode()))); + for(;it!=ings.end();it++) + { + if(!ref2->contains((*it)->getNode())) + return false; + } + ret=ref2; + return true; +} diff --git a/src/engine/AbstractPoint.hxx b/src/engine/AbstractPoint.hxx new file mode 100644 index 000000000..1adc0839d --- /dev/null +++ b/src/engine/AbstractPoint.hxx @@ -0,0 +1,90 @@ +// Copyright (C) 2015 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 +// + +#ifndef __ABSTRACTPOINT_HXX__ +#define __ABSTRACTPOINT_HXX__ + +#include "YACSlibEngineExport.hxx" + +#include +#include +#include +#include + +namespace YACS +{ + namespace ENGINE + { + class Node; + class InGate; + class OutGate; + class BlocPoint; + class ForkBlocPoint; + class LinkedBlocPoint; + + class YACSLIBENGINE_EXPORT AbstractPoint + { + public: + AbstractPoint(AbstractPoint *father):_father(father) { } + AbstractPoint *getFather() const { return _father; } + AbstractPoint *getGodFather(); + bool amIGod() { return getGodFather()==0; } + void setFather(AbstractPoint *father) { _father=father; } + // + bool isBegin(); + bool isLast(); + bool isSimplyLinkedBeforeAfter(BlocPoint *sop); + bool isSimplyLinkedAfterNullBefore(BlocPoint *sop); + bool isSimplyLinkedBeforeNullAfter(BlocPoint *sop); + // + LinkedBlocPoint *tryAsLink(BlocPoint *sop); + ForkBlocPoint *tryAsFork(BlocPoint *sop); + ForkBlocPoint *tryAsForkBis(BlocPoint *sop); + ForkBlocPoint *tryAsForkTer(BlocPoint *sop); + // + virtual Node *getFirstNode() = 0; + virtual Node *getLastNode() = 0; + virtual AbstractPoint *findPointWithNode(Node *node) = 0; + virtual bool contains(Node *node) = 0; + virtual int getNumberOfNodes() const = 0; + virtual int getMaxLevelOfParallelism() const = 0; + virtual std::string getRepr() const = 0; + virtual ~AbstractPoint(); + public: + static bool IsGatherB4Ext(Node *node); + bool isSimplyLinkedAfter(BlocPoint *sop, Node *node); + static bool IsSimplyLinkedAfterExt(Node *node); + static bool IsScatterAfterExt(Node *node); + bool isSimplyLinkedBefore(BlocPoint *sop, Node *node); + static bool IsSimplyLinkedBeforeExt(Node *node); + static bool IsNoLinksBefore(Node *node); + static bool IsNoLinksAfter(Node *node); + static Node *GetNodeB4(Node *node); + static Node *GetNodeAfter(Node *node); + static AbstractPoint *GetDirectSonOf(AbstractPoint *refFather, AbstractPoint *sonOrLittleSon); + static bool IsCommonDirectSonOf(AbstractPoint *refFather, const std::list& outgs, AbstractPoint *&ret); + static bool IsCommonDirectSonOf(AbstractPoint *refFather, const std::set& ings, AbstractPoint *&ret); + protected: + AbstractPoint *_father; + }; + } +} + + +#endif diff --git a/src/engine/BagPoint.cxx b/src/engine/BagPoint.cxx new file mode 100644 index 000000000..89e3c2d10 --- /dev/null +++ b/src/engine/BagPoint.cxx @@ -0,0 +1,149 @@ +// Copyright (C) 2015 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 +// + +#include "BagPoint.hxx" +#include "Exception.hxx" +#include "LinkedBlocPoint.hxx" +#include "ForkBlocPoint.hxx" + +#include +#include + +using namespace YACS::ENGINE; + +BagPoint::BagPoint(const std::list& nodes, AbstractPoint *father):BlocPoint(nodes,father) +{ +} + +Node *BagPoint::getFirstNode() +{ + if(_nodes.size()!=1) + throw YACS::Exception("BagPoint::getFirstNode : invalid call !"); + else + return (*_nodes.begin())->getFirstNode(); +} + +Node *BagPoint::getLastNode() +{ + if(_nodes.size()!=1) + throw YACS::Exception("BagPoint::getLastNode : invalid call !"); + else + return (*_nodes.begin())->getLastNode(); +} + +int BagPoint::getMaxLevelOfParallelism() const +{ + if(_nodes.size()!=1) + throw YACS::Exception("BagPoint::getMaxLevelOfParallelism : invalid call !"); + else + return (*_nodes.begin())->getMaxLevelOfParallelism(); +} + +std::string BagPoint::getRepr() const +{ + std::ostringstream oss; + for(std::list::const_iterator it=_nodes.begin();it!=_nodes.end();it++) + oss << (*it)->getRepr() << " - "; + return oss.str(); +} + +#include + +void BagPoint::replaceInMe(BlocPoint *aSet) +{ + const std::list& pts(aSet->getListOfPoints()); + for(std::list::const_iterator it0=pts.begin();it0!=pts.end();it0++) + { + std::list::iterator it1(std::find(_nodes.begin(),_nodes.end(),*it0)); + if(it1==_nodes.end()) + throw Exception("SetOfPoints::replaceInMe : internal error !"); + _nodes.erase(it1); + } + _nodes.push_back(aSet); +} + +void BagPoint::deal1(bool& somethingDone) +{ + somethingDone=false; + for(std::list::iterator it=_nodes.begin();it!=_nodes.end();it++) + { + if(!(*it)->isSimplyLinkedBeforeAfter(this)) + if(!(*it)->isSimplyLinkedAfterNullBefore(this) && !(*it)->isSimplyLinkedBeforeNullAfter(this)) + continue; + LinkedBlocPoint *try0((*it)->tryAsLink(this)); + if(try0) + { + replaceInMe(try0); + somethingDone=true; + break; + } + } +} + +void BagPoint::deal2(bool& somethingDone) +{ + somethingDone=false; + for(std::list::iterator it=_nodes.begin();it!=_nodes.end();it++) + { + if(!(*it)->isSimplyLinkedBeforeAfter(this)) + continue; + ForkBlocPoint *try1((*it)->tryAsFork(this)); + if(try1) + { + replaceInMe(try1); + somethingDone=true; + break; + } + } +} + +void BagPoint::deal2Bis(bool& somethingDone) +{ + somethingDone=false; + for(std::list::iterator it=_nodes.begin();it!=_nodes.end();it++) + { + if(!(*it)->isSimplyLinkedAfterNullBefore(this)) + continue; + ForkBlocPoint *try1((*it)->tryAsForkBis(this)); + if(try1) + { + replaceInMe(try1); + somethingDone=true; + break; + } + } +} + +void BagPoint::deal2Ter(bool& somethingDone) +{ + somethingDone=false; + for(std::list::iterator it=_nodes.begin();it!=_nodes.end();it++) + { + if(!(*it)->isSimplyLinkedBeforeNullAfter(this)) + continue; + ForkBlocPoint *try1((*it)->tryAsForkTer(this)); + if(try1) + { + replaceInMe(try1); + somethingDone=true; + break; + } + } +} + diff --git a/src/engine/BagPoint.hxx b/src/engine/BagPoint.hxx new file mode 100644 index 000000000..3ad8c32c5 --- /dev/null +++ b/src/engine/BagPoint.hxx @@ -0,0 +1,53 @@ +// Copyright (C) 2015 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 +// + +#ifndef __BAGPOINT_HXX__ +#define __BAGPOINT_HXX__ + +#include "YACSlibEngineExport.hxx" +#include "BlocPoint.hxx" + +#include + +namespace YACS +{ + namespace ENGINE + { + class YACSLIBENGINE_EXPORT BagPoint : public BlocPoint + { + public: + BagPoint(const std::list& nodes, AbstractPoint *father); + public://overloading + Node *getFirstNode(); + Node *getLastNode(); + int getMaxLevelOfParallelism() const; + std::string getRepr() const; + public: + int size() const { return (int)_nodes.size(); } + void replaceInMe(BlocPoint *aSet); + void deal1(bool& somethingDone); + void deal2(bool& somethingDone); + void deal2Bis(bool& somethingDone); + void deal2Ter(bool& somethingDone); + }; + } +} + + +#endif diff --git a/src/engine/Bloc.cxx b/src/engine/Bloc.cxx index a2def0cc0..6395112b5 100644 --- a/src/engine/Bloc.cxx +++ b/src/engine/Bloc.cxx @@ -26,6 +26,7 @@ #include "ElementaryNode.hxx" #include "Visitor.hxx" +#include #include #include @@ -224,6 +225,54 @@ void Bloc::edRemoveChild(Node *node) throw(YACS::Exception) } } +std::vector< std::list > Bloc::splitIntoIndependantGraph() const +{ + std::size_t sz(_setOfNode.size()); + list::const_iterator it=_setOfNode.begin(); + for(;it!=_setOfNode.end();it++) + (*it)->_colour=White; + it=_setOfNode.begin(); + std::vector< list > ret; + while(it!=_setOfNode.end()) + { + Node *start(*it); start->_colour=Grey; + ret.push_back(list()); + list& ll(ret.back()); + std::queue fifo; fifo.push(start); + while(!fifo.empty()) + { + Node *cur(fifo.front()); fifo.pop(); + ll.push_back(cur); + // + OutGate *og(cur->getOutGate()); + set og2(og->edSetInGate()); + for(set::const_iterator it2=og2.begin();it2!=og2.end();it2++) + { + Node *cur2((*it2)->getNode()); + if(cur2->_colour==White) + { + cur2->_colour=Grey; + fifo.push(cur2); + } + } + // + InGate *ig(cur->getInGate()); + list bl(ig->getBackLinks()); + for(list::const_iterator it3=bl.begin();it3!=bl.end();it3++) + { + Node *cur3((*it3)->getNode()); + if(cur3->_colour==White) + { + cur3->_colour=Grey; + fifo.push(cur3); + } + } + } + for(it=_setOfNode.begin();it!=_setOfNode.end() && (*it)->_colour!=White;it++); + } + return ret; +} + Node *Bloc::getChildByShortName(const std::string& name) const throw(YACS::Exception) { for (list::const_iterator iter = _setOfNode.begin(); iter != _setOfNode.end(); iter++) diff --git a/src/engine/Bloc.hxx b/src/engine/Bloc.hxx index 0bd35120d..18a0dfd76 100644 --- a/src/engine/Bloc.hxx +++ b/src/engine/Bloc.hxx @@ -51,6 +51,7 @@ namespace YACS void edRemoveChild(Node *node) throw(Exception); std::list getChildren() const { return _setOfNode; } std::list edGetDirectDescendants() const { return _setOfNode; } + std::vector< std::list > splitIntoIndependantGraph() const; Node *getChildByShortName(const std::string& name) const throw(Exception); virtual void writeDot(std::ostream &os) const; void accept(Visitor *visitor); diff --git a/src/engine/BlocPoint.cxx b/src/engine/BlocPoint.cxx new file mode 100644 index 000000000..381d1eb71 --- /dev/null +++ b/src/engine/BlocPoint.cxx @@ -0,0 +1,92 @@ +// Copyright (C) 2015 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 +// + +#include "BlocPoint.hxx" +#include "Node.hxx" + +using namespace YACS::ENGINE; + +BlocPoint::BlocPoint(const std::list& nodes, AbstractPoint *father):AbstractPoint(father),_nodes(nodes) +{ + for(std::list::const_iterator it=_nodes.begin();it!=_nodes.end();it++) + (*it)->setFather(this); +} + +AbstractPoint *BlocPoint::findPointWithNode(Node *node) +{ + for(std::list::iterator it=_nodes.begin();it!=_nodes.end();it++) + { + AbstractPoint *ret((*it)->findPointWithNode(node)); + if(ret) + return AbstractPoint::GetDirectSonOf(this,ret); + } + return 0; +} + +AbstractPoint *BlocPoint::getNodeAfter(Node *node) +{ + OutGate *oug(node->getOutGate()); + std::set fl(oug->edSetInGate()); + if(fl.size()>=1) + { + AbstractPoint *ret(0); + IsCommonDirectSonOf(this,fl,ret); + return ret; + } + else + return 0; +} + +AbstractPoint *BlocPoint::getNodeB4(Node *node) +{ + InGate *ing(node->getInGate()); + std::list bl(ing->getBackLinks()); + if(bl.size()>=1) + { + AbstractPoint *ret(0); + IsCommonDirectSonOf(this,bl,ret); + return ret; + } + else + return 0; +} + +bool BlocPoint::contains(Node *node) +{ + for(std::list::iterator it=_nodes.begin();it!=_nodes.end();it++) + { + if((*it)->contains(node)) + return true; + } + return false; +} + +int BlocPoint::getNumberOfNodes() const +{ + int ret(0); + for(std::list::const_iterator it=_nodes.begin();it!=_nodes.end();it++) + ret+=(*it)->getNumberOfNodes(); + return ret; +} + +BlocPoint::~BlocPoint() +{ + for(std::list::iterator it=_nodes.begin();it!=_nodes.end();it++) + delete *it; +} diff --git a/src/engine/BlocPoint.hxx b/src/engine/BlocPoint.hxx new file mode 100644 index 000000000..52d2a715e --- /dev/null +++ b/src/engine/BlocPoint.hxx @@ -0,0 +1,50 @@ +// Copyright (C) 2015 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 +// + +#ifndef __BLOCPOINT_HXX__ +#define __BLOCPOINT_HXX__ + +#include "YACSlibEngineExport.hxx" +#include "AbstractPoint.hxx" + +#include + +namespace YACS +{ + namespace ENGINE + { + class YACSLIBENGINE_EXPORT BlocPoint : public AbstractPoint + { + protected: + std::list _nodes; + public: + BlocPoint(const std::list& nodes, AbstractPoint *father); + AbstractPoint *findPointWithNode(Node *node); + AbstractPoint *getNodeAfter(Node *node); + AbstractPoint *getNodeB4(Node *node); + bool contains(Node *node); + int getNumberOfNodes() const; + const std::list& getListOfPoints() const { return _nodes; } + virtual ~BlocPoint(); + }; + } +} + + +#endif diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt index 28c6fde49..a8a477e1e 100644 --- a/src/engine/CMakeLists.txt +++ b/src/engine/CMakeLists.txt @@ -99,6 +99,13 @@ SET(YACSlibEngine_HEADERS AnyOutputPort.hxx ServerNode.hxx InPropertyPort.hxx + AbstractPoint.hxx + BlocPoint.hxx + BagPoint.hxx + ForkBlocPoint.hxx + LinkedBlocPoint.hxx + ElementaryPoint.hxx + SetOfPoints.hxx ) # --- sources --- @@ -164,6 +171,13 @@ SET(YACSlibEngine_SOURCES Task.cxx Scheduler.cxx InPropertyPort.cxx + AbstractPoint.cxx + BlocPoint.cxx + BagPoint.cxx + ForkBlocPoint.cxx + LinkedBlocPoint.cxx + ElementaryPoint.cxx + SetOfPoints.cxx ) # --- rules --- diff --git a/src/engine/DataPort.cxx b/src/engine/DataPort.cxx index be0c2eb5d..895b0cb35 100644 --- a/src/engine/DataPort.cxx +++ b/src/engine/DataPort.cxx @@ -28,17 +28,20 @@ const char DataPort::NAME[]="DataPort"; DataPort::~DataPort() { - _type->decrRef(); + if(_type) + _type->decrRef(); } DataPort::DataPort(const std::string& name, Node *node, TypeCode* type):Port(node),_name(name),_type(type) { - _type->incrRef(); + if(_type) + _type->incrRef(); } DataPort::DataPort(const DataPort& other, Node *newHelder):Port(other,newHelder),_name(other._name),_type(other._type) { - _type->incrRef(); + if(_type) + _type->incrRef(); } void DataPort::edSetType(TypeCode* type) diff --git a/src/engine/ElementaryPoint.cxx b/src/engine/ElementaryPoint.cxx new file mode 100644 index 000000000..e8cedfc7c --- /dev/null +++ b/src/engine/ElementaryPoint.cxx @@ -0,0 +1,65 @@ +// Copyright (C) 2015 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 +// + +#include "ElementaryPoint.hxx" +#include "Node.hxx" + +using namespace YACS::ENGINE; + +ElementaryPoint::~ElementaryPoint() +{ +} + +AbstractPoint *ElementaryPoint::findPointWithNode(Node *node) +{ + if(node==_node) + return this; + else + return 0; +} + +bool ElementaryPoint::contains(Node *node) +{ + return _node==node; +} + +Node *ElementaryPoint::getFirstNode() +{ + return _node; +} + +Node *ElementaryPoint::getLastNode() +{ + return _node; +} + +int ElementaryPoint::getNumberOfNodes() const +{ + return 1; +} + +int ElementaryPoint::getMaxLevelOfParallelism() const +{ + return _node->getMaxLevelOfParallelism(); +} + +std::string ElementaryPoint::getRepr() const +{ + return _node->getName(); +} diff --git a/src/engine/ElementaryPoint.hxx b/src/engine/ElementaryPoint.hxx new file mode 100644 index 000000000..127704aaa --- /dev/null +++ b/src/engine/ElementaryPoint.hxx @@ -0,0 +1,53 @@ +// Copyright (C) 2015 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 +// + +#ifndef __ELEMENTARYPOINT_HXX__ +#define __ELEMENTARYPOINT_HXX__ + +#include "YACSlibEngineExport.hxx" +#include "AbstractPoint.hxx" + +#include + +namespace YACS +{ + namespace ENGINE + { + class Node; + + class YACSLIBENGINE_EXPORT ElementaryPoint : public AbstractPoint + { + private: + Node *_node; + public: + ElementaryPoint(Node *node):AbstractPoint(0),_node(node) { } + AbstractPoint *findPointWithNode(Node *node); + bool contains(Node *node); + Node *getFirstNode(); + Node *getLastNode(); + int getNumberOfNodes() const; + int getMaxLevelOfParallelism() const; + std::string getRepr() const; + virtual ~ElementaryPoint(); + }; + } +} + + +#endif diff --git a/src/engine/ForkBlocPoint.cxx b/src/engine/ForkBlocPoint.cxx new file mode 100644 index 000000000..1275183e3 --- /dev/null +++ b/src/engine/ForkBlocPoint.cxx @@ -0,0 +1,74 @@ +// Copyright (C) 2015 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 +// + +#include "ForkBlocPoint.hxx" +#include "Exception.hxx" + +#include + +using namespace YACS::ENGINE; + +ForkBlocPoint::ForkBlocPoint(const std::list& nodes, AbstractPoint *father):BlocPoint(nodes,father) +{ +} + +ForkBlocPoint::~ForkBlocPoint() +{ +} + +Node *ForkBlocPoint::getFirstNode() +{ + if(_nodes.empty()) + throw Exception("ForkBlocPoint::getFirstNode : error no branches !"); + return _nodes.front()->getFirstNode(); +} + +Node *ForkBlocPoint::getLastNode() +{ + if(_nodes.empty()) + throw Exception("ForkBlocPoint::getLastNode : error no branches !"); + return _nodes.front()->getLastNode();//not a bug - seen from the outside only first branch exists ! +} + +int ForkBlocPoint::getMaxLevelOfParallelism() const +{ + int ret(0); + for(std::list::const_iterator it=_nodes.begin();it!=_nodes.end();it++) + ret+=(*it)->getMaxLevelOfParallelism(); + return ret; +} + +std::string ForkBlocPoint::getRepr() const +{ + std::size_t sz(_nodes.size()),ii(0); + std::string ret("["); + std::vector elts(sz); + for(std::list::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++) + elts[ii]=(*it)->getRepr(); + std::sort(elts.begin(),elts.end()); + ii=0; + for(std::list::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++) + { + ret+=elts[ii]; + if(ii!=sz-1) + ret+="*"; + } + ret+="]"; + return ret; +} diff --git a/src/engine/ForkBlocPoint.hxx b/src/engine/ForkBlocPoint.hxx new file mode 100644 index 000000000..e7fd79ddf --- /dev/null +++ b/src/engine/ForkBlocPoint.hxx @@ -0,0 +1,44 @@ +// Copyright (C) 2015 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 +// + +#ifndef __FORKBLOCPOINT_HXX__ +#define __BLOKBLOCPOINT_HXX__ + +#include "YACSlibEngineExport.hxx" +#include "BlocPoint.hxx" + +namespace YACS +{ + namespace ENGINE + { + class YACSLIBENGINE_EXPORT ForkBlocPoint : public BlocPoint + { + public: + ForkBlocPoint(const std::list& nodes, AbstractPoint *father); + Node *getFirstNode(); + Node *getLastNode(); + int getMaxLevelOfParallelism() const; + std::string getRepr() const; + virtual ~ForkBlocPoint(); + }; + } +} + + +#endif diff --git a/src/engine/LinkedBlocPoint.cxx b/src/engine/LinkedBlocPoint.cxx new file mode 100644 index 000000000..edeecca4f --- /dev/null +++ b/src/engine/LinkedBlocPoint.cxx @@ -0,0 +1,67 @@ +// Copyright (C) 2015 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 +// + +#include "LinkedBlocPoint.hxx" +#include "Exception.hxx" + +using namespace YACS::ENGINE; + +LinkedBlocPoint::LinkedBlocPoint(const std::list& nodes, AbstractPoint *father):BlocPoint(nodes,father) +{ +} + +Node *LinkedBlocPoint::getFirstNode() +{ + if(_nodes.empty()) + throw Exception("LinkedBlocPoint::getFirstNode : error no branches !"); + return _nodes.front()->getFirstNode(); +} + +Node *LinkedBlocPoint::getLastNode() +{ + if(_nodes.empty()) + throw Exception("LinkedBlocPoint::getFirstNode : error no branches !"); + return _nodes.back()->getLastNode(); +} + +int LinkedBlocPoint::getMaxLevelOfParallelism() const +{ + int ret(0); + for(std::list::const_iterator it=_nodes.begin();it!=_nodes.end();it++) + ret=std::max(ret,(*it)->getMaxLevelOfParallelism()); + return ret; +} + +std::string LinkedBlocPoint::getRepr() const +{ + std::size_t sz(_nodes.size()),ii(0); + std::string ret("("); + for(std::list::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++) + { + ret+=(*it)->getRepr(); + if(ii!=sz-1) + ret+="+"; + } + ret+=")"; + return ret; +} + +LinkedBlocPoint::~LinkedBlocPoint() +{ +} diff --git a/src/engine/LinkedBlocPoint.hxx b/src/engine/LinkedBlocPoint.hxx new file mode 100644 index 000000000..b080b3238 --- /dev/null +++ b/src/engine/LinkedBlocPoint.hxx @@ -0,0 +1,46 @@ +// Copyright (C) 2015 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 +// + +#ifndef __LINKEDBLOCPOINT_HXX__ +#define __LINKEDBLOCPOINT_HXX__ + +#include "YACSlibEngineExport.hxx" +#include "BlocPoint.hxx" + +#include + +namespace YACS +{ + namespace ENGINE + { + class YACSLIBENGINE_EXPORT LinkedBlocPoint : public BlocPoint + { + public: + LinkedBlocPoint(const std::list& nodes, AbstractPoint *father); + Node *getFirstNode(); + Node *getLastNode(); + int getMaxLevelOfParallelism() const; + std::string getRepr() const; + virtual ~LinkedBlocPoint(); + }; + } +} + + +#endif diff --git a/src/engine/SetOfPoints.cxx b/src/engine/SetOfPoints.cxx new file mode 100644 index 000000000..dd2158163 --- /dev/null +++ b/src/engine/SetOfPoints.cxx @@ -0,0 +1,88 @@ +// Copyright (C) 2015 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 +// + +#include "SetOfPoints.hxx" +#include "BagPoint.hxx" +#include "LinkedBlocPoint.hxx" +#include "ForkBlocPoint.hxx" +#include "ElementaryPoint.hxx" +#include "Exception.hxx" + +#include + +using namespace YACS::ENGINE; + +SetOfPoints::SetOfPoints(const std::list& nodes):_bp(0) +{ + std::list nodes2; + for(std::list::const_iterator it=nodes.begin();it!=nodes.end();it++) + { + nodes2.push_back(new ElementaryPoint(*it)); + } + _bp=new BagPoint(nodes2,0); +} + +SetOfPoints::~SetOfPoints() +{ + if(!_bp) + return; + delete _bp; +} + +void SetOfPoints::simplify() +{ + while(_bp->size()>1) + { + bool somethingDone(false); + _bp->deal1(somethingDone); + if(somethingDone) + continue; + _bp->deal2(somethingDone); + if(somethingDone) + continue; + _bp->deal2Bis(somethingDone); + if(somethingDone) + continue; + _bp->deal2Ter(somethingDone); + if(!somethingDone) + throw Exception("SetOfPoints::simplify : not implemented yet !"); + } +} + +std::string SetOfPoints::getRepr() const +{ + return _bp->getRepr(); +} + +AbstractPoint *SetOfPoints::findPointWithNode(Node *node) +{ + if(node==0) + return 0; + return _bp->findPointWithNode(node); +} + +const std::list& SetOfPoints::getListOfPoints() const +{ + return _bp->getListOfPoints(); +} + +int SetOfPoints::getMaxLevelOfParallelism() const +{ + return _bp->getMaxLevelOfParallelism(); +} diff --git a/src/engine/SetOfPoints.hxx b/src/engine/SetOfPoints.hxx new file mode 100644 index 000000000..ade89ae66 --- /dev/null +++ b/src/engine/SetOfPoints.hxx @@ -0,0 +1,53 @@ +// Copyright (C) 2015 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 +// + +#ifndef __SETOFPOINTS_HXX__ +#define __SETOFPOINTS_HXX__ + +#include "YACSlibEngineExport.hxx" + +#include +#include + +namespace YACS +{ + namespace ENGINE + { + class Node; + class BagPoint; + class AbstractPoint; + + class YACSLIBENGINE_EXPORT SetOfPoints + { + public: + SetOfPoints(const std::list& nodes); + ~SetOfPoints(); + void simplify(); + std::string getRepr() const; + AbstractPoint *findPointWithNode(Node *node); + const std::list& getListOfPoints() const; + int getMaxLevelOfParallelism() const; + private: + BagPoint *_bp; + }; + } +} + + +#endif diff --git a/src/engine/Test/engineTest.cxx b/src/engine/Test/engineTest.cxx index cc823cc17..2a47afd94 100644 --- a/src/engine/Test/engineTest.cxx +++ b/src/engine/Test/engineTest.cxx @@ -26,6 +26,7 @@ #include "Loop.hxx" #include "Switch.hxx" #include "VisitorSaveState.hxx" +#include "SetOfPoints.hxx" #include "SharedPtr.hxx" #include "RuntimeForEngineTest.hxx" @@ -1072,3 +1073,155 @@ void EngineTest::checkLogger() CPPUNIT_ASSERT(logger->getStr()==expected2); delete proc; } + +void EngineTest::checkGraphAnalyser0() +{ + { + static const int N=2; + Bloc *t[N]; + Bloc proc("proc"); + for(int i=0;i > r(proc.splitIntoIndependantGraph()); + CPPUNIT_ASSERT_EQUAL(1,(int)r.size()); + CPPUNIT_ASSERT_EQUAL(N,(int)r[0].size()); + SetOfPoints sop(r[0]); + sop.simplify(); + CPPUNIT_ASSERT(sop.getRepr()=="(n1+n2) - "); + } +} + +void EngineTest::checkGraphAnalyser1() +{ + { + static const int N=24; + Bloc *t[N]; + Bloc proc("proc"); + for(int i=0;i > r(proc.splitIntoIndependantGraph()); + CPPUNIT_ASSERT_EQUAL(1,(int)r.size()); + CPPUNIT_ASSERT_EQUAL(N,(int)r[0].size()); + SetOfPoints sop(r[0]); + sop.simplify(); + CPPUNIT_ASSERT(sop.getRepr()=="([n21*n23]+(n22+n16+[((n13+n12)+[n10*n11]+(n9+n8+n7))*((n17+n18+n20)+[n19*n3*n4]+n5)*(n15+[(n1+n2+n24)*n14])]+n6)) - "); + } + // + { + static const int N=10; + Bloc *t[N]; + Bloc proc("proc"); + for(int i=0;i > r(proc.splitIntoIndependantGraph()); + CPPUNIT_ASSERT_EQUAL(1,(int)r.size()); + CPPUNIT_ASSERT_EQUAL(N,(int)r[0].size()); + SetOfPoints sop(r[0]); + sop.simplify(); + CPPUNIT_ASSERT(sop.getRepr()=="((n10+n1)+[([(n9+n4)*n3]+n5)*(n2+n7+n8)]+n6) - "); + } +} + +void EngineTest::checkGraphAnalyser2() +{ + { + static const int N=8; + Bloc *t[N]; + Bloc proc("proc"); + for(int i=0;i > r(proc.splitIntoIndependantGraph()); + CPPUNIT_ASSERT_EQUAL(1,(int)r.size()); + CPPUNIT_ASSERT_EQUAL(N,(int)r[0].size()); + SetOfPoints sop(r[0]); + sop.simplify(); + CPPUNIT_ASSERT(sop.getRepr()=="((n8+n5)+[(n1+n2)*(n3+n4)]+(n6+n7)) - "); + } + // + { + static const int NN=6; + Bloc *tt[NN]; + Bloc proc2("proc2"); + tt[0]=new Bloc("n21") ; tt[1]=new Bloc("n22") ; tt[2]=new Bloc("n23") ; tt[3]=new Bloc("n16"); tt[4]=new Bloc("n21@1"); tt[5]=new Bloc("n23@1"); + for(int i=0;i > rr(proc2.splitIntoIndependantGraph()); + CPPUNIT_ASSERT_EQUAL(1,(int)rr.size()); + CPPUNIT_ASSERT_EQUAL(NN,(int)rr[0].size()); + SetOfPoints sop2(rr[0]); + sop2.simplify(); + CPPUNIT_ASSERT(sop2.getRepr()=="([(n21+n21@1)*(n23+n23@1)]+(n22+n16)) - "); + } + // + { + static const int NNN=6; + Bloc *ttt[NNN]; + Bloc proc3("proc3"); + ttt[0]=new Bloc("n21") ; ttt[1]=new Bloc("n22") ; ttt[2]=new Bloc("n23") ; ttt[3]=new Bloc("n16"); ttt[4]=new Bloc("n21@1"); ttt[5]=new Bloc("n23@1"); + for(int i=0;i > rrr(proc3.splitIntoIndependantGraph()); + CPPUNIT_ASSERT_EQUAL(1,(int)rrr.size()); + CPPUNIT_ASSERT_EQUAL(NNN,(int)rrr[0].size()); + SetOfPoints sop3(rrr[0]); + sop3.simplify(); + CPPUNIT_ASSERT(sop3.getRepr()=="((n22+n16)+[(n21+n21@1)*(n23+n23@1)]) - "); + } +} + +void EngineTest::checkGraphAnalyser3() +{ + { + static const int NNN=6; + Bloc *ttt[NNN]; + Bloc proc3("proc3"); + for(int i=0;i > rrr(proc3.splitIntoIndependantGraph()); + CPPUNIT_ASSERT_EQUAL(1,(int)rrr.size()); + CPPUNIT_ASSERT_EQUAL(NNN,(int)rrr[0].size()); + SetOfPoints sop3(rrr[0]); + //sop3.simplify(); + //std:cerr << std::endl << sop3.getRepr() << std::endl; + //CPPUNIT_ASSERT(sop3.getRepr()=="((n22+n16)+[(n21+n21@1)*(n23+n23@1)]) - "); + } +} diff --git a/src/engine/Test/engineTest.hxx b/src/engine/Test/engineTest.hxx index 3bdd05139..e51f30000 100644 --- a/src/engine/Test/engineTest.hxx +++ b/src/engine/Test/engineTest.hxx @@ -59,6 +59,10 @@ namespace YACS CPPUNIT_TEST(RecursiveBlocs_removeNodes ); CPPUNIT_TEST(cleanUp); CPPUNIT_TEST(checkLogger); + CPPUNIT_TEST(checkGraphAnalyser0); + CPPUNIT_TEST(checkGraphAnalyser1); + CPPUNIT_TEST(checkGraphAnalyser2); + CPPUNIT_TEST(checkGraphAnalyser3); CPPUNIT_TEST_SUITE_END(); public: @@ -93,7 +97,10 @@ namespace YACS void RecursiveBlocs_multipleRecursion(); void RecursiveBlocs_removeNodes(); void checkLogger(); - + void checkGraphAnalyser0(); + void checkGraphAnalyser1(); + void checkGraphAnalyser2(); + void checkGraphAnalyser3(); protected: static std::map _nodeMap; static std::map _compoMap; -- 2.39.2