41namespace steiner_tree {
92 for (
node v : terminals) {
139 m_copy.setWeight(e, value);
168 if (
other->valid()) {
194 T
cost = std::numeric_limits<T>::max();
207 class SortedNodeListHashFunc;
216 return &
m_map.lookup(key)->info();
227#ifdef OGDF_FULL_COMPONENT_GENERATION_ALWAYS_SAFE
269 subset.forEachMemberAndNonmember(
303 template<
typename CONTAINER>
336 if (v->index() <
t->index()) {
343 if (!
m_map.member(key)) {
344 T
dist = distance[v];
362 cost = split[w].cost;
413 best.add(split[
tO].subgraph1);
414 best.add(split[
tO].subgraph2);
421 template<
typename CONTAINER>
523 && v->degree() > 1) {
533 static const unsigned int c_prime = 0x7fffffff;
543 unsigned int hash = 0;
545 hash = (hash * m_random + v->index()) % c_prime;
Extends the GraphCopy concept to weighted graphs.
Declaration of classes used for hashing.
Declaration of ogdf::MinSteinerTreeModule.
A class that allows to enumerate k-subsets.
Class for adjacency list elements.
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
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.
Dynamic arrays indexed with edges.
Class for the representation of edges.
node opposite(node v) const
Returns the adjacent node different from v.
node target() const
Returns the target node of the edge.
node source() const
Returns the source node of the edge.
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.
static void singleSourceShortestPaths(const EdgeWeightedGraph< T > &G, node source, const NodeArray< bool > &isTerminal, NodeArray< T > &distance, NodeArray< edge > &pred)
The default single-source-shortest-paths algorithm.
Dynamic arrays indexed with nodes.
Class for the representation of nodes.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
int index() const
Returns the (unique) node index.
Enumerator for k-subsets of a given type.
Necessary because ogdf::EdgeWeightedGraphCopy<T> is rubbish.
NodeArray< bool > m_isTerminal
True for terminals in the auxiliary graph.
EdgeWeightedGraph< T > m_copy
The auxiliary copy.
NodeArray< node > m_copyOfNode
A mapping from original nodes to copied nodes.
AuxiliaryGraph(const EdgeWeightedGraph< T > &orig, const List< node > &terminals)
Constructs a copy of the original graph with an added source node having edges to all other nodes.
node source() const
Returns the source node.
const NodeArray< bool > & terminalArray() const
Returns a const reference to m_isTerminal.
const EdgeWeightedGraph< T > & m_original
A reference to the original graph.
NodeArray< node > m_origOfNode
A mapping from copied nodes to original nodes.
void setWeight(edge e, T value)
Sets the weight of a copied edge.
EdgeArray< edge > m_origOfEdge
A mapping from copied edges to original edges.
T weight(edge e) const
Returns the weight of a copied edge.
const EdgeWeightedGraph< T > & graph() const
Returns a const reference to the graph.
node m_source
The source node.
node original(node v) const
Returns the original node for the copied node v.
edge original(edge e) const
Returns the original edge for the copied edge e.
node copy(node v) const
Returns the copied node of the original node v.
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...
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 call(int restricted)
AuxiliaryGraph m_auxG
An auxiliary graph to compute partial solutions.
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 insertValidBestSubtree(node v, const NodeArray< DWMSplit > &split, const NodeArray< edge > &pred, const List< node > &newSubset, const List< node > &terminals)
Inserts the valid best subtree (based on the SSSP computation) into the hash map.
const NodeArray< bool > & m_isTerminal
A reference to the terminal incidence vector.
bool isValidComponent(const EdgeWeightedGraphCopy< T > &tree) const
Checks if a given tree is a valid full component.
const DWMData * dataOf(const List< node > &key) const
Returns a pointer to the relevant data of the partial solution given by key.
void computePartialSolutions(const CONTAINER &targets)
Computes all partial solutions for given m_terminalSubset.
T costOf(const List< node > &key) const
Returns the cost of the partial solution given by key.
edge addNewPath(DWMData &result, node curr, const NodeArray< edge > &pred) const
Adds the shortest path from the source to curr into result.
void initializeMap()
Initializes the hash array with all node-terminal-pairs.
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.
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.
FullComponentGeneratorDreyfusWagnerWithoutMatrix(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal)
The constructor.
void insertBestSubtrees(const CONTAINER &targets, const NodeArray< DWMSplit > &split, const NodeArray< edge > &pred, const NodeArray< T > &distance, const List< node > &terminals)
Inserts the best subtrees into the hash map.
bool safeIfSumSmaller(const T summand1, const T summand2, const T compareValue) const
Checks overflow-safe if summand1 plus summand2 is less than compareValue.
void insertInvalidBestSubtree(node v, const NodeArray< T > &distance, const List< node > &newSubset)
Inserts the invalid best subtree (based on the SSSP computation) into the hash map.
SubsetEnumerator< node > m_terminalSubset
Handling subsets of terminals.
void makeKey(List< node > &newSubset, node v) const
Makes a list from the current terminal subset including an correctly inserted node v.
void updateAuxGraph(NodeArray< DWMSplit > &split, SubsetEnumerator< node > &subset, T oldCost)
Updates the auxiliary graph.
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.
Hashing< List< node >, DWMData, SortedNodeListHashFunc > m_map
A hash array for keys of size > 2.
const List< node > & m_terminals
A reference to the index-sorted list of terminals.
const EdgeWeightedGraph< T > & m_G
A reference to the graph instance.
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).
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
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 edges) and their cost for a partial solution.
DWMData(T _cost=std::numeric_limits< T >::max())
void clear()
Remove all subgraphs and edges and set cost to zero.
void add(edge e, T c)
Adds an edge e of cost c.
ArrayBuffer< const DWMData * > subgraphs
ArrayBuffer< edge > edges
bool valid() const
Returns true iff the data is valid.
void invalidate()
Invalidates the data.
DWMData(T _cost, ArrayBuffer< edge > _edges)
void add(const DWMData *other)
Adds other subgraph to ours.
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 * subgraph2
const DWMData * subgraph1