Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
CoreEdgeRandomSpanningTree.h
Go to the documentation of this file.
1
32#pragma once
33
37
38namespace ogdf {
39namespace steiner_tree {
40namespace goemans {
41
43template<typename T>
45 std::minstd_rand& m_rng;
46
47public:
48 CoreEdgeRandomSpanningTree(std::minstd_rand& rng) : m_rng(rng) { }
49
50 void call(const Graph& graph, const List<node>& terminals,
51 EdgeArray<bool>& isInTree) const override {
52 // Let's do Kruskal's algorithm without weights but on a randomly permuted edge list.
53 // We virtually contract all terminals in the union-find data structure.
54 NodeArray<int> setID(graph, -1);
55 isInTree.init(graph, false);
56 DisjointSets<> uf(graph.numberOfNodes() - terminals.size() + 1);
57
58 int contractedID = uf.makeSet();
60 for (node t : terminals) {
62 }
63 for (node v : graph.nodes) {
64 if (setID[v] < 0) {
65 setID[v] = uf.makeSet();
66 }
67 }
68
69 // obtain a random edge permutation
71 for (edge e : graph.edges) {
73 }
74 edgePermutation.permute(m_rng);
75
76 // add edges if we do not close a cycle
77 for (edge e : edgePermutation) {
78 const int v = setID[e->source()];
79 const int w = setID[e->target()];
80 if (uf.find(v) != uf.find(w)) {
81 isInTree[e] = true;
82 uf.link(uf.find(v), uf.find(w));
83 }
84 }
85 }
86};
87
88}
89}
90}
Definition of ogdf::steiner_tree::goemans::CoreEdgeModule class template.
Implementation of disjoint sets data structures (union-find functionality).
Declaration and implementation of NodeArray class.
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition ArrayBuffer.h:56
void push(E e)
Puts a new element in the buffer.
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
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
int numberOfNodes() const
Returns the number of nodes in the graph.
Definition Graph_d.h:622
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition Graph_d.h:589
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition Graph_d.h:592
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
int size() const
Returns the number of elements in the list.
Definition List.h:1472
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
Class for the representation of nodes.
Definition Graph_d.h:177
Interface for core edge finder algorithms.
void call(const Graph &graph, const List< node > &terminals, EdgeArray< bool > &isInTree) const override
Compute a set of core edges.
#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.