Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
BlowupComponents.h
Go to the documentation of this file.
1
32#pragma once
33
35
36//#define OGDF_STEINER_TREE_GOEMANS_BLOWUP_COMPONENTS_LOGGING
37
38namespace ogdf {
39namespace steiner_tree {
40namespace goemans {
41
43template<typename T>
45protected:
46 // To represent Gamma(X) [the set of all components in the blowup graph], we give
47 // - terminals, source and target the component id 0
48 // - all other nodes a component id > 0. Nodes with same id belong to the same component.
49 // Note that this is also fine for 2-components with only one edge, since this
50 // is a core edge and hence a dummy node is inserted.
52 // We also save lists of terminals for each component in the specified array buffer.
54 // To efficiently traverse the found component, we save the edge from the root of the component
56 // Finally a component -> cost array.
58
59 int maxId; // == the size of the arraybuffers
60
64 const node start = rootEdge->target();
65 queue.pushBack(start);
69 if (!blowupGraph.getOriginal(start)) { // start node is a core edge
71 } else {
73 }
75 ++maxId;
76 while (!queue.empty()) {
77 const node v = queue.popBackRet();
78 componentId[v] = maxId;
79 for (adjEntry adj : v->adjEntries) {
80 const node w = adj->twinNode();
81 if (componentId[w] < 0) {
82 // count coreEdge cost only once
83 if (blowupGraph.getOriginal(v)) { // v is no core edge
84 cost += blowupGraph.getCost(adj->theEdge());
85 }
86 if (blowupGraph.isTerminal(w)) {
87 terms.push(w);
88 } else {
89 queue.pushBack(w);
90 }
91 }
92 }
93 }
94#ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_COMPONENTS_LOGGING
95 std::cout << " * component with terminals " << terms << " starting with edge " << rootEdge
96 << " having cost " << cost << " and capacity "
97 << blowupGraph.getCapacity(rootEdge) << std::endl;
98#endif
99 }
100
101public:
104 : componentId(blowupGraph.getGraph(), -1), maxId(0) {
105 componentId[blowupGraph.getSource()] = 0;
106 componentId[blowupGraph.getPseudotarget()] = 0;
107 componentId[blowupGraph.getTarget()] = 0;
108
109#ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_COMPONENTS_LOGGING
110 std::cout << "Finding components in blowup graph:" << std::endl;
111#endif
112 for (node t : blowupGraph.terminals()) {
113 for (adjEntry rootAdj : t->adjEntries) {
114 const edge rootEdge = rootAdj->theEdge();
115 if (rootEdge->source() != t) {
116 continue;
117 }
118 const node r = rootAdj->twinNode();
120 if (componentId[r] < 0) {
122 }
123 }
124 }
125
126 // now set terminals to id 0 [XXX: why dont we keep -1?]
127 for (node t : blowupGraph.terminals()) {
128 componentId[t] = 0;
129 }
130 }
131
133 const ArrayBuffer<node>& terminals(int id) const {
134 OGDF_ASSERT(id > 0);
135 return componentTerminals[id - 1];
136 }
137
139 int id(node v) const { return componentId[v]; }
140
142 const T& cost(int id) const {
143 OGDF_ASSERT(id > 0);
144 return componentCost[id - 1];
145 }
146
148 int size() const { return maxId; }
149
151 edge rootEdge(int id) const {
152 OGDF_ASSERT(id > 0);
153 return componentRootEdge[id - 1];
154 }
155
157 void setRootEdge(int id, edge e) // beware of using!
158 {
159 OGDF_ASSERT(id > 0);
160 componentRootEdge[id - 1] = e;
161 OGDF_ASSERT(componentTerminals[id - 1].linearSearch(e->source()) != -1);
162 }
163};
164
165}
166}
167}
Definition of ogdf::steiner_tree::goemans::BlowupGraph class template.
Class for adjacency list elements.
Definition Graph_d.h:79
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.
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
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
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
Obtain and provides information about components in a given blowup graph.
int id(node v) const
Return the component id a given node is contained in.
const T & cost(int id) const
Return total cost of a given component.
void initializeComponent(edge rootEdge, const BlowupGraph< T > &blowupGraph)
Initialize all information about the component starting with rootEdge in the blowup graph.
edge rootEdge(int id) const
Return the edge coming from the root of a given component.
void setRootEdge(int id, edge e)
Set the edge coming from the root for a given component.
BlowupComponents(const BlowupGraph< T > &blowupGraph)
Find all components in the blowup graph and initialize information them.
const ArrayBuffer< node > & terminals(int id) const
Return list of terminals for a given component.
ArrayBuffer< ArrayBuffer< node > > componentTerminals
int size() const
Return number of components.
A special-purpose blowup graph for gammoid computation: directed, with special source and target,...
Definition BlowupGraph.h:50
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
int r[]
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.