46#define OGDF_STEINERTREE_RZLOSS_REDUCE_ON
83 if (
m_alg ==
nullptr) {
86 return m_alg->numberOfGeneratedComponents();
91 if (
m_alg ==
nullptr) {
94 return m_alg->numberOfContractedComponents();
99 if (
m_alg ==
nullptr) {
102 return m_alg->numberOfComponentLookUps();
123 template<
typename TYPE>
143 template<
typename FCG>
159 tree.createEmpty(m_G);
163 m_G.numberOfEdges())) {
166 findFullComponentsEMV(
tree);
174 generateInitialTerminalSpanningTree(
tree, distance, pred);
178 findFullComponentsDW(
tree, distance, pred);
180 findFull3Components(
tree, distance, pred);
184 m_fullCompStore.computeAllLosses();
185 m_componentsGenerated = m_fullCompStore.size();
208 template<
typename TERMINAL_CONTAINER>
222 std::unique_ptr<steiner_tree::SaveStatic<T>>
m_save;
254 , m_isTerminal(isTerminal)
255 , m_terminals(terminals)
257 m_restricted(min(
restricted, terminals.size()))
258 , m_fullCompStore(m_G, m_terminals, m_isTerminal)
259 , m_isNewTerminal(m_G,
false)
260 , m_componentsGenerated(0)
261 , m_componentsContracted(0)
262 , m_componentsLookUps(0) {
265 for (
node v : terminals) {
285 for (
node v : m_terminals) {
294 if (p[
vO] !=
nullptr) {
308 fcg.
call(m_G, m_terminals, m_isTerminal, distance, pred,
318#ifdef OGDF_STEINERTREE_RZLOSS_REDUCE_ON
319 if (gain(std::vector<node> {t0, t1, t2},
tree) >
minCost) {
320 m_fullCompStore.insert(
minComp);
323 m_fullCompStore.insert(
minComp);
329template<
typename FCG>
337#ifdef OGDF_STEINERTREE_RZLOSS_REDUCE_ON
340 fcg.getSteinerTreeFor(terminals, component);
343 gain(terminals,
tree) > cost &&
345 fcg.isValidComponent(component)) {
346 m_fullCompStore.
insert(component);
370 while (!m_fullCompStore.isEmpty()) {
374 ++m_componentsContracted;
377 m_fullCompStore.foreachNode(
maxCompId, [&](
node v) { m_isNewTerminal[v] =
true; });
382 if (!m_fullCompStore.isEmpty()) {
396 for (
int i = 0; i < m_fullCompStore.size();) {
397 ++m_componentsLookUps;
399 gain(m_fullCompStore.terminals(i),
steinerTree) - m_fullCompStore.cost(i);
401 const double r =
winAbs / m_fullCompStore.loss(i);
408#ifdef OGDF_STEINERTREE_RZLOSS_REDUCE_ON
411 m_fullCompStore.remove(i);
419template<
typename TERMINAL_CONTAINER>
426 for (
auto it1 = terminals.begin();
it1 != terminals.end(); ++
it1) {
429 for (
auto it2 = next;
it2 != terminals.end(); ++
it2) {
447 for (
edge e : m_fullCompStore.lossBridges(
compId)) {
448 const node u = m_fullCompStore.lossTerminal(e->source());
450 const node v = m_fullCompStore.lossTerminal(e->target());
453 m_fullCompStore.graph().weight(e));
Definition of ogdf::steiner_tree::Full3ComponentGeneratorVoronoi class template.
Definition of the FullComponentGeneratorCaller class template.
Definition of the ogdf::steiner_tree::FullComponentGeneratorDreyfusWagner class template.
Definition of the ogdf::steiner_tree::FullComponentGeneratorDreyfusWagnerWithoutMatrix class template...
Definition of the FullComponentStore class template.
Implementation of Mehlhorn's minimum Steiner tree 2(1-1/l)-approximation algorithm.
#define OGDF_STEINERTREE_RZLOSS_REDUCE_ON
Implementation of the staticLCATree option for calculating save edges in Zelikovsky's 11/6-approximat...
Class for the representation of edges.
void createEmpty(const Graph &wG)
Doubly linked lists (maintaining the length of the list).
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
Serves as an interface for various methods to compute or approximate minimum Steiner trees on undirec...
static void sortTerminals(List< node > &terminals)
Sort terminals by index.
double extractMaxComponent(const EdgeWeightedGraphCopy< T > &steinerTree, int &maxCompId)
Traverses over all full components and finds the one with the highest win-objective.
std::unique_ptr< steiner_tree::SaveStatic< T > > m_save
The save data structure.
const EdgeWeightedGraph< T > & m_G
The original edge-weighted graph.
NodeArray< bool > m_isNewTerminal
Incidence vector for nonterminal nodes marked as terminals for improvement.
Main(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, int restricted)
long m_componentsGenerated
Number of generated components.
long m_componentsContracted
Number of contracted components.
long numberOfContractedComponents()
Returns the number of contracted components.
const NodeArray< bool > & m_isTerminal
Incidence vector for terminal nodes.
void findFullComponentsEMV(const EdgeWeightedGraphCopy< T > &tree)
Find full components using algorithm by Erickson et al.
void retrieveComponents(const FCG &fcg, const EdgeWeightedGraphCopy< T > &tree)
Auxiliary function to retrieve components by Dreyfus-Wagner/Erickson et al implementation.
long numberOfComponentLookUps()
Returns the number of components lookups during execution time.
T gain(const TERMINAL_CONTAINER &terminals, const EdgeWeightedGraphCopy< T > &steinerTree)
void generateInitialTerminalSpanningTree(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< NodeArray< T > > &distance, const NodeArray< NodeArray< edge > > &pred)
Builds a minimum terminal spanning tree (via a MST call on the complete terminal graph)
long numberOfGeneratedComponents()
Returns the number of generated components.
void findFullComponentsDW(const EdgeWeightedGraphCopy< T > &tree, const NodeArray< NodeArray< T > > &distance, const NodeArray< NodeArray< edge > > &pred)
Find full components using algorithm by Dreyfus-Wagner.
steiner_tree::FullComponentWithLossStore< T > m_fullCompStore
All generated full components.
long m_componentsLookUps
Number of components lookups.
void findFull3Components(const EdgeWeightedGraphCopy< T > &tree, const NodeArray< NodeArray< T > > &distance, const NodeArray< NodeArray< edge > > &pred)
Find full components of size 3.
void multiPass(EdgeWeightedGraphCopy< T > &steinerTree)
Contraction phase of the algorithm.
List< node > m_terminals
List of terminal nodes (will be copied and sorted)
void contractLoss(EdgeWeightedGraphCopy< T > &steinerTree, int compId)
Contracts the loss of a full component and integrates it into the given terminal-spanning tree.
void setup(EdgeWeightedGraphCopy< T > &tree)
Setup (build initial terminal-spanning tree, its save data structure, and find all components)
T getApproximation(EdgeWeightedGraphCopy< T > *&finalSteinerTree) const
int m_restricted
Parameter for the number of terminals in a full component.
This class implements the loss-contracting (1.55+epsilon)-approximation algorithm for the Steiner tre...
long numberOfComponentLookUps()
Returns the number of components lookups during execution time.
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.
long numberOfContractedComponents()
Returns the number of contracted components.
long numberOfGeneratedComponents()
Returns the number of generated components.
MinSteinerTreeRZLoss(int v)
virtual ~MinSteinerTreeRZLoss()
void setMaxComponentSize(int k)
Sets the maximal number of terminals in a full component.
std::unique_ptr< Main > m_alg
Dynamic arrays indexed with nodes.
Class for the representation of nodes.
node succ() const
Returns the successor in the list of all nodes.
Enumerator for k-subsets of a given type.
Full 3-component generation using Voronoi regions.
void call(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, const NodeArray< NodeArray< T > > &distance, const NodeArray< NodeArray< edge > > &pred, std::function< void(node, node, node, node, T)> generateFunction) const
Generate full components and call generateFunction for each full component.
static void computeDistanceMatrix(NodeArray< NodeArray< T > > &distance, NodeArray< NodeArray< edge > > &pred, const EdgeWeightedGraph< T > &graph, const List< node > &terminals, const NodeArray< bool > &isTerminal, int restricted)
Computes distance and predecessor matrix.
A generator for restricted full components (for Steiner tree approximations) based on the Dreyfus-Wag...
A generator for restricted full components (for Steiner tree approximations) based on the Dreyfus-Wag...
A data structure to store full components with additional "loss" functionality.
This class behaves basically the same as SaveDynamic except that the update of the weighted graph is ...
T makeMinimumSpanningTree(Graph &G, const EdgeArray< T > &weight)
Reduce a graph to its minimum spanning tree (MST) using Kruskal's algorithm.
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.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
T obtainFinalSteinerTree(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, const NodeArray< bool > &isOriginalTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
T constructTerminalSpanningTreeUsingVoronoiRegions(EdgeWeightedGraphCopy< T > &terminalSpanningTree, const EdgeWeightedGraph< T > &graph, const List< node > &terminals)
The namespace for all OGDF objects.
@ tree
for every hyperedge e a minimal subcubic tree connecting all hypernodes incident with e together is a...
static bool shouldUseErickson(int n, int m)
Returns true iff the rule of thumb predicts to use the algorithm by Erickson et al instead of the Dre...