81 , m_separateCycles(false)
113 m_use2approx = use2approx;
123 m_preprocess = !preprocess;
154 std::minstd_rand rng(
m_seed);
192 void find3RestrictedComponents();
194 void findFullComponentsDW();
196 void findFullComponentsEMV();
198 template<
typename FCG>
199 void retrieveComponents(
const FCG& fcg);
201 void findFullComponents();
209 for (
int k = m_fullCompStore.
size() - 1; k >= 0; --k) {
211 if (m_fullCompStore.
extra(k) <= m_eps) {
212 m_fullCompStore.
remove(k);
221 for (
int i = ids.
size() - 1; i >= 0; --i) {
222 m_fullCompStore.
remove(ids[i]);
230 isNewTerminal[v] =
true;
243 for (
int i = 0; i < m_fullCompStore.
size(); ++i) {
271 if (innerNodes <= 1) {
273 addComponent(isNewTerminal,
id[c]);
276 inactive.
push(
id[c]);
285 removeComponents(inactive);
293 int restricted,
bool use2approx,
bool separateCycles,
double eps = 1e-8)
295 , m_isTerminal(isTerminal)
296 , m_terminals(terminals)
297 , m_fullCompStore(G, m_terminals, isTerminal)
298 , m_restricted(restricted)
301 , m_approx2SteinerTree(nullptr)
304 if (m_use2approx == Approx2State::On) {
306 m_approx2Weight = mstT.
call(m_G, m_terminals, m_isTerminal, m_approx2SteinerTree);
309 if (m_restricted > m_terminals.
size()) {
310 m_restricted = m_terminals.
size();
313 findFullComponents();
318 m_use2approx = Approx2State::JustUseIt;
327 T getApproximation(
EdgeWeightedGraphCopy<T> *&finalSteinerTree,
const std::minstd_rand &rng,
const bool doPreprocessing =
true);
334 fcg.
call(m_G, m_terminals, distance, pred,
339 m_fullCompStore.insert(minComp);
347 fcg.
call(m_G, m_terminals, m_isTerminal, distance, pred,
353 minComp.
newEdge(minComp.
newNode(t0), minCenterC, distance[t0][minCenter]);
354 minComp.
newEdge(minComp.
newNode(t1), minCenterC, distance[t1][minCenter]);
355 minComp.
newEdge(minComp.
newNode(t2), minCenterC, distance[t2][minCenter]);
356 m_fullCompStore.insert(minComp);
367 findFull2Components(distance, pred);
369 findFull3Components(distance, pred);
374 template<
typename FCG>
380 terminalSubset.
list(terminals);
381 fcg.getSteinerTreeFor(terminals, component);
382 if (fcg.isValidComponent(component)) {
383 m_fullCompStore.insert(component);
396 retrieveComponents(fcg);
403 retrieveComponents(fcg);
411 findFullComponentsEMV();
413 findFullComponentsDW();
416 find3RestrictedComponents();
426 finalSteinerTree = m_approx2SteinerTree;
427 return m_approx2Weight;
430 removeInactiveComponents();
433 for (
node v : m_terminals) {
434 isNewTerminal[v] =
true;
437 if (doPreprocessing) {
438 preprocess(isNewTerminal);
441 if (!m_fullCompStore.isEmpty()) {
443 approx.
solve(isNewTerminal);
449 if (m_approx2Weight < cost) {
450 delete finalSteinerTree;
451 finalSteinerTree = m_approx2SteinerTree;
452 cost = m_approx2Weight;
454 delete m_approx2SteinerTree;
void removeInactiveComponents()
Remove inactive components from m_fullCompStore (since we do not need them any longer) ...
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 findFullComponentsEMV()
Find full components using algorithm by Erickson et al.
void findFullComponentsDW()
Find full components using algorithm by Dreyfus-Wagner.
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
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.
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
iterator pushBack(const E &x)
Adds element x at the end of the list.
Data type for general directed graphs (adjacency list representation).
Full 3-component generation using Voronoi regions.
virtual void delNode(node v)
Removes node v and all incident edges from the graph.
const NodeArray< bool > & m_isTerminal
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.
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...
int degree() const
Returns the degree of the node (indegree + outdegree).
void retrieveComponents(const FCG &fcg)
Auxiliary function to retrieve components by Dreyfus-Wagner/Erickson et al implementation.
edge newEdge(node u, node v, T weight)
iterator begin()
Returns an iterator to the first element of the list.
const Array< node > & terminals(int id) const
Returns the list of terminals in the full component with given id.
steiner_tree::FullComponentWithExtraStore< T, double > m_fullCompStore
all enumerated full components, with solution
void push(E e)
Puts a new element in the buffer.
bool valid() const
Checks if the current subset is valid. If not, the subset is either not initialized or all subsets ha...
virtual ~MinSteinerTreeGoemans139()
void quicksort()
Sorts buffer using Quicksort.
Definition of ogdf::steiner_tree::goemans::Approximation class template.
bool solve()
Solve the LP. The solution will be written to the extra data of the full component store...
void del(iterator it)
Removes it from the list.
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...
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)
void remove(int id)
Removes a component by its id.
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.
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.
void begin(int low, int high)
Initializes the SubsetEnumerator to enumerate subsets of cardinalities from low to high...
static void copy(const T &from, T &to)
A generator for restricted full components (for Steiner tree approximations) based on the Dreyfus-Wag...
Enumerator for k-subsets of a given type.
Doubly linked lists (maintaining the length of the list).
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
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...
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Class managing the component-based subtour elimination LP relaxation for the Steiner tree problem and...
Definition of ogdf::steiner_tree::Full2ComponentGenerator class template.
The actual 1.39-approximation algorithm by Goemans et al. with a set of terminalized nodes as result...
Class for the representation of nodes.
void removeComponents(ArrayBuffer< int > &ids)
Remove the full components with the given ids.
Encapsulates a pointer to a list element.
T obtainFinalSteinerTree(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, const NodeArray< bool > &isOriginalTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
INDEX size() const
Returns number of elements in the buffer.
void call(int restricted)
const double m_eps
epsilon for double operations
This class implements the minimum Steiner tree 2-approximation algorithm by Takahashi and Matsuyama w...
void solve(NodeArray< bool > &isNewTerminal)
Perform the actual approximation algorithm on the LP solution.
void setMaxComponentSize(int k)
Sets the maximal number of terminals in a full component.
void addComponent(NodeArray< bool > &isNewTerminal, int id)
Add a full component to the final solution (by changing nonterminals to terminals) ...
void list(List< T > &subset) const
Obtains (appends) a list of the subset members.
void next()
Obtains 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.
Approx2State m_use2approx
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.
Algorithms used by at least two functions of Steiner tree code or its internal helpers.
EdgeWeightedGraphCopy< T > * m_approx2SteinerTree
The namespace for all OGDF objects.
MinSteinerTreeGoemans139()
node newNode()
Creates a new node and returns it.
int size() const
Returns the number of full components in the store.
Definition of ogdf::steiner_tree::LPRelaxationSER class template.
Trivial full 2-component generation by lookups of shortest paths between terminal pairs...
This class implements the (1.39+epsilon)-approximation algorithm for the Steiner tree problem by Goem...
void findFull3Components(const NodeArray< NodeArray< T >> &distance, const NodeArray< NodeArray< edge >> &pred)
Find full components of size 3.
void findFullComponents()
Find full components.
void foreachNode(int id, Fun f) const
void findFull2Components(const NodeArray< NodeArray< T >> &distance, const NodeArray< NodeArray< edge >> &pred)
Find full components of size 2.
const List< node > & m_terminals
List of terminals.
void setSeed(int seed)
Set seed for the random number generation.
Definition of the ogdf::steiner_tree::FullComponentGeneratorDreyfusWagner class template.
Class managing LP-based approximation.
void use2Approximation(bool use2approx=true)
Use Takahashi-Matsuyama 2-approximation as upper bounds.
Class for adjacency list elements.
void separateCycles(bool separateCycles=true)
Use stronger LP relaxation (not recommended in general)
void preprocess(NodeArray< bool > &isNewTerminal)
Preprocess LP solution.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
void disablePreprocessing(bool preprocess=true)
Disable preprocessing of LP solutions.
const EdgeWeightedGraph< T > & m_G
void find3RestrictedComponents()
Find 3-restricted components.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.