Open
Graph Drawing
Framework

 v.2012.05
 

UpwardPlanarModule.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  
00045 #ifdef _MSC_VER
00046 #pragma once
00047 #endif
00048 
00049 #ifndef OGDF_UPWARD_PLANAR_MODULE_H
00050 #define OGDF_UPWARD_PLANAR_MODULE_H
00051 
00052 
00053 #include <ogdf/basic/CombinatorialEmbedding.h>
00054 #include <ogdf/basic/NodeArray.h>
00055 #include <ogdf/basic/SList.h>
00056 
00057 
00058 namespace ogdf {
00059 
00060     class OGDF_EXPORT SPQRTree;
00061     class OGDF_EXPORT Skeleton;
00062     class OGDF_EXPORT StaticPlanarSPQRTree;
00063     class OGDF_EXPORT ExpansionGraph;
00064     class OGDF_EXPORT FaceSinkGraph;
00065 
00066 //---------------------------------------------------------
00067 // UpwardPlanarModule
00068 //---------------------------------------------------------
00069 class OGDF_EXPORT UpwardPlanarModule
00070 {
00071 public:
00072     // constructor
00073     UpwardPlanarModule() { }
00074 
00075 
00076     //------------------------------
00077     // general single-source graphs
00078 
00079     // tests if single-source digraph G is upward planar
00080     bool upwardPlanarityTest(Graph &G) {
00081         NodeArray<SListPure<adjEntry> > adjacentEdges;
00082         return doUpwardPlanarityTest(G,false,adjacentEdges);
00083     }
00084 
00085     // tests if single-source digraph G is upward planar and, if true,
00086     // constructs an upward-planar embeding of G
00087     bool upwardPlanarEmbed(Graph &G)
00088     {
00089         NodeArray<SListPure<adjEntry> > adjacentEdges(G);
00090         if(doUpwardPlanarityTest(G,true,adjacentEdges) == false)
00091             return false;
00092         SList<node> augmentedNodes;
00093         SList<edge> augmentedEdges;
00094         doUpwardPlanarityEmbed(G,adjacentEdges,false,augmentedNodes,augmentedEdges);
00095         return true;
00096     }
00097 
00098     // tests if single-source digraph G is upward planar and, if true,
00099     // augments G to a planar st-digraph
00100     bool upwardPlanarAugment(Graph &G,
00101         SList<node> &augmentedNodes,
00102         SList<edge> &augmentedEdges)
00103     {
00104         NodeArray<SListPure<adjEntry> > adjacentEdges(G);
00105         if(doUpwardPlanarityTest(G,true,adjacentEdges) == false)
00106             return false;
00107         doUpwardPlanarityEmbed(G,adjacentEdges,true,augmentedNodes,augmentedEdges);
00108         return true;
00109     }
00110 
00111     // tests if single-source digraph G is upward planar and, if true,
00112     // augments G to a planar st-digraph
00113     bool upwardPlanarAugment(Graph &G,
00114         node &superSink,
00115         SList<edge> &augmentedEdges)
00116     {
00117         NodeArray<SListPure<adjEntry> > adjacentEdges(G);
00118         if(doUpwardPlanarityTest(G,true,adjacentEdges) == false)
00119             return false;
00120         doUpwardPlanarityEmbed(G,adjacentEdges,true,superSink,augmentedEdges);
00121         return true;
00122     }
00123 
00124     // tests if single-source digraph G is upward planar and, if true,
00125     // augments G to a planar st-digraph
00126     bool upwardPlanarAugment(Graph &G)
00127     {
00128         node superSink;
00129         SList<edge> augmentedEdges;
00130         return upwardPlanarAugment(G,superSink,augmentedEdges);
00131     }
00132 
00133 
00134     // --------------------------------
00135     // embedded single-source digraphs
00136 
00137     // tests if embedded single-source digraph G can be drawn upward-planar
00138     // realizing the given embedding and returns in externalFaces the set
00139     // of faces which can be choosen as external face
00140     bool testEmbeddedBiconnected(
00141         const Graph &G,                       // embedded input graph
00142         const ConstCombinatorialEmbedding &E, // embedding
00143         SList<face> &externalFaces);          // possible external faces
00144 
00145     // tests if embedded single-source digraph G can be drawn upward-planar
00146     // realizing the given embedding and augments G to a planar st-digraph
00147     bool testAndAugmentEmbedded(
00148         Graph &G,                    // embedded input graph 
00149         SList<node> &augmentedNodes, // augmented nodes
00150         SList<edge> &augmentedEdges);// augmented edges
00151 
00152     bool testAndAugmentEmbedded(
00153         Graph &G,                    // embedded input graph 
00154         node  &superSink,            // super sink
00155         SList<edge> &augmentedEdges);// augmented edges
00156 
00157 
00158 private:
00159 
00160     struct DegreeInfo {
00161         int m_indegSrc;
00162         int m_outdegSrc;
00163         int m_indegTgt;
00164         int m_outdegTgt;
00165     };
00166 
00167     // classes defined and used in UpwardPlanarModule.cpp
00168     class OGDF_EXPORT SkeletonInfo;
00169     class ConstraintRooting;
00170 
00171 
00172     // returns the single-source if present, 0 otherwise
00173     node getSingleSource(const Graph &G);
00174 
00175     //-----------------------------------------------------------
00176     // the following functions perform actual testing, embedding,
00177     // and augmenting
00178 
00179     // test and compute adjacency lists of embedding
00180     bool doUpwardPlanarityTest(
00181         Graph &G,
00182         bool  embed,
00183         NodeArray<SListPure<adjEntry> > &adjacentEdges);
00184 
00185     // embed and compute st-augmentation (original implementation - inserts
00186     // also new nodes corresponding to faces into G)
00187     void doUpwardPlanarityEmbed(
00188         Graph &G,
00189         NodeArray<SListPure<adjEntry> > &adjacentEdges,
00190         bool augment,
00191         SList<node> &augmentedNodes,
00192         SList<edge> &augmentedEdges);
00193 
00194     // embed and compute st-augmentation (new implementation - inserts only
00195     // one new node into G which is the super sink)
00196     void doUpwardPlanarityEmbed(
00197         Graph &G,
00198         NodeArray<SListPure<adjEntry> > &adjacentEdges,
00199         bool augment,
00200         node &superSink,
00201         SList<edge> &augmentedEdges);
00202 
00203     // performs the actual test (and computation of sorted adjacency lists) for
00204     // each biconnected component
00205     bool testBiconnectedComponent(
00206         ExpansionGraph &exp,
00207         node sG,
00208         int parentBlock,
00209         bool embed,
00210         NodeArray<SListPure<adjEntry> > &adjacentEdges);
00211 
00212 
00213     //-------------------------------
00214     // computatation of st-skeletons
00215 
00216     // compute sT-skeletons
00217     // test for upward-planarity, build constraints for rooting, and find a
00218     // rooting of the tree satisfying all constraints
00219     // returns true iff such a rooting exists
00220     edge directSkeletons(
00221         SPQRTree &T,
00222         NodeArray<SkeletonInfo> &skInfo);
00223 
00224     // precompute information: in-/outdegrees in pertinent graph, contains
00225     // pertinent graph the source?
00226     void computeDegreesInPertinent(
00227         const SPQRTree &T,
00228         node s,
00229         NodeArray<SkeletonInfo> &skInfo, 
00230         node vT);
00231 
00232     
00233     //------------------------
00234     // embedding of skeletons
00235 
00236     bool initFaceSinkGraph(const Graph &M, SkeletonInfo &skInfo);
00237 
00238     void embedSkeleton(
00239         Graph &G,
00240         StaticPlanarSPQRTree &T,
00241         NodeArray<SkeletonInfo> &skInfo,
00242         node vT,
00243         bool extFaceIsLeft);
00244 
00245 
00246     //--------------------------
00247     // assigning sinks to faces
00248 
00249     void assignSinks(
00250         FaceSinkGraph &F,
00251         face extFace,
00252         NodeArray<face> &assignedFace);
00253 
00254     node dfsAssignSinks(
00255         FaceSinkGraph &F,
00256         node v,                      // current node
00257         node parent,                 // its parent
00258         NodeArray<face> &assignedFace);
00259 
00260 
00261     //------------------------------
00262     // for testing / debugging only
00263 
00264     bool checkDegrees(
00265         SPQRTree &T,
00266         node s,
00267         NodeArray<SkeletonInfo> &skInfo);
00268 
00269     bool virtualEdgesDirectedEqually(const SPQRTree &T);
00270 
00271 
00272 
00273 }; // class UpwardPlanarModule
00274 
00275 
00276 } // end namespace ogdf
00277 
00278 
00279 #endif