Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
common_algorithms.h
Go to the documentation of this file.
1
33#pragma once
34
37
38//#define OGDF_COMMON_ALG_FIND_BEST_TAKAHASHI_ROOT
39
40
41namespace ogdf {
42namespace steiner_tree {
43
52template<typename T>
55 NodeArray<edge>& treeEdge,
57{
58 // sort edges by weight
60 int i = 0;
61 for (edge e : inputTree.edges) {
62 sortEdges[i] = Prioritized<edge, T>(e, inputTree.weight(e));
63 ++i;
64 }
65 sortEdges.quicksort();
66
67 // insert edges into forest (which in the end makes up a tree)
70 node edgeNode = nullptr;
71 for (i = 0; i < inputTree.numberOfEdges(); ++i) {
72 edgeNode = outputTree.newNode();
73 edge e = sortEdges[i].item();
74 treeEdge[edgeNode] = e;
75
76 node u = e->source();
77 node v = e->target();
78 if (externalNodes[u]) {
79 node* uRoot = root[externalNodes[u]];
81 while (root[*uRoot] != uRoot) {
82 *uRoot = *root[*uRoot];
83 uRoot = root[*uRoot];
85 }
86 outputTree.newEdge(edgeNode, *uRoot);
87 root[edgeNode] = uRoot;
88 if (externalNodes[v]) {
89 node* vRoot = root[externalNodes[v]];
91 while (root[*vRoot] != vRoot) {
92 *vRoot = *root[*vRoot];
93 vRoot = root[*vRoot];
95 }
96 outputTree.newEdge(edgeNode, *vRoot);
97 *vRoot = edgeNode;
98 } else {
100 }
101 } else {
103 if (externalNodes[v]) {
104 node* vRoot = root[externalNodes[v]];
106 while (root[*vRoot] != vRoot) {
107 *vRoot = *root[*vRoot];
108 vRoot = root[*vRoot];
110 }
111 outputTree.newEdge(edgeNode, *vRoot);
112 root[edgeNode] = vRoot;
113 } else {
114 root[edgeNode] = new node;
115 garbage.pushBack(root[edgeNode]);
117 }
118 }
119 *root[edgeNode] = edgeNode;
120 }
122
123 // garbage collect
124 for (node* p : garbage) {
125 delete p;
126 }
127
128 return edgeNode;
129}
130
142template<typename T>
145 if (save0 == save1) {
146 st.delEdge(save1);
147 st.delEdge(save2);
148 } else {
149 st.delEdge(save0);
150 st.delEdge(save1);
151 }
152 ne0 = st.newEdge(st.copy(t.s0()), st.copy(t.s1()), 0);
153 ne1 = st.newEdge(st.copy(t.s0()), st.copy(t.s2()), 0);
154}
155
156template<typename T>
162
163template<typename T>
166 List<node> terminals;
167 MinSteinerTreeModule<T>::getTerminals(terminals, G, isTerminal);
168
169 finalSteinerTree = nullptr;
171#ifdef OGDF_COMMON_ALG_FIND_BEST_TAKAHASHI_ROOT
172 // find minimum Steiner tree of G among Takahashi approximations for each start node
173 T bestMstWeight = std::numeric_limits<T>::max();
174 for (node v : terminals) {
176 T tmpMstWeight = mstt.call(G, terminals, isTerminal, isOriginalTerminal, tmpSteinerTree, v);
179 delete finalSteinerTree;
181 } else {
182 delete tmpSteinerTree;
183 }
184 }
185 return bestMstWeight;
186#else
187 return mstt.call(G, terminals, isTerminal, isOriginalTerminal, finalSteinerTree);
188#endif
189}
190
191}
192}
Extends the GraphCopy concept to weighted graphs.
Implementation of the 2(1-1/l)-approximation algorithm for the minimum Steiner tree problem by Matsuy...
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
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
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
static void getTerminals(List< node > &terminals, const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal)
Generates a list (as List<node>) of all terminals.
This class implements the minimum Steiner tree 2-approximation algorithm by Takahashi and Matsuyama w...
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
Class for the representation of nodes.
Definition Graph_d.h:177
This class represents a triple used by various contraction-based minimum Steiner tree approximations.
Definition Triple.h:44
NodeElement * node
The type of nodes.
Definition Graph_d.h:64
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
node buildHeaviestEdgeInComponentTree(const EdgeWeightedGraphCopy< T > &inputTree, NodeArray< node > &externalNodes, NodeArray< edge > &treeEdge, Graph &outputTree)
Given an edge-weighted tree, builds an auxiliary arborescence where each arc of the input tree is a n...
void contractTripleInSteinerTree(const Triple< T > &t, EdgeWeightedGraphCopy< T > &st, edge save0, edge save1, edge save2, edge &ne0, edge &ne1)
Updates the Steiner tree by deleting save edges, removing all direct connections between the terminal...
T obtainFinalSteinerTree(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, const NodeArray< bool > &isOriginalTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
The namespace for all OGDF objects.