41 namespace steiner_tree {
64 , nodepairs(_nodepairs)
68 : cost(numeric_limits<T>::max())
80 if (key.
size() == 2) {
84 return m_map.
lookup(key)->info();
90 if (key.
size() == 2) {
91 return m_distance[key.
front()][key.
back()];
94 return m_map.
lookup(key)->info().cost;
101 if (v->
index() < (*it)->index()) {
115 , m_terminals(terminals)
116 , m_distance(distance)
124 for (terminalSubset.
begin(2, restricted-1); terminalSubset.
valid(); terminalSubset.
next()) {
126 terminalSubset.
list(terminals);
130 auto computeSplit = [&](
node v) {
135 subset.
list(list1, list2);
139 if (tmp < best.cost) {
141 DWMData data =
dataOf(list2);
142 best.cost += data.
cost;
143 int bsize = best.nodepairs.size();
145 best.nodepairs.grow(dsize);
146 for (
int i = 0; i < dsize; ++i) {
147 best.nodepairs[bsize + i] = data.
nodepairs[i];
154 auto computePartialSolutions = [&](
node v) {
157 if (m_map.
member(newTerminals)) {
162 T dist = m_distance[v][w];
169 tmp =
costOf(terminals) + dist;
170 if (tmp < best.
cost) {
181 tmp = split[w].cost + dist;
182 if (tmp < best.
cost) {
193 if (terminalSubset.
size() != restricted - 1) {
196 computePartialSolutions(v);
200 for (
node v : m_terminals) {
202 computePartialSolutions(v);
213 DWMData data =
dataOf(terminals);
216 node uO = nodepair.source;
217 node vO = nodepair.target;
226 const T dist = m_distance[uO][vO];
238 static const int c_prime = 0x7fffffff;
251 int hash = (*it)->index();
252 for (; it.
valid(); ++it) {
253 hash = (hash * m_random + (*it)->index()) % c_prime;
HashElement< K, I > * lookup(const K &key) const
Returns the hash element with key key in the hash table; returns 0 if no such element.
bool member(const K &key) const
Returns true iff the hash table contains an element with key key.
const DWMData dataOf(const List< node > &key) const
A generator for full components (for Steiner tree approximations) based on the Dreyfus-Wagner algorit...
DreyfusWagnerFullComponentGenerator(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< NodeArray< T >> &distance)
The constructor.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
iterator pushBack(const E &x)
Adds element x at the end of the list.
void insertSorted(List< node > &list, node v) const
T getSteinerTreeFor(const List< node > &terminals, EdgeWeightedGraphCopy< T > &tree)
Construct a Steiner tree for the given set of terminals.
void call(int restricted)
int randomNumber(int low, int high)
Returns random integer between low and high (including).
edge newEdge(node u, node v, T weight)
iterator begin()
Returns an iterator to the first element of the list.
static void sortTerminals(List< node > &terminals)
Sort terminals by index.
Declaration of classes used for hashing.
Extends the GraphCopy concept to weighted graphs.
bool valid() const
Is the current subset valid? If not, all subsets have already been enumerated.
void createEmpty(const Graph &wG)
Dynamic arrays indexed with nodes.
void quicksort()
Sorts the list using Quicksort.
void begin(int low, int high)
Initialize the SubsetEnumerator to enumerate subsets of cardinalities from low to high...
INDEX size() const
Returns the size (number of elements) of the array.
const_reference front() const
Returns a const reference to the first element.
Enumerator for k-subsets of a given type.
Doubly linked lists (maintaining the length of the list).
Hashing< List< node >, DWMData, SortedNodeListHashFunc > m_map
A hash array for keys of size > 2.
void grow(INDEX add, const E &x)
Enlarges the array by add elements and sets new elements to x.
static uint32_t hash(uint32_t x)
T costOf(const List< node > &key) const
Class for the representation of nodes.
Encapsulates a pointer to a list element.
const NodeArray< NodeArray< T > > & m_distance
A reference to the full distance matrix.
DWMData(T _cost, NodePairs _nodepairs)
The IndexComparer compares entities like nodes, edges, adjacency entries, based on their index...
bool hasMember(const T &element) const
Check in O(subset cardinality) whether the argument is a member of the subset.
int hash(const List< node > &key) const
int index() const
Returns the (unique) node index.
HashElement< K, I > * fastInsert(const K &key, const I &info)
Inserts a new element with key key and information info into the hash table.
void list(List< T > &list) const
Obtain (append) a list of the elements in the subset.
const EdgeWeightedGraph< T > & m_G
A reference to the graph instance.
void next()
Obtain the next subset if possible. The result should be checked using the valid() method...
IndexComparer definition.
int size() const
Returns the number of elements in the list.
bool isTree(const Graph &G)
Returns true iff G is a tree, i.e. contains no undirected cycle and is connected. ...
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
Hashing with chaining and table doubling.
int size() const
Return the cardinality of the subset.
The namespace for all OGDF objects.
const List< node > & m_terminals
A reference to the index-sorted list of terminals.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
A class that allows to enumerate k-subsets of lists.
bool valid() const
Returns true iff the iterator points to an element.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
const_reference back() const
Returns a const reference to the last element.