40 namespace steiner_tree {
68 explicit DWMData(T _cost = std::numeric_limits<T>::max()) : cost(_cost) {}
78 return cost == 0 || !(nodepairs.
empty() && subgraphs.
empty());
85 subgraphs.
push(other);
102 nodepairs.
push(nodepair);
110 T cost = std::numeric_limits<T>::max();
118 cost = s1->
cost + s2->cost;
132 return &m_map.
lookup(key)->info();
138 if (key.
size() == 2) {
139 #ifdef OGDF_FULL_COMPONENT_GENERATION_TERMINAL_SSSP_AWARE 140 if (m_isTerminal[key.
front()]) {
141 return m_distance[key.
front()][key.
back()];
144 return m_distance[key.
back()][key.
front()];
147 return m_distance[key.
front()][key.
back()];
156 #ifdef OGDF_FULL_COMPONENT_GENERATION_ALWAYS_SAFE 157 return summand1 + summand2 < compareValue;
159 return summand1 < std::numeric_limits<T>::max()
160 && summand2 < std::numeric_limits<T>::max()
161 && summand1 + summand2 < compareValue;
178 if (!inserted && w->
index() > newNode->
index()) {
188 bool inserted =
false;
198 bool insertedIntoSubset =
false;
199 bool insertedIntoComplement =
false;
204 if (!insertedIntoSubset) {
207 if (!insertedIntoComplement) {
218 if (split[v].subgraph1 !=
nullptr) {
225 makeKey(newSubset, newComplement, subset, v);
242 if (!m_map.
member(newSubset)) {
243 T oldCost =
costOf(terminals);
245 auto addPair = [&](
node v1,
node v2, T dist) {
247 if (m_pred[v1][v2] ==
nullptr) {
252 T dist = m_distance[v][w];
266 best.
add(split[w].subgraph1);
267 best.
add(split[w].subgraph2);
279 template<
typename CONTAINER>
282 m_terminalSubset.
list(terminals);
285 for (
node v : nodeContainer) {
295 for (
node t : m_terminals) {
299 if (v->
index() < t->index()) {
306 if (m_pred[t][v] ==
nullptr) {
327 node uO = nodepair.source;
328 node vO = nodepair.target;
337 #ifdef OGDF_FULL_COMPONENT_GENERATION_TERMINAL_SSSP_AWARE 338 const T dist = m_isTerminal[uO] ? m_distance[uO][vO] : m_distance[vO][uO];
340 const T dist = m_distance[uO][vO];
347 for (
const DWMData* subgraph : data.
subgraphs) {
364 , m_terminals(terminals)
365 , m_isTerminal(isTerminal)
366 , m_distance(distance)
368 , m_terminalSubset(m_terminals)
378 for (m_terminalSubset.
begin(2, restricted-1); m_terminalSubset.
valid(); m_terminalSubset.
next()) {
379 if (m_terminalSubset.
size() != restricted - 1) {
415 static const unsigned int c_prime = 0x7fffffff;
429 unsigned int hash = 0;
431 hash = (hash * m_random + v->index()) % c_prime;
HashElement< K, I > * lookup(const K &key) const
Returns the hash element with key key in the hash table; returns nullptr if no such element exists...
bool member(const K &key) const
Returns true iff the hash table contains an element with key key.
T getSteinerTreeFor(const List< node > &terminals, EdgeWeightedGraphCopy< T > &tree) const
Constructs a Steiner tree for the given set of terminals if it is valid, otherwise an empty tree is r...
void clear()
Clears the buffer.
void clear()
Remove all subgraphs and edges and set cost to zero.
void add(const DWMData *other)
Adds other subgraph to ours.
void invalidate()
Invalidates the data.
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.
bool safeIfSumSmaller(const T summand1, const T summand2, const T compareValue) const
Checks overflow-safe if summand1 plus summand2 is less than compareValue.
int randomNumber(int low, int high)
Returns random integer between low and high (including).
int degree() const
Returns the degree of the node (indegree + outdegree).
A collection of two subgraphs and their total cost.
edge newEdge(node u, node v, T weight)
Declaration of classes used for hashing.
void push(E e)
Puts a new element in the buffer.
static void sortedInserter(node w, List< node > &list, bool &inserted, node newNode)
Is being used as a callback to ogdf::SubsetEnumerator's forEach* methods to get the subset plus a cor...
void add(NodePair nodepair, T c)
Adds a nodepair of cost c.
Extends the GraphCopy concept to weighted graphs.
bool valid() const
Checks if the current subset is valid. If not, the subset is either not initialized or all subsets ha...
SortedNodeListHashFunc()
Initializes the random number.
const NodeArray< bool > & m_isTerminal
A reference to the terminal incidence vector.
DWMData(T _cost=std::numeric_limits< T >::max())
DWMData(T _cost, NodePairs _nodepairs)
const EdgeWeightedGraph< T > & m_G
A reference to the graph instance.
void call(int restricted)
void createEmpty(const Graph &wG)
void updateMin(T &min, const T &newValue)
Stores the minimum of min and newValue in min.
T costOf(const List< node > &key) const
Returns the cost of the partial solution given by key.
const List< node > & m_terminals
A reference to the index-sorted list of terminals.
void initializeMap()
Initializes the hash array with all node-terminal-pairs.
SubsetEnumerator< node > m_terminalSubset
Handling subsets of terminals.
void computePartialSolution(NodeArray< DWMSplit > &split, node v, SubsetEnumerator< node > &subset, const List< node > &terminals)
Computes a partial solution for given terminals and node v.
bool isAcyclicUndirected(const Graph &G, List< edge > &backedges)
Returns true iff the undirected graph G is acyclic.
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
void begin(int low, int high)
Initializes the SubsetEnumerator to enumerate subsets of cardinalities from low to high...
bool empty() const
Returns true if the buffer is empty, false otherwise.
unsigned int hash(const List< node > &key) const
The actual hash function.
A generator for restricted full components (for Steiner tree approximations) based on the Dreyfus-Wag...
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).
static uint32_t hash(uint32_t x)
void makeKey(List< node > &newSubset, node v) const
Makes a list from the current terminal subset including an correctly inserted node v...
T getSteinerTreeFor(const DWMData &data, EdgeWeightedGraphCopy< T > &tree) const
Adds edges to construct a Steiner tree from the given data (recursively) if the data is valid...
Class for the representation of nodes.
const Graph & original() const
Returns a reference to the original graph.
bool hasMember(const T &element) const
Checks in O(subset cardinality) whether element is a member of the subset.
const NodeArray< NodeArray< T > > & m_distance
A reference to the full distance matrix.
void forEachMemberAndNonmember(std::function< void(const T &)> funcIn, std::function< void(const T &)> funcNotIn) const
Calls funcIn for each subset member and funcNotIn for each other element of the set.
void set(const DWMData *s1, const DWMData *s2)
Sets subgraph1 and subgraph2 and computes cost.
void computeSplit(NodeArray< DWMSplit > &split, node v, SubsetEnumerator< node > &subset) const
Populates split that contains a partial solution for an included nonterminal v in m_G...
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 > &subset) const
Obtains (appends) a list of the subset members.
void next()
Obtains the next subset if possible. The result should be checked using the valid() method...
int size() const
Returns the number of elements in the list.
Hashing< List< node >, DWMData, SortedNodeListHashFunc > m_map
A hash array for keys of size > 2.
void forEachMember(std::function< void(const T &)> func) const
Calls func for each member in the subset.
bool isTree(const Graph &G)
Returns true iff G is a tree, i.e. contains no undirected cycle and is connected. ...
Hashing with chaining and table doubling.
int size() const
Returns the cardinality of the subset.
The namespace for all OGDF objects.
FullComponentGeneratorDreyfusWagner(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, const NodeArray< NodeArray< T >> &distance, const NodeArray< NodeArray< edge >> &pred)
The constructor.
const NodeArray< NodeArray< edge > > & m_pred
A reference to the full predecessor matrix.
const DWMData * dataOf(const List< node > &key) const
Returns a pointer to the relevant data of the partial solution given by key.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
int numberOfMembersAndNonmembers() const
Returns the cardinality of the (super-)set. This is the maximum size that can be used for a subset...
bool isValidComponent(const EdgeWeightedGraphCopy< T > &graph) const
Checks if a given graph is a valid full component.
ArrayBuffer< const DWMData * > subgraphs
void makeKey(List< node > &newSubset, List< node > &newComplement, const SubsetEnumerator< node > &subset, node v) const
Makes a list from subset and its complement, each including an correctly inserted node v...
Subgraphs (given by other subgraphs and additional node pairs) and their cost for a partial solution...
void computePartialSolutions(const CONTAINER &nodeContainer)
Computes all partial solutions for given m_terminalSubset.
A class that allows to enumerate k-subsets.
bool empty() const
Returns true iff the graph is empty, i.e., contains no nodes.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
bool valid() const
Returns true iff the data is valid.
const_reference back() const
Returns a const reference to the last element.