Open
Graph Drawing
Framework

 v.2012.05
 

UpwardPlanRep.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  
00044 #ifdef _MSC_VER
00045 #pragma once
00046 #endif
00047 
00048 #ifndef OGDF_UPWARDPLANREP_H
00049 #define OGDF_UPWARDPLANREP_H
00050 
00051 
00052 #include <ogdf/basic/GraphCopy.h>
00053 
00054 #include <iostream>
00055 
00056 //class SubgraphUpwardPlanarizer;
00057 
00058 
00059 
00060 namespace ogdf {
00061 
00062 
00073 class OGDF_EXPORT UpwardPlanRep : public GraphCopy
00074 {
00075 public:
00076     
00077     friend class SubgraphUpwardPlanarizer;
00078 
00079     //debug only
00080     //friend class FixedEmbeddingUpwardEdgeInserter;
00081 
00082     /* @{
00083      * \brief Creates a planarized representation with respect to \a Gamma.
00084      * Gamma muss be an upward planar embedding with a fixed ext. face      
00085      * Precondition: the graph is a single source graph
00086      */
00087     
00088     UpwardPlanRep(const CombinatorialEmbedding &Gamma); //upward planar embedding with a fixed ext. face            
00089     
00090     UpwardPlanRep(const GraphCopy &GC, // muss be upward embedded and single source
00091         adjEntry adj_ext); // the right face of this adjEntry is the external face      
00092     
00094     UpwardPlanRep(const UpwardPlanRep &UPR);
00095     
00097     UpwardPlanRep(): GraphCopy(), isAugmented(false), t_hat(0), s_hat(0), extFaceHandle(0), crossings(0) // multisources(false)
00098     {
00099         m_Gamma.init(*this);
00100         m_isSinkArc.init(*this, false);
00101         m_isSourceArc.init(*this, false);
00102     }
00103     
00104     virtual ~UpwardPlanRep() {}     
00105 
00107     void insertEdgePathEmbedded(
00108         edge eOrig,     
00109         SList<adjEntry> crossedEdges,
00110         EdgeArray<int> &cost);          
00111 
00113     // pred. the graph muss be a sinlge source graph
00114     // We construct node t and connect the sink-switches with t. The new arcs are sSinkArc.
00115     // For simplicity we construct an additional edge (t,t_hat) (the extFaceArc), where t_hat is the super sink.  
00116     void augment();     
00117 
00119     bool augmented() const { return isAugmented; }
00120 
00122     const CombinatorialEmbedding & getEmbedding() const {return m_Gamma;}
00123 
00124     CombinatorialEmbedding & getEmbedding() {return m_Gamma;}
00125 
00126     node getSuperSink() const {return t_hat;}
00127 
00128     node getSuperSource() const {return s_hat;}  
00129 
00130     int numberOfCrossings() const {return crossings;}
00131 
00133     UpwardPlanRep &operator=(const UpwardPlanRep &copy);
00134 
00135     bool isSinkArc(edge e) const {return m_isSinkArc[e];}
00136 
00137     bool isSourceArc(edge e) const {return m_isSourceArc[e];}   
00138     
00141     adjEntry sinkSwitchOf(node v) {return m_sinkSwitchOf[v];}
00142 
00143     // return the adjEntry of v which right face is f.
00144     adjEntry getAdjEntry(const CombinatorialEmbedding &Gamma, node v, face f) const {
00145         adjEntry adj;       
00146         forall_adj(adj, v) {
00147             if (Gamma.rightFace(adj) == f)
00148                 break;  
00149         }
00150     
00151         OGDF_ASSERT(Gamma.rightFace(adj) == f);
00152         
00153         return adj;
00154     }
00155 
00156     //return the left in edge of node v.
00157     adjEntry leftInEdge(node v) const 
00158     {
00159         if (v->indeg() == 0)
00160             return 0;
00161         adjEntry adj;
00162         forall_adj(adj, v) {
00163             if (adj->theEdge()->target() == v && adj->cyclicSucc()->theEdge()->source() == v)
00164                 break;
00165         }
00166         return adj;
00167     }
00168 
00169     //*************************** debug ********************************
00170     void outputFaces (const CombinatorialEmbedding &embedding) const {
00171         cout << endl << "Face UPR " << endl;            
00172         face f;
00173         forall_faces(f, embedding) {
00174             cout << "face " << f->index() << ": ";
00175             adjEntry adjNext = f->firstAdj();
00176             do {
00177                 cout << adjNext->theEdge() << "; ";
00178                 adjNext = adjNext->faceCycleSucc();
00179             } while(adjNext != f->firstAdj());
00180             cout << endl;
00181         }
00182         if (embedding.externalFace() != 0)
00183             cout << "ext. face of the graph is: " << embedding.externalFace()->index() << endl;
00184         else
00185         cout << "no ext. face set." << endl;
00186         }
00187 
00188     
00189 
00190 protected:
00191 
00192     bool isAugmented; 
00193 
00194     CombinatorialEmbedding m_Gamma; 
00195 
00196     node t_hat; 
00197 
00198     node s_hat; 
00199 
00200     // sinkArk are edges which are added to transform the original graph to single sink graph.
00201     // note: the extFaceHandle is a sink arc.
00202     EdgeArray<bool> m_isSinkArc;
00203 
00204     // source arc are edges which are added to transform the original graph to a single source graph
00205     EdgeArray<bool> m_isSourceArc;
00206 
00207     // 0 if node v is not a non-top-sink-switch of a internal face.
00208     // else v is (non-top) sink-switch of f (= right face of adjEntry). 
00209     NodeArray<adjEntry> m_sinkSwitchOf;
00210 
00211     adjEntry extFaceHandle; // the right face of this adjEntry is always the ext. face  
00212 
00213     int crossings;  
00214     
00215 
00216 private:
00217     void computeSinkSwitches();
00218 
00220     void initMe();
00221 
00222     void copyMe(const UpwardPlanRep &UPR);
00223 
00224     void removeSinkArcs(SList<adjEntry> &crossedEdges);
00225 
00226     void constructSinkArcs(face f, node t);
00227 
00228 };//UpwardPlanRep
00229 
00230 } // end namespace ogdf
00231 
00232 
00233 #endif