Open
Graph Drawing
Framework

 v.2012.05
 

Hierarchy.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00043 #ifdef _MSC_VER
00044 #pragma once
00045 #endif
00046 
00047 #ifndef OGDF_HIERARCHY_H
00048 #define OGDF_HIERARCHY_H
00049 
00050 
00051 #include <ogdf/basic/EdgeArray.h>
00052 #include <ogdf/layered/Level.h>
00053 #include <ogdf/basic/GraphCopy.h>
00054 
00055 
00056 namespace ogdf {
00057 
00058 
00060 
00063 class OGDF_EXPORT Hierarchy {
00064 public:
00065     friend class Level;     
00066 
00067     friend class LayerBasedUPRLayout;
00068     friend class HierarchyLayoutModule;
00069 
00071     enum TraversingDir { downward, upward };
00072 
00073 private:
00074     Array<Level *> m_pLevel; 
00075     GraphCopy m_GC; 
00076     NodeArray<int> m_pos;  
00077     NodeArray<int> m_rank; 
00078 
00079     NodeArray<Array<node> > m_lowerAdjNodes;
00081     NodeArray<Array<node> > m_upperAdjNodes;
00082 
00083     NodeArray<int> m_nSet; 
00084 
00086     NodeArray<ListIterator<node> > m_lastOcc;
00087 
00088     TraversingDir m_direction; 
00089 
00090     bool getMarkedNodes(NodeArray<bool> &markedNodes, int r, List<node> &result, List<int> &positions) {
00091         result.clear();
00092         positions.clear();
00093         bool allDummies = true;
00094         
00095         if (r > high() || r < 0)
00096             return false;
00097 
00098         Level &lvl = *m_pLevel[r];
00099         
00100         for(int i = 0; i <= lvl.high(); i++) {
00101             node v = lvl[i];
00102             if (markedNodes[v]) {
00103                 result.pushBack(v);
00104                 positions.pushBack(pos(v));
00105                 if (!isLongEdgeDummy(v))
00106                     allDummies = false;
00107             }
00108         }       
00109         positions.quicksort();
00110         return allDummies;
00111     }
00112 
00113 
00114 public:
00116     Hierarchy() { }
00118     Hierarchy(const Graph &G, const NodeArray<int> &rank);
00119 
00120     // destruction
00121     ~Hierarchy();
00122 
00123     void createEmpty(const Graph &G);
00124     void initByNodes(const List<node> &nodes,
00125         EdgeArray<edge> &eCopy,
00126         const NodeArray<int> &rank);
00127 
00129     operator const GraphCopy &() const { return m_GC; }
00130 
00132     TraversingDir direction() const {
00133         return m_direction;
00134     }
00135 
00137     void direction (TraversingDir dir) {
00138         m_direction = dir;
00139     }
00140 
00142     int size() const { return m_pLevel.size(); }
00143 
00145     int high() const { return m_pLevel.high(); }
00146 
00148     int rank(node v) const { return m_rank[v]; }
00149 
00151     int pos(node v) const { return m_pos[v]; }
00152 
00154     const Array<node> &adjNodes(node v) {
00155         return (m_direction == downward) ? m_lowerAdjNodes[v] :
00156         m_upperAdjNodes[v];
00157     }
00158     
00160     const Array<node> &adjNodes(node v, TraversingDir dir) const {
00161         return (dir == downward) ? m_lowerAdjNodes[v] :
00162         m_upperAdjNodes[v];
00163     }
00164 
00166     const Level &adjLevel(int i) const {
00167         return (m_direction == downward) ? *m_pLevel[i-1] : *m_pLevel[i+1];
00168     
00169     }
00170 
00171     bool isLongEdgeDummy(node v) const {
00172         return (m_GC.isDummy(v) && v->outdeg() == 1);
00173     }
00174 
00176     const Level &operator[](int i) const { return *m_pLevel[i]; }
00177 
00179     Level &operator[](int i) { return *m_pLevel[i]; }
00180 
00181     
00183     int calculateCrossings(int i);
00185     int calculateCrossings();
00186 
00188     int calculateCrossingsPlaneSweep(int i);
00190     int calculateCrossingsPlaneSweep();
00191 
00193     int calculateCrossingsSimDraw(int i, const EdgeArray<unsigned int> *edgeSubGraph);
00195     int calculateCrossingsSimDraw(const EdgeArray<unsigned int> *edgeSubGraph);
00196 
00197     
00199     void storePos (NodeArray<int> &oldPos);
00201     void restorePos (const NodeArray<int> &newPos);
00202 
00204     void permute();
00205 
00207     void separateCCs(int numCC, NodeArray<int> &component);
00208 
00209     bool transpose(node v);
00210 
00211     void print(ostream &os);
00212 
00213     void buildAdjNodes(int i);
00214     void buildAdjNodes();
00215 
00216     void check();
00217 
00218 private:
00219     void doInit(const NodeArray<int> &rank);
00220 
00221     int transposePart(const Array<node> &adjV, const Array<node> &adjW);    
00222 
00223     OGDF_MALLOC_NEW_DELETE
00224 };
00225 
00226 
00227 } // end namespace ogdf
00228 
00229 
00230 #endif