Open
Graph Drawing
Framework

 v.2012.05
 

CPlanarSubClusteredST.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  
00042 #ifdef _MSC_VER
00043 #pragma once
00044 #endif
00045 
00046 #ifndef OGDF_CPLANAR_SUBCLUSTERED_ST_H
00047 #define OGDF_CPLANAR_SUBCLUSTERED_ST_H
00048 
00049 
00050 #include <ogdf/cluster/ClusterGraph.h>
00051 #include <ogdf/cluster/ClusterArray.h>
00052 #include <ogdf/basic/EdgeArray.h>
00053 
00054 namespace ogdf {
00055 
00057 class CPlanarSubClusteredST
00058 {
00059 
00060 public:
00061 
00062     CPlanarSubClusteredST() {};
00063 
00065     virtual void call(const ClusterGraph& CG, EdgeArray<bool>& inST);
00068     virtual void call(const ClusterGraph& CG, 
00069         EdgeArray<bool>& inST,
00070         EdgeArray<double>& weight);
00071 
00072 private:
00073 
00075     void dfsBuildOriginalST(/*ClusterGraph& CG,*/
00076     node v,
00077     ClusterArray< EdgeArray<bool> > &treeEdges,    //edges in repgraph
00078     EdgeArray<bool>& inST,                         //original edges
00079     NodeArray<bool> &visited);
00080     //builds spanning tree on graph of node v in treeEdges
00081     void dfsBuildSpanningTree(node v, 
00082                               EdgeArray<bool> &treeEdges,
00083                               NodeArray<bool> &visited);
00084 
00088     void constructRepresentationGraphNodes(const ClusterGraph& CG,
00089                                            Graph& g, 
00090                                            cluster c
00091                                            )
00092     {
00093         
00094         //insert nodes for all child clusters
00095         ListConstIterator<cluster> it;
00096         for (it = c->cBegin(); it.valid(); it++) 
00097         {
00098             node v = g.newNode();
00099             m_cRepNode[*it] = v;
00100         }//for
00101         //insert nodes for all node entries in c
00102         ListConstIterator<node> itn;
00103         for (itn = c->nBegin(); itn.valid(); itn++) 
00104         {
00105             node v = g.newNode();
00106             m_vRepNode[*itn] = v;
00107         }//for
00108     }//constructRepresentationGraphNodes
00109 
00111     void constructRepresentationGraphEdges(const ClusterGraph& CG,
00112                                            ClusterArray<Graph*>& RepGraph)
00113     {
00114         edge e;
00115         forall_edges(e, CG.getGraph())
00116         {
00117             //insert representation in RepGraph[allocation cluster]
00118             //defined by lowest common ancestor of end points
00119             node u = e->source();
00120             node v = e->target();
00121             cluster uAncestor, vAncestor;
00122             cluster allocCluster = 
00123                 CG.commonClusterLastAncestors(u,v, uAncestor, vAncestor);
00124             m_allocCluster[e] = allocCluster;
00125             //now derive the real ancestors (maybe the nodes themselves from
00126             //the supplied clusters
00127 
00128             //Case1: both nodes in same cluster => connect the nodes in the 
00129             //cluster representation graph
00130             if (uAncestor == vAncestor)
00131             {
00132                 m_repEdge[e] = RepGraph[uAncestor]->newEdge(
00133                                 m_vRepNode[u], m_vRepNode[v]);
00134             }//if
00135             else 
00136             {
00137                 OGDF_ASSERT(!((uAncestor == CG.rootCluster())&&
00138                     (vAncestor == CG.rootCluster())))
00139                 //now only one node can be directly in rootcluster
00140                 //this case now seems to fall together with else else...
00141                 if (uAncestor == CG.rootCluster())
00142                 {
00143                     m_repEdge[e] = RepGraph[uAncestor]->newEdge(
00144                                 m_vRepNode[u], m_cRepNode[vAncestor]);
00145                 }//if u in rootcluster
00146                 else if (vAncestor == CG.rootCluster())
00147                 {
00148                     m_repEdge[e] = RepGraph[vAncestor]->newEdge(
00149                                 m_cRepNode[uAncestor], m_vRepNode[v]);
00150                 }//if v in rootcluster
00151                 else
00152                 {
00153                     OGDF_ASSERT(allocCluster != 0)
00154                     //now create edge in lowest common cluster
00155                     node v1, v2;
00156                     v1 = ( (uAncestor == 0) ? m_vRepNode[u] : 
00157                                 m_cRepNode[uAncestor]);
00158                     v2 = ( (vAncestor == 0) ? m_vRepNode[v] : 
00159                                 m_cRepNode[vAncestor]);
00160                     m_repEdge[e] = RepGraph[allocCluster]->newEdge(v1, v2);
00161                 }
00162             }//else
00163 
00164         }//foralledges
00165         //m_repEdge
00166     }//constructRepresentationGraphEdges
00167 
00169     void computeRepresentationGraphs(const ClusterGraph& CG, 
00170                                      ClusterArray<Graph*>& RepGraph)
00171     {
00172         cluster c;
00173         forall_clusters(c, CG)
00174         {
00175             RepGraph[c] = new Graph;
00176             constructRepresentationGraphNodes(CG, *RepGraph[c], c);
00177         }//forallclusters
00178         constructRepresentationGraphEdges(CG, RepGraph);
00179     }//computeRepresentationGraphs
00180 
00181     void deleteRepresentationGraphs(const ClusterGraph& CG, 
00182                                      ClusterArray<Graph*>& RepGraph)
00183     {
00184         cluster c;
00185         forall_clusters(c, CG)
00186         {
00187             if (RepGraph[c])
00188                 delete RepGraph[c];
00189         }//forallclusters
00190     
00191     }//deleteRepresentationGraphs
00192 
00194     void initialize(const ClusterGraph& CG);
00195     
00196     //****************************************************
00197     //data fields
00198 
00199     // store status of original edge: in subclustered graph? also used to check spanning tree
00200     //EdgeArray<int> m_edgeStatus;
00201 
00203     EdgeArray<cluster> m_allocCluster;
00205     EdgeArray<edge> m_repEdge;
00207     ClusterArray<node> m_cRepNode;
00208     NodeArray<node> m_vRepNode;
00209     //pointer to input ClusterPlanRep
00210     //set in call, not to be used anywhere else
00211     //m_pCPR;
00212     //int m_genDebug; //only for debugging
00213 
00214 };//cplanarsubclusteredST
00215 
00216 } // end namespace ogdf
00217 
00218 
00219 #endif