45 #define OGDF_STEINERTREE_RZLOSS_REDUCE_ON 65 std::unique_ptr<Main>
m_alg;
91 if (m_alg ==
nullptr) {
94 return m_alg->numberOfGeneratedComponents();
99 if (m_alg ==
nullptr) {
102 return m_alg->numberOfContractedComponents();
107 if (m_alg ==
nullptr) {
110 return m_alg->numberOfComponentLookUps();
128 m_alg.reset(
new Main(G, terminals, isTerminal, m_restricted));
129 return m_alg->getApproximation(finalSteinerTree);
152 template<
typename FCG>
173 findFullComponentsEMV(tree);
180 generateInitialTerminalSpanningTree(tree, distance, pred);
184 findFullComponentsDW(tree, distance, pred);
186 findFull3Components(tree, distance, pred);
190 m_fullCompStore.computeAllLosses();
191 m_componentsGenerated = m_fullCompStore.size();
214 template<
typename TERMINAL_CONTAINER>
228 std::unique_ptr<steiner_tree::SaveStatic<T>>
m_save;
246 return m_componentsGenerated;
251 return m_componentsContracted;
256 return m_componentsLookUps;
263 m_isTerminal(isTerminal),
264 m_terminals(terminals),
266 m_fullCompStore(m_G, m_terminals, m_isTerminal),
267 m_isNewTerminal(m_G, false),
268 m_componentsGenerated(0),
269 m_componentsContracted(0),
270 m_componentsLookUps(0) {
273 for (
node v : terminals) {
301 if (p[vO] !=
nullptr) {
302 steinerTree.
newEdge(u, v, dist[vO]);
321 minComp.
newEdge(minComp.
newNode(t0), minCenterC, distance[t0][minCenter]);
322 minComp.
newEdge(minComp.
newNode(t1), minCenterC, distance[t1][minCenter]);
323 minComp.
newEdge(minComp.
newNode(t2), minCenterC, distance[t2][minCenter]);
325 #ifdef OGDF_STEINERTREE_RZLOSS_REDUCE_ON 326 if (
gain(std::vector<node>{t0, t1, t2},
tree) > minCost) {
336 template<
typename FCG>
342 terminalSubset.
list(terminals);
343 #ifdef OGDF_STEINERTREE_RZLOSS_REDUCE_ON 346 fcg.getSteinerTreeFor(terminals, component);
349 gain(terminals, tree) > cost &&
351 fcg.isValidComponent(component)) {
414 #ifdef OGDF_STEINERTREE_RZLOSS_REDUCE_ON 425 template<
typename TERMINAL_CONTAINER>
427 std::set<edge> saveEdges;
431 for (
auto it1 = terminals.begin(); it1 != terminals.end(); ++it1) {
434 for (
auto it2 = next; it2 != terminals.end(); ++it2) {
440 for (
edge e : saveEdges) {
441 result += steinerTree.
weight(e);
const NodeArray< bool > & m_isTerminal
Incidence vector for terminal nodes.
long numberOfContractedComponents()
Returns the number of contracted components.
steiner_tree::FullComponentWithLossStore< T > m_fullCompStore
All generated full components.
const EdgeWeightedGraph< T > & m_G
The original edge-weighted graph.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
std::unique_ptr< Main > m_alg
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.
Full 3-component generation using Voronoi regions.
void findFullComponentsDW(const EdgeWeightedGraphCopy< T > &tree, const NodeArray< NodeArray< T >> &distance, const NodeArray< NodeArray< edge >> &pred)
Find full components using algorithm by Dreyfus-Wagner.
Definition of the FullComponentGeneratorCaller class template.
static void sortTerminals(List< node > &terminals)
Sort terminals by index.
Serves as an interface for various methods to compute or approximate minimum Steiner trees on undirec...
Main(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, int restricted)
edge newEdge(node u, node v, T weight)
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) ...
Implementation of Mehlhorn's minimum Steiner tree 2(1-1/l)-approximation algorithm.
long numberOfGeneratedComponents()
Returns the number of generated components.
bool valid() const
Checks if the current subset is valid. If not, the subset is either not initialized or all subsets ha...
T makeMinimumSpanningTree(Graph &G, const EdgeArray< T > &weight)
Reduce a graph to its minimum spanning tree (MST) using Kruskal's algorithm.
long m_componentsContracted
Number of contracted components.
long numberOfComponentLookUps()
Returns the number of components lookups during execution time.
node succ() const
Returns the successor in the list of all nodes.
List< node > m_terminals
List of terminal nodes (will be copied and sorted)
long numberOfContractedComponents()
Returns the number of contracted components.
Implementation of the staticLCATree option for calculating save edges in Zelikovsky's 11/6-approximat...
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...
MinSteinerTreeRZLoss(int v)
void multiPass(EdgeWeightedGraphCopy< T > &steinerTree)
Contraction phase of the algorithm.
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.
void call(int restricted)
void createEmpty(const Graph &wG)
int numberOfEdges() const
Returns the number of edges in the graph.
void begin(int low, int high)
Initializes the SubsetEnumerator to enumerate subsets of cardinalities from low to high...
int m_restricted
Parameter for the number of terminals in a full component.
A generator for restricted full components (for Steiner tree approximations) based on the Dreyfus-Wag...
const EdgeArray< T > & edgeWeights() const
long numberOfGeneratedComponents()
Returns the number of generated components.
Enumerator for k-subsets of a given type.
NodeArray< bool > m_isNewTerminal
Incidence vector for nonterminal nodes marked as terminals for improvement.
Definition of the FullComponentStore class template.
std::unique_ptr< steiner_tree::SaveStatic< T > > m_save
The save data structure.
Doubly linked lists (maintaining the length of the list).
double extractMaxComponent(const EdgeWeightedGraphCopy< T > &steinerTree, int &maxCompId)
Traverses over all full components and finds the one with the highest win-objective.
Definition of ogdf::steiner_tree::Full3ComponentGeneratorVoronoi class template.
A generator for restricted full components (for Steiner tree approximations) based on the Dreyfus-Wag...
Definition of the ogdf::steiner_tree::FullComponentGeneratorDreyfusWagnerWithoutMatrix class template...
Class for the representation of edges.
void setMaxComponentSize(int k)
Sets the maximal number of terminals in a full component.
void setup(EdgeWeightedGraphCopy< T > &tree)
Setup (build initial terminal-spanning tree, its save data structure, and find all components) ...
T gain(const TERMINAL_CONTAINER &terminals, const EdgeWeightedGraphCopy< T > &steinerTree)
Calculates the gain for a full component.
A data structure to store full components with additional "loss" functionality.
Class for the representation of nodes.
T getApproximation(EdgeWeightedGraphCopy< T > *&finalSteinerTree) const
T obtainFinalSteinerTree(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, const NodeArray< bool > &isOriginalTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
const Graph & original() const
Returns a reference to the original graph.
void call(int restricted)
#define OGDF_STEINERTREE_RZLOSS_REDUCE_ON
void list(List< T > &subset) const
Obtains (appends) a list of the subset members.
void findFull3Components(const EdgeWeightedGraphCopy< T > &tree, const NodeArray< NodeArray< T >> &distance, const NodeArray< NodeArray< edge >> &pred)
Find full components of size 3.
void next()
Obtains the next subset if possible. The result should be checked using the valid() method...
long m_componentsLookUps
Number of components lookups.
T constructTerminalSpanningTreeUsingVoronoiRegions(EdgeWeightedGraphCopy< T > &terminalSpanningTree, const EdgeWeightedGraph< T > &graph, const List< node > &terminals)
void retrieveComponents(const FCG &fcg, const EdgeWeightedGraphCopy< T > &tree)
Auxiliary function to retrieve components by Dreyfus-Wagner/Erickson et al implementation.
bool isTree(const Graph &G)
Returns true iff G is a tree, i.e. contains no undirected cycle and is connected. ...
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.
virtual ~MinSteinerTreeRZLoss()
for every hyperedge e a minimal subcubic tree connecting all hypernodes incident with e together is a...
void findFullComponentsEMV(const EdgeWeightedGraphCopy< T > &tree)
Find full components using algorithm by Erickson et al.
The namespace for all OGDF objects.
long numberOfComponentLookUps()
Returns the number of components lookups during execution time.
int numberOfNodes() const
Returns the number of nodes in the graph.
long m_componentsGenerated
Number of generated components.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
void contractLoss(EdgeWeightedGraphCopy< T > &steinerTree, int compId)
Contracts the loss of a full component and integrates it into the given terminal-spanning tree...
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.
Definition of the ogdf::steiner_tree::FullComponentGeneratorDreyfusWagner class template.
#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