178 for(
node v : nodes) {
183 for(
edge e : edges) {
193 #ifdef OGDF_DUAL_ASCENT_LOGGING 196 <<
"root terminal is node " <<
m_rootTerminal <<
"." << std::endl;
220 return (
m_rootTerminal != w || rootIsTerminal) && (*m_pIsTerminal)[w];
228 #ifdef OGDF_DUAL_ASCENT_LOGGING 229 std::cout <<
" searching for active component.." << std::endl;
237 if(!checked[candidate]) {
238 checked[candidate] =
true;
244 #ifdef OGDF_DUAL_ASCENT_LOGGING 245 std::cout <<
" active component found: component " << result <<
", terminal " << *terminal << std::endl;
252 #ifdef OGDF_DUAL_ASCENT_LOGGING 254 std::cout <<
" could not find an active component" << std::endl;
269 visited[root] =
true;
276 while(!queue.
empty()) {
292 for(
node v : weakComp) {
311 bool danglingTerminalFound =
false;
312 bool hasTerminal =
false;
314 #ifdef OGDF_DUAL_ASCENT_LOGGING 315 std::cout <<
" checking whether component of node " << source <<
" is active.. " << std::endl;
316 std::cout <<
" component has id " << comp << std::endl;
322 visited[source] =
true;
323 #ifdef OGDF_DUAL_ASCENT_LOGGING 324 while(!queue.
empty()) {
326 while(!queue.
empty() && !danglingTerminalFound) {
341 #ifdef OGDF_DUAL_ASCENT_LOGGING 342 if(hasTerminal) { std::cout <<
" component includes a terminal" << std::endl; }
343 if(danglingTerminalFound) { std::cout <<
" component has dangling terminal" << std::endl; }
344 if(hasTerminal && !danglingTerminalFound) { std::cout <<
" component is active!" << std::endl; }
346 return hasTerminal && !danglingTerminalFound;
356 #ifdef OGDF_DUAL_ASCENT_LOGGING 357 std::cout <<
"MinSteinerTreeDualAscent called." << std::endl;
358 std::cout <<
"terminals are: ";
360 for(
node v : terminals) {
361 std::cout << v <<
" ";
363 std::cout << std::endl;
377 node terminal =
nullptr;
379 #ifdef OGDF_DUAL_ASCENT_LOGGING 380 std::cout <<
"main loop starting.." << std::endl;
389 edge minEdge =
nullptr;
391 #ifdef OGDF_DUAL_ASCENT_LOGGING 392 std::cout <<
" cut edges:";
394 for(
edge e : *cutEdges) {
395 #ifdef OGDF_DUAL_ASCENT_LOGGING 396 std::cout <<
" " << e;
403 #ifdef OGDF_DUAL_ASCENT_LOGGING 404 std::cout << std::endl <<
" next edge: " << minEdge << std::endl;
409 for(
edge e : *cutEdges) {
421 if (finalSteinerTree->
copy(origEdge->
source()) ==
nullptr) {
424 if (finalSteinerTree->
copy(origEdge->
target()) ==
nullptr) {
427 if (finalSteinerTree->
copy(origEdge) ==
nullptr) {
428 finalSteinerTree->
newEdge(origEdge, cost);
433 #ifdef OGDF_DUAL_ASCENT_LOGGING 434 std::cout <<
"removing expendable edges" << std::endl;
439 #ifdef OGDF_DUAL_ASCENT_LOGGING 440 std::cout <<
"algorithm terminated." << std::endl;
node target() const
Returns the target node of the edge.
node m_rootTerminal
root node
edge theEdge() const
Returns the edge associated with this adjacency entry.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
EdgeArray< T > m_edgeSlacks
slack variables for each directed edge representing the adjusted weight
const List< node > * m_pTerminals
list of terminals passed to the module
const NodeArray< bool > * m_pIsTerminal
terminal incidence vector passed to the module
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.
NodeArray< int > m_componentMapping
maps each node to its component
void init()
Reinitializes the array. Associates the array with no graph.
Serves as an interface for various methods to compute or approximate minimum Steiner trees on undirec...
Indexed arrays using hashing for element access.
edge newEdge(node u, node v, T weight)
Declaration of ogdf::MinSteinerTreeModule.
Dual ascent heuristic for the minimum Steiner tree problem.
void createEmpty(const Graph &G)
Associates the graph copy with G, but does not create any nodes or edges.
Extends the GraphCopy concept to weighted graphs.
Dynamic arrays indexed with edges.
List< edge > * computeCutSet(const node v) const
Returns all incoming cut edges of the component of v.
const EdgeWeightedGraph< T > * m_pOrigGraph
original graph passed to the module
bool isActiveComponent(const node v) const
Determines whether a strongly connected component is active (paper says "is root component").
bool isTerminal(const node v, bool rootIsTerminal) const
Returns whether this node is a terminal.
void updateComponents()
Re-establishes all strongly connected components for the Steiner graph.
edge newEdge(edge eOrig)
Creates a new edge (v,w) with original edge eOrig.
T computeSteinerTree(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
Creates a minimum Steiner tree given a weighted graph and a list of terminals.
void createEmpty(const Graph &wG)
int numberOfEdges() const
Returns the number of edges in the graph.
virtual void clear() override
Removes all nodes and all edges from the graph.
void init()
Intializes all relevant variables.
int findActiveComponent(node *terminal) const
Searches for the next active component.
Doubly linked lists (maintaining the length of the list).
Class for the representation of edges.
E popFrontRet()
Removes the first element from the list and returns it.
Copies of graphs supporting edge splitting.
Class for the representation of nodes.
GraphCopy m_steinerGraph
the to-be constructed "almost" Steiner tree
EdgeArray< edge > m_origMapping
maps each directed edge to its undirected original
const Graph & original() const
Returns a reference to the original graph.
static T pruneAllDanglingSteinerPaths(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal)
Prunes nonterminal leaves and their paths to terminal or branching nodes.
static T removeCyclesFrom(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal)
Remove remaining cycles from a Steiner "almost" tree.
node source() const
Returns the source node of the edge.
The namespace for all OGDF objects.
int strongComponents(const Graph &G, NodeArray< int > &component)
Computes the strongly connected components of the digraph G.
int numberOfNodes() const
Returns the number of nodes in the graph.
bool empty() const
Returns true iff the list is empty.
Class for adjacency list elements.
int findComponent(const node v) const
Returns the component of node v.
EdgeArray< bool > m_edgeInclusions
stores the resulting Steiner tree
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
GraphCopy m_diGraph
the directed graph
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.