Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

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 {
46 protected:
47  // To represent Gamma(X) [the set of all components in the blowup graph], we give
48  // - terminals, source and target the component id 0
49  // - all other nodes a component id > 0. Nodes with same id belong to the same component.
50  // Note that this is also fine for 2-components with only one edge, since this
51  // is a core edge and hence a dummy node is inserted.
53  // We also save lists of terminals for each component in the specified array buffer.
55  // To efficiently traverse the found component, we save the edge from the root of the component
57  // Finally a component -> cost array.
59 
60  int maxId; // == the size of the arraybuffers
61 
63  void initializeComponent(edge rootEdge, const BlowupGraph<T> &blowupGraph)
64  {
65  List<node> queue;
66  const node start = rootEdge->target();
67  queue.pushBack(start);
68  componentRootEdge.push(rootEdge);
69  componentTerminals.push(ArrayBuffer<node>());
70  auto &terms = componentTerminals[maxId];
71  if (!blowupGraph.getOriginal(start)) { // start node is a core edge
72  componentCost.push(blowupGraph.getCost(rootEdge));
73  } else {
74  componentCost.push(0);
75  }
76  T &cost = componentCost[maxId];
77  ++maxId;
78  while (!queue.empty()) {
79  const node v = queue.popBackRet();
80  componentId[v] = maxId;
81  for (adjEntry adj : v->adjEntries) {
82  const node w = adj->twinNode();
83  if (componentId[w] < 0) {
84  // count coreEdge cost only once
85  if (blowupGraph.getOriginal(v)) { // v is no core edge
86  cost += blowupGraph.getCost(adj->theEdge());
87  }
88  if (blowupGraph.isTerminal(w)) {
89  terms.push(w);
90  } else {
91  queue.pushBack(w);
92  }
93  }
94  }
95  }
96 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_COMPONENTS_LOGGING
97  std::cout
98  << " * component with terminals " << terms
99  << " starting with edge " << rootEdge
100  << " having cost " << cost
101  << " and capacity " << blowupGraph.getCapacity(rootEdge) << std::endl;
102 #endif
103  }
104 
105 public:
107  BlowupComponents(const BlowupGraph<T> &blowupGraph)
108  : componentId(blowupGraph.getGraph(), -1)
109  , maxId(0)
110  {
111  componentId[blowupGraph.getSource()] = 0;
112  componentId[blowupGraph.getPseudotarget()] = 0;
113  componentId[blowupGraph.getTarget()] = 0;
114 
115 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_COMPONENTS_LOGGING
116  std::cout << "Finding components in blowup graph:" << std::endl;
117 #endif
118  for (node t : blowupGraph.terminals()) {
119  for (adjEntry rootAdj : t->adjEntries) {
120  const edge rootEdge = rootAdj->theEdge();
121  if (rootEdge->source() != t) {
122  continue;
123  }
124  const node r = rootAdj->twinNode();
125  OGDF_ASSERT(r == rootEdge->target());
126  if (componentId[r] < 0) {
127  initializeComponent(rootEdge, blowupGraph);
128  }
129  }
130  }
131 
132  // now set terminals to id 0 [XXX: why dont we keep -1?]
133  for (node t : blowupGraph.terminals()) {
134  componentId[t] = 0;
135  }
136  }
137 
139  const ArrayBuffer<node> &terminals(int id) const
140  {
141  OGDF_ASSERT(id > 0);
142  return componentTerminals[id-1];
143  }
144 
146  int id(node v) const
147  {
148  return componentId[v];
149  }
150 
152  const T &cost(int id) const
153  {
154  OGDF_ASSERT(id > 0);
155  return componentCost[id-1];
156  }
157 
159  int size() const
160  {
161  return maxId;
162  }
163 
165  edge rootEdge(int id) const
166  {
167  OGDF_ASSERT(id > 0);
168  return componentRootEdge[id-1];
169  }
170 
172  void setRootEdge(int id, edge e) // beware of using!
173  {
174  OGDF_ASSERT(id > 0);
175  componentRootEdge[id-1] = e;
176  OGDF_ASSERT(componentTerminals[id-1].linearSearch(e->source()) != -1);
177  }
178 };
179 
180 }
181 }
182 }
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:328
void initializeComponent(edge rootEdge, const BlowupGraph< T > &blowupGraph)
Initialize all information about the component starting with rootEdge in the blowup graph...
node getSource() const
Returns the source node.
Definition: BlowupGraph.h:503
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:96
BlowupComponents(const BlowupGraph< T > &blowupGraph)
Find all components in the blowup graph and initialize information them.
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1373
const List< node > & terminals() const
Returns a reference to the list containing all terminals in the blowup graph.
Definition: BlowupGraph.h:548
const ArrayBuffer< node > & terminals(int id) const
Return list of terminals for a given component.
Obtain and provides information about components in a given blowup graph.
void push(E e)
Puts a new element in the buffer.
Definition: ArrayBuffer.h:102
E popBackRet()
Removes the last element from the list and returns it.
Definition: List.h:1430
An array that keeps track of the number of inserted elements; also usable as an efficient stack...
Definition: Array.h:45
const T & cost(int id) const
Return total cost of a given component.
node getTarget() const
Returns the target node.
Definition: BlowupGraph.h:513
Doubly linked lists (maintaining the length of the list).
Definition: List.h:40
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition: Graph_d.h:108
Class for the representation of edges.
Definition: Graph_d.h:292
int getCapacity(edge e) const
Returns the capacity of e.
Definition: BlowupGraph.h:518
Class for the representation of nodes.
Definition: Graph_d.h:169
edge rootEdge(int id) const
Return the edge coming from the root of a given component.
bool isTerminal(node v) const
Returns true if and only if v is a terminal.
Definition: BlowupGraph.h:553
A special-purpose blowup graph for gammoid computation: directed, with special source and target...
Definition: BlowupGraph.h:50
T getCost(edge e) const
Returns the cost of e.
Definition: BlowupGraph.h:528
void setRootEdge(int id, edge e)
Set the edge coming from the root for a given component.
int size() const
Return number of components.
node getPseudotarget() const
Returns the pseudotarget node.
Definition: BlowupGraph.h:508
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:326
int id(node v) const
Return the component id a given node is contained in.
The namespace for all OGDF objects.
Definition of ogdf::steiner_tree::goemans::BlowupGraph class template.
node getOriginal(node v) const
Returns the original node of v.
Definition: BlowupGraph.h:533
bool empty() const
Returns true iff the list is empty.
Definition: List.h:256
ArrayBuffer< ArrayBuffer< node > > componentTerminals
Class for adjacency list elements.
Definition: Graph_d.h:79
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:200