Open
Graph Drawing
Framework

 v.2010.10
 

extended_graph_alg.h

Go to the documentation of this file.
00001 /*
00002  * $Revision: 2027 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2010-09-01 11:55:17 +0200 (Wed, 01 Sep 2010) $ 
00007  ***************************************************************/
00008  
00052 #ifdef _MSC_VER
00053 #pragma once
00054 #endif
00055 
00056 #ifndef OGDF_EXTENDED_GRAPH_ALG_H
00057 #define OGDF_EXTENDED_GRAPH_ALG_H
00058 
00059 
00060 #include <ogdf/cluster/ClusterGraph.h>
00061 
00062 namespace ogdf {
00063 
00064 
00065 //---------------------------------------------------------
00066 // Methods for induced subgraphs
00067 //---------------------------------------------------------
00068 
00070 template<class LISTITERATOR>
00071 void inducedSubGraph(const Graph &G, LISTITERATOR start, Graph &subGraph)
00072 {
00073     NodeArray<node> nodeTableOrig2New;
00074     inducedSubGraph(G,start,subGraph,nodeTableOrig2New);
00075 }
00076 
00078 template<class LISTITERATOR>
00079 void inducedSubGraph(const Graph &G,
00080                      LISTITERATOR start,
00081                      Graph &subGraph,
00082                      NodeArray<node> &nodeTableOrig2New)
00083 {
00084     subGraph.clear();
00085     nodeTableOrig2New.init(G,0);
00086 
00087     EdgeArray<bool> mark(G,false);
00088 
00089     LISTITERATOR its;
00090     for (its = start; its.valid(); its++)
00091     {
00092         node w = (*its);
00093         OGDF_ASSERT(w != 0 && w->graphOf() == &G);
00094         nodeTableOrig2New[w] = subGraph.newNode();
00095 
00096         adjEntry adj = w->firstAdj();
00097         forall_adj(adj,w)
00098         {
00099             edge e = adj->theEdge();
00100             if (nodeTableOrig2New[e->source()] && nodeTableOrig2New[e->target()] && !mark[e])
00101             {
00102                 subGraph.newEdge(nodeTableOrig2New[e->source()],nodeTableOrig2New[e->target()]);
00103                 mark[e] = true;
00104             }
00105         }
00106     }
00107 }
00108                      
00109 
00111 template<class LISTITERATOR>
00112 void inducedSubGraph(const Graph &G,
00113                      LISTITERATOR start,
00114                      Graph &subGraph,
00115                      NodeArray<node> &nodeTableOrig2New,
00116                      EdgeArray<edge> &edgeTableOrig2New)
00117 {
00118     subGraph.clear();
00119     nodeTableOrig2New.init(G,0);
00120     edgeTableOrig2New.init(G,0);
00121 
00122     EdgeArray<bool> mark(G,false);
00123 
00124     LISTITERATOR its;
00125     for (its = start; its.valid(); its++)
00126     {
00127         node w = (*its);
00128         OGDF_ASSERT(w != 0 && w->graphOf() == &G);
00129         nodeTableOrig2New[w] = subGraph.newNode();
00130 
00131         adjEntry adj = w->firstAdj();
00132         forall_adj(adj,w)
00133         {
00134             edge e = adj->theEdge();
00135             if (nodeTableOrig2New[e->source()] && 
00136                 nodeTableOrig2New[e->target()] && 
00137                 !mark[e])
00138             {
00139                 edgeTableOrig2New[e] = 
00140                     subGraph.newEdge(
00141                         nodeTableOrig2New[e->source()],
00142                         nodeTableOrig2New[e->target()]);
00143                 mark[e] = true;
00144             }
00145         }
00146     }
00147 }
00148 
00149 
00150 template<class NODELISTITERATOR,class EDGELIST>
00151 void inducedSubgraph(Graph &G,NODELISTITERATOR &it,EDGELIST &E)
00152 {
00153     NODELISTITERATOR itBegin = it;
00154     NodeArray<bool>  mark(G,false);
00155 
00156     for (;it.valid();it++)
00157         mark[(*it)] = true;
00158     it = itBegin;
00159     for (;it.valid();it++)
00160     {
00161         node v = (*it);
00162         adjEntry adj;
00163         forall_adj(adj,v)
00164         {
00165             edge e = adj->theEdge();
00166             if (mark[e->source()] && mark[e->target()])
00167                 E.pushBack(e);
00168         }
00169     }
00170 }
00171 
00172 
00173 //---------------------------------------------------------
00174 // Methods for clustered graphs
00175 //---------------------------------------------------------
00176 
00177 
00178 // true <=> C is C-connected
00179 OGDF_EXPORT bool isCConnected(const ClusterGraph &C);
00180 
00181 //connect clusters to achieve c-connectivity (probably loosing planarity)
00182 //GG is underlying graph of C, returns inserted edges in addededges
00183 //simple: only connect underlying cluster subgraph without crossing check
00184 OGDF_EXPORT void makeCConnected(
00185     ClusterGraph& C,
00186     Graph& GG,
00187     List<edge>& addedEdges,
00188     bool simple = true);
00189 
00190 
00191 
00192 
00193 //---------------------------------------------------------
00194 // Methods for st-numbering
00195 //---------------------------------------------------------
00196 
00197 
00198 // Computes an st-Numbering.
00199 // Precondition: G must be biconnected and simple.
00200 // Exception: the Graph is allowed to have isolated nodes.
00201 // The st-numbers are stored in NodeArray. Return value is 
00202 // the number t. It is 0, if the computation was unsuccessful.
00203 // The nodes s and t may be specified. In this case 
00204 // s and t have to be adjacent.
00205 // If s and t are set 0 and parameter randomized is set to true,
00206 // the st edge is chosen to be a random edge in G.
00207 OGDF_EXPORT int stNumber(const Graph &G,
00208     NodeArray<int> &numbering,
00209     node s = 0,
00210     node t = 0,
00211     bool randomized = false);
00212 
00213 // Tests, whether a numbering is an st-numbering
00214 // Precondition: G must be biconnected and simple.
00215 // Exception: the Graph is allowed to have isolated nodes.
00216 OGDF_EXPORT bool testSTnumber(const Graph &G, NodeArray<int> &st_no,int max);
00217 
00218 
00219 //---------------------------------------------------------
00220 // Methods for minimum spanning tree computation
00221 //---------------------------------------------------------
00223 
00229 double computeMinST(const Graph &G, EdgeArray<double> &weight, EdgeArray<bool> &isInTree);
00230 
00231 } // end namespace ogdf
00232 
00233 
00234 #endif