Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

ConnectedSubgraph.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/GraphList.h>
36 
37 namespace ogdf {
38 namespace embedder {
39 
40 template<class T>
42 public:
43  //constructor
45 
55  static void call(const Graph& G, Graph& SG, const node& nG, node& nSG,
56  const NodeArray<T>& nodeLengthG, NodeArray<T>& nodeLengthSG) {
57  EdgeArray<T> edgeLengthG(G, 1);
58  EdgeArray<T> edgeLengthSG;
59  call(G, SG, nG, nSG, nodeLengthG, nodeLengthSG, edgeLengthG, edgeLengthSG);
60  }
61 
71  static void call(const Graph& G, Graph& SG, const node& nG, const NodeArray<T>& nodeLengthG,
72  NodeArray<T>& nodeLengthSG, NodeArray<node>& nG_to_nSG) {
73  node nSG;
74  NodeArray<node> nSG_to_nG;
75  EdgeArray<edge> eSG_to_eG;
76  EdgeArray<edge> eG_to_eSG;
77  EdgeArray<T> edgeLengthG(G, 1);
78  EdgeArray<T> edgeLengthSG;
79  call(G, SG, nG, nSG, nSG_to_nG, eSG_to_eG, nG_to_nSG, eG_to_eSG, nodeLengthG, nodeLengthSG,
80  edgeLengthG, edgeLengthSG);
81  }
82 
94  static void call(const Graph& G, Graph& SG, const node& nG, node& nSG,
95  const NodeArray<T>& nodeLengthG, NodeArray<T>& nodeLengthSG,
96  const EdgeArray<T>& edgeLengthG, EdgeArray<T>& edgeLengthSG) {
97  NodeArray<node> nSG_to_nG(SG);
98  EdgeArray<edge> eSG_to_eG(SG);
99  call(G, SG, nG, nSG, nSG_to_nG, eSG_to_eG, nodeLengthG, nodeLengthSG, edgeLengthG,
100  edgeLengthSG);
101  }
102 
111  static void call(const Graph& G, Graph& SG, const node& nG, const NodeArray<T>& nodeLengthG,
112  NodeArray<T>& nodeLengthSG) {
113  node nSG;
114  call(G, SG, nG, nSG, nodeLengthG, nodeLengthSG);
115  }
116 
127  static void call(const Graph& G, Graph& SG, const node& nG, const NodeArray<T>& nodeLengthG,
128  NodeArray<T>& nodeLengthSG, const EdgeArray<T>& edgeLengthG, EdgeArray<T>& edgeLengthSG) {
129  node nSG = nullptr;
130  call(G, SG, nG, nSG, nodeLengthG, nodeLengthSG, edgeLengthG, edgeLengthSG);
131  }
132 
146  static void call(const Graph& G, Graph& SG, const node& nG, node& nSG,
147  NodeArray<node>& nSG_to_nG, EdgeArray<edge>& eSG_to_eG, const NodeArray<T>& nodeLengthG,
148  NodeArray<T>& nodeLengthSG, const EdgeArray<T>& edgeLengthG, EdgeArray<T>& edgeLengthSG) {
149  NodeArray<node> nG_to_nSG;
150  EdgeArray<edge> eG_to_eSG;
151  call(G, SG, nG, nSG, nSG_to_nG, eSG_to_eG, nG_to_nSG, eG_to_eSG, nodeLengthG, nodeLengthSG,
152  edgeLengthG, edgeLengthSG);
153  }
154 
170  static void call(const Graph& G, Graph& SG, const node& nG, node& nSG,
171  NodeArray<node>& nSG_to_nG, EdgeArray<edge>& eSG_to_eG, NodeArray<node>& nG_to_nSG,
172  EdgeArray<edge>& eG_to_eSG, const NodeArray<T>& nodeLengthG, NodeArray<T>& nodeLengthSG,
173  const EdgeArray<T>& edgeLengthG, EdgeArray<T>& edgeLengthSG);
174 
185  static void call(const Graph& G, Graph& SG, const node& nG, NodeArray<node>& nSG_to_nG,
186  EdgeArray<edge>& eSG_to_eG, NodeArray<node>& nG_to_nSG, EdgeArray<edge>& eG_to_eSG);
187 
195  static void call(const Graph& G, Graph& SG, const node& nG, NodeArray<node>& nSG_to_nG) {
196  NodeArray<T> nodeLengthG(G, 0);
197  NodeArray<T> nodeLengthSG(SG);
198  EdgeArray<T> edgeLengthG(G, 0);
199  EdgeArray<T> edgeLengthSG(SG);
200  node nSG;
201  EdgeArray<edge> eSG_to_eG;
202  call(G, SG, nG, nSG, nSG_to_nG, eSG_to_eG, nodeLengthG, nodeLengthSG, edgeLengthG,
203  edgeLengthSG);
204  }
205 
206 private:
226  static void recursion(Graph& SG, NodeArray<bool>& nodeVisited, EdgeArray<bool>& edgeVisited,
227  const node& nG, const NodeArray<T>& nodeLengthG, NodeArray<T>& nodeLengthSG,
228  const EdgeArray<T>& edgeLengthG, EdgeArray<T>& edgeLengthSG, NodeArray<node>& nSG_to_nG,
229  EdgeArray<edge>& eSG_to_eG, NodeArray<node>& nG_to_nSG, EdgeArray<edge>& eG_to_eSG);
230 };
231 
232 template<class T>
234  EdgeArray<bool>& edgeVisited, const node& nG, const NodeArray<T>& nodeLengthG,
235  NodeArray<T>& nodeLengthSG, const EdgeArray<T>& edgeLengthG, EdgeArray<T>& edgeLengthSG,
236  NodeArray<node>& nSG_to_nG, EdgeArray<edge>& eSG_to_eG, NodeArray<node>& nG_to_nSG,
237  EdgeArray<edge>& eG_to_eSG) {
238  node nSG = SG.newNode();
239  nodeLengthSG[nSG] = nodeLengthG[nG];
240  nG_to_nSG[nG] = nSG;
241  nSG_to_nG[nSG] = nG;
242  nodeVisited[nG] = true;
243 
244  for (adjEntry adj : nG->adjEntries) {
245  edge eG = adj->theEdge();
246  if (!nodeVisited[eG->source()]) {
247  recursion(SG, nodeVisited, edgeVisited, eG->source(), nodeLengthG, nodeLengthSG,
248  edgeLengthG, edgeLengthSG, nSG_to_nG, eSG_to_eG, nG_to_nSG, eG_to_eSG);
249  } else if (!nodeVisited[eG->target()]) {
250  recursion(SG, nodeVisited, edgeVisited, eG->target(), nodeLengthG, nodeLengthSG,
251  edgeLengthG, edgeLengthSG, nSG_to_nG, eSG_to_eG, nG_to_nSG, eG_to_eSG);
252  }
253  if (!edgeVisited[eG]) {
254  edge eSG = SG.newEdge(nG_to_nSG[eG->source()], nG_to_nSG[eG->target()]);
255  edgeLengthSG[eSG] = edgeLengthG[eG];
256  eG_to_eSG[eG] = eSG;
257  eSG_to_eG[eSG] = eG;
258  edgeVisited[eG] = true;
259  }
260  }
261 }
262 
263 template<class T>
264 void ConnectedSubgraph<T>::call(const Graph& G, Graph& SG, const node& nG, node& nSG,
265  NodeArray<node>& nSG_to_nG, EdgeArray<edge>& eSG_to_eG, NodeArray<node>& nG_to_nSG,
266  EdgeArray<edge>& eG_to_eSG, const NodeArray<T>& nodeLengthG, NodeArray<T>& nodeLengthSG,
267  const EdgeArray<T>& edgeLengthG, EdgeArray<T>& edgeLengthSG) {
268  SG.clear();
269 
270  NodeArray<bool> nodeVisited(G, false);
271  EdgeArray<bool> edgeVisited(G, false);
272 
273 #if 0
274  const int n = G.numberOfNodes();
275  const int m = G.numberOfEdges();
276 
277  bool* nodeVisited = new bool[n];
278  bool* edgeVisited = new bool[m];
279  for (int i = 0; i < n; i++)
280  nodeVisited[i] = false;
281  for (int i = 0; i < m; i++)
282  edgeVisited[i] = false;
283 #endif
284  nSG_to_nG.init(SG);
285  eSG_to_eG.init(SG);
286  nodeLengthSG.init(SG);
287  edgeLengthSG.init(SG);
288  nG_to_nSG.init(G);
289  eG_to_eSG.init(G);
290 
291  recursion(SG, nodeVisited, edgeVisited, nG, nodeLengthG, nodeLengthSG, edgeLengthG,
292  edgeLengthSG, nSG_to_nG, eSG_to_eG, nG_to_nSG, eG_to_eSG);
293  nSG = nG_to_nSG[nG];
294 
295 #if 0
296  delete[] nodeVisited;
297  delete[] edgeVisited;
298 #endif
299 }
300 
301 template<class T>
302 void ConnectedSubgraph<T>::call(const Graph& G, Graph& SG, const node& nG, NodeArray<node>& nSG_to_nG,
303  EdgeArray<edge>& eSG_to_eG, NodeArray<node>& nG_to_nSG, EdgeArray<edge>& eG_to_eSG) {
304  SG.clear();
305 
306  NodeArray<bool> nodeVisited(G, false);
307  EdgeArray<bool> edgeVisited(G, false);
308 
309 #if 0
310  bool* nodeVisited = new bool[G.numberOfNodes()];
311  bool* edgeVisited = new bool[G.numberOfEdges()];
312  for (int i = 0; i < G.numberOfNodes(); i++)
313  nodeVisited[i] = false;
314  for (int i = 0; i < G.numberOfEdges(); i++)
315  edgeVisited[i] = false;
316 #endif
317  nSG_to_nG.init(SG);
318  eSG_to_eG.init(SG);
319  NodeArray<T> nodeLengthG(G, 0);
320  NodeArray<T> nodeLengthSG(SG);
321  EdgeArray<T> edgeLengthG(G, 1);
322  EdgeArray<T> edgeLengthSG(SG);
323  nG_to_nSG.init(G);
324  eG_to_eSG.init(G);
325 
326  recursion(SG, nodeVisited, edgeVisited, nG, nodeLengthG, nodeLengthSG, edgeLengthG,
327  edgeLengthSG, nSG_to_nG, eSG_to_eG, nG_to_nSG, eG_to_eSG);
328 
329 #if 0
330  delete[] nodeVisited;
331  delete[] edgeVisited;
332 #endif
333 }
334 
335 }
336 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
ogdf::embedder::ConnectedSubgraph::call
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.
Definition: ConnectedSubgraph.h:94
ogdf::embedder::ConnectedSubgraph::call
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.
Definition: ConnectedSubgraph.h:146
ogdf::embedder::ConnectedSubgraph::recursion
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.
Definition: ConnectedSubgraph.h:233
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:160
ogdf::Graph::clear
virtual void clear()
Removes all nodes and all edges from the graph.
ogdf::embedder::ConnectedSubgraph::call
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.
Definition: ConnectedSubgraph.h:55
ogdf::embedder::ConnectedSubgraph::call
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.
Definition: ConnectedSubgraph.h:195
GraphList.h
Decralation of GraphElement and GraphList classes.
ogdf::NodeElement::adjEntries
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:271
ogdf::embedder::ConnectedSubgraph::call
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.
Definition: ConnectedSubgraph.h:127
ogdf::EdgeElement::source
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:398
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::embedder::ConnectedSubgraph::call
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.
Definition: ConnectedSubgraph.h:71
ogdf::embedder::ConnectedSubgraph::ConnectedSubgraph
ConnectedSubgraph()
Definition: ConnectedSubgraph.h:44
ogdf::Graph::newNode
node newNode(int index=-1)
Creates a new node and returns it.
Definition: Graph_d.h:1064
ogdf::embedder::ConnectedSubgraph
Definition: ConnectedSubgraph.h:41
ogdf::embedder::ConnectedSubgraph::call
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.
Definition: ConnectedSubgraph.h:111
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
ogdf::RegisteredArray< GraphRegistry< Key >, Value, WithDefault, Graph >::init
void init(const Graph *base=nullptr)
Reinitializes the array. Associates the array with the matching registry of base.
Definition: RegisteredArray.h:858
ogdf::EdgeElement::target
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:401
ogdf::Graph::newEdge
edge newEdge(node v, node w, int index=-1)
Creates a new edge (v,w) and returns it.
Definition: Graph_d.h:1083
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716