Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

ConnectedSubgraph.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/NodeArray.h>
35 #include <ogdf/basic/EdgeArray.h>
36 
37 namespace ogdf {
38 namespace embedder {
39 
40 template<class T>
42 {
43 public:
44  //constructor
46 
56  static void call(const Graph& G,
57  Graph& SG,
58  const node& nG,
59  node& nSG,
60  const NodeArray<T>& nodeLengthG,
61  NodeArray<T>& nodeLengthSG)
62  {
63  EdgeArray<T> edgeLengthG(G, 1);
64  EdgeArray<T> edgeLengthSG;
65  call(G, SG, nG, nSG, nodeLengthG, nodeLengthSG, edgeLengthG, edgeLengthSG);
66  }
67 
77  static void call(const Graph& G,
78  Graph& SG,
79  const node& nG,
80  const NodeArray<T>& nodeLengthG,
81  NodeArray<T>& nodeLengthSG,
82  NodeArray<node>& nG_to_nSG)
83  {
84  node nSG;
85  NodeArray<node> nSG_to_nG;
86  EdgeArray<edge> eSG_to_eG;
87  EdgeArray<edge> eG_to_eSG;
88  EdgeArray<T> edgeLengthG(G, 1);
89  EdgeArray<T> edgeLengthSG;
90  call(G, SG, nG, nSG, nSG_to_nG, eSG_to_eG, nG_to_nSG, eG_to_eSG,
91  nodeLengthG, nodeLengthSG, edgeLengthG, edgeLengthSG);
92  }
93 
105  static void call(const Graph& G,
106  Graph& SG,
107  const node& nG,
108  node& nSG,
109  const NodeArray<T>& nodeLengthG,
110  NodeArray<T>& nodeLengthSG,
111  const EdgeArray<T>& edgeLengthG,
112  EdgeArray<T>& edgeLengthSG)
113  {
114  NodeArray<node> nSG_to_nG(SG);
115  EdgeArray<edge> eSG_to_eG(SG);
116  call(G, SG, nG, nSG, nSG_to_nG, eSG_to_eG, nodeLengthG,
117  nodeLengthSG, edgeLengthG, edgeLengthSG);
118  }
119 
128  static void call(const Graph& G,
129  Graph& SG,
130  const node& nG,
131  const NodeArray<T>& nodeLengthG,
132  NodeArray<T>& nodeLengthSG)
133  {
134  node nSG;
135  call(G, SG, nG, nSG, nodeLengthG, nodeLengthSG);
136  }
137 
148  static void call(const Graph& G,
149  Graph& SG,
150  const node& nG,
151  const NodeArray<T>& nodeLengthG,
152  NodeArray<T>& nodeLengthSG,
153  const EdgeArray<T>& edgeLengthG,
154  EdgeArray<T>& edgeLengthSG)
155  {
156  node nSG = nullptr;
157  call(G, SG, nG, nSG, nodeLengthG, nodeLengthSG, edgeLengthG, edgeLengthSG);
158  }
159 
173  static void call(const Graph& G,
174  Graph& SG,
175  const node& nG,
176  node& nSG,
177  NodeArray<node>& nSG_to_nG,
178  EdgeArray<edge>& eSG_to_eG,
179  const NodeArray<T>& nodeLengthG,
180  NodeArray<T>& nodeLengthSG,
181  const EdgeArray<T>& edgeLengthG,
182  EdgeArray<T>& edgeLengthSG)
183  {
184  NodeArray<node> nG_to_nSG;
185  EdgeArray<edge> eG_to_eSG;
186  call(G, SG, nG, nSG, nSG_to_nG, eSG_to_eG, nG_to_nSG, eG_to_eSG, nodeLengthG,
187  nodeLengthSG, edgeLengthG, edgeLengthSG);
188  }
189 
205  static void call(const Graph& G,
206  Graph& SG,
207  const node& nG,
208  node& nSG,
209  NodeArray<node>& nSG_to_nG,
210  EdgeArray<edge>& eSG_to_eG,
211  NodeArray<node>& nG_to_nSG,
212  EdgeArray<edge>& eG_to_eSG,
213  const NodeArray<T>& nodeLengthG,
214  NodeArray<T>& nodeLengthSG,
215  const EdgeArray<T>& edgeLengthG,
216  EdgeArray<T>& edgeLengthSG);
217 
228  static void call(const Graph& G,
229  Graph& SG,
230  const node& nG,
231  NodeArray<node>& nSG_to_nG,
232  EdgeArray<edge>& eSG_to_eG,
233  NodeArray<node>& nG_to_nSG,
234  EdgeArray<edge>& eG_to_eSG);
235 
243  static void call(const Graph& G,
244  Graph& SG,
245  const node& nG,
246  NodeArray<node>& nSG_to_nG)
247  {
248  NodeArray<T> nodeLengthG(G, 0);
249  NodeArray<T> nodeLengthSG(SG);
250  EdgeArray<T> edgeLengthG(G, 0);
251  EdgeArray<T> edgeLengthSG(SG);
252  node nSG;
253  EdgeArray<edge> eSG_to_eG;
254  call(G, SG, nG, nSG, nSG_to_nG, eSG_to_eG, nodeLengthG, nodeLengthSG, edgeLengthG, edgeLengthSG);
255  }
256 
257 private:
277  static void recursion(Graph& SG,
278  NodeArray<bool> &nodeVisited,
279  EdgeArray<bool> &edgeVisited,
280  const node& nG,
281  const NodeArray<T>& nodeLengthG,
282  NodeArray<T>& nodeLengthSG,
283  const EdgeArray<T>& edgeLengthG,
284  EdgeArray<T>& edgeLengthSG,
285  NodeArray<node>& nSG_to_nG,
286  EdgeArray<edge>& eSG_to_eG,
287  NodeArray<node>& nG_to_nSG,
288  EdgeArray<edge>& eG_to_eSG);
289 };
290 
291 
292 template<class T>
294  Graph& SG,
295  NodeArray<bool> &nodeVisited,
296  EdgeArray<bool> &edgeVisited,
297  const node& nG,
298  const NodeArray<T>& nodeLengthG,
299  NodeArray<T>& nodeLengthSG,
300  const EdgeArray<T>& edgeLengthG,
301  EdgeArray<T>& edgeLengthSG,
302  NodeArray<node>& nSG_to_nG,
303  EdgeArray<edge>& eSG_to_eG,
304  NodeArray<node>& nG_to_nSG,
305  EdgeArray<edge>& eG_to_eSG)
306 {
307  node nSG = SG.newNode();
308  nodeLengthSG[nSG] = nodeLengthG[nG];
309  nG_to_nSG[nG] = nSG;
310  nSG_to_nG[nSG] = nG;
311  nodeVisited[nG] = true;
312 
313  for(adjEntry adj : nG->adjEntries) {
314  edge eG = adj->theEdge();
315  if (!nodeVisited[eG->source()])
316  recursion(SG, nodeVisited, edgeVisited, eG->source(),
317  nodeLengthG, nodeLengthSG, edgeLengthG, edgeLengthSG,
318  nSG_to_nG, eSG_to_eG, nG_to_nSG, eG_to_eSG);
319  else if (!nodeVisited[eG->target()])
320  recursion(SG, nodeVisited, edgeVisited, eG->target(),
321  nodeLengthG, nodeLengthSG, edgeLengthG, edgeLengthSG,
322  nSG_to_nG, eSG_to_eG, nG_to_nSG, eG_to_eSG);
323  if (!edgeVisited[eG])
324  {
325  edge eSG = SG.newEdge(nG_to_nSG[eG->source()], nG_to_nSG[eG->target()]);
326  edgeLengthSG[eSG] = edgeLengthG[eG];
327  eG_to_eSG[eG] = eSG;
328  eSG_to_eG[eSG] = eG;
329  edgeVisited[eG] = true;
330  }
331  }
332 }
333 
334 
335 template<class T>
337  Graph& SG,
338  const node& nG,
339  node& nSG,
340  NodeArray<node>& nSG_to_nG,
341  EdgeArray<edge>& eSG_to_eG,
342  NodeArray<node>& nG_to_nSG,
343  EdgeArray<edge>& eG_to_eSG,
344  const NodeArray<T>& nodeLengthG,
345  NodeArray<T>& nodeLengthSG,
346  const EdgeArray<T>& edgeLengthG,
347  EdgeArray<T>& edgeLengthSG)
348 {
349  SG.clear();
350 
351  NodeArray<bool> nodeVisited(G,false);
352  EdgeArray<bool> edgeVisited(G,false);
353 
354 #if 0
355  const int n = G.numberOfNodes();
356  const int m = G.numberOfEdges();
357 
358  bool* nodeVisited = new bool[n];
359  bool* edgeVisited = new bool[m];
360  for (int i = 0; i < n; i++)
361  nodeVisited[i] = false;
362  for (int i = 0; i < m; i++)
363  edgeVisited[i] = false;
364 #endif
365  nSG_to_nG.init(SG);
366  eSG_to_eG.init(SG);
367  nodeLengthSG.init(SG);
368  edgeLengthSG.init(SG);
369  nG_to_nSG.init(G);
370  eG_to_eSG.init(G);
371 
372  recursion(SG, nodeVisited, edgeVisited, nG,
373  nodeLengthG, nodeLengthSG, edgeLengthG, edgeLengthSG,
374  nSG_to_nG, eSG_to_eG, nG_to_nSG, eG_to_eSG);
375  nSG = nG_to_nSG[nG];
376 
377 #if 0
378  delete[] nodeVisited;
379  delete[] edgeVisited;
380 #endif
381 }
382 
383 
384 template<class T>
386  Graph& SG,
387  const node& nG,
388  NodeArray<node>& nSG_to_nG,
389  EdgeArray<edge>& eSG_to_eG,
390  NodeArray<node>& nG_to_nSG,
391  EdgeArray<edge>& eG_to_eSG)
392 {
393  SG.clear();
394 
395  NodeArray<bool> nodeVisited(G,false);
396  EdgeArray<bool> edgeVisited(G,false);
397 
398 #if 0
399  bool* nodeVisited = new bool[G.numberOfNodes()];
400  bool* edgeVisited = new bool[G.numberOfEdges()];
401  for (int i = 0; i < G.numberOfNodes(); i++)
402  nodeVisited[i] = false;
403  for (int i = 0; i < G.numberOfEdges(); i++)
404  edgeVisited[i] = false;
405 #endif
406  nSG_to_nG.init(SG);
407  eSG_to_eG.init(SG);
408  NodeArray<T> nodeLengthG(G, 0);
409  NodeArray<T> nodeLengthSG(SG);
410  EdgeArray<T> edgeLengthG(G, 1);
411  EdgeArray<T> edgeLengthSG(SG);
412  nG_to_nSG.init(G);
413  eG_to_eSG.init(G);
414 
415  recursion(SG, nodeVisited, edgeVisited, nG,
416  nodeLengthG, nodeLengthSG, edgeLengthG, edgeLengthSG,
417  nSG_to_nG, eSG_to_eG, nG_to_nSG, eG_to_eSG);
418 
419 #if 0
420  delete[] nodeVisited;
421  delete[] edgeVisited;
422 #endif
423 }
424 
425 }
426 }
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:327
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:95
virtual void clear()
Removes all nodes and all edges from the graph.
void init()
Reinitializes the array. Associates the array with no graph.
Definition: EdgeArray.h:320
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
void init()
Reinitializes the array. Associates the array with no graph.
Definition: NodeArray.h:292
static void call(const Graph &G, Graph &SG, const node &nG, const NodeArray< T > &nodeLengthG, NodeArray< T > &nodeLengthSG, NodeArray< node > &nG_to_nSG)
Computes a connected subgraph SG of G containing node nG.
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
static void call(const Graph &G, Graph &SG, const node &nG, node &nSG, NodeArray< node > &nSG_to_nG, EdgeArray< edge > &eSG_to_eG, const NodeArray< T > &nodeLengthG, NodeArray< T > &nodeLengthSG, const EdgeArray< T > &edgeLengthG, EdgeArray< T > &edgeLengthSG)
Computes a connected subgraph SG of G containing node nG.
static void recursion(Graph &SG, NodeArray< bool > &nodeVisited, EdgeArray< bool > &edgeVisited, const node &nG, const NodeArray< T > &nodeLengthG, NodeArray< T > &nodeLengthSG, const EdgeArray< T > &edgeLengthG, EdgeArray< T > &edgeLengthSG, NodeArray< node > &nSG_to_nG, EdgeArray< edge > &eSG_to_eG, NodeArray< node > &nG_to_nSG, EdgeArray< edge > &eG_to_eSG)
Copies to SG node nG and recursively all adjacent edges and nodes.
int numberOfEdges() const
Returns the number of edges in the graph.
Definition: Graph_d.h:581
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
Declaration and implementation of EdgeArray class.
static void call(const Graph &G, Graph &SG, const node &nG, node &nSG, const NodeArray< T > &nodeLengthG, NodeArray< T > &nodeLengthSG)
Computes a connected subgraph SG of G containing node nG.
static void call(const Graph &G, Graph &SG, const node &nG, const NodeArray< T > &nodeLengthG, NodeArray< T > &nodeLengthSG)
Computes a connected subgraph SG of G containing node nG.
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
Class for the representation of edges.
Definition: Graph_d.h:291
Class for the representation of nodes.
Definition: Graph_d.h:167
Declaration and implementation of NodeArray class.
static void call(const Graph &G, Graph &SG, const node &nG, const NodeArray< T > &nodeLengthG, NodeArray< T > &nodeLengthSG, const EdgeArray< T > &edgeLengthG, EdgeArray< T > &edgeLengthSG)
Computes a connected subgraph SG of G containing node nG.
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:325
The namespace for all OGDF objects.
int numberOfNodes() const
Returns the number of nodes in the graph.
Definition: Graph_d.h:578
node newNode()
Creates a new node and returns it.
static void call(const Graph &G, Graph &SG, const node &nG, node &nSG, const NodeArray< T > &nodeLengthG, NodeArray< T > &nodeLengthSG, const EdgeArray< T > &edgeLengthG, EdgeArray< T > &edgeLengthSG)
Computes a connected subgraph SG of G containing node nG.
static void call(const Graph &G, Graph &SG, const node &nG, NodeArray< node > &nSG_to_nG)
Computes a connected subgraph SG of G containing node nG.
Class for adjacency list elements.
Definition: Graph_d.h:78
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:198