Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Full3ComponentGeneratorModule.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/List.h>
36 
37 #include <functional>
38 
39 namespace ogdf {
40 template<typename T>
41 class EdgeWeightedGraph;
42 
43 namespace steiner_tree {
44 
52 template<typename T>
53 class Full3ComponentGeneratorModule {
54 public:
56  virtual ~Full3ComponentGeneratorModule() = default;
57 
59  virtual void call(const EdgeWeightedGraph<T>& G, const List<node>& terminals,
60  const NodeArray<bool>& isTerminal, const NodeArray<NodeArray<T>>& distance,
61  const NodeArray<NodeArray<edge>>& pred,
62  std::function<void(node, node, node, node, T)> generateFunction) const = 0;
63 
64 protected:
74  inline void updateBestCenter(node x, node& center, T& minCost, const NodeArray<T>& dist1,
75  const NodeArray<T>& dist2, const NodeArray<T>& dist3) const {
76 #ifdef OGDF_FULL_COMPONENT_GENERATION_ALWAYS_SAFE
77  if (true) {
78 #else
79  if (dist1[x] < std::numeric_limits<T>::max() && dist2[x] < std::numeric_limits<T>::max()
80  && dist3[x] < std::numeric_limits<T>::max()) {
81 #endif
82  const T tmp = dist1[x] + dist2[x] + dist3[x];
83  if (tmp < minCost) {
84  center = x;
85  minCost = tmp;
86  }
87  }
88  }
89 
90  inline void forAllTerminalTriples(const List<node>& terminals,
91  const NodeArray<NodeArray<T>>& distance,
92  std::function<void(node, node, node, const NodeArray<T>&, const NodeArray<T>&,
93  const NodeArray<T>&)>
94  func) const {
95  for (ListConstIterator<node> it_u = terminals.begin(); it_u.valid(); ++it_u) {
96  for (ListConstIterator<node> it_v = it_u.succ(); it_v.valid(); ++it_v) {
97  for (ListConstIterator<node> it_w = it_v.succ(); it_w.valid(); ++it_w) {
98  func(*it_u, *it_v, *it_w, distance[*it_u], distance[*it_v], distance[*it_w]);
99  }
100  }
101  }
102  }
103 
104  inline void checkAndGenerateFunction(node u, node v, node w, node center, T minCost,
105  const NodeArray<NodeArray<edge>>& pred, const NodeArray<bool>& isTerminal,
106  std::function<void(node, node, node, node, T)> generateFunction) const {
107  if (center && !isTerminal[center] && pred[u][center] && pred[v][center] && pred[w][center]) {
108  generateFunction(u, v, w, center, minCost);
109  }
110  }
111 };
112 
113 }
114 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::steiner_tree::Full3ComponentGeneratorModule::forAllTerminalTriples
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
Definition: Full3ComponentGeneratorModule.h:90
Graph.h
Includes declaration of graph class.
ogdf::NodeArray
internal::GraphRegisteredArray< NodeElement, Value, WithDefault > NodeArray
RegisteredArray for labeling the nodes in a Graph with an arbitrary Value.
Definition: Graph_d.h:740
ogdf::ListIteratorBase::succ
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
Definition: List.h:174
ogdf::steiner_tree::Full3ComponentGeneratorModule::checkAndGenerateFunction
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
Definition: Full3ComponentGeneratorModule.h:104
ogdf::steiner_tree::Full3ComponentGeneratorModule::~Full3ComponentGeneratorModule
virtual ~Full3ComponentGeneratorModule()=default
ogdf::node
NodeElement * node
The type of nodes.
Definition: Graph_d.h:70
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: DfsMakeBiconnected.h:40
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::steiner_tree::Full3ComponentGeneratorModule::updateBestCenter
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.
Definition: Full3ComponentGeneratorModule.h:74
List.h
Declaration of doubly linked lists and iterators.
ogdf::steiner_tree::Full3ComponentGeneratorModule::call
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.
ogdf::ListIteratorBase
Encapsulates a pointer to a list element.
Definition: List.h:51
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::steiner_tree::Full3ComponentGeneratorModule::Full3ComponentGeneratorModule
Full3ComponentGeneratorModule()=default