43 namespace steiner_tree {
97 const edge e = adj->theEdge();
117 for (
int id = 1;
id <= gamma.
size(); ++id) {
151 std::unique_ptr<ArrayBuffer<std::pair<node,int>>> basis(
new ArrayBuffer<std::pair<node,int>>);
158 #ifdef OGDF_STEINER_TREE_GOEMANS_APPROXIMATION_LOGGING 159 std::cout <<
"Computing min-cost flow for blowup component " <<
id <<
" of " << gamma.
size() << std::endl;
160 std::cout <<
" * terminals of component are " << gamma.
terminals(
id) << std::endl;
163 std::cout <<
" * supply node " << v <<
" with supply " << supply[v] << std::endl;
166 std::cout <<
" * demand node " << v <<
" with demand " << -supply[v] << std::endl;
172 <<
" with cost " << blowupGraph.
getCost(e)
173 <<
" and flow bounds [" << lB[e]
188 for (
edge e : sourceCoreEdges) {
190 basis->push(std::make_pair(e->target(), flow[e]));
191 weight -= flow[e] * cost[e];
195 #ifdef OGDF_STEINER_TREE_GOEMANS_APPROXIMATION_LOGGING 197 <<
"Basis weight is " << weight << std::endl
199 << gamma.
cost(
id) <<
"(component cost) * " << blowupGraph.
getLCM()
200 <<
"(lcm) <= " << weight
201 <<
"(basis weight)" << std::endl;
206 #ifdef OGDF_STEINER_TREE_GOEMANS_APPROXIMATION_LOGGING 207 std::cout <<
"Using basis because it is feasible." << std::endl;
209 maxBasis.swap(basis);
225 for (
int id = 1;
id <= gamma.
size(); ++id) {
226 if (gamma.
cost(
id) > cost) {
227 cost = gamma.
cost(
id);
232 maxBasis.reset(
new ArrayBuffer<std::pair<node,int>>());
245 while (!stack.
empty()) {
252 isNewTerminal[vO] =
true;
268 #ifdef OGDF_STEINER_TREE_GOEMANS_APPROXIMATION_LOGGING 269 std::cout <<
"Remove basis from blowup graph" << std::endl;
275 for (
auto p : basis) {
276 const node v = p.first;
277 const int count = p.second;
280 #ifdef OGDF_STEINER_TREE_GOEMANS_APPROXIMATION_LOGGING 281 std::cout <<
" * node " << v <<
" with count " << count <<
" (of " << origCap <<
")" << std::endl;
283 if (count < origCap) {
285 #ifdef OGDF_STEINER_TREE_GOEMANS_APPROXIMATION_LOGGING 286 std::cout <<
" -> deferred because fractional" << std::endl;
292 #ifdef OGDF_STEINER_TREE_GOEMANS_APPROXIMATION_LOGGING 293 std::cout <<
" -> done" << std::endl;
298 #ifdef OGDF_STEINER_TREE_GOEMANS_APPROXIMATION_LOGGING 299 if (!fractionalCoreEdges.
empty()) {
300 std::cout <<
"Deferred core edges:" << std::endl;
303 for (
auto p : fractionalCoreEdges) {
304 const node v = p.item();
305 const int count = -p.priority();
307 #ifdef OGDF_STEINER_TREE_GOEMANS_APPROXIMATION_LOGGING 308 std::cout <<
" * node " << v <<
" with count " << count <<
" of " << origCap << std::endl;
323 const std::minstd_rand &rng,
double eps = 1e-8)
325 , m_isTerminal(isTerminal)
326 , m_terminals(terminals)
327 , m_fullCompStore(fullCompStore)
342 #ifdef OGDF_STEINER_TREE_GOEMANS_APPROXIMATION_LOGGING 343 std::cout <<
"Start solving based on LP solution" << std::endl;
349 while (blowupGraph.
terminals().size() > 1) {
350 #ifdef OGDF_STEINER_TREE_GOEMANS_APPROXIMATION_LOGGING 351 std::cout <<
"Iteration " << ++iteration <<
" with " << blowupGraph.
terminals().size() <<
" terminals" << std::endl;
358 std::unique_ptr<ArrayBuffer<std::pair<node,int>>> maxBasis;
359 int compId = blowupGraph.
getY() > 0
373 if (blowupGraph.
terminals().size() > 1) {
node target() const
Returns the target node of the edge.
node getSource() const
Returns the source node.
int findComponentAndMaxBasis(std::unique_ptr< ArrayBuffer< std::pair< node, int >>> &maxBasis, BlowupGraph< T > &blowupGraph, const BlowupComponents< T > &gamma)
Finds the best component and its maximum-weight basis in the given blowup graph with given core and w...
Definition of ogdf::steiner_tree::goemans::CoreEdgeRandomSpanningTree class template.
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition of ogdf::MinCostFlowReinelt class template.
Add edges into a blowup graph and delete them on destruction.
int findCheapestComponentAndRemainingBasis(std::unique_ptr< ArrayBuffer< std::pair< node, int >>> &maxBasis, const BlowupGraph< T > &blowupGraph, const BlowupComponents< T > &gamma)
For the end of the algorithm: find cheapest component and choose all remaining core edges as basis...
void removeFractionalBasisAndCleanup(ArrayBuffer< std::pair< node, int >> &basis, BlowupGraph< T > &blowupGraph, BlowupComponents< T > &gamma)
Remove a given basis and cleanup, the basis may be given fractionally.
const List< node > & terminals() const
Returns a reference to the list containing all terminals in the blowup graph.
const ArrayBuffer< node > & terminals(int id) const
Return list of terminals for a given component.
Obtain and provides information about components in a given blowup graph.
const FullComponentWithExtraStore< T, double > & m_fullCompStore
all enumerated full components, with solution
int capacity() const
Returns the current capacity of the datastructure. Note that this value is rather irrelevant if the a...
void push(edge e)
Puts a new element in the buffer.
void contract(node &v, node t)
Contracts node v and terminal t into v.
edge add(node v, node w, T cost, int capacity)
Add a temporary edge to the blowup graph.
An array that keeps track of the number of inserted elements; also usable as an efficient stack...
void copyComponent(const edge origEdge, const int origCap, const int copyCap)
Copy a component in the blowup graph and set original capacity to origCap and capacity of copy to cop...
int getLCM() const
Returns the least common multiple of all denominators.
void quicksort()
Sorts buffer using Quicksort.
int getY() const
Returns the y-value of all terminals.
Augments any data elements of type X with keys of type Priority. This class is also its own Comparer...
void delCore(node e)
Remove a core edge.
Declaration and implementation of Goldberg-Tarjan max-flow algorithm with global relabeling and gap r...
const EdgeWeightedGraph< T > & m_G
edge findRootEdge(node v)
Finds the root node of a component given by v, an arbitrary inner nonterminal of the component...
double computeCoreWeight(node v) const
Compute the weight of a core edge.
const NodeArray< bool > & m_isTerminal
const double m_eps
epsilon for double operations
const T & cost(int id) const
Return total cost of a given component.
const Graph & getGraph() const
const EdgeArray< int > & capacities() const
Returns a reference to the edge array containing all capacities.
bool empty() const
Returns true if the buffer is empty, false otherwise.
node getTarget() const
Returns the target node.
Computes a random set of core edges.
Doubly linked lists (maintaining the length of the list).
T getCoreCapacity(node v) const
Get capacity of a core edge.
TCap computeValue(const EdgeArray< TCap > &cap, const node &s, const node &t)
Compute only the value of the flow.
bool isLoopFree(const Graph &G)
Returns true iff G contains no self-loop.
Class for the representation of edges.
void updateSpecialCapacities()
Updates capacities from source to terminals and terminals to pseudotarget.
constexpr double gamma
The Euler-Mascheroni constant gamma.
The actual 1.39-approximation algorithm by Goemans et al. with a set of terminalized nodes as result...
int getCapacity(edge e) const
Returns the capacity of e.
Class for the representation of nodes.
const List< node > & m_terminals
edge rootEdge(int id) const
Return the edge coming from the root of a given component.
bool isTerminal(node v) const
Returns true if and only if v is a terminal.
void removeBasis(node v)
Removes a basis and cleans up.
Approximation(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, const FullComponentWithExtraStore< T, double > &fullCompStore, const std::minstd_rand &rng, double eps=1e-8)
Initialize everything.
void solve(NodeArray< bool > &isNewTerminal)
Perform the actual approximation algorithm on the LP solution.
void addComponent(NodeArray< bool > &isNewTerminal, const BlowupGraph< T > &blowupGraph, const edge rootEdge)
Add a component of the blowup graph to the final solution (by changing nonterminals to terminals) ...
E popRet()
Removes the newest element from the buffer and returns it.
A special-purpose blowup graph for gammoid computation: directed, with special source and target...
TemporaryEdges(BlowupGraph< T > &blowupGraph)
Construct object for a specific blowupGraph.
Definition of the ogdf::steiner_tree::goemans::BlowupComponents class template.
T getCost(edge e) const
Returns the cost of e.
~TemporaryEdges()
Remove the edges again.
int size() const
Return number of components.
node source() const
Returns the source node of the edge.
The namespace for all OGDF objects.
Computes a min-cost flow using a network simplex method.
BlowupGraph< T > & m_blowupGraph
int gammoidGetRank(const BlowupGraph< T > &blowupGraph) const
Computes the rank of the gammoid (given by the blowup graph)
node getOriginal(node v) const
Returns the original node of v.
Computes a max flow via Preflow-Push (global relabeling and gap relabeling heuristic).
Class for adjacency list elements.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
const List< node > & core() const
Return list of core edges (implemented by nodes)