Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
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
39namespace ogdf {
40template<typename T>
41class EdgeWeightedGraph;
42
43namespace steiner_tree {
44
52template<typename T>
54public:
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
64protected:
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}
Includes declaration of graph class.
Declaration of doubly linked lists and iterators.
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Encapsulates a pointer to a list element.
Definition List.h:113
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
Definition List.h:174
iterator begin()
Returns an iterator to the first element of the list.
Definition List.h:391
Class for the representation of nodes.
Definition Graph_d.h:241
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
Interface for full 3-component generation including auxiliary functions.
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 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
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.
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
The namespace for all OGDF objects.