|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
83 template<
typename TYPE>
85 template<
typename TYPE>
222 const double gain = save.
gain(u, v, w);
223 const double win =
calcWin(gain, minCost);
227 Triple<T> triple(u, v, w, center, minCost, win);
270 isNewTerminal[triple.
z()] =
true;
288 bool updated =
false;
291 T best = std::numeric_limits<T>::max();
307 if (s != s0 &&
m_pred[s][center] !=
nullptr) {
311 if (!s1 || best < tmp) {
324 if (s != s0 && s != s1 &&
m_pred[s][center] !=
nullptr) {
327 save2Val = save.
saveWeight(tmp == save1 ? s1 : s0, s);
330 if (!s2 || best < tmpWin) {
338 && best > maxTriple.
win()) {
372 return gain / cost - 1.0;
419 != TripleGeneration::ondemand
420 || (winCalculation() == WinCalculation::absolute
421 && saveCalculation() != SaveCalculation::hybrid && pass() != Pass::one));
423 m_originalGraph = &G;
424 m_terminals = &terminals;
425 m_isTerminal = &isTerminal;
429 for (
node v : *m_terminals) {
430 isNewTerminal[v] =
true;
433 if (terminals.
size() >= 3) {
434 computeDistanceMatrix();
439 generateInitialTerminalSpanningTree(steinerTree);
442 switch (saveCalculation()) {
443 case SaveCalculation::staticEnum:
446 case SaveCalculation::staticLCATree:
449 case SaveCalculation::dynamicLCATree:
450 case SaveCalculation::hybrid:
456 if (tripleGeneration() == TripleGeneration::ondemand) {
457 tripleOnDemand(*save, isNewTerminal);
460 if (saveCalculation() == SaveCalculation::hybrid) {
462 generateTriples(saveTriple);
464 generateTriples(*save);
467 if (pass() == Pass::multi) {
468 multiPass(*save, isNewTerminal);
470 onePass(*save, isNewTerminal);
485 if (m_ssspDistances) {
487 *m_isTerminal, m_distance, m_pred);
501 for (
node center : nonterminals) {
502 if (findBestTripleForCenter(center, save, maxTriple)) {
503 ++m_triplesGenerated;
507 if (maxTriple.
win() > 0) {
508 contractTriple(maxTriple, save, isNewTerminal);
510 }
while (maxTriple.
win() > 0);
516 [](
const Triple<T>& x) ->
double {
return -x.
win(); }));
520 if (calcWin(
double(save.
gain(t.s0(), t.s1(), t.s2())), t.cost()) > 0) {
521 contractTriple(t, save, isNewTerminal);
543 if (tripleReduction() == TripleReduction::on && t.
win() <= 0) {
550 contractTriple(*maxTriple, save, isNewTerminal);
551 m_triples.del(maxTriple);
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
virtual ~MinSteinerTreeZelikovsky()
The namespace for all OGDF objects.
long numberOfTripleLookUps() const
Returns the number of triple 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.
Declaration and implementation of ArrayBuffer class.
Includes declaration of graph class.
static void allTerminalShortestPaths(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T >> &distance, NodeArray< NodeArray< edge >> &pred, std::function< void(const EdgeWeightedGraph< T > &, node, const NodeArray< bool > &, NodeArray< T > &, NodeArray< edge > &)> ssspFunc=singleSourceShortestPaths)
Runs a given (or the default) single-source-shortest-paths function from all terminals.
This class implements the 11/6-approximation algorithm by Zelikovsky for the minimum Steiner tree pro...
virtual T gain(node u, node v, node w) const =0
Returns the gain (sum of the save edges) of a node triple.
void generateTriples(const Save< T > &save, const steiner_tree::Full3ComponentGeneratorModule< T > &fcg)
Generates triples using the given full 3-component generator.
This class represents a triple used by various contraction-based minimum Steiner tree approximations.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
const EdgeWeightedGraph< T > * m_originalGraph
The original edge-weighted graph.
void computeDistanceMatrix()
Computes the distance matrix for the original graph.
virtual edge saveEdge(node u, node v) const =0
Returns the save edge between two nodes.
Implementation of the staticLCATree option for calculating save edges in Zelikovsky's 11/6-approximat...
void saveCalculation(SaveCalculation sv)
Sets type of save calculation.
Interface for full 3-component generation including auxiliary functions.
void generateTriples(const Save< T > &save)
Generates triples according to the chosen option.
void contractTriple(const Triple< T > &triple, Save< T > &save, NodeArray< bool > &isNewTerminal)
Contracts a triple and updates the save data structure.
double calcWin(double gain, T cost) const
Calculate the win.
void setOriginalGraph(const Graph *wG) override
Associates the graph copy with G, but does not create any nodes or edges.
T obtainFinalSteinerTree(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, const NodeArray< bool > &isOriginalTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
Declaration of extended graph algorithms.
TripleGeneration tripleGeneration() const
Returns type of triple generation currently in use.
static void getNonterminals(ArrayBuffer< node > &nonterminals, const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal)
Generates a list (as ArrayBuffer<node>) of all nonterminals.
Pass pass() const
Returns type of pass currently in use.
void onePass(Save< T > &save, NodeArray< bool > &isNewTerminal)
Contraction phase for the one pass heuristic.
void generateInitialTerminalSpanningTree(EdgeWeightedGraphCopy< T > &steinerTree)
NodeArray< NodeArray< T > > m_distance
The distance matrix.
edge newEdge(node u, node v, T weight)
virtual T saveWeight(node u, node v) const =0
Returns the weight of the save edge between two nodes.
void forceAPSP(bool force=true)
For the 3-restricted case, it is sufficient to compute an SSSP from every terminal instead of doing a...
@ exhaustive
try all possibilities
virtual T call(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree) override
Calls the Steiner tree algorithm for nontrivial cases but handles trivial cases directly.
@ staticLCATree
Builds a "weight tree" (save edges are inner nodes, terminals are leaves and searches save edges via ...
long numberOfContractedTriples() const
Returns the number of contracted triples.
Definition of a Triple used in contraction-based approximation algorithm for the minimum Steiner tree...
@ multi
normal, greedy version
This class serves as an interface for different approaches concerning the calculation of save edges.
Implementation of the staticTree option for calculating save edges in Zelikovsky's 11/6-approximation...
WinCalculation m_winCalculation
Chosen option for gain calculation.
void winCalculation(WinCalculation wc)
Sets type of gain calculation.
Extends the GraphCopy concept to weighted graphs.
SaveCalculation saveCalculation() const
Returns type of save calculation currently in use.
Serves as an interface for various methods to compute or approximate minimum Steiner trees on undirec...
MinSteinerTreeZelikovsky(WinCalculation wc=WinCalculation::absolute, TripleGeneration tg=TripleGeneration::voronoi, SaveCalculation sc=SaveCalculation::hybrid, TripleReduction tr=TripleReduction::on, Pass pass=Pass::multi)
Pass m_pass
Chosen option for pass.
Declaration of ogdf::MinSteinerTreeModule.
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
SaveCalculation m_saveCalculation
Chosen option for save calculation.
TripleGeneration m_tripleGeneration
Chosen option for triple generation.
List< Triple< T > > m_triples
The list of triples during the algorithm.
Full 3-component generation using Voronoi regions.
This class computes save edges recursively and stores for every node pair their save edge in a HashAr...
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Algorithms used by at least two functions of Steiner tree code or its internal helpers.
bool findBestTripleForCenter(node center, const Save< T > &save, Triple< T > &maxTriple) const
Find the best triple for a given nonterminal center.
@ one
heuristic: evaluate all triples, sort them descending by gain, traverse sorted triples once,...
@ ondemand
generate triples "on the fly", only usable with WinCalculation::absolute
Full 3-component generation using enumeration.
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
void generateTriple(node u, node v, node w, node center, const T &minCost, const Save< T > &save)
Add a found triple to the triples list.
@ voronoi
use voronoi regions
Doubly linked lists (maintaining the length of the list).
RegisteredArray for nodes, edges and adjEntries of a graph.
bool m_ssspDistances
True iff we only compute SSSP from terminals instead of APSP for full component construction.
void multiPass(Save< T > &save, NodeArray< bool > &isNewTerminal)
Contraction phase for the original version of the algorithm.
long m_tripleLookUps
Number of triple lookups.
@ dynamicLCATree
Same as staticLCATree but each time a triple has been contracted the "weight tree" is updated dynamic...
const List< node > * m_terminals
List of terminal nodes.
virtual T call(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
Calls the Steiner tree algorithm for nontrivial cases but handles trivial cases directly.
Dynamically updatable weighted Tree for determining save edges via LCA computation.
TripleReduction
Switches immediate triple dropping.
long numberOfGeneratedTriples() const
Returns the number of generated triples.
void tripleReduction(TripleReduction tr)
Sets type of triple reduction.
long m_triplesGenerated
Number of generated triples.
WinCalculation
Choice of objective function.
Basic declarations, included by all source files.
const EdgeArray< T > & edgeWeights() const
SaveCalculation
Different methods for obtaining save edges.
void pass(Pass p)
Sets type of pass.
@ hybrid
Uses staticEnum for the triple generation phase (many queries) and dynamicLCATree during the contract...
T makeMinimumSpanningTree(Graph &G, const EdgeArray< T > &weight)
Reduce a graph to its minimum spanning tree (MST) using Kruskal's algorithm.
node succ() const
Returns the successor in the list of all nodes.
TripleGeneration
Choice of triple generation.
Class for the representation of edges.
Declaration of doubly linked lists and iterators.
static void allPairShortestPaths(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T >> &distance, NodeArray< NodeArray< edge >> &pred)
The default all-pair-shortest-paths algorithm.
virtual 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 =0
Generate full components and call generateFunction for each full component.
TripleReduction tripleReduction() const
Returns type of triple reduction currently in use.
const NodeArray< bool > * m_isTerminal
Incidence vector for terminal nodes.
int size() const
Returns the number of elements in the list.
A weighted tree as auxiliary data structure for contraction based algorithms.
Definition of ogdf::steiner_tree::Full3ComponentGeneratorEnumeration class template.
Encapsulates a pointer to a list element.
Interface for various LCA methods.
Definition of ogdf::steiner_tree::Full3ComponentGeneratorVoronoi class template.
@ on
removes triples as soon as their gain is known to be non positive
@ staticEnum
Stores explicitly the save edge for every pair of terminals. Needs O(n^2) space but has fast query ti...
Declarations for Comparer objects.
Class for the representation of nodes.
void tripleGeneration(TripleGeneration tg)
Sets type of triple generation.
Pass
Enables a heuristic version (for TG exhaustive and voronoi only)
Compare elements based on a single comparable attribute.
This class behaves basically the same as SaveDynamic except that the update of the weighted graph is ...
virtual void update(const Triple< T > &t)=0
Updates the weighted tree data structure given a contracted triple.
const Graph & original() const
Returns a reference to the original graph.
@ off
keeps triples all the time
WinCalculation winCalculation() const
Returns type of gain calculation currently in use.
TripleReduction m_tripleReduction
Chosen option for triple reduction.
void tripleOnDemand(Save< T > &save, NodeArray< bool > &isNewTerminal)
Contraction phase for algorithm generating triples on demand.
NodeArray< NodeArray< edge > > m_pred
The predecessor matrix.
long m_triplesContracted
Number of contracted triples.