283 copiedNodes[v] = copiedNode;
288 target = copiedNodes[e->
target()];
298 T result =
solve(chosenEdges);
303 for(
edge e : chosenEdges) {
313 if(finalSteinerTree->
copy(v) ==
nullptr) {
316 if(finalSteinerTree->
copy(w) ==
nullptr) {
441 edge result =
nullptr;
445 T sumOfMinWeights = 0;
446 T sumOfMinTermWeights = 0;
455 edge minEdge =
nullptr;
460 edge e = adj->theEdge();
462 secondMinWeight = minWeight;
474 if(minTermWeight < absoluteMinTermWeight) {
475 absoluteMinTermWeight = minTermWeight;
481 sumOfMinTermWeights += minTermWeight;
486 OGDF_ASSERT(absoluteMinTermWeight <= sumOfMinTermWeights);
497 sumOfMinWeights += minWeight;
499 T penalty = secondMinWeight - minWeight;
500 if(penalty > maxPenalty) {
501 maxPenalty = penalty;
508 if(result !=
nullptr) {
511 sumOfMinTermWeights -= absoluteMinTermWeight;
513 if(maxCost <= sumOfMinWeights && maxCost <= sumOfMinTermWeights) {
527 #ifdef OGDF_MINSTEINERTREE_SHORE_LOGGING 544 T branchingEdgeWeight =
weightOf(branchingEdge);
546 #ifdef OGDF_MINSTEINERTREE_SHORE_LOGGING 548 cout <<
"branching on edge: " << branchingEdge << std::endl;
558 nodeToRemove = branchingEdge->
target();
559 targetNode = branchingEdge->
source();
594 adjNext = adj->
succ();
595 edge e = adj->theEdge();
602 bool deletedEdgeE =
false;
620 if(e->
target() == nodeToRemove) {
638 bool targetNodeIsTerminal =
isTerminal(targetNode),
639 nodeToRemoveIsTerminal =
isTerminal(nodeToRemove);
641 OGDF_ASSERT(targetNodeIsTerminal || nodeToRemoveIsTerminal);
645 #ifdef OGDF_MINSTEINERTREE_SHORE_LOGGING 647 cout <<
"inclusion branch" << std::endl;
650 currentEdges.
pushFront(origBranchingEdge);
651 result =
bnbInternal(branchingEdgeWeight + prevCost, currentEdges);
662 while(!movedEdges.
empty()) {
678 while(!delEdges.
empty()) {
688 #ifdef OGDF_MINSTEINERTREE_SHORE_LOGGING 690 cout <<
"exclusion branch" << std::endl;
693 T exEdgeResult =
bnbInternal(prevCost, currentEdges);
696 if(exEdgeResult < result) {
697 result = exEdgeResult;
701 newEdge(nodeToRemove, targetNode, origBranchingEdge);
717 for(
node v : nodes) {
723 for(
edge e : edges) {
726 std::stringstream filename;
node target() const
Returns the target node of the edge.
void clear()
Removes all elements from the list.
NodeArray< ListIterator< node > > m_isTerminal
node copy(node v) const
Returns the node in the graph copy corresponding to v.
List< edge > m_chosenEdges
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
void moveTarget(edge e, node w)
Moves the target node of edge e to node w.
Data type for general directed graphs (adjacency list representation).
edge searchEdge(node v, node w) const
Searches and returns an edge connecting nodes v and w in time O( min(deg(v ), deg(w )))...
void popFront()
Removes the first element from the list.
This class serves as an interface for various methods to compute minimum or approximations of minimum...
int degree() const
Returns the degree of the node (indegree + outdegree).
virtual T computeSteinerTree(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree) override
Builds a minimum Steiner tree given a weighted graph and a list of terminals.
edge newEdge(node u, node v, T weight)
Interface of Minimum Steiner Tree Algorithms.
T bnbInternal(T prevCost, List< edge > ¤tEdges)
Calculates the optimal Steinter tree recursivly.
virtual void delEdge(edge e)
Removes edge e from the graph.
Extends the GraphCopy concept to weighted graphs.
void setEdgeLookup(const node u, const node v, const edge e)
Sets the edge incident to both node u and v.
Dynamic arrays indexed with edges.
edge newEdge(node source, node target, const edge originalEdge)
Creates a new edge.
void moveSource(edge e, node v)
Moves the source of the edge to the specified node.
void moveTarget(edge e, node v)
Moves the target of the edge to the specified node.
bool isTerminal(const node v) const
Returns whether this node is a terminal or a Steiner node.
void createEmpty(const Graph &wG)
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Declaration and implementation of EdgeArray class.
T weightOf(edge e) const
Returns the cost of the specified edge.
const_reference front() const
Returns a const reference to the first element.
bool validateMapping() const
Used to validate the current mapping of edges to orignal edges Used solely for debugging.
Doubly linked lists (maintaining the length of the list).
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
edge lookupEdge(const node u, const node v) const
Retrieves the edge incident to both node u and v.
const List< node > * m_originalTerminals
Class for the representation of edges.
void allEdges(EDGELIST &edgeList) const
Returns a list with all edges of the graph.
E popFrontRet()
Removes the first element from the list and returns it.
The parameterized class Array2D implements dynamic two-dimensional arrays.
Class for the representation of nodes.
Declaration and implementation of NodeArray class.
Encapsulates a pointer to a list element.
void setTerminal(const node v, bool makeTerminal)
Updates the status of the given node to either terminal or Steiner node.
node opposite(node v) const
Returns the adjacent node different from v.
edge determineBranchingEdge(T prevCost) const
Decides which edge to branch on.
void moveSource(edge e, node w)
Moves the source node of edge e to node w.
virtual ~MinSteinerTreeShore()
Implementation of Shore, Foulds and Gibbons exact branch and bound algorithm for solving Steiner tree...
edge deleteEdge(edge e)
Removes the specified edge from the graph.
EdgeArray< edge > m_mapping
int index() const
Returns the (unique) node index.
adjEntry succ() const
Returns the successor in the adjacency list.
void allNodes(NODELIST &nodeList) const
Returns a list with all nodes of the graph.
node source() const
Returns the source node of the edge.
The namespace for all OGDF objects.
static void drawSteinerTreeSVG(const EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal, const char *filename)
Writes a SVG that shows only the given Steiner tree.
node newNode()
Creates a new node and returns it.
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
const EdgeWeightedGraph< T > * m_originalGraph
bool empty() const
Returns true iff the list is empty.
Class for adjacency list elements.
void printSVG()
Prints the current recursion status as a SVG image of the current reduced STP.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Declaration of doubly linked lists and iterators.
T solve(List< edge > &chosenEdges)
Solves the current STP instance.