From 801615750079484c1ff105ca408a2452f376832d Mon Sep 17 00:00:00 2001 From: EricLaoGitHub Date: Fri, 17 Jun 2016 16:26:27 +0200 Subject: [PATCH] Temporary commit to pull and merge last commit. --- anabatic/src/Dijkstra.cpp | 43 ++++++++++++++++++++++++++ anabatic/src/GCell.cpp | 52 ++++++++++++++++++++++++++++++++ anabatic/src/anabatic/Dijkstra.h | 28 +++++++++++++++++ anabatic/src/anabatic/GCell.h | 5 +++ 4 files changed, 128 insertions(+) diff --git a/anabatic/src/Dijkstra.cpp b/anabatic/src/Dijkstra.cpp index 3088484f..7e28849a 100644 --- a/anabatic/src/Dijkstra.cpp +++ b/anabatic/src/Dijkstra.cpp @@ -113,6 +113,49 @@ namespace Anabatic { } + bool Dijkstra::isRestricted ( const Vertex* v1, const Vertex* v2 ) const + { + bool restricted = true; + GCell* c1 = v1->getGCell(); + GCell* c2 = v2->getGCell(); + + // Check from GCell 1 + if ( c1->isNorth(c2) ) { + if ( !v1->isNRestricted() ) restricted = false; + } else if ( c1->isSouth(c2) ) { + if ( !v1->isSRestricted() ) restricted = false; + } else if ( c1->isEast (c2) ) { + if ( !v1->isERestricted() ) restricted = false; + } else if ( c1->isWest (c2) ) { + if ( !v1->isWRestricted() ) restricted = false; + } else { + cerr << Error( "GCells are not side by side." ) << endl; + return true; + } + + if (restricted) return true; + else { + // Check from GCell 2 + if ( c2->isNorth(c1) ) { + if ( v2->isNRestricted() ) return true; + else return false; + } else if ( c2->isSouth(c1) ) { + if ( v2->isSRestricted() ) return true; + else return false; + } else if ( c2->isEast (c1) ) { + if ( v2->isERestricted() ) return true; + else return false; + } else if ( c2->isWest (c1) ) { + if ( v2->isWRestricted() ) return true; + else return false; + } else { + cerr << Error( "GCells are not side by side." ) << endl; + return true; + } + } + } + + Dijkstra::Dijkstra ( AnabaticEngine* anabatic ) : _anabatic (anabatic) , _vertexes () diff --git a/anabatic/src/GCell.cpp b/anabatic/src/GCell.cpp index 534c4c7d..779ff899 100644 --- a/anabatic/src/GCell.cpp +++ b/anabatic/src/GCell.cpp @@ -573,6 +573,58 @@ namespace Anabatic { } + bool GCell::isNorth ( GCell* c ) const + { + bool found = false; + for (vector::const_iterator it = _northEdges.begin(); it != _northEdges.end(); it++){ + if ( (*it)->getOpposite(this)->getId() == getId() ) { + found = true; + break; + } + } + return found; + } + + + bool GCell::isSouth ( GCell* c ) const + { + bool found = false; + for (vector::const_iterator it = _southEdges.begin(); it != _southEdges.end(); it++){ + if ( (*it)->getOpposite(this)->getId() == getId() ) { + found = true; + break; + } + } + return found; + } + + + bool GCell::isEast ( GCell* c ) const + { + bool found = false; + for (vector::const_iterator it = _eastEdges.begin(); it != _eastEdges.end(); it++){ + if ( (*it)->getOpposite(this)->getId() == getId() ) { + found = true; + break; + } + } + return found; + } + + + bool GCell::isWest ( GCell* c ) const + { + bool found = false; + for (vector::const_iterator it = _westEdges.begin(); it != _westEdges.end(); it++){ + if ( (*it)->getOpposite(this)->getId() == getId() ) { + found = true; + break; + } + } + return found; + } + + string GCell::_getTypeName () const { return getString(_extensionName); } diff --git a/anabatic/src/anabatic/Dijkstra.h b/anabatic/src/anabatic/Dijkstra.h index 721dbd1b..30452764 100644 --- a/anabatic/src/anabatic/Dijkstra.h +++ b/anabatic/src/anabatic/Dijkstra.h @@ -44,6 +44,13 @@ namespace Anabatic { public: inline bool operator() ( const Vertex* lhs, const Vertex* rhs ); }; + public: + enum FlagR { NoRestriction = 0 + , NRestricted = (1<<0) + , SRestricted = (1<<1) + , ERestricted = (1<<2) + , WRestricted = (1<<3) + }; public: static float unreached; public: @@ -67,6 +74,15 @@ namespace Anabatic { inline void setStamp ( int ); inline void setConnexId ( int ); inline void setFrom ( Edge* ); + + inline bool isNorth ( Vertex* ) const; + inline bool isSouth ( Vertex* ) const; + inline bool isEast ( Vertex* ) const; + inline bool isWest ( Vertex* ) const; + inline bool isNRestricted () const; + inline bool isSRestricted () const; + inline bool isERestricted () const; + inline bool isWRestricted () const; // Inspector support. string _getString () const; private: @@ -80,6 +96,7 @@ namespace Anabatic { int _stamp; float _distance; Edge* _from; + FlagR _flags; }; @@ -91,6 +108,7 @@ namespace Anabatic { , _stamp (-1) , _distance(unreached) , _from (NULL) + , _flags (NoRestriction) { gcell->setObserver( GCell::Observable::Vertex, &_observer ); } @@ -129,6 +147,15 @@ namespace Anabatic { typedef set VertexSet; + inline bool Vertex::isNorth ( Vertex* v ) const { return _gcell->isNorth(v->getGCell()); } + inline bool Vertex::isSouth ( Vertex* v ) const { return _gcell->isSouth(v->getGCell()); } + inline bool Vertex::isEast ( Vertex* v ) const { return _gcell->isEast (v->getGCell()); } + inline bool Vertex::isWest ( Vertex* v ) const { return _gcell->isWest (v->getGCell()); } + inline bool Vertex::isNRestricted () const { return (_flags & NRestricted); } + inline bool Vertex::isSRestricted () const { return (_flags & SRestricted); } + inline bool Vertex::isERestricted () const { return (_flags & ERestricted); } + inline bool Vertex::isWRestricted () const { return (_flags & WRestricted); } + // ------------------------------------------------------------------- // Class : "Anabatic::PriorityQueue". @@ -214,6 +241,7 @@ namespace Anabatic { public: float getDistance ( const Vertex*, const Vertex*, const Edge* ); + bool isRestricted ( const Vertex*, const Vertex* ) const; public: Dijkstra ( AnabaticEngine* ); ~Dijkstra (); diff --git a/anabatic/src/anabatic/GCell.h b/anabatic/src/anabatic/GCell.h index 1c742fef..7cab666e 100644 --- a/anabatic/src/anabatic/GCell.h +++ b/anabatic/src/anabatic/GCell.h @@ -101,6 +101,11 @@ namespace Anabatic { GCell* vcut ( DbU::Unit x ); bool doGrid (); Contact* getGContact ( Net* ); + + bool isNorth ( GCell* ) const; + bool isSouth ( GCell* ) const; + bool isEast ( GCell* ) const; + bool isWest ( GCell* ) const; // Misc. functions. inline const Flags& flags () const; inline Flags& flags ();