42 namespace steiner_tree {
107 for (
int i = 0; i < m_fullCompStore.
size(); ++i) {
113 denominators.
push(denom);
117 for (
int denom : denominators) {
120 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 121 std::cout <<
"Normalizing factor is " << m_lcm << std::endl;
128 m_isTerminal[v] =
true;
131 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 132 std::cout <<
"Add terminal " << v <<
" representing original terminal " << t << std::endl;
139 m_original[vCopy] = v;
151 while (!queueT.
empty()) {
176 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 177 std::cout <<
"Add source node " <<
getSource() <<
" with edges to:" << std::endl;
179 for (
auto root : roots) {
180 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 182 <<
" * node " << root.first
183 <<
" with cost 0 and capacity " << root.second << std::endl;
194 for (
node t : terminals) {
197 for (
int i = 0; i < m_fullCompStore.
size(); ++i) {
200 roots.
push(std::make_pair(root, cap));
205 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 209 <<
" of cost " << m_cost[e]
210 <<
" and capacity " << m_capacity[e] << std::endl;
224 m_pseudotarget = m_graph.
newNode();
226 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 227 std::cout <<
"Add pseudo-target " <<
getPseudotarget() <<
" with edges coming from:" << std::endl;
234 for (
adjEntry adj : v->adjEntries) {
243 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 245 <<
" * terminal " << v
246 <<
" with zero cost and capacity " << y_v << std::endl;
259 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 263 <<
" with zero cost and capacity " << m_y << std::endl;
269 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 270 std::cout <<
" * updating for terminal " << v << std::endl;
274 int capTarget = -
getLCM();
275 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 276 std::cout <<
" * target capacity initialized to " << capTarget <<
", source capacity and delta to 0" << std::endl;
282 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 283 std::cout <<
" * remove edge with capacity " <<
getCapacity(adj->theEdge()) <<
" from source " <<
getSource() << std::endl;
288 m_graph.
delEdge(adj->theEdge());
292 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 295 <<
" with capacity " <<
getCapacity(adj->theEdge())
296 <<
" participating in delta" << std::endl;
302 m_graph.
delEdge(adj->theEdge());
305 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 307 <<
" * update target capacity for edge " << adj->theEdge()
308 <<
" by adding " <<
getCapacity(adj->theEdge()) << std::endl;
313 if (v != adj->theEdge()->target()) {
314 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 315 std::cout <<
" and change source capacity by the same amount" << std::endl;
321 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 323 <<
" * new target capacity is " << capTarget
324 <<
" and delta = " << delta << std::endl;
329 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 331 <<
" * new edge from pseudotarget to target with zero cost and capacity " 332 << capTarget << std::endl;
336 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 338 <<
" * new edge from source to " << v <<
" with zero cost and capacity " 339 << capSource << std::endl;
344 return delta + capTarget;
348 m_capacity[e] = capacity;
363 m_witness[e].push(f);
372 m_witnessCard.
init(m_graph, 0);
373 m_witness.
init(m_graph);
383 if (!isLossEdge[e]) {
384 splitMap[e] = m_graph.
newNode();
394 while (!stack.
empty()) {
401 if (!pred[v] || w != pred[v]->theNode()) {
406 for (
node x = v; pred[x]; x = pred[x]->theNode()) {
416 for (
edge e : coreEdges) {
418 const node x = splitMap[e];
436 const edge eO = pair.key();
437 const edge eC = pair.info();
440 m_witnessCard[eC] = m_witnessCard[eO];
450 for (
edge e : m_witness[vO]) {
451 m_witness[vC].push(edgeMap[e]);
464 : m_fullCompStore(fullCompStore)
467 , m_isTerminal(m_graph, false)
468 , m_original(m_graph, nullptr)
470 , m_capacity(m_graph)
473 , m_pseudotarget(nullptr)
475 , m_ceModule(ceModule)
479 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 480 std::cout <<
"Full components to use in blowup graph:\n";
481 for (
int k = 0; k < m_fullCompStore.
size(); ++k) {
484 <<
" cost " << m_fullCompStore.
cost(k)
485 <<
" support " << m_fullCompStore.
extra(k)
486 <<
" (normalized to " << m_fullCompStore.
extra(k) * m_lcm <<
")" << std::endl;
519 return m_capacity[e];
534 return m_original[v];
554 return m_isTerminal[v];
591 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 592 std::cout <<
"Updating capacities (y = " << m_y <<
")" << std::endl;
596 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 597 std::cout <<
" * new y = " << m_y << std::endl;
609 m_capacity[e] = capacity;
615 for (
edge e : edges) {
628 m_isTerminal[t] =
false;
630 if (t->degree() > 0) {
639 template<
typename NODELIST>
641 auto it = nodes.begin();
643 for (++it; it != nodes.end(); ++it) {
661 while (!cleanup.
empty()) {
666 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 667 std::cout <<
" * remove pendant node " << v <<
" for cleanup" << std::endl;
672 if (v->
indeg() == 0) {
673 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 674 std::cout <<
" * " << v <<
" has no incoming edge -> fix directions" << std::endl;
678 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING 679 std::cout <<
" * make " << w <<
" parent of " << v <<
" (reverse edge " << e <<
")" << std::endl;
700 if ((*it)->degree() == 0) {
709 edge rootEdge =
nullptr;
712 edge e = (*it)->theEdge();
739 while (!todo.
empty()) {
777 for (
edge f : m_witness[e]) {
786 return m_witnessCard[e];
node target() const
Returns the target node of the edge.
List< node > m_coreEdges
the core edges as nodes
NodeArray< ArrayBuffer< edge > > m_witness
node getSource() const
Returns the source node.
void addWitness(node e, edge f)
Adds e to W(f)
void delEdges(ArrayBuffer< edge > edges)
Removes edges in edges.
Declaration and implementation of HashArray class.
edge theEdge() const
Returns the edge associated with this adjacency entry.
void makeCWCopy(const HashArray< edge, edge > &edgeMap)
Copies witness sets and core edges for a given copy map.
void init()
Reinitializes the array. Associates the array with no graph.
iterator pushBack(const E &x)
Adds element x at the end of the list.
Data type for general directed graphs (adjacency list representation).
virtual void delNode(node v)
Removes node v and all incident edges from the graph.
const List< node > & terminals() const
Returns a reference to the list containing all terminals in the blowup graph.
void init()
Reinitializes the array. Associates the array with no graph.
void initPseudotarget()
Connects pseudotarget.
Indexed arrays using hashing for element access.
int degree() const
Returns the degree of the node (indegree + outdegree).
NodeArray< bool > m_isTerminal
Incidence vector for the blowup graph terminals.
int indeg() const
Returns the indegree of the node.
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.
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
const CoreEdgeModule< T > & m_ceModule
void setCapacity(edge e, int capacity)
virtual void delEdge(edge e)
Removes edge e from the graph.
void push(E e)
Puts a new element in the buffer.
void contract(node &v, node t)
Contracts node v and terminal t into v.
T gcd(T a, T b)
Returns the greatest common divisor of two numbers.
Dynamic arrays indexed with edges.
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 removeIsolatedTerminals()
Removes isolated terminals.
int getY() const
Returns the y-value of all terminals.
adjEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
void delCore(node e)
Remove a core edge.
bool isTerminal(int id, node t) const
checks if a given node t is a terminal in the full component with given id
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.
void del(iterator it)
Removes it from the list.
T lcm(T a, T b)
Returns the least common multipler of two numbers.
void reverseEdge(edge e)
Reverses the edge e, i.e., exchanges source and target node.
void moveAdjAfter(adjEntry adjMove, adjEntry adjAfter)
Moves adjacency entry adjMove after adjAfter.
const Graph & getGraph() const
const EdgeArray< int > & capacities() const
Returns a reference to the edge array containing all capacities.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
int numberOfWitnesses(edge e) const
Return the number of witnesses of an edge.
node initBlowupGraphComponent(const NodeArray< node > ©, adjEntry start, int cap)
Does a bfs of the component tree to add directed components with the first terminal as root...
Iterators for hash tables.
bool empty() const
Returns true if the buffer is empty, false otherwise.
EdgeArray< int > m_witnessCard
Definition of ogdf::steiner_tree::goemans::CoreEdgeModule class template.
static void copy(const T &from, T &to)
node getTarget() const
Returns the target node.
node contract(edge e)
Contracts edge e while preserving the order of adjacency entries.
Definition of the FullComponentStore class template.
const double m_eps
epsilon for double operations
Doubly linked lists (maintaining the length of the list).
T getCoreCapacity(node v) const
Get capacity of a core edge.
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
void initCoreWitness()
Finds a "random" set of core edges and "replace" found edges by nodes, also find the witness sets for...
void initBlowupGraphComponents(const EdgeWeightedGraph< T > &originalGraph, const List< node > &terminals)
Initializes all components in the blowup graph as well as core edges and witness sets.
T getCoreCost(node v) const
Get cost of a core edge.
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Class for the representation of edges.
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
void getFraction(double d, int &num, int &denom, const double epsilon=5e-10, const int count=10)
Converts a double to a fraction.
E popFrontRet()
Removes the first element from the list and returns it.
void updateSpecialCapacities()
Updates capacities from source to terminals and terminals to pseudotarget.
int getCapacity(edge e) const
Returns the capacity of e.
adjEntry lastAdj() const
Returns the last entry in the adjacency list.
void initSource(ArrayBuffer< std::pair< node, int >> &roots)
Connects source to component roots.
Class for the representation of nodes.
virtual void call(const Graph &graph, const List< node > &terminals, EdgeArray< bool > &isInTree) const =0
Compute a set of core edges.
node original(node v) const
Encapsulates a pointer to a list element.
bool isTerminal(node v) const
Returns true if and only if v is a terminal.
void initTarget()
Connects target.
void removeBasis(node v)
Removes a basis and cleans up.
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...
int updateSourceAndTargetArcCapacities(const node v)
Updates arc capacities s->v and v->t.
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
adjEntry succ() const
Returns the successor in the adjacency list.
T getCost(edge e) const
Returns the cost of e.
Interface for core edge finder algorithms.
const ArrayBuffer< edge > & witnessList(node e) const
Return list of loss edges f in W(e)
adjEntry start(int i) const
HashConstIterator< I, E, H > begin() const
Returns an iterator to the first element in the list of all elements.
node getPseudotarget() const
Returns the pseudotarget node.
node source() const
Returns the source node of the edge.
EdgeArray< int > m_capacity
NodeArray< node > m_original
Mapping of blowup graph nodes to original nodes. If a node in a blowup graph represents more than one...
const EdgeWeightedGraph< T > & graph() const
List< node > m_terminals
The terminals in the blowup graph.
The namespace for all OGDF objects.
T cost(int i) const
Returns the sum of edge costs of this full component.
void contract(NODELIST &nodes)
Contracts nodes.
void addCore(node e)
Adds a core edge.
node newNode()
Creates a new node and returns it.
int size() const
Returns the number of full components in the store.
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
BlowupGraph(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const FullComponentWithExtraStore< T, double > &fullCompStore, const CoreEdgeModule< T > &ceModule, double eps=1e-8)
Initializes a blowup graph including core edges and witness sets.
void computeLCM()
Computes the least common multiple of the values assigned to the full components. ...
node initTerminal(node t)
Inserts a terminal.
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
node getOriginal(node v) const
Returns the original node of v.
bool empty() const
Returns true iff the list is empty.
edge newEdge(node v, node w, T cost, int capacity)
Adds and returns a new edge between v and w of specified cost and capacity.
node theNode() const
Returns the node whose adjacency list contains this element.
Class for adjacency list elements.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
const FullComponentWithExtraStore< T, double > & m_fullCompStore
all enumerated full components, with solution
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)