Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
extended_graph_alg.h
Go to the documentation of this file.
1
32#pragma once
33
38
39namespace ogdf {
40
43
45
54template<class LISTITERATOR>
59
61
71template<class LISTITERATOR>
74 subGraph.clear();
75 nodeTableOrig2New.init(G, nullptr);
76
77 EdgeArray<bool> mark(G, false);
78
80 for (its = start; its.valid(); its++) {
81 node w = (*its);
82 OGDF_ASSERT(w != nullptr);
83 OGDF_ASSERT(w->graphOf() == &G);
84 nodeTableOrig2New[w] = subGraph.newNode();
85
86 for (adjEntry adj : w->adjEntries) {
87 edge e = adj->theEdge();
88 if (nodeTableOrig2New[e->source()] && nodeTableOrig2New[e->target()] && !mark[e]) {
90 mark[e] = true;
91 }
92 }
93 }
94}
95
97
108template<class LISTITERATOR>
111 subGraph.clear();
112 nodeTableOrig2New.init(G, nullptr);
113 edgeTableOrig2New.init(G, nullptr);
114
115 EdgeArray<bool> mark(G, false);
116
118 for (its = start; its.valid(); its++) {
119 node w = (*its);
120 OGDF_ASSERT(w != nullptr);
121 OGDF_ASSERT(w->graphOf() == &G);
122 nodeTableOrig2New[w] = subGraph.newNode();
123
124 for (adjEntry adj : w->adjEntries) {
125 edge e = adj->theEdge();
126 if (nodeTableOrig2New[e->source()] && nodeTableOrig2New[e->target()] && !mark[e]) {
129 mark[e] = true;
130 }
131 }
132 }
133}
134
136
145template<class LISTITERATOR>
147 subGraph.clear();
148 subGraph.createEmpty(G);
149 EdgeArray<bool> mark(G, false);
150
152 for (its = start; its.valid(); its++) {
153 node w = (*its);
154 OGDF_ASSERT(w != nullptr);
155 OGDF_ASSERT(w->graphOf() == &G);
156 subGraph.newNode(w);
157
158 for (adjEntry adj : w->adjEntries) {
159 edge e = adj->theEdge();
160 if (subGraph.copy(e->source()) && subGraph.copy(e->target()) && !subGraph.copy(e)) {
161 subGraph.newEdge(e);
162 }
163 }
164 }
165}
166
168
178template<class NODELISTITERATOR, class EDGELIST>
181 NodeArray<bool> mark(G, false);
182
183 for (; it.valid(); it++) {
184 mark[*it] = true;
185 }
186 it = itBegin;
187 for (; it.valid(); it++) {
188 node v = (*it);
189 for (adjEntry adj : v->adjEntries) {
190 edge e = adj->theEdge();
191 if (mark[e->source()] && mark[e->target()]) {
192 E.pushBack(e);
193 }
194 }
195 }
196}
197
201
203
207
209
219 bool simple = true);
220
224
226
235template<typename T>
236inline T computeMinST(const Graph& G, const EdgeArray<T>& weight, EdgeArray<bool>& isInTree) {
237 NodeArray<edge> pred(G, nullptr);
238 return computeMinST(G.firstNode(), G, weight, pred, isInTree);
239}
240
242
252template<typename T>
253inline T computeMinST(const Graph& G, const EdgeArray<T>& weight, NodeArray<edge>& pred,
254 EdgeArray<bool>& isInTree) {
255 return computeMinST(G.firstNode(), G, weight, pred, isInTree);
256}
257
259
267template<typename T>
268inline void computeMinST(const Graph& G, const EdgeArray<T>& weight, NodeArray<edge>& pred) {
269 computeMinST(G.firstNode(), G, weight, pred);
270}
271
273
282template<typename T>
283void computeMinST(node s, const Graph& G, const EdgeArray<T>& weight, NodeArray<edge>& pred) {
284 PrioritizedMapQueue<node, T> pq(G); // priority queue of front vertices
285
286 // insert start node
287 T tmp(0);
288 pq.push(s, tmp);
289
290 // extract the nodes again along a minimum ST
291 NodeArray<bool> processed(G, false);
292 pred.init(G, nullptr);
293
294 while (!pq.empty()) {
295 const node v = pq.topElement();
296 pq.pop();
297 processed[v] = true;
298 for (adjEntry adj = v->firstAdj(); adj; adj = adj->succ()) {
299 const node w = adj->twinNode();
300 const edge e = adj->theEdge();
301 if (pred[w] == nullptr && w != s) {
302 tmp = weight[e];
303 pq.push(w, tmp);
304 pred[w] = e;
305 } else if (!processed[w] && weight[e] < pq.priority(w)) {
306 pq.decrease(w, weight[e]);
307 pred[w] = e;
308 }
309 }
310 }
311}
312
314
325template<typename T>
326T computeMinST(node s, const Graph& G, const EdgeArray<T>& weight, NodeArray<edge>& pred,
327 EdgeArray<bool>& isInTree) {
328 computeMinST(s, G, weight, pred);
329
330 // now just compute isInTree and total weight
331#ifdef OGDF_DEBUG
332 int rootcount = 0;
333#endif
334 T treeWeight = 0;
335 isInTree.init(G, false);
336 for (node v = G.firstNode(); v; v = v->succ()) {
337 if (pred[v]) {
338 isInTree[pred[v]] = true;
339 treeWeight += weight[pred[v]];
340 }
341#ifdef OGDF_DEBUG
342 else {
343 ++rootcount;
344 }
345#endif
346 }
347 OGDF_ASSERT(rootcount == 1); // is connected
348
349 return treeWeight;
350}
351
353
361template<typename T>
363 T total(0);
364 Array<Prioritized<edge, T>> sortEdges(G.numberOfEdges());
365 int i = 0;
366 for (edge e : G.edges) {
367 sortEdges[i++] = Prioritized<edge, T>(e, weight[e]);
368 }
369 sortEdges.quicksort();
370
371 // now let's do Kruskal's algorithm
373 DisjointSets<> uf(G.numberOfNodes());
374 for (node v : G.nodes) {
375 setID[v] = uf.makeSet();
376 }
377
378 for (auto prioEdge : sortEdges) {
379 const edge e = prioEdge.item();
380 const int v = setID[e->source()];
381 const int w = setID[e->target()];
382 if (uf.find(v) != uf.find(w)) {
383 uf.link(uf.find(v), uf.find(w));
384 total += weight[e];
385 } else {
386 G.delEdge(e);
387 }
388 }
389 return total;
390}
391
393
395
403inline bool isPlanar(const Graph& G) { return BoyerMyrvold().isPlanar(G); }
404
416inline bool isSTPlanar(const Graph& graph, const node s, const node t) {
417 OGDF_ASSERT(s != nullptr);
418 OGDF_ASSERT(t != nullptr);
419 OGDF_ASSERT(s->graphOf() == &graph);
420 OGDF_ASSERT(t->graphOf() == &graph);
421
422 GraphCopy copy(graph);
423 copy.newEdge(copy.copy(s), copy.copy(t));
424
425 return isPlanar(copy);
426}
427
429
437inline bool planarEmbed(Graph& G) { return BoyerMyrvold().planarEmbed(G); }
438
450inline bool planarSTEmbed(Graph& graph, node s, node t) {
451 edge e = graph.newEdge(s, t);
452 bool result = planarEmbed(graph);
453 graph.delEdge(e);
454
455 return result;
456}
457
459
473
474}
Declaration of the wrapper class of the Boyer-Myrvold planarity test.
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
Implementation of disjoint sets data structures (union-find functionality).
Priority queue interface wrapping various heaps.
Class for adjacency list elements.
Definition Graph_d.h:79
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
Wrapper class used for preprocessing and valid invocation of the planarity test.
virtual bool planarEmbed(Graph &G) override
Returns true, if G is planar, false otherwise. If true, G contains a planar embedding.
virtual bool isPlanar(const Graph &g) override
Returns true, iff a copy of the constant graph g is planar.
virtual bool planarEmbedPlanarGraph(Graph &G) override
Constructs a planar embedding of G. G has to be planar!
Representation of clustered graphs.
A Union/Find data structure for maintaining disjoint sets.
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
void init()
Reinitializes the array. Associates the array with no graph.
Definition EdgeArray.h:292
Class for the representation of edges.
Definition Graph_d.h:300
node target() const
Returns the target node of the edge.
Definition Graph_d.h:338
node source() const
Returns the source node of the edge.
Definition Graph_d.h:335
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:254
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition GraphCopy.h:338
edge newEdge(edge eOrig)
Creates a new edge (v,w) with original edge eOrig.
Copies of graphs with mapping between nodes and edges.
Definition GraphCopy.h:59
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
virtual void delEdge(edge e)
Removes edge e from the graph.
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
void init()
Reinitializes the array. Associates the array with no graph.
Definition NodeArray.h:266
Class for the representation of nodes.
Definition Graph_d.h:177
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition Graph_d.h:208
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition Graph_d.h:223
Prioritized queue interface wrapper for heaps.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
void makeCConnected(ClusterGraph &C, Graph &G, List< edge > &addedEdges, bool simple=true)
Makes a cluster graph c-connected by adding edges.
bool isCConnected(const ClusterGraph &C)
Returns true iff cluster graph C is c-connected.
void inducedSubgraph(Graph &G, NODELISTITERATOR &it, EDGELIST &E)
Computes the edges in a node-induced subgraph.
void inducedSubGraph(const Graph &G, LISTITERATOR start, Graph &subGraph)
Computes the subgraph induced by a list of nodes.
T makeMinimumSpanningTree(Graph &G, const EdgeArray< T > &weight)
Reduce a graph to its minimum spanning tree (MST) using Kruskal's algorithm.
T computeMinST(const Graph &G, const EdgeArray< T > &weight, EdgeArray< bool > &isInTree)
Computes a minimum spanning tree using Prim's algorithm.
bool planarEmbedPlanarGraph(Graph &G)
Constructs a planar embedding of G. It assumes that G is planar!
bool planarEmbed(Graph &G)
Returns true, if G is planar, false otherwise. If true is returned, G will be planarly embedded.
bool planarSTEmbed(Graph &graph, node s, node t)
s-t-planarly embeds a graph.
bool isSTPlanar(const Graph &graph, const node s, const node t)
Returns whether G is s-t-planar (i.e.
bool isPlanar(const Graph &G)
Returns true, if G is planar, false otherwise.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.