46class EdgeWeightedGraph;
48class EdgeWeightedGraphCopy;
50namespace steiner_tree {
79 explicit DWMData(T _cost = std::numeric_limits<T>::max()) :
cost(_cost) { }
119 T
cost = std::numeric_limits<T>::max();
132 class SortedNodeListHashFunc;
141 return &
m_map.lookup(key)->info();
147 if (key.
size() == 2) {
148#ifdef OGDF_FULL_COMPONENT_GENERATION_TERMINAL_SSSP_AWARE
164#ifdef OGDF_FULL_COMPONENT_GENERATION_ALWAYS_SAFE
165 return summand1 + summand2 < compareValue;
167 return summand1 < std::numeric_limits<T>::max() && summand2 < std::numeric_limits<T>::max()
168 && summand1 + summand2 < compareValue;
184 if (!inserted && w->
index() > newNode->
index()) {
193 bool inserted =
false;
203 bool insertedIntoSubset =
false;
204 bool insertedIntoComplement =
false;
209 if (!insertedIntoSubset) {
212 if (!insertedIntoComplement) {
223 if (split[v].subgraph1 !=
nullptr) {
231 makeKey(newSubset, newComplement, subset, v);
245 if (!
m_map.member(newSubset)) {
246 T oldCost =
costOf(terminals);
248 auto addPair = [&](
node v1,
node v2, T dist) {
250 if (
m_pred[v1][v2] ==
nullptr) {
269 best.
add(split[w].subgraph1);
270 best.
add(split[w].subgraph2);
277 m_map.fastInsert(newSubset, best);
282 template<
typename CONTAINER>
288 for (
node v : nodeContainer) {
302 if (v->index() < t->index()) {
308 if (!
m_map.member(key)) {
309 if (
m_pred[t][v] ==
nullptr) {
330 node uO = nodepair.source;
331 node vO = nodepair.target;
335 uC =
tree.newNode(uO);
338 vC =
tree.newNode(vO);
340#ifdef OGDF_FULL_COMPONENT_GENERATION_TERMINAL_SSSP_AWARE
345 tree.newEdge(uC, vC, dist);
407 && v->degree() > 1) {
417 static const unsigned int c_prime = 0x7fffffff;
427 unsigned int hash = 0;
429 hash = (hash * m_random + v->index()) % c_prime;
Declaration and implementation of ArrayBuffer class.
Includes declaration of graph class.
Declaration of classes used for hashing.
Declaration of doubly linked lists and iterators.
A class that allows to enumerate k-subsets.
Basic declarations, included by all source files.
void clear()
Clears the buffer.
void push(E e)
Puts a new element in the buffer.
bool empty() const
Returns true if the buffer is empty, false otherwise.
const Graph & original() const
Returns a reference to the original graph.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
bool empty() const
Returns true iff the graph is empty, i.e., contains no nodes.
Hashing with chaining and table doubling.
Doubly linked lists (maintaining the length of the list).
int size() const
Returns the number of elements in the list.
iterator pushBack(const E &x)
Adds element x at the end of the list.
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
const_reference front() const
Returns a const reference to the first element.
const_reference back() const
Returns a const reference to the last element.
Class for the representation of nodes.
int index() const
Returns the (unique) node index.
Enumerator for k-subsets of a given type.
void begin(int low, int high)
Initializes the SubsetEnumerator to enumerate subsets of cardinalities from low to high.
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.
bool valid() const
Checks if the current subset is valid. If not, the subset is either not initialized or all subsets ha...
int numberOfMembersAndNonmembers() const
Returns the cardinality of the (super-)set. This is the maximum size that can be used for a subset.
void next()
Obtains the next subset if possible. The result should be checked using the valid() method.
RegisteredArray for nodes, edges and adjEntries of a graph.
unsigned int hash(const List< node > &key) const
The actual hash function.
SortedNodeListHashFunc()
Initializes the random number.
A generator for restricted full components (for Steiner tree approximations) based on the Dreyfus-Wag...
const EdgeWeightedGraph< T > & m_G
A reference to the graph instance.
void computePartialSolution(NodeArray< DWMSplit > &split, node v, SubsetEnumerator< node > &subset, const List< node > &terminals)
Computes a partial solution for given terminals and node v.
void makeKey(List< node > &newSubset, node v) const
Makes a list from the current terminal subset including an correctly inserted node v.
void computePartialSolutions(const CONTAINER &nodeContainer)
Computes all partial solutions for given m_terminalSubset.
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.
bool safeIfSumSmaller(const T summand1, const T summand2, const T compareValue) const
Checks overflow-safe if summand1 plus summand2 is less than compareValue.
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.
void initializeMap()
Initializes the hash array with all node-terminal-pairs.
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.
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...
const List< node > & m_terminals
A reference to the index-sorted list of terminals.
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.
Hashing< List< node >, DWMData, SortedNodeListHashFunc > m_map
A hash array for keys of size > 2.
const DWMData * dataOf(const List< node > &key) const
Returns a pointer to the relevant data of the partial solution given by key.
void call(int restricted)
const NodeArray< NodeArray< T > > & m_distance
A reference to the full distance matrix.
const NodeArray< bool > & m_isTerminal
A reference to the terminal incidence vector.
bool isValidComponent(const EdgeWeightedGraphCopy< T > &graph) const
Checks if a given graph is a valid full component.
const NodeArray< NodeArray< edge > > & m_pred
A reference to the full predecessor matrix.
SubsetEnumerator< node > m_terminalSubset
Handling subsets of terminals.
T costOf(const List< node > &key) const
Returns the cost of the partial solution given by 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...
bool isAcyclicUndirected(const Graph &G, List< edge > &backedges)
Returns true iff the undirected graph G is acyclic.
bool isTree(const Graph &G)
Returns true iff G is a tree, i.e. contains no undirected cycle and is connected.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
int randomNumber(int low, int high)
Returns random integer between low and high (including).
void updateMin(T &min, const T &newValue)
Stores the minimum of min and newValue in min.
The namespace for all OGDF objects.
@ tree
for every hyperedge e a minimal subcubic tree connecting all hypernodes incident with e together is a...
Subgraphs (given by other subgraphs and additional node pairs) and their cost for a partial solution.
void add(const DWMData *other)
Adds other subgraph to ours.
ArrayBuffer< const DWMData * > subgraphs
DWMData(T _cost=std::numeric_limits< T >::max())
DWMData(T _cost, NodePairs _nodepairs)
void invalidate()
Invalidates the data.
bool valid() const
Returns true iff the data is valid.
void add(NodePair nodepair, T c)
Adds a nodepair of cost c.
void clear()
Remove all subgraphs and edges and set cost to zero.
A collection of two subgraphs and their total cost.
void set(const DWMData *s1, const DWMData *s2)
Sets subgraph1 and subgraph2 and computes cost.
const DWMData * subgraph1
const DWMData * subgraph2