45 #define OGDF_STEINERTREE_RZLOSS_REDUCE_ON 142 if (
m_pred[u][v] ==
nullptr) {
194 template<
typename TERMINAL_CONTAINER>
229 for (
node u : G.nodes) {
230 if (!isTerminal[u]) {
240 for (
node u : terminals) {
249 for (
node v : terminals) {
250 isNewTerminal[v] =
true;
268 multiPass(save, steinerTree, isNewTerminal);
291 if (pred[vO] !=
nullptr) {
292 steinerTree.
newEdge(u, v, dist[vO]);
307 for (terminalSubset.
begin(3); terminalSubset.
valid(); terminalSubset.
next()) {
308 const node t0 = terminalSubset[0];
309 const node t1 = terminalSubset[1];
310 const node t2 = terminalSubset[2];
318 node minCenter =
nullptr;
324 if (cost < minCost) {
332 &&
m_pred[t2][minCenter]) {
341 #ifdef OGDF_STEINERTREE_RZLOSS_REDUCE_ON 343 terminalSubset.
array(terminals);
344 if (
gain(terminals, tree, save) > minCost) {
366 terminalSubset.
list(terminals);
367 #ifdef OGDF_STEINERTREE_RZLOSS_REDUCE_ON 369 if (
gain(terminals, tree, save) > cost
396 isNewTerminal[v] =
true;
430 #ifdef OGDF_STEINERTREE_RZLOSS_REDUCE_ON 442 template<
typename TERMINAL_CONTAINER>
445 std::set<edge> saveEdges;
449 for (
auto it1 = terminals.begin(); it1 != terminals.end(); ++it1) {
452 for (
auto it2 = next; it2 != terminals.end(); ++it2) {
458 for (
edge e : saveEdges) {
459 result += steinerTree.
weight(e);
node target() const
Returns the target node of the edge.
long numberOfContractedComponents()
Returns the number of contracted components.
A generator for full components (for Steiner tree approximations) based on the Dreyfus-Wagner algorit...
bool isValidComponent(const EdgeWeightedGraphCopy< T > &graph)
const EdgeWeightedGraph< T > * m_originalGraph
The original edge-weighted graph.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
This class behaves basically the same as SaveDynamic except that the update of the weighted graph is ...
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
T getSteinerTreeFor(const List< node > &terminals, EdgeWeightedGraphCopy< T > &tree)
Construct a Steiner tree for the given set of terminals.
void call(int restricted)
virtual T call(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree) override
Builds a minimum Steiner tree given a weighted graph and a list of terminals.
virtual T call(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
Builds a minimum Steiner tree given a weighted graph and a list of terminals.
This class serves as an interface for various methods to compute minimum or approximations of minimum...
int degree() const
Returns the degree of the node (indegree + outdegree).
edge newEdge(node u, node v, T weight)
Interface of Minimum Steiner Tree Algorithms.
int m_restricted
Parameter for the number of terminals in a full component.
static void sortTerminals(List< node > &terminals)
Sort terminals by index.
void forceAPSP(bool force=true)
For the 3-restricted case, it is sufficient to compute an SSSP from every terminal instead of doing a...
long numberOfGeneratedComponents()
Returns the number of generated components.
Extends the GraphCopy concept to weighted graphs.
void findFull3Components(SubsetEnumerator< node > &terminalSubset, const EdgeWeightedGraphCopy< T > &tree, const SaveStatic< T > &save)
bool valid() const
Is the current subset valid? If not, all subsets have already been enumerated.
T makeMinimumSpanningTree(Graph &G, const EdgeArray< T > &weight)
Reduce a graph to its minimum spanning tree (MST) using Kruskal's algorithm.
long numberOfComponentLookUps()
Returns the number of components lookups during execution time.
node succ() const
Returns the successor in the list of all nodes.
void findFullComponents(const EdgeWeightedGraphCopy< T > &tree, const SaveStatic< T > &save)
Finds all k-restricted full components (except 2-components).
long m_componentsLookUps
Number of components lookups.
Implementation of the staticLCATree option for calculating save edges in Zelikovsky's 11/6-approximat...
MinSteinerTreeRZLoss(int v)
T gain(const TERMINAL_CONTAINER &terminals, const EdgeWeightedGraphCopy< T > &steinerTree, const SaveStatic< T > &save)
Calculates the gain for a full component.
void createEmpty(const Graph &wG)
const NodeArray< bool > * m_isTerminal
Incidence vector for terminal nodes.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
int numberOfEdges() const
Returns the number of edges in the graph.
void begin(int low, int high)
Initialize the SubsetEnumerator to enumerate subsets of cardinalities from low to high...
virtual edge saveEdge(node u, node v) const
Determines the save edge between two nodes by a LCA query.
double extractMaxComponent(const EdgeWeightedGraphCopy< T > &steinerTree, int &maxCompId, SaveStatic< T > &save)
Traverses over all full components and finds the one with the highest win-objective.
const EdgeArray< T > & edgeWeights() const
Enumerator for k-subsets of a given type.
Definition and implementation of FullComponentStore, a data structure to store full components...
Doubly linked lists (maintaining the length of the list).
NodeArray< NodeArray< T > > m_distance
List< node > m_nonterminals
List of Steiner (non-terminal) nodes.
Declaration and implementation of list-based queues (classes QueuePure<E> and Queue<E>).
long m_componentsGenerated
Number of generated components.
Class for the representation of edges.
void rebuild()
Rebuild the data structure (necessary if the tree has changed)
void setMaxComponentSize(int k)
Sets the maximal number of terminals in a full component.
A data structure to store full components with additional "loss" functionality.
Class for the representation of nodes.
T obtainFinalSteinerTree(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, const NodeArray< bool > &isOriginalTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
virtual T computeSteinerTree(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree) override
Builds a minimum Steiner tree given a weighted graph and a list of terminals.
const Graph & original() const
Returns a reference to the original graph.
void multiPass(SaveStatic< T > &save, EdgeWeightedGraphCopy< T > &steinerTree, NodeArray< bool > &isNewTerminal)
Contraction phase of the algorithm.
void generateInitialTerminalSpanningTree(EdgeWeightedGraphCopy< T > &steinerTree)
Builds a minimum terminal spanning tree (via a MST call on the complete terminal graph) ...
void list(List< T > &list) const
Obtain (append) a list of the elements in the subset.
void next()
Obtain 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.
NodeArray< NodeArray< edge > > m_pred
bool isTree(const Graph &G)
Returns true iff G is a tree, i.e. contains no undirected cycle and is connected. ...
node source() const
Returns the source node of the edge.
virtual ~MinSteinerTreeRZLoss()
steiner_tree::FullComponentWithLossStore< T > * m_fullCompStore
All generated full components.
Algorithms used by at least two functions of Steiner tree code or its internal helpers.
void contractLoss(EdgeWeightedGraphCopy< T > &steinerTree, int compId)
Contracts the loss of a full component and integrates it into the given terminal-spanning tree...
for every hyperedge e a minimal subcubic tree connecting all hypernodes incident with e together is a...
The namespace for all OGDF objects.
bool m_ssspDistances
True iff we only compute SSSP from terminals instead of APSP for full component construction.
static void allPairShortestPathsStrict(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T > > &distance, NodeArray< NodeArray< edge > > &pred)
int numberOfNodes() const
Returns the number of nodes in the graph.
long m_componentsContracted
Number of contracted components.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition and implementation of a full component generator based on the Dreyfus-Wagner algorithm...
static void singleSourceShortestPathsStrict(const EdgeWeightedGraph< T > &G, node source, const NodeArray< bool > &isTerminal, NodeArray< T > &distance, NodeArray< edge > &pred)
A class that allows to enumerate k-subsets of lists.
List< node > m_terminals
List of terminal nodes (will be copied and sorted)
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
This class implements the loss-contracting (1.55+epsilon)-approximation algorithm for the Steiner tre...
T weight(const edge e) const
void array(Array< T > &array) const
Obtain an array of the elements in the subset.