Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

BlowupGraph.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Math.h>
35 #include <ogdf/basic/HashArray.h>
38 
39 //#define OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
40 
41 namespace ogdf {
42 namespace steiner_tree {
43 namespace goemans {
44 
49 template<typename T>
50 class BlowupGraph {
51 private:
54  const double m_eps;
55 
58 
65 
68 
69  int m_lcm;
70  int m_y;
74 
76 
78 
79  /* witness set (for some component and specified K (core edge set))
80  *
81  * W(e) = { e } if e is a core edge
82  * W(e) =
83  * take the path P of loss edges from u to e in the component
84  * add every incident core edge of u
85  * that is: if we root the loss connected component at the terminal,
86  * W(e) = all core edges incident to the subtree below e
87  *
88  * Need fast lookups for:
89  * (1) |W(f)|
90  * (2) all loss edges f such that given core edge e is in W(f)
91  * (3) all loss edges f such that W(f) is a subset of a given basis -> for each e \in B: do (2)
92  *
93  * Data Structures:
94  * - witnessCard[e] = |W(e)|
95  * - witness[v_e] = { f | e \in W(f) }
96  * (Note that core edges are given as nodes.)
97  * Also note that we can save it all much sparser.
98  */
101 
102 protected:
104  void computeLCM() {
105  ArrayBuffer<int> denominators;
106 
107  for (int i = 0; i < m_fullCompStore.size(); ++i) {
108  OGDF_ASSERT(m_fullCompStore.extra(i) <= 1.0 + m_eps);
109  OGDF_ASSERT(m_fullCompStore.extra(i) >= m_eps);
110  int num, denom;
111  Math::getFraction(m_fullCompStore.extra(i), num, denom);
112  OGDF_ASSERT(Math::gcd(num, denom) == 1);
113  denominators.push(denom);
114  }
115 
116  m_lcm = 1;
117  for (int denom : denominators) {
118  m_lcm = Math::lcm(m_lcm, denom);
119  }
120 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
121  std::cout << "Normalizing factor is " << m_lcm << std::endl;
122 #endif
123  }
124 
127  const node v = m_graph.newNode();
128  m_isTerminal[v] = true;
129  m_terminals.pushBack(v);
130  m_original[v] = t;
131 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
132  std::cout << "Add terminal " << v << " representing original terminal " << t << std::endl;
133 #endif
134  return v;
135  }
136 
138  const node vCopy = m_graph.newNode();
139  m_original[vCopy] = v;
140  return vCopy;
141  }
142 
146  node v = m_fullCompStore.original(start->theNode());
147  List<adjEntry> queueT;
148  List<node> queueC;
149  queueT.pushBack(start);
150  queueC.pushBack(copy[v]);
151  while (!queueT.empty()) {
152  const adjEntry inAdj = queueT.popFrontRet();
153  const node wT = inAdj->twinNode();
154  const node vC = queueC.popFrontRet();
155 
156  const node wO = m_fullCompStore.original(wT);
157  if (m_fullCompStore.isTerminal(wT)) {
158  newEdge(vC, copy[wO], m_fullCompStore.graph().weight(inAdj->theEdge()), cap);
159  } else { // not a terminal
160  const node wC = initNode(wO);
161  newEdge(vC, wC, m_fullCompStore.graph().weight(inAdj->theEdge()), cap);
162  const adjEntry back = inAdj->twin();
163  for (adjEntry adj = back->cyclicSucc(); adj != back; adj = adj->cyclicSucc()) {
164  queueT.pushBack(adj);
165  queueC.pushBack(wC);
166  }
167  }
168  }
169  return copy[v];
170  }
171 
173  void initSource(ArrayBuffer<std::pair<node, int>> &roots) {
174  OGDF_ASSERT(m_source == nullptr);
175  m_source = m_graph.newNode();
176 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
177  std::cout << "Add source node " << getSource() << " with edges to:" << std::endl;
178 #endif
179  for (auto root : roots) {
180 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
181  std::cout
182  << " * node " << root.first
183  << " with cost 0 and capacity " << root.second << std::endl;
184 #endif
185  newEdge(getSource(), root.first, 0, root.second);
186  }
187  }
188 
191  ArrayBuffer<std::pair<node, int>> roots; // roots (in the blowupGraph) and their capacities
192 
193  NodeArray<node> copy(originalGraph, nullptr);
194  for (node t : terminals) { // generate all terminals
195  copy[t] = initTerminal(t);
196  }
197  for (int i = 0; i < m_fullCompStore.size(); ++i) {
198  int cap = int(getLCM() * m_fullCompStore.extra(i) + m_eps);
199  node root = initBlowupGraphComponent(copy, m_fullCompStore.start(i), cap);
200  roots.push(std::make_pair(root, cap));
201  }
202 
203  removeIsolatedTerminals(); // can exist by preprocessing
204 
205 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
206  for (edge e : m_graph.edges) {
207  std::cout
208  << "Edge from " << e
209  << " of cost " << m_cost[e]
210  << " and capacity " << m_capacity[e] << std::endl;
211  }
212 #endif
213 
214  // compute core edges (and replace these edges by nodes)
215  // and witness sets
216  initCoreWitness();
217 
218  initSource(roots);
219  }
220 
223  OGDF_ASSERT(m_pseudotarget == nullptr);
224  m_pseudotarget = m_graph.newNode();
225 
226 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
227  std::cout << "Add pseudo-target " << getPseudotarget() << " with edges coming from:" << std::endl;
228 #endif
229  for (node v : terminals()) {
230  OGDF_ASSERT(v);
231  int y_v = -getLCM();
232  // compute y_v, the number of components containing v in the blow up graph - N
233  // NOTE: for the non-blowup variant this is simply the sum of all x_C where C contains v ... - 1
234  for (adjEntry adj : v->adjEntries) {
235  if (adj->twinNode() != getSource()) {
236  y_v += getCapacity(adj->theEdge());
237  }
238  }
239  OGDF_ASSERT(y_v >= 0);
240 
241  if (y_v > 0) {
242  newEdge(v, getPseudotarget(), 0, y_v);
243 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
244  std::cout
245  << " * terminal " << v
246  << " with zero cost and capacity " << y_v << std::endl;
247 #endif
248  m_y += y_v;
249  }
250  }
251  }
252 
254  void initTarget() {
255  OGDF_ASSERT(m_target == nullptr);
256  m_target = m_graph.newNode();
257 
258  newEdge(getPseudotarget(), getTarget(), 0, m_y);
259 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
260  std::cout
261  << "Add edge from pseudo-target " << getPseudotarget()
262  << " to target " << getTarget()
263  << " with zero cost and capacity " << m_y << std::endl;
264 #endif
265  }
266 
269 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
270  std::cout << " * updating for terminal " << v << std::endl;
271 #endif
272  int delta = 0;
273  int capSource = 0;
274  int capTarget = -getLCM();
275 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
276  std::cout << " * target capacity initialized to " << capTarget << ", source capacity and delta to 0" << std::endl;
277 #endif
278  adjEntry adj2;
279  for (adjEntry adj = v->firstAdj(); adj; adj = adj2) {
280  adj2 = adj->succ();
281  if (adj->twinNode() == getSource()) {
282 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
283  std::cout << " * remove edge with capacity " << getCapacity(adj->theEdge()) << " from source " << getSource() << std::endl;
284 #endif
285  OGDF_ASSERT(adj->theEdge()->source() == getSource());
286 
287  // remove arcs from the source
288  m_graph.delEdge(adj->theEdge());
289  }
290  else
291  if (adj->twinNode() == getPseudotarget()) {
292 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
293  std::cout
294  << " * remove edge to pseudotarget " << getPseudotarget()
295  << " with capacity " << getCapacity(adj->theEdge())
296  << " participating in delta" << std::endl;
297 #endif
298  OGDF_ASSERT(adj->theEdge()->target() == getPseudotarget());
299 
300  // remove arcs to the pseudotarget
301  delta -= getCapacity(adj->theEdge());
302  m_graph.delEdge(adj->theEdge());
303  }
304  else {
305 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
306  std::cout
307  << " * update target capacity for edge " << adj->theEdge()
308  << " by adding " << getCapacity(adj->theEdge()) << std::endl;
309 #endif
310  // compute y_v for the contraction node
311  capTarget += getCapacity(adj->theEdge());
312  // compute s->v capacity
313  if (v != adj->theEdge()->target()) { // outgoing edge
314 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
315  std::cout << " and change source capacity by the same amount" << std::endl;
316 #endif
317  capSource += getCapacity(adj->theEdge());
318  }
319  }
320  }
321 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
322  std::cout
323  << " * new target capacity is " << capTarget
324  << " and delta = " << delta << std::endl;
325 #endif
326  OGDF_ASSERT(capTarget >= 0);
327  if (capTarget > 0) {
328  newEdge(v, getPseudotarget(), 0, capTarget);
329 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
330  std::cout
331  << " * new edge from pseudotarget to target with zero cost and capacity "
332  << capTarget << std::endl;
333 #endif
334  }
335  if (capSource > 0) {
336 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
337  std::cout
338  << " * new edge from source to " << v << " with zero cost and capacity "
339  << capSource << std::endl;
340 #endif
341  newEdge(getSource(), v, 0, capSource);
342  }
343 
344  return delta + capTarget;
345  }
346 
347  void setCapacity(edge e, int capacity) {
348  m_capacity[e] = capacity;
349  }
350 
353 
356  void addCore(node e) {
357  m_coreEdges.pushBack(e);
358  }
359 
361  void addWitness(node e, edge f) {
362  ++m_witnessCard[f];
363  m_witness[e].push(f);
364  }
365 
372  m_witnessCard.init(m_graph, 0);
373  m_witness.init(m_graph);
374 
375  // compute set of core edges
376  EdgeArray<bool> isLossEdge;
377  m_ceModule.call(m_graph, terminals(), isLossEdge);
378 
379  // add nodes for core edges and be able to map them
380  EdgeArray<node> splitMap(m_graph, nullptr);
381  ArrayBuffer<edge> coreEdges;
382  for (edge e : m_graph.edges) {
383  if (!isLossEdge[e]) {
384  splitMap[e] = m_graph.newNode();
385  coreEdges.push(e);
386  }
387  }
388 
389  // traverse losses from all terminals to find witness sets
390  NodeArray<adjEntry> pred(m_graph, nullptr);
391  for (node t : terminals()) {
392  ArrayBuffer<node> stack;
393  stack.push(t);
394  while (!stack.empty()) {
395  // for each node v "below" an edge e in the traversal:
396  // add all incident core edges vw to W(e)
397  const node v = stack.popRet();
398  for (adjEntry adj : v->adjEntries) {
399  const edge e = adj->theEdge();
400  const node w = adj->twinNode();
401  if (!pred[v] || w != pred[v]->theNode()) { // do not look at backward arcs in the tree
402  if (isLossEdge[e]) {
403  stack.push(w);
404  pred[w] = adj;
405  } else {
406  for (node x = v; pred[x]; x = pred[x]->theNode()) {
407  addWitness(splitMap[e], pred[x]->theEdge());
408  }
409  }
410  }
411  }
412  }
413  }
414 
415  // finally replace core edges by nodes
416  for (edge e : coreEdges) {
417  const T w = getCost(e);
418  const node x = splitMap[e];
419  const int cap = getCapacity(e);
420  OGDF_ASSERT(x);
421  newEdge(e->source(), x, w, cap);
422  newEdge(x, e->target(), 0, cap);
423  // the cost of a core edge node is hence the weight of one incident edge;
424  // also keep capacity.
425  // Note that we cannot guarantee throughout the algorithm that the edge
426  // with the non-zero cost is the first one nor that it is the incoming one
427  // because both directions and adjacency orders can be changed.
428  m_graph.delEdge(e);
429  addCore(x);
430  }
431  }
432 
434  void makeCWCopy(const HashArray<edge,edge> &edgeMap) {
435  for (HashConstIterator<edge,edge> pair = edgeMap.begin(); pair.valid(); ++pair) {
436  const edge eO = pair.key();
437  const edge eC = pair.info();
438  const node vO = eO->target();
439  const node vC = eC->target();
440  m_witnessCard[eC] = m_witnessCard[eO]; // copy witness cardinality
441  if (vC == vO) { // target is a terminal, so it cannot be a core edge
442  continue;
443  }
444  for (ListIterator<node> it = m_coreEdges.begin(); it.valid(); ++it) {
445  if (*it == vO) { // vO is a core edge
446  m_coreEdges.insertAfter(vC, it); // make vC a core edge
447 
448  // copy witness sets
449  // XXX: do we need this or are witness sets computed after the loop again?!
450  for (edge e : m_witness[vO]) {
451  m_witness[vC].push(edgeMap[e]);
452  }
453  break;
454  }
455  }
456  }
457  }
458 
460 
461 public:
463  BlowupGraph(const EdgeWeightedGraph<T> &G, const List<node> &terminals, const FullComponentWithExtraStore<T, double> &fullCompStore, const CoreEdgeModule<T> &ceModule, double eps = 1e-8)
464  : m_fullCompStore(fullCompStore)
465  , m_eps(eps)
466  , m_terminals()
467  , m_isTerminal(m_graph, false)
468  , m_original(m_graph, nullptr)
469  , m_cost(m_graph)
470  , m_capacity(m_graph)
471  , m_y(0)
472  , m_source(nullptr)
473  , m_pseudotarget(nullptr)
474  , m_target(nullptr)
475  , m_ceModule(ceModule)
476  {
477  computeLCM();
478 
479 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
480  std::cout << "Full components to use in blowup graph:\n";
481  for (int k = 0; k < m_fullCompStore.size(); ++k) {
482  std::cout
483  << " * " << m_fullCompStore.terminals(k)
484  << " cost " << m_fullCompStore.cost(k)
485  << " support " << m_fullCompStore.extra(k)
486  << " (normalized to " << m_fullCompStore.extra(k) * m_lcm << ")" << std::endl;
487  }
488 #endif
489 
490  initBlowupGraphComponents(G, terminals);
492  initTarget();
493  }
494 
497 
498  const Graph &getGraph() const {
499  return m_graph;
500  }
501 
503  node getSource() const {
504  return m_source;
505  }
506 
509  return m_pseudotarget;
510  }
511 
513  node getTarget() const {
514  return m_target;
515  }
516 
518  int getCapacity(edge e) const {
519  return m_capacity[e];
520  }
521 
523  const EdgeArray<int> &capacities() const {
524  return m_capacity;
525  }
526 
528  T getCost(edge e) const {
529  return m_cost[e];
530  }
531 
533  node getOriginal(node v) const {
534  return m_original[v];
535  }
536 
538  int getLCM() const {
539  return m_lcm;
540  }
541 
543  int getY() const {
544  return m_y;
545  }
546 
548  const List<node> &terminals() const {
549  return m_terminals;
550  }
551 
553  bool isTerminal(node v) const {
554  return m_isTerminal[v];
555  }
556 
560 
562  T getCoreCapacity(node v) const {
563  OGDF_ASSERT(v->degree() == 2);
564  return getCapacity(v->firstAdj()->theEdge());
565  }
566 
568  T getCoreCost(node v) const {
569  OGDF_ASSERT(v->degree() == 2);
570  T val = getCost(v->firstAdj()->theEdge());
571  if (val == 0) {
572  val = getCost(v->lastAdj()->theEdge());
573  }
574  return val;
575  }
576 
578  double computeCoreWeight(node v) const {
579  double weight = (double)getCoreCost(v);
580  for (edge e : witnessList(v)) {
582  weight += (double)getCost(e) / numberOfWitnesses(e);
583  }
584  return weight;
585  }
586 
588 
591 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
592  std::cout << "Updating capacities (y = " << m_y << ")" << std::endl;
593 #endif
594  for (node t : terminals()) {
596 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
597  std::cout << " * new y = " << m_y << std::endl;
598 #endif
599  }
600  // XXX: doing it for v and all terminals we have met during cleanup would be sufficient
601  OGDF_ASSERT(getTarget()->degree() == 1);
602  setCapacity(getTarget()->firstAdj()->theEdge(), m_y);
603  }
604 
606  edge newEdge(node v, node w, T cost, int capacity) {
607  edge e = m_graph.newEdge(v, w);
608  m_cost[e] = cost;
609  m_capacity[e] = capacity;
610  return e;
611  }
612 
615  for (edge e : edges) {
616  m_graph.delEdge(e);
617  }
618  }
619 
621  void contract(node &v, node t) {
622  if (v->degree() == 0) {
623  std::swap(v, t);
624  }
625 
626  OGDF_ASSERT(m_isTerminal[t]);
627  m_terminals.removeFirst(t);
628  m_isTerminal[t] = false;
629 
630  if (t->degree() > 0) {
631  v = m_graph.contract(m_graph.newEdge(v, t));
632  // the contract method ensures that capacities, weights, and everything is kept
633  } else {
634  m_graph.delNode(t);
635  }
636  }
637 
639  template<typename NODELIST>
640  void contract(NODELIST& nodes) {
641  auto it = nodes.begin();
642  node v = *it;
643  for (++it; it != nodes.end(); ++it) {
644  contract(v, *it);
645  }
646  }
647 
653  void removeBasis(node v) {
654  ArrayBuffer<node> cleanup;
655  cleanup.push(v->firstAdj()->twinNode());
656  cleanup.push(v->lastAdj()->twinNode());
657  OGDF_ASSERT(v->degree() == 2);
658  OGDF_ASSERT(v->firstAdj()->twinNode() != v->lastAdj()->twinNode());
659  m_graph.delNode(v);
660 
661  while (!cleanup.empty()) {
662  v = cleanup.popRet();
663  if (!isTerminal(v)) {
664  OGDF_ASSERT(v->degree() >= 1);
665  if (v->degree() == 1) { // v is a pendant node, delete
666 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
667  std::cout << " * remove pendant node " << v << " for cleanup" << std::endl;
668 #endif
669  cleanup.push(v->firstAdj()->twinNode());
670  m_graph.delNode(v);
671  } else
672  if (v->indeg() == 0) { // v has no incoming edge, fix
673 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
674  std::cout << " * " << v << " has no incoming edge -> fix directions" << std::endl;
675 #endif
676  const node w = v->firstAdj()->twinNode();
677  const edge e = v->firstAdj()->theEdge();
678 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
679  std::cout << " * make " << w << " parent of " << v << " (reverse edge " << e << ")" << std::endl;
680 #endif
681  m_graph.reverseEdge(e);
682  OGDF_ASSERT(e->source() == w);
683  if (!isTerminal(w)) {
684  cleanup.push(w);
685  // when w is cleaned up, it must not go back to v
686  if (w->firstAdj()->theEdge() == e) {
687  // move first adjacency entries of w away (w->v is not first anymore)
688  m_graph.moveAdjAfter(w->firstAdj(), w->lastAdj());
689  }
690  }
691  }
692  }
693  }
694  }
695 
698  for (ListIterator<node> it = m_terminals.begin(), itNext; it.valid(); it = itNext) {
699  itNext = it.succ();
700  if ((*it)->degree() == 0) {
701  m_graph.delNode(*it);
702  m_terminals.del(it);
703  }
704  }
705  }
706 
709  edge rootEdge = nullptr;
710  OGDF_ASSERT(!isTerminal(v));
711  for (auto it = v->adjEntries.begin(); it != v->adjEntries.end();) {
712  edge e = (*it)->theEdge();
713  if (e->source() != v) { // incoming edge
714  rootEdge = e;
715  if (isTerminal(e->source())) {
716  break;
717  }
718  v = e->source();
719  it = v->adjEntries.begin();
720  } else {
721  ++it;
722  }
723  }
724  OGDF_ASSERT(rootEdge != nullptr);
725  OGDF_ASSERT(isTerminal(rootEdge->source()));
726  return rootEdge;
727  }
728 
730  void copyComponent(const edge origEdge, const int origCap, const int copyCap) {
731  if (copyCap == 0) {
732  return;
733  }
734  List<edge> todo;
735  List<node> origin;
736  HashArray<edge,edge> edgeMap;
737  todo.pushBack(origEdge);
738  origin.pushBack(origEdge->source());
739  while (!todo.empty()) {
740  edge eO = todo.popFrontRet();
741  node vC = origin.popFrontRet();
742  node wO = eO->target();
743  node wC = wO;
744  if (!isTerminal(wO)) {
745  wC = initNode(getOriginal(wO));
746  }
747  edge eC = newEdge(vC, wC, getCost(eO), copyCap);
748  setCapacity(eO, origCap);
749  edgeMap[eO] = eC;
750  if (!isTerminal(wO)) {
751  for (adjEntry adj = eO->adjTarget()->cyclicSucc(); adj != eO->adjTarget(); adj = adj->cyclicSucc()) {
752  OGDF_ASSERT(adj->theEdge()->target() != eO->target()); // outgoing edges
753  origin.pushBack(wC);
754  todo.pushBack(adj->theEdge());
755  }
756  }
757  }
758  makeCWCopy(edgeMap);
759  }
760 
763 
765  const List<node> &core() const {
766  return m_coreEdges;
767  }
768 
771  void delCore(node e) {
772  /* What happens when we remove a core edge?
773  * - loss edges are not affected
774  * - we have to remove a core edge e from W(f) for all f, which means:
775  * for all elements f of witness[v_e], decrease witnessCard[f], then remove witness[v_e]
776  */
777  for (edge f : m_witness[e]) {
778  --m_witnessCard[f];
779  }
780  // witness[e] is removed by removing the node from the graph
781  m_coreEdges.removeFirst(e);
782  }
783 
785  int numberOfWitnesses(edge e) const {
786  return m_witnessCard[e];
787  }
788 
791  return m_witness[e];
792  }
793 
795 };
796 
797 }
798 }
799 }
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:328
List< node > m_coreEdges
the core edges as nodes
Definition: BlowupGraph.h:77
NodeArray< ArrayBuffer< edge > > m_witness
Definition: BlowupGraph.h:100
node getSource() const
Returns the source node.
Definition: BlowupGraph.h:503
void addWitness(node e, edge f)
Adds e to W(f)
Definition: BlowupGraph.h:361
void delEdges(ArrayBuffer< edge > edges)
Removes edges in edges.
Definition: BlowupGraph.h:614
Declaration and implementation of HashArray class.
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:96
void makeCWCopy(const HashArray< edge, edge > &edgeMap)
Copies witness sets and core edges for a given copy map.
Definition: BlowupGraph.h:434
void init()
Reinitializes the array. Associates the array with no graph.
Definition: EdgeArray.h:283
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1373
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
virtual void delNode(node v)
Removes node v and all incident edges from the graph.
const List< node > & terminals() const
Returns a reference to the list containing all terminals in the blowup graph.
Definition: BlowupGraph.h:548
void init()
Reinitializes the array. Associates the array with no graph.
Definition: NodeArray.h:255
void initPseudotarget()
Connects pseudotarget.
Definition: BlowupGraph.h:222
Indexed arrays using hashing for element access.
Definition: HashArray.h:94
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition: Graph_d.h:210
NodeArray< bool > m_isTerminal
Incidence vector for the blowup graph terminals.
Definition: BlowupGraph.h:57
int indeg() const
Returns the indegree of the node.
Definition: Graph_d.h:206
iterator begin()
Returns an iterator to the first element of the list.
Definition: List.h:352
const Array< node > & terminals(int id) const
Returns the list of terminals in the full component with given id.
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
Definition: List.h:1398
const CoreEdgeModule< T > & m_ceModule
Definition: BlowupGraph.h:75
void setCapacity(edge e, int capacity)
Definition: BlowupGraph.h:347
virtual void delEdge(edge e)
Removes edge e from the graph.
void push(E e)
Puts a new element in the buffer.
Definition: ArrayBuffer.h:102
void contract(node &v, node t)
Contracts node v and terminal t into v.
Definition: BlowupGraph.h:621
T gcd(T a, T b)
Returns the greatest common divisor of two numbers.
Definition: Math.h:175
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
void copyComponent(const edge origEdge, const int origCap, const int copyCap)
Copy a component in the blowup graph and set original capacity to origCap and capacity of copy to cop...
Definition: BlowupGraph.h:730
int getLCM() const
Returns the least common multiple of all denominators.
Definition: BlowupGraph.h:538
void removeIsolatedTerminals()
Removes isolated terminals.
Definition: BlowupGraph.h:697
int getY() const
Returns the y-value of all terminals.
Definition: BlowupGraph.h:543
adjEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
Definition: Graph_d.h:279
void delCore(node e)
Remove a core edge.
Definition: BlowupGraph.h:771
bool isTerminal(int id, node t) const
checks if a given node t is a terminal in the full component with given id
edge findRootEdge(node v)
Finds the root node of a component given by v, an arbitrary inner nonterminal of the component...
Definition: BlowupGraph.h:708
double computeCoreWeight(node v) const
Compute the weight of a core edge.
Definition: BlowupGraph.h:578
void del(iterator it)
Removes it from the list.
Definition: List.h:1437
T lcm(T a, T b)
Returns the least common multipler of two numbers.
Definition: Math.h:197
void reverseEdge(edge e)
Reverses the edge e, i.e., exchanges source and target node.
void moveAdjAfter(adjEntry adjMove, adjEntry adjAfter)
Moves adjacency entry adjMove after adjAfter.
Definition: Graph_d.h:1100
const EdgeArray< int > & capacities() const
Returns a reference to the edge array containing all capacities.
Definition: BlowupGraph.h:523
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:568
int numberOfWitnesses(edge e) const
Return the number of witnesses of an edge.
Definition: BlowupGraph.h:785
node initBlowupGraphComponent(const NodeArray< node > &copy, adjEntry start, int cap)
Does a bfs of the component tree to add directed components with the first terminal as root...
Definition: BlowupGraph.h:145
Iterators for hash tables.
Definition: Hashing.h:208
Mathematical Helpers.
bool empty() const
Returns true if the buffer is empty, false otherwise.
Definition: ArrayBuffer.h:116
Definition of ogdf::steiner_tree::goemans::CoreEdgeModule class template.
static void copy(const T &from, T &to)
Definition: Alg.h:61
node getTarget() const
Returns the target node.
Definition: BlowupGraph.h:513
node contract(edge e)
Contracts edge e while preserving the order of adjacency entries.
Definition of the FullComponentStore class template.
const double m_eps
epsilon for double operations
Definition: BlowupGraph.h:54
Doubly linked lists (maintaining the length of the list).
Definition: List.h:40
T getCoreCapacity(node v) const
Get capacity of a core edge.
Definition: BlowupGraph.h:562
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
void initCoreWitness()
Finds a "random" set of core edges and "replace" found edges by nodes, also find the witness sets for...
Definition: BlowupGraph.h:371
void initBlowupGraphComponents(const EdgeWeightedGraph< T > &originalGraph, const List< node > &terminals)
Initializes all components in the blowup graph as well as core edges and witness sets.
Definition: BlowupGraph.h:190
T getCoreCost(node v) const
Get cost of a core edge.
Definition: BlowupGraph.h:568
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
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition: Graph_d.h:105
void getFraction(double d, int &num, int &denom, const double epsilon=5e-10, const int count=10)
Converts a double to a fraction.
Definition: Math.h:204
E popFrontRet()
Removes the first element from the list and returns it.
Definition: List.h:1417
void updateSpecialCapacities()
Updates capacities from source to terminals and terminals to pseudotarget.
Definition: BlowupGraph.h:590
int getCapacity(edge e) const
Returns the capacity of e.
Definition: BlowupGraph.h:518
adjEntry lastAdj() const
Returns the last entry in the adjacency list.
Definition: Graph_d.h:215
void initSource(ArrayBuffer< std::pair< node, int >> &roots)
Connects source to component roots.
Definition: BlowupGraph.h:173
Class for the representation of nodes.
Definition: Graph_d.h:169
virtual void call(const Graph &graph, const List< node > &terminals, EdgeArray< bool > &isInTree) const =0
Compute a set of core edges.
Encapsulates a pointer to a list element.
Definition: List.h:42
bool isTerminal(node v) const
Returns true if and only if v is a terminal.
Definition: BlowupGraph.h:553
void initTarget()
Connects target.
Definition: BlowupGraph.h:254
void removeBasis(node v)
Removes a basis and cleans up.
Definition: BlowupGraph.h:653
E popRet()
Removes the newest element from the buffer and returns it.
Definition: ArrayBuffer.h:113
A special-purpose blowup graph for gammoid computation: directed, with special source and target...
Definition: BlowupGraph.h:50
ExtraDataType & extra(int i)
Returns a reference to the extra data of this full component.
int updateSourceAndTargetArcCapacities(const node v)
Updates arc capacities s->v and v->t.
Definition: BlowupGraph.h:268
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
Definition: List.h:1443
adjEntry succ() const
Returns the successor in the adjacency list.
Definition: Graph_d.h:148
T getCost(edge e) const
Returns the cost of e.
Definition: BlowupGraph.h:528
Interface for core edge finder algorithms.
const ArrayBuffer< edge > & witnessList(node e) const
Return list of loss edges f in W(e)
Definition: BlowupGraph.h:790
HashConstIterator< I, E, H > begin() const
Returns an iterator to the first element in the list of all elements.
Definition: HashArray.h:113
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
NodeArray< node > m_original
Mapping of blowup graph nodes to original nodes. If a node in a blowup graph represents more than one...
Definition: BlowupGraph.h:64
const EdgeWeightedGraph< T > & graph() const
List< node > m_terminals
The terminals in the blowup graph.
Definition: BlowupGraph.h:56
The namespace for all OGDF objects.
T cost(int i) const
Returns the sum of edge costs of this full component.
void contract(NODELIST &nodes)
Contracts nodes.
Definition: BlowupGraph.h:640
void addCore(node e)
Adds a core edge.
Definition: BlowupGraph.h:356
node newNode()
Creates a new node and returns it.
int size() const
Returns the number of full components in the store.
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition: Graph_d.h:213
BlowupGraph(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const FullComponentWithExtraStore< T, double > &fullCompStore, const CoreEdgeModule< T > &ceModule, double eps=1e-8)
Initializes a blowup graph including core edges and witness sets.
Definition: BlowupGraph.h:463
void computeLCM()
Computes the least common multiple of the values assigned to the full components. ...
Definition: BlowupGraph.h:104
node initTerminal(node t)
Inserts a terminal.
Definition: BlowupGraph.h:126
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition: Graph_d.h:335
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
edge newEdge(node v, node w, T cost, int capacity)
Adds and returns a new edge between v and w of specified cost and capacity.
Definition: BlowupGraph.h:606
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:100
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
const FullComponentWithExtraStore< T, double > & m_fullCompStore
all enumerated full components, with solution
Definition: BlowupGraph.h:53
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:200
const List< node > & core() const
Return list of core edges (implemented by nodes)
Definition: BlowupGraph.h:765