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) {
437 edge result =
nullptr;
441 T sumOfMinWeights = 0;
442 T sumOfMinTermWeights = 0;
451 edge minEdge =
nullptr;
456 edge e = adj->theEdge();
458 secondMinWeight = minWeight;
470 if(minTermWeight < absoluteMinTermWeight) {
471 absoluteMinTermWeight = minTermWeight;
477 sumOfMinTermWeights += minTermWeight;
482 OGDF_ASSERT(absoluteMinTermWeight <= sumOfMinTermWeights);
493 sumOfMinWeights += minWeight;
495 T penalty = secondMinWeight - minWeight;
496 if(penalty > maxPenalty) {
497 maxPenalty = penalty;
504 if(result !=
nullptr) {
507 sumOfMinTermWeights -= absoluteMinTermWeight;
509 if(maxCost <= sumOfMinWeights && maxCost <= sumOfMinTermWeights) {
523 #ifdef OGDF_MINSTEINERTREE_SHORE_LOGGING 540 T branchingEdgeWeight =
weightOf(branchingEdge);
542 #ifdef OGDF_MINSTEINERTREE_SHORE_LOGGING 544 std::cout <<
"branching on edge: " << branchingEdge << std::endl;
554 nodeToRemove = branchingEdge->
target();
555 targetNode = branchingEdge->
source();
590 adjNext = adj->
succ();
591 edge e = adj->theEdge();
598 bool deletedEdgeE =
false;
616 if(e->
target() == nodeToRemove) {
634 bool targetNodeIsTerminal =
isTerminal(targetNode),
635 nodeToRemoveIsTerminal =
isTerminal(nodeToRemove);
637 OGDF_ASSERT(targetNodeIsTerminal || nodeToRemoveIsTerminal);
641 #ifdef OGDF_MINSTEINERTREE_SHORE_LOGGING 643 std::cout <<
"inclusion branch" << std::endl;
646 currentEdges.
pushFront(origBranchingEdge);
647 result =
bnbInternal(branchingEdgeWeight + prevCost, currentEdges);
658 while(!movedEdges.
empty()) {
674 while(!delEdges.
empty()) {
684 #ifdef OGDF_MINSTEINERTREE_SHORE_LOGGING 686 std::cout <<
"exclusion branch" << std::endl;
689 T exEdgeResult =
bnbInternal(prevCost, currentEdges);
692 if(exEdgeResult < result) {
693 result = exEdgeResult;
697 newEdge(nodeToRemove, targetNode, origBranchingEdge);
713 for(
node v : nodes) {
719 for(
edge e : edges) {
722 std::stringstream filename;
node target() const
Returns the target node of the edge.
void clear()
Removes all elements from the list.
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).
void popFront()
Removes the first element from the list.
Serves as an interface for various methods to compute or approximate minimum Steiner trees on undirec...
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)
Declaration of ogdf::MinSteinerTreeModule.
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.
edge searchEdge(node v, node w, bool directed=false) const
Searches and returns an edge connecting nodes v and w in time O( min(deg(v ), deg(w )))...
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.
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.
std::unique_ptr< NodeSet<> > m_terminals
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(CONTAINER &nodeContainer) const
Returns a container with all nodes of the graph.
node source() const
Returns the source node of the edge.
The namespace for all OGDF objects.
void allEdges(CONTAINER &edgeContainer) const
Returns a container with all edges of the graph.
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.
Declaration and implementation of ogdf::NodeSet.
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.