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#include <ogdf/basic/Graph.h>
37#include <ogdf/basic/List.h>
38#include <ogdf/basic/basic.h>
39
40#include <iostream>
41
43template<typename T>
44class BlowupGraph;
45} // namespace ogdf::steiner_tree::goemans
46
47//#define OGDF_STEINER_TREE_GOEMANS_BLOWUP_COMPONENTS_LOGGING
48
49namespace ogdf {
50namespace steiner_tree {
51namespace goemans {
52
54template<typename T>
56protected:
57 // To represent Gamma(X) [the set of all components in the blowup graph], we give
58 // - terminals, source and target the component id 0
59 // - all other nodes a component id > 0. Nodes with same id belong to the same component.
60 // Note that this is also fine for 2-components with only one edge, since this
61 // is a core edge and hence a dummy node is inserted.
63 // We also save lists of terminals for each component in the specified array buffer.
65 // To efficiently traverse the found component, we save the edge from the root of the component
67 // Finally a component -> cost array.
69
70 int maxId; // == the size of the arraybuffers
71
73 void initializeComponent(edge rootEdge, const BlowupGraph<T>& blowupGraph) {
74 List<node> queue;
75 const node start = rootEdge->target();
76 queue.pushBack(start);
79 auto& terms = componentTerminals[maxId];
80 if (!blowupGraph.getOriginal(start)) { // start node is a core edge
81 componentCost.push(blowupGraph.getCost(rootEdge));
82 } else {
84 }
86 ++maxId;
87 while (!queue.empty()) {
88 const node v = queue.popBackRet();
89 componentId[v] = maxId;
90 for (adjEntry adj : v->adjEntries) {
91 const node w = adj->twinNode();
92 if (componentId[w] < 0) {
93 // count coreEdge cost only once
94 if (blowupGraph.getOriginal(v)) { // v is no core edge
95 cost += blowupGraph.getCost(adj->theEdge());
96 }
97 if (blowupGraph.isTerminal(w)) {
98 terms.push(w);
99 } else {
100 queue.pushBack(w);
101 }
102 }
103 }
104 }
105#ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_COMPONENTS_LOGGING
106 std::cout << " * component with terminals " << terms << " starting with edge " << rootEdge
107 << " having cost " << cost << " and capacity "
108 << blowupGraph.getCapacity(rootEdge) << std::endl;
109#endif
110 }
111
112public:
115 : componentId(blowupGraph.getGraph(), -1), maxId(0) {
116 componentId[blowupGraph.getSource()] = 0;
117 componentId[blowupGraph.getPseudotarget()] = 0;
118 componentId[blowupGraph.getTarget()] = 0;
119
120#ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_COMPONENTS_LOGGING
121 std::cout << "Finding components in blowup graph:" << std::endl;
122#endif
123 for (node t : blowupGraph.terminals()) {
124 for (adjEntry rootAdj : t->adjEntries) {
125 const edge rootEdge = rootAdj->theEdge();
126 if (rootEdge->source() != t) {
127 continue;
128 }
129 const node r = rootAdj->twinNode();
131 if (componentId[r] < 0) {
132 initializeComponent(rootEdge, blowupGraph);
133 }
134 }
135 }
136
137 // now set terminals to id 0 [XXX: why dont we keep -1?]
138 for (node t : blowupGraph.terminals()) {
139 componentId[t] = 0;
140 }
141 }
142
144 const ArrayBuffer<node>& terminals(int id) const {
145 OGDF_ASSERT(id > 0);
146 return componentTerminals[id - 1];
147 }
148
150 int id(node v) const { return componentId[v]; }
151
153 const T& cost(int id) const {
154 OGDF_ASSERT(id > 0);
155 return componentCost[id - 1];
156 }
157
159 int size() const { return maxId; }
160
162 edge rootEdge(int id) const {
163 OGDF_ASSERT(id > 0);
164 return componentRootEdge[id - 1];
165 }
166
168 void setRootEdge(int id, edge e) // beware of using!
169 {
170 OGDF_ASSERT(id > 0);
171 componentRootEdge[id - 1] = e;
172 OGDF_ASSERT(componentTerminals[id - 1].linearSearch(e->source()) != -1);
173 }
174};
175
176}
177}
178}
Declaration and implementation of ArrayBuffer class.
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Declaration of doubly linked lists and iterators.
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition ArrayBuffer.h:64
void push(E e)
Puts a new element in the buffer.
Class for the representation of edges.
Definition Graph_d.h:364
node target() const
Returns the target node of the edge.
Definition Graph_d.h:402
node source() const
Returns the source node of the edge.
Definition Graph_d.h:399
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:1547
E popBackRet()
Removes the last element from the list and returns it.
Definition List.h:1604
bool empty() const
Returns true iff the list is empty.
Definition List.h:286
Class for the representation of nodes.
Definition Graph_d.h:241
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition Graph_d.h:272
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
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:70
T getCost(edge e) const
Returns the cost of e.
node getSource() const
Returns the source node.
node getTarget() const
Returns the target node.
int getCapacity(edge e) const
Returns the capacity of e.
const List< node > & terminals() const
Returns a reference to the list containing all terminals in the blowup graph.
node getPseudotarget() const
Returns the pseudotarget node.
node getOriginal(node v) const
Returns the original node of v.
bool isTerminal(node v) const
Returns true if and only if v is a terminal.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.