134 std::minstd_rand
rng(m_seed);
174 void find3RestrictedComponents();
176 void findFullComponentsDW();
178 void findFullComponentsEMV();
180 template<
typename FCG>
181 void retrieveComponents(
const FCG&
fcg);
183 void findFullComponents();
191 for (
int k = m_fullCompStore.size() - 1; k >= 0; --k) {
193 if (m_fullCompStore.extra(k) <= m_eps) {
194 m_fullCompStore.remove(k);
202 for (
int i =
ids.size() - 1; i >= 0; --i) {
203 m_fullCompStore.remove(
ids[i]);
220 for (
int i = 0; i < m_fullCompStore.size(); ++i) {
221 const node center =
H.newNode();
225 for (
node vG : m_fullCompStore.terminals(i)) {
231 H.newEdge(
vH, center);
246 innerNodes += (adj->twinNode()->degree() != 1);
253 inactive.
push(
id[c]);
262 removeComponents(inactive);
273 , m_isTerminal(isTerminal)
274 , m_terminals(terminals)
275 , m_fullCompStore(G, m_terminals, isTerminal)
279 , m_approx2SteinerTree(
nullptr)
280 , m_approx2Weight(0) {
283 m_approx2Weight =
mstT.
call(m_G, m_terminals, m_isTerminal, m_approx2SteinerTree);
290 findFullComponents();
323 fcg.
call(m_G, m_terminals, m_isTerminal, distance, pred,
332 m_fullCompStore.insert(
minComp);
344 findFull2Components(distance, pred);
346 findFull3Components(distance, pred);
351template<
typename FCG>
358 fcg.getSteinerTreeFor(terminals, component);
359 if (
fcg.isValidComponent(component)) {
360 m_fullCompStore.
insert(component);
375 retrieveComponents(
fcg);
383 retrieveComponents(
fcg);
390 m_G.numberOfEdges())) {
391 findFullComponentsEMV();
393 findFullComponentsDW();
396 find3RestrictedComponents();
406 return m_approx2Weight;
409 removeInactiveComponents();
412 for (
node v : m_terminals) {
420 if (!m_fullCompStore.isEmpty()) {
422 m_fullCompStore,
rng, m_eps);
429 if (m_approx2Weight < cost) {
432 cost = m_approx2Weight;
434 delete m_approx2SteinerTree;
Definition of ogdf::steiner_tree::goemans::Approximation class template.
Definition of ogdf::steiner_tree::Full2ComponentGenerator class template.
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 ogdf::steiner_tree::LPRelaxationSER class template.
Class for adjacency list elements.
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
void push(E e)
Puts a new element in the buffer.
void createEmpty(const Graph &wG)
Data type for general directed graphs (adjacency list representation).
Doubly linked lists (maintaining the length of the list).
int size() const
Returns the number of elements in the list.
iterator insert(const E &x, iterator it, Direction dir=Direction::after)
Inserts element x before or after it.
Encapsulates a pointer to a list element.
bool valid() const
Returns true iff the iterator points to an element.
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
Class managing LP-based approximation.
const List< node > & m_terminals
List of terminals.
T getApproximation(EdgeWeightedGraphCopy< T > *&finalSteinerTree, const std::minstd_rand &rng, const bool doPreprocessing=true)
Obtain an (1.39+epsilon)-approximation based on the LP solution.
void removeComponents(ArrayBuffer< int > &ids)
Remove the full components with the given ids.
void addComponent(NodeArray< bool > &isNewTerminal, int id)
Add a full component to the final solution (by changing nonterminals to terminals)
const NodeArray< bool > & m_isTerminal
const EdgeWeightedGraph< T > & m_G
const double m_eps
epsilon for double operations
void removeInactiveComponents()
Remove inactive components from m_fullCompStore (since we do not need them any longer)
void find3RestrictedComponents()
Find 3-restricted components.
void retrieveComponents(const FCG &fcg)
Auxiliary function to retrieve components by Dreyfus-Wagner/Erickson et al implementation.
void findFullComponents()
Find full components.
steiner_tree::FullComponentWithExtraStore< T, double > m_fullCompStore
all enumerated full components, with solution
void findFull2Components(const NodeArray< NodeArray< T > > &distance, const NodeArray< NodeArray< edge > > &pred)
Find full components of size 2.
EdgeWeightedGraphCopy< T > * m_approx2SteinerTree
void findFullComponentsEMV()
Find full components using algorithm by Erickson et al.
Main(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, int restricted, bool use2approx, bool separateCycles, double eps=1e-8)
Initialize all attributes, sort the terminal list.
void preprocess(NodeArray< bool > &isNewTerminal)
Preprocess LP solution.
void findFullComponentsDW()
Find full components using algorithm by Dreyfus-Wagner.
void findFull3Components(const NodeArray< NodeArray< T > > &distance, const NodeArray< NodeArray< edge > > &pred)
Find full components of size 3.
Approx2State m_use2approx
This class implements the (1.39+epsilon)-approximation algorithm for the Steiner tree problem by Goem...
void setSeed(int seed)
Set seed for the random number generation.
void setMaxComponentSize(int k)
Sets the maximal number of terminals in a full component.
virtual ~MinSteinerTreeGoemans139()
void separateCycles(bool separateCycles=true)
Use stronger LP relaxation (not recommended in general)
void disablePreprocessing(bool preprocess=true)
Disable preprocessing of LP solutions.
MinSteinerTreeGoemans139()
virtual T computeSteinerTree(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree) override
Builds a minimum Steiner tree for a given weighted graph with terminals.
void use2Approximation(bool use2approx=true)
Use Takahashi-Matsuyama 2-approximation as upper bounds.
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.
This class implements the minimum Steiner tree 2-approximation algorithm by Takahashi and Matsuyama w...
virtual T call(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree, const node startNode)
An extended call method with specific start node.
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.
Enumerator for k-subsets of a given type.
Trivial full 2-component generation by lookups of shortest paths between terminal pairs.
void call(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< NodeArray< T > > &distance, const NodeArray< NodeArray< edge > > &pred, std::function< void(node, node, T)> generateFunction) const
Generate full 2-components and call generateFunction for each full 2-component.
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...
void insert(const EdgeWeightedGraphCopy< T > &comp)
Inserts a component. Note that comp is copied and degree-2 nodes are removed.
Class managing the component-based subtour elimination LP relaxation for the Steiner tree problem and...
bool solve()
Solve the LP. The solution will be written to the extra data of the full component store.
The actual 1.39-approximation algorithm by Goemans et al. with a set of terminalized nodes as result.
Algorithms used by at least two functions of Steiner tree code or its internal helpers.
#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)
The namespace for all OGDF objects.
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...