Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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 
38 namespace ogdf {
39 namespace steiner_tree {
40 namespace goemans {
41 
43 template<typename T>
45 protected:
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 
62  void initializeComponent(edge rootEdge, const BlowupGraph<T>& blowupGraph) {
63  List<node> queue;
64  const node start = rootEdge->target();
65  queue.pushBack(start);
68  auto& terms = componentTerminals[maxId];
69  if (!blowupGraph.getOriginal(start)) { // start node is a core edge
70  componentCost.push(blowupGraph.getCost(rootEdge));
71  } else {
73  }
74  T& cost = componentCost[maxId];
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 
101 public:
103  BlowupComponents(const BlowupGraph<T>& blowupGraph)
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();
119  OGDF_ASSERT(r == rootEdge->target());
120  if (componentId[r] < 0) {
121  initializeComponent(rootEdge, blowupGraph);
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 }
ogdf::ArrayBuffer
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition: Array.h:46
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::steiner_tree::goemans::BlowupComponents::size
int size() const
Return number of components.
Definition: BlowupComponents.h:148
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
ogdf::steiner_tree::goemans::BlowupComponents::componentTerminals
ArrayBuffer< ArrayBuffer< node > > componentTerminals
Definition: BlowupComponents.h:53
ogdf::steiner_tree::goemans::BlowupComponents::maxId
int maxId
Definition: BlowupComponents.h:59
ogdf::steiner_tree::goemans::BlowupComponents::componentId
NodeArray< int > componentId
Definition: BlowupComponents.h:51
ogdf::steiner_tree::goemans::BlowupComponents::componentRootEdge
ArrayBuffer< edge > componentRootEdge
Definition: BlowupComponents.h:55
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:135
ogdf::steiner_tree::goemans::BlowupGraph::terminals
const List< node > & terminals() const
Returns a reference to the list containing all terminals in the blowup graph.
Definition: BlowupGraph.h:513
ogdf::steiner_tree::goemans::BlowupGraph::getOriginal
node getOriginal(node v) const
Returns the original node of v.
Definition: BlowupGraph.h:504
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:153
r
int r[]
Definition: hierarchical-ranking.cpp:8
ogdf::steiner_tree::goemans::BlowupGraph::getCost
T getCost(edge e) const
Returns the cost of e.
Definition: BlowupGraph.h:501
ogdf::steiner_tree::goemans::BlowupComponents::BlowupComponents
BlowupComponents(const BlowupGraph< T > &blowupGraph)
Find all components in the blowup graph and initialize information them.
Definition: BlowupComponents.h:103
ogdf::NodeElement::adjEntries
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:264
ogdf::ArrayBuffer::push
void push(E e)
Puts a new element in the buffer.
Definition: ArrayBuffer.h:209
ogdf::steiner_tree::goemans::BlowupGraph::getSource
node getSource() const
Returns the source node.
Definition: BlowupGraph.h:486
BlowupGraph.h
Definition of ogdf::steiner_tree::goemans::BlowupGraph class template.
ogdf::steiner_tree::goemans::BlowupGraph::getPseudotarget
node getPseudotarget() const
Returns the pseudotarget node.
Definition: BlowupGraph.h:489
ogdf::EdgeElement::source
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:391
ogdf::steiner_tree::goemans::BlowupComponents::setRootEdge
void setRootEdge(int id, edge e)
Set the edge coming from the root for a given component.
Definition: BlowupComponents.h:157
ogdf::steiner_tree::goemans::BlowupComponents::componentCost
ArrayBuffer< T > componentCost
Definition: BlowupComponents.h:57
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: List.h:42
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:651
ogdf::steiner_tree::goemans::BlowupComponents
Obtain and provides information about components in a given blowup graph.
Definition: BlowupComponents.h:44
ogdf::steiner_tree::goemans::BlowupGraph::getTarget
node getTarget() const
Returns the target node.
Definition: BlowupGraph.h:492
ogdf::List::popBackRet
E popBackRet()
Removes the last element from the list and returns it.
Definition: List.h:1594
ogdf::AdjElement::twinNode
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition: Graph_d.h:168
ogdf::steiner_tree::goemans::BlowupComponents::id
int id(node v) const
Return the component id a given node is contained in.
Definition: BlowupComponents.h:139
ogdf::steiner_tree::goemans::BlowupComponents::terminals
const ArrayBuffer< node > & terminals(int id) const
Return list of terminals for a given component.
Definition: BlowupComponents.h:133
ogdf::steiner_tree::goemans::BlowupComponents::cost
const T & cost(int id) const
Return total cost of a given component.
Definition: BlowupComponents.h:142
ogdf::steiner_tree::goemans::BlowupGraph::isTerminal
bool isTerminal(node v) const
Returns true if and only if v is a terminal.
Definition: BlowupGraph.h:516
ogdf::steiner_tree::goemans::BlowupComponents::initializeComponent
void initializeComponent(edge rootEdge, const BlowupGraph< T > &blowupGraph)
Initialize all information about the component starting with rootEdge in the blowup graph.
Definition: BlowupComponents.h:62
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
ogdf::steiner_tree::goemans::BlowupComponents::rootEdge
edge rootEdge(int id) const
Return the edge coming from the root of a given component.
Definition: BlowupComponents.h:151
ogdf::steiner_tree::goemans::BlowupGraph
A special-purpose blowup graph for gammoid computation: directed, with special source and target,...
Definition: BlowupGraph.h:50
ogdf::EdgeElement::target
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:394
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::List::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1537
ogdf::steiner_tree::goemans::BlowupGraph::getCapacity
int getCapacity(edge e) const
Returns the capacity of e.
Definition: BlowupGraph.h:495