Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

Full3ComponentGeneratorModule.h
Go to the documentation of this file.
1 
32 #pragma once
33 
35 
36 namespace ogdf {
37 namespace steiner_tree {
38 
46 template<typename T>
48 {
49 public:
51  virtual ~Full3ComponentGeneratorModule() = default;
52 
54  virtual void call(
55  const EdgeWeightedGraph<T> &G,
56  const List<node> &terminals,
57  const NodeArray<bool> &isTerminal,
58  const NodeArray<NodeArray<T>> &distance,
59  const NodeArray<NodeArray<edge>> &pred,
60  std::function<void(node, node, node, node, T)> generateFunction) const = 0;
61 
62 protected:
72  inline void updateBestCenter(node x, node &center, T &minCost, const NodeArray<T> &dist1, const NodeArray<T> &dist2, const NodeArray<T> &dist3) const
73  {
74 #ifdef OGDF_FULL_COMPONENT_GENERATION_ALWAYS_SAFE
75  if (true) {
76 #else
77  if (dist1[x] < std::numeric_limits<T>::max()
78  && dist2[x] < std::numeric_limits<T>::max()
79  && dist3[x] < std::numeric_limits<T>::max()) {
80 #endif
81  const T tmp = dist1[x] + dist2[x] + dist3[x];
82  if (tmp < minCost) {
83  center = x;
84  minCost = tmp;
85  }
86  }
87  }
88 
89  inline void forAllTerminalTriples(
90  const List<node> &terminals,
91  const NodeArray<NodeArray<T>> &distance,
92  std::function<void(node, node, node, const NodeArray<T> &, const NodeArray<T> &, const NodeArray<T> &)> func) const
93  {
94  for (ListConstIterator<node> it_u = terminals.begin(); it_u.valid(); ++it_u) {
95  for (ListConstIterator<node> it_v = it_u.succ(); it_v.valid(); ++it_v) {
96  for (ListConstIterator<node> it_w = it_v.succ(); it_w.valid(); ++it_w) {
97  func(*it_u, *it_v, *it_w, distance[*it_u], distance[*it_v], distance[*it_w]);
98  }
99  }
100  }
101  }
102 
103  inline void checkAndGenerateFunction(node u, node v, node w, node center, T minCost,
104  const NodeArray<NodeArray<edge>> &pred,
105  const NodeArray<bool> &isTerminal,
106  std::function<void(node, node, node, node, T)> generateFunction) const
107  {
108  if (center
109  && !isTerminal[center]
110  && pred[u][center]
111  && pred[v][center]
112  && pred[w][center]) {
113  generateFunction(u, v, w, center, minCost);
114  }
115  }
116 };
117 
118 }
119 }
Interface for full 3-component generation including auxiliary functions.
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
Definition: List.h:145
iterator begin()
Returns an iterator to the first element of the list.
Definition: List.h:352
void checkAndGenerateFunction(node u, node v, node w, node center, T minCost, const NodeArray< NodeArray< edge >> &pred, const NodeArray< bool > &isTerminal, std::function< void(node, node, node, node, T)> generateFunction) const
void updateBestCenter(node x, node &center, T &minCost, const NodeArray< T > &dist1, const NodeArray< T > &dist2, const NodeArray< T > &dist3) const
Update center node if it is the best so far.
void forAllTerminalTriples(const List< node > &terminals, const NodeArray< NodeArray< T >> &distance, std::function< void(node, node, node, const NodeArray< T > &, const NodeArray< T > &, const NodeArray< T > &)> func) const
virtual void call(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, const NodeArray< NodeArray< T >> &distance, const NodeArray< NodeArray< edge >> &pred, std::function< void(node, node, node, node, T)> generateFunction) const =0
Generate full components and call generateFunction for each full component.
Doubly linked lists (maintaining the length of the list).
Definition: List.h:40
Declaration of class EdgeWeightedGraph.
Class for the representation of nodes.
Definition: Graph_d.h:169
Encapsulates a pointer to a list element.
Definition: List.h:42
The namespace for all OGDF objects.