|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
52 template<
typename T,
typename ExtraDataType>
62 namespace steiner_tree {
133 denominators.
push(denom);
137 for (
int denom : denominators) {
140 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
141 std::cout <<
"Normalizing factor is " <<
m_lcm << std::endl;
151 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
152 std::cout <<
"Add terminal " << v <<
" representing original terminal " << t << std::endl;
171 while (!queueT.empty()) {
196 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
197 std::cout <<
"Add source node " <<
getSource() <<
" with edges to:" << std::endl;
199 for (
auto root : roots) {
200 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
201 std::cout <<
" * node " << root.first <<
" with cost 0 and capacity " << root.second
220 roots.
push(std::make_pair(root, cap));
225 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
227 std::cout <<
"Edge from " << e <<
" of cost " <<
m_cost[e] <<
" and capacity "
244 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
246 <<
" with edges coming from:" << std::endl;
253 for (
adjEntry adj : v->adjEntries) {
262 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
263 std::cout <<
" * terminal " << v <<
" with zero cost and capacity " << y_v
277 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
278 std::cout <<
"Add edge from pseudo-target " <<
getPseudotarget() <<
" to target "
279 <<
getTarget() <<
" with zero cost and capacity " <<
m_y << std::endl;
285 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
286 std::cout <<
" * updating for terminal " << v << std::endl;
290 int capTarget = -
getLCM();
291 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
292 std::cout <<
" * target capacity initialized to " << capTarget
293 <<
", source capacity and delta to 0" << std::endl;
299 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
300 std::cout <<
" * remove edge with capacity " <<
getCapacity(adj->theEdge())
301 <<
" from source " <<
getSource() << std::endl;
308 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
310 <<
" with capacity " <<
getCapacity(adj->theEdge())
311 <<
" participating in delta" << std::endl;
319 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
320 std::cout <<
" * update target capacity for edge " << adj->theEdge()
321 <<
" by adding " <<
getCapacity(adj->theEdge()) << std::endl;
326 if (v != adj->theEdge()->target()) {
327 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
328 std::cout <<
" and change source capacity by the same amount" << std::endl;
334 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
335 std::cout <<
" * new target capacity is " << capTarget <<
" and delta = " << delta
341 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
342 std::cout <<
" * new edge from pseudotarget to target with zero cost and capacity "
343 << capTarget << std::endl;
347 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
348 std::cout <<
" * new edge from source to " << v <<
" with zero cost and capacity "
349 << capSource << std::endl;
354 return delta + capTarget;
389 if (!isLossEdge[e]) {
400 while (!stack.
empty()) {
407 if (!pred[v] || w != pred[v]->theNode()) {
412 for (
node x = v; pred[x]; x = pred[x]->theNode()) {
422 for (
edge e : coreEdges) {
424 const node x = splitMap[e];
442 const edge eO = pair.key();
443 const edge eC = pair.info();
486 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
487 std::cout <<
"Full components to use in blowup graph:\n";
572 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
573 std::cout <<
"Updating capacities (y = " <<
m_y <<
")" << std::endl;
577 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
578 std::cout <<
" * new y = " <<
m_y << std::endl;
596 for (
edge e : edges) {
611 if (t->degree() > 0) {
620 template<
typename NODELIST>
622 auto it = nodes.begin();
624 for (++it; it != nodes.end(); ++it) {
642 while (!cleanup.
empty()) {
647 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
648 std::cout <<
" * remove pendant node " << v <<
" for cleanup" << std::endl;
652 }
else if (v->
indeg() == 0) {
653 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
654 std::cout <<
" * " << v <<
" has no incoming edge -> fix directions"
659 #ifdef OGDF_STEINER_TREE_GOEMANS_BLOWUP_GRAPH_LOGGING
660 std::cout <<
" * make " << w <<
" parent of " << v <<
" (reverse edge "
661 << e <<
")" << std::endl;
682 if ((*it)->degree() == 0) {
691 edge rootEdge =
nullptr;
694 edge e = (*it)->theEdge();
721 while (!todo.empty()) {
Declaration and implementation of HashArray class.
int numberOfWitnesses(edge e) const
Return the number of witnesses of an edge.
The namespace for all OGDF objects.
Declaration and implementation of ArrayBuffer class.
Includes declaration of graph class.
void initCoreWitness()
Finds a "random" set of core edges and "replace" found edges by nodes, also find the witness sets for...
const FullComponentWithExtraStore< T, double > & m_fullCompStore
all enumerated full components, with solution
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
bool empty() const
Returns true if the buffer is empty, false otherwise.
virtual void delNode(node v)
Removes node v and all incident edges from the graph.
node original(node v) const
node theNode() const
Returns the node whose adjacency list contains this element.
const Graph & getGraph() const
const Array< node > & terminals(int id) const
Returns the list of terminals 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.
T lcm(T a, T b)
Returns the least common multipler of two numbers.
void initSource(ArrayBuffer< std::pair< node, int >> &roots)
Connects source to component roots.
Declaration of classes used for hashing.
void removeBasis(node v)
Removes a basis and cleans up.
adjEntry lastAdj() const
Returns the last entry in the adjacency list.
NodeArray< node > m_original
Mapping of blowup graph nodes to original nodes. If a node in a blowup graph represents more than one...
void delEdges(ArrayBuffer< edge > edges)
Removes edges in edges.
NodeArray< bool > m_isTerminal
Incidence vector for the blowup graph terminals.
void initPseudotarget()
Connects pseudotarget.
E popFrontRet()
Removes the first element from the list and returns it.
int updateSourceAndTargetArcCapacities(const node v)
Updates arc capacities s->v and v->t.
void moveAdjAfter(adjEntry adjMove, adjEntry adjAfter)
Moves adjacency entry adjMove after adjAfter.
T getCoreCost(node v) const
Get cost of a core edge.
void addWitness(node e, edge f)
Adds e to W(f)
int size() const
Returns the number of full components in the store.
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.
E popRet()
Removes the newest element from the buffer and returns it.
HashConstIterator< I, E, H > begin() const
Returns an iterator to the first element in the list of all elements.
void getFraction(double d, int &num, int &denom, const double epsilon=5e-10, const int count=10)
Converts a double to a fraction.
const double m_eps
epsilon for double operations
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
virtual void delEdge(edge e)
Removes edge e from the graph.
Class for adjacency list elements.
void reverseEdge(edge e)
Reverses the edge e, i.e., exchanges source and target node.
const List< node > & terminals() const
Returns a reference to the list containing all terminals in the blowup graph.
List< node > m_terminals
The terminals in the blowup graph.
int getY() const
Returns the y-value of all terminals.
T gcd(T a, T b)
Returns the greatest common divisor of two numbers.
node getOriginal(node v) const
Returns the original node of v.
void addCore(node e)
Adds a core edge.
edge theEdge() const
Returns the edge associated with this adjacency entry.
void setCapacity(edge e, int capacity)
const List< node > & core() const
Return list of core edges (implemented by nodes)
static void copy(const T &from, T &to)
int degree() const
Returns the degree of the node (indegree + outdegree).
EdgeArray< int > m_capacity
T getCost(edge e) const
Returns the cost of e.
EdgeArray< int > m_witnessCard
Decralation of GraphElement and GraphList classes.
adjEntry succ() const
Returns the successor in the adjacency list.
void delCore(node e)
Remove a core edge.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
int indeg() const
Returns the indegree of the node.
T getCoreCapacity(node v) const
Get capacity of a core edge.
Indexed arrays using hashing for element access.
const CoreEdgeModule< T > & m_ceModule
void contract(NODELIST &nodes)
Contracts nodes.
void push(E e)
Puts a new element in the buffer.
node getSource() const
Returns the source node.
T cost(int i) const
Returns the sum of edge costs of this full component.
node getPseudotarget() const
Returns the pseudotarget node.
node source() const
Returns the source node of the edge.
Doubly linked lists (maintaining the length of the list).
RegisteredArray for nodes, edges and adjEntries of a graph.
Data type for general directed graphs (adjacency list representation).
node getTarget() const
Returns the target node.
Iterators for hash tables.
adjEntry start(int i) const
int getLCM() const
Returns the least common multiple of all denominators.
void initTarget()
Connects target.
bool isTerminal(int id, node t) const
checks if a given node t is a terminal in the full component with given id
const EdgeWeightedGraph< T > & graph() const
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
adjEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
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.
void updateSpecialCapacities()
Updates capacities from source to terminals and terminals to pseudotarget.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
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...
Basic declarations, included by all source files.
void contract(node &v, node t)
Contracts node v and terminal t into v.
const EdgeArray< int > & capacities() const
Returns a reference to the edge array containing all capacities.
node newNode(int index=-1)
Creates a new node and returns it.
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
bool isTerminal(node v) const
Returns true if and only if v is a terminal.
Interface for core edge finder algorithms.
Class for the representation of edges.
Declaration of doubly linked lists and iterators.
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.
void makeCWCopy(const HashArray< edge, edge > &edgeMap)
Copies witness sets and core edges for a given copy map.
List< node > m_coreEdges
the core edges as nodes
node contract(edge e, bool keepSelfLoops=false)
Contracts edge e while preserving the order of adjacency entries.
Encapsulates a pointer to a list element.
node target() const
Returns the target node of the edge.
edge newEdge(node v, node w, int index=-1)
Creates a new edge (v,w) and returns it.
node initTerminal(node t)
Inserts a terminal.
Class for the representation of nodes.
const ArrayBuffer< edge > & witnessList(node e) const
Return list of loss edges f in W(e)
NodeArray< ArrayBuffer< edge > > m_witness
double computeCoreWeight(node v) const
Compute the weight of a core edge.
iterator pushBack(const E &x)
Adds element x at the end of the list.
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
void removeIsolatedTerminals()
Removes isolated terminals.
int getCapacity(edge e) const
Returns the capacity of e.
void computeLCM()
Computes the least common multiple of the values assigned to the full components.
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.