34 #include <forward_list> 45 #include <unordered_map> 50 namespace steiner_tree {
59 return static_cast<int>((
static_cast<long long>(
143 T cost = mst.
call(m_copyGraph, m_copyTerminals, m_copyIsTerminal, reducedSolution);
144 cost += costEdgesAlreadyInserted();
145 computeOriginalSolution(*reducedSolution, *finalSteinerTree);
146 delete reducedSolution;
162 for (
node t : m_copyTerminals) {
163 const node tC = nCopy[t];
165 ccIsTerminal[tC] =
true;
170 T cost = mst.
call(ccGraph, ccTerminals, ccIsTerminal, ccSolution);
171 cost += costEdgesAlreadyInserted();
177 if (ccSolution->
copy(nCopy[v]) !=
nullptr) {
182 if (ccSolution->
copy(eCopy[e]) !=
nullptr) {
188 computeOriginalSolution(reducedSolution, *finalSteinerTree);
212 inline T costEdgesAlreadyInserted()
const {
return m_costAlreadyInserted; }
232 return repeat([
this]() {
233 bool changed =
false;
234 changed |= degree2Test();
236 changed |= deleteLeaves();
245 bool changed = deleteComponentsWithoutTerminals();
246 bool triviallyChanged =
false;
247 changed |= repeat([
this, &triviallyChanged, k]() {
248 bool innerChanged =
false;
249 triviallyChanged = reduceTrivial();
253 innerChanged |= NTDkTest(10, k);
259 innerChanged |= longEdgesTest();
263 innerChanged |= lowerBoundBasedNodeTest();
266 if (lowerBoundBasedEdgeTest()) {
268 deleteComponentsWithoutTerminals();
274 if (terminalDistanceTest()) {
276 deleteComponentsWithoutTerminals();
280 innerChanged |= PTmTest(k);
283 innerChanged |= repeat([
this]() {
285 bool innerInnerChanged = shortLinksTest();
290 innerInnerChanged |= nearestVertexTest();
292 return innerInnerChanged;
296 return changed | triviallyChanged;
330 bool deleteComponentsWithoutTerminals();
338 bool leastCostTest();
355 bool PTmTest(
const int k = 3);
365 bool terminalDistanceTest();
373 bool longEdgesTest();
385 bool NTDkTest(
const int maxTestedDegree = 5,
const int k = 3);
395 bool nearestVertexTest();
405 bool shortLinksTest();
417 bool lowerBoundBasedNodeTest();
429 bool lowerBoundBasedEdgeTest();
441 bool reachabilityTest(
int maxDegreeTest = 0,
const int k = 3);
451 bool cutReachabilityTest();
462 m_costUpperBoundAlgorithm.reset(pMinSteinerTreeModule);
469 template<
typename Fun>
472 bool changed =
false;
502 template<
typename TWhat,
typename TWhatArray>
503 void addNew(TWhat x,
const std::vector<node> &replacedNodes,
const std::vector<edge> &replacedEdges,
bool deleteReplacedElements,
504 TWhatArray &whatSonsListIndex);
507 inline void addNewNode(
node v,
const std::vector<node> &replacedNodes,
const std::vector<edge> &replacedEdges,
bool deleteReplacedElements)
509 addNew(v, replacedNodes, replacedEdges, deleteReplacedElements, m_nodeSonsListIndex);
513 inline void addNewEdge(
edge e,
const std::vector<node> &replacedNodes,
const std::vector<edge> &replacedEdges,
bool deleteReplacedElements)
515 addNew(e, replacedNodes, replacedEdges, deleteReplacedElements, m_edgeSonsListIndex);
524 bool addEdgesToSolution(
const List<edge> &edgesToBeAddedInSolution);
527 void recomputeTerminalsList();
537 finalSteinerTree =
nullptr;
538 return m_costUpperBoundAlgorithm->call(m_copyGraph, m_copyTerminals, m_copyIsTerminal, finalSteinerTree);
545 T treeCostUpperBound = computeMinSteinerTreeUpperBound(finalSteinerTree);
546 delete finalSteinerTree;
547 return treeCostUpperBound;
551 void addToSolution(
const int listIndex,
Array<bool, int> &isInSolution)
const;
554 bool deleteNodesAboveUpperBound(
const NodeArray<T> &lowerBoundWithNode,
const T upperBound);
556 bool deleteEdgesAboveUpperBound(
const EdgeArray<T> &lowerBoundWithEdge,
const T upperBound);
570 void findClosestNonTerminals(
node source,
List<node> &reachedNodes,
NodeArray<T> &distance, T maxDistance,
int expandedEdges)
const;
583 void computeClosestKTerminals(
const int k,
NodeArray<
List<std::pair<node,T>>> &closestTerminals)
const;
586 void computeRadiusOfTerminals(
NodeArray<T> &terminalRadius)
const;
589 T computeRadiusSum()
const;
592 template<
typename LAMBDA>
593 void computeOptimalTerminals(
node v, LAMBDA dist,
node &optimalTerminal1,
node &optimalTerminal2,
NodeArray<T> &distance)
const;
602 , m_origTerminals(terminals)
603 , m_origIsTerminal(isTerminal)
623 const node vC = nCopy[v];
646 template<
typename TWhat,
typename TWhatArray>
648 const std::vector<node> &replacedNodes,
649 const std::vector<edge> &replacedEdges,
650 bool deleteReplacedElements,
651 TWhatArray &whatSonsListIndex)
653 std::vector<int> sonsIndexList;
654 for (
node replacedNode : replacedNodes) {
657 for (
edge replacedEdge : replacedEdges) {
662 whatSonsListIndex[x] = (int)
m_sonsList.size() - 1;
664 if (deleteReplacedElements) {
665 for (
edge e : replacedEdges) {
668 for (
node v :replacedNodes) {
678 isInSolution[listIndex] =
true;
695 for (
node v : reducedGraphSolution.
nodes) {
698 for (
edge e : reducedGraphSolution.
edges) {
705 if (isInSolution[-(nextIndex++)]) {
706 correspondingOriginalSolution.
newNode(v);
710 if (isInSolution[-(nextIndex++)]) {
728 std::forward_list<NewEdgeData> newEdges;
734 const edge e2 = adj2->theEdge();
735 const node adjacentNode2 = adj2->twinNode();
749 newEdges.emplace_front(NewEdgeData{e1, e2, f, edgeWeight});
753 for (
const auto &newEdge : newEdges) {
756 if (newEdge.already) {
758 m_copyGraph.setWeight(newEdge.already, newEdge.weight);
759 newEdgeInGraph = newEdge.already;
761 newEdgeInGraph =
m_copyGraph.newEdge(newEdge.e1->opposite(v), newEdge.e2->opposite(v), newEdge.weight);
763 addNewEdge(newEdgeInGraph, {v}, {newEdge.e1, newEdge.e2},
false);
784 const NodeArray<
List<std::pair<node, T>>> &closestTerminals)
const 786 T bottleneckDistance = numeric_limits<T>::max();
788 for (
auto &xCloseTerminalDistancePair : closestTerminals[x]) {
789 for (
auto &yCloseTerminalDistancePair : closestTerminals[y]) {
790 T possibleBottleneckDistance = xCloseTerminalDistancePair.second + yCloseTerminalDistancePair.second;
792 node xTprimeCopy = tprime.
copy(xCloseTerminalDistancePair.first);
793 node yTprimeCopy = tprime.
copy(yCloseTerminalDistancePair.first);
796 bottleneckDistance = min(bottleneckDistance, possibleBottleneckDistance);
800 return bottleneckDistance;
827 void buildMaxSegmentTree(std::vector<T> &segmentTree,
const int nodeIndex,
const int left,
const int right,
const std::vector<T> &baseArray)
const 830 segmentTree[nodeIndex] = baseArray[left];
834 int middle = (left+right)>>1;
835 int leftNodeIndex = nodeIndex+nodeIndex+1;
836 int rightNodeIndex = leftNodeIndex + 1;
838 buildMaxSegmentTree(segmentTree, leftNodeIndex, left, middle, baseArray);
839 buildMaxSegmentTree(segmentTree, rightNodeIndex, middle+1, right, baseArray);
841 segmentTree[nodeIndex] = max(segmentTree[leftNodeIndex], segmentTree[rightNodeIndex]);
847 T
getMaxSegmentTree(
const std::vector<T> &segmentTree,
const int nodeIndex,
const int left,
const int right,
const int queryLeft,
const int queryRight)
const 849 if (queryLeft > queryRight
851 || queryLeft > right) {
855 if (queryLeft <= left
856 && right <= queryRight) {
857 return segmentTree[nodeIndex];
860 int middleIndex = (left + right)>>1;
861 int leftNodeIndex = nodeIndex+nodeIndex+1;
862 int rightNodeIndex = leftNodeIndex + 1;
865 if (queryLeft <= middleIndex) {
866 maxValue = max(maxValue, getMaxSegmentTree(segmentTree, leftNodeIndex, left, middleIndex, queryLeft, queryRight));
868 if (queryRight > middleIndex) {
869 maxValue = max(maxValue, getMaxSegmentTree(segmentTree, rightNodeIndex, middleIndex+1, right, queryLeft, queryRight));
881 if (ancestor ==
nullptr) {
882 return distanceToRoot[v];
884 return distanceToRoot[v] - distanceToRoot[ancestor];
894 longestDistToSteinerAncestorOnChain.resize((
int)chains.size());
895 for (
int i = 0; i < (int)chains.size(); ++i) {
896 longestDistToSteinerAncestorOnChain[i].resize((
int)chains[i].size());
897 for (
int j = 0; j < (int)chains[i].size(); ++j) {
898 longestDistToSteinerAncestorOnChain[i][j] = distanceToAncestor(chains[i][j], closestSteinerAncestor[chains[i][j]]);
900 longestDistToSteinerAncestorOnChain[i][j] = max(longestDistToSteinerAncestorOnChain[i][j], longestDistToSteinerAncestorOnChain[i][j-1]);
913 longestDistToSteinerAncestorSegTree.resize((
int)chains.size());
914 for (
int i = 0; i < (int)chains.size(); ++i) {
915 longestDistToSteinerAncestorSegTree[i].resize(4*(
int)chains[i].size());
917 std::vector<T> distanceToSteinerAncestor_byPosition;
918 distanceToSteinerAncestor_byPosition.resize(chains[i].size());
919 for (
int j = 0; j < (int)chains[i].size(); ++j) {
920 distanceToSteinerAncestor_byPosition[j] = distanceToAncestor(chains[i][j], closestSteinerAncestor[chains[i][j]]);
923 buildMaxSegmentTree(longestDistToSteinerAncestorSegTree[i], 0, 0, (
int)chains[i].size()-1, distanceToSteinerAncestor_byPosition);
933 weightOfSubtree[v] = 1;
934 node heaviestSon =
nullptr;
935 closestSteinerAncestor[v] = closestSteinerUpNode;
941 if (weightOfSubtree[son] != 0) {
945 nodeLevel[son] = nodeLevel[v] + 1;
946 distanceToRoot[son] = distanceToRoot[v] + tree.
weight(e);
948 dfsHeavyPathDecomposition(son, v);
950 fatherOfChain[chainOfNode[son]] = v;
951 weightOfSubtree[v] += weightOfSubtree[son];
952 if (heaviestSon ==
nullptr 953 || weightOfSubtree[heaviestSon] < weightOfSubtree[son]) {
958 if (heaviestSon ==
nullptr) {
961 std::vector<node>new_chain;
962 chains.push_back(new_chain);
963 chainsOfTerminals.push_back(new_chain);
965 fatherOfChain.push_back(
nullptr);
966 chainOfNode[v] = (int)chains.
size()-1;
968 chainOfNode[v] = chainOfNode[heaviestSon];
971 chains[chainOfNode[v]].push_back(v);
972 chainsOfTerminals[chainOfNode[v]].push_back(v);
973 positionOnChain[v] = (int)chains[chainOfNode[v]].size()-1;
983 int left = 0, middle, right = (int)chainOfTerminals.size()-1;
984 while (left <= right) {
985 middle = (left+right)>>1;
987 if (nodeLevel[chainOfTerminals[middle]] >= nodeLevel[v]) {
994 if (left == (
int)chainOfTerminals.size()) {
997 return chainOfTerminals[left];
1011 node upmostTerminal = x;
1012 while (closestSteinerAncestor[chains[chainOfNode[x]][0]] !=
nullptr 1013 && nodeLevel[closestSteinerAncestor[chains[chainOfNode[x]][0]]] >= nodeLevel[ancestor]) {
1014 longestPathDistance = max(longestPathDistance, longestDistToSteinerAncestorOnChain[chainOfNode[x]][positionOnChain[x]]);
1016 if (!chainsOfTerminals[chainOfNode[x]].empty()
1017 && nodeLevel[chainsOfTerminals[chainOfNode[x]][0]] <= nodeLevel[x]) {
1018 upmostTerminal = chainsOfTerminals[chainOfNode[x]][0];
1020 x = fatherOfChain[chainOfNode[x]];
1024 node upmostTerminalLastChain = binarySearchUpmostTerminal(ancestor, chainsOfTerminals[chainOfNode[x]]);
1025 if (nodeLevel[upmostTerminalLastChain] > nodeLevel[x]) {
1026 upmostTerminalLastChain =
nullptr;
1028 if (upmostTerminalLastChain !=
nullptr) {
1029 upmostTerminal = upmostTerminalLastChain;
1032 if (upmostTerminalLastChain !=
nullptr) {
1033 longestPathDistance = max(longestPathDistance,
1034 getMaxSegmentTree(longestDistToSteinerAncestorSegTree[chainOfNode[x]], 0, 0,
1035 static_cast<int>(chains[chainOfNode[x]].size()) - 1,
1036 positionOnChain[upmostTerminalLastChain] + 1,
1037 positionOnChain[x]));
1040 fromLowestToAncestor = distanceToAncestor(upmostTerminal, ancestor);
1046 : tree(treeEWGraphCopy)
1050 chainOfNode.
init(treeEWGraphCopy, -1);
1051 positionOnChain.
init(treeEWGraphCopy, -1);
1052 weightOfSubtree.
init(treeEWGraphCopy, 0);
1053 nodeLevel.
init(treeEWGraphCopy, 0);
1054 distanceToRoot.
init(treeEWGraphCopy, 0);
1055 closestSteinerAncestor.
init(treeEWGraphCopy,
nullptr);
1057 dfsHeavyPathDecomposition(root,
nullptr);
1058 fatherOfChain[chainOfNode[root]] =
nullptr;
1061 int numberOfChains =
static_cast<int>(chains.size());
1062 for (
int i = 0; i < numberOfChains; ++i) {
1063 reverse(chains[i].begin(), chains[i].end());
1064 reverse(chainsOfTerminals[i].begin(), chainsOfTerminals[i].end());
1065 for (
node v : chains[i]) {
1066 positionOnChain[v] = (int)chains[i].size()-1-positionOnChain[v];
1070 computeLongestDistToSteinerAncestorOnChain();
1071 computeLongestDistToSteinerAncestorSegTree();
1080 while (chainOfNode[x] != chainOfNode[y]) {
1081 int xlevelOfFatherOfChain = fatherOfChain[chainOfNode[x]] !=
nullptr ? nodeLevel[fatherOfChain[chainOfNode[x]]] : -1;
1082 int ylevelOfFatherOfChain = fatherOfChain[chainOfNode[y]] !=
nullptr ? nodeLevel[fatherOfChain[chainOfNode[y]]] : -1;
1084 if (xlevelOfFatherOfChain >= ylevelOfFatherOfChain) {
1085 x = fatherOfChain[chainOfNode[x]];
1087 y = fatherOfChain[chainOfNode[y]];
1091 if (nodeLevel[x] <= nodeLevel[y]) {
1103 T xLongestPathDistance = 0, yLongestPathDistance = 0;
1104 T xFromLowestToLCA = 0, yFromLowestToLCA = 0;
1105 node xyLowestCommonAncestor = lowestCommonAncestor(x, y);
1107 computeBottleneckOnBranch(x, xyLowestCommonAncestor, xLongestPathDistance, xFromLowestToLCA);
1108 computeBottleneckOnBranch(y, xyLowestCommonAncestor, yLongestPathDistance, yFromLowestToLCA);
1110 T maxValue = max(xLongestPathDistance, yLongestPathDistance);
1111 maxValue = max(maxValue, xFromLowestToLCA+yFromLowestToLCA);
1117 template<
typename T>
1121 auto deleteAll = [
this]() {
1147 if (eraseQueue.empty()) {
1151 for (; !eraseQueue.empty(); eraseQueue.pop()) {
1152 node v = eraseQueue.top();
1160 edge e = v->firstAdj()->theEdge();
1176 if (w->degree() == 2) {
1177 eraseQueue.append(w);
1189 template<
typename T>
1192 bool changed =
false;
1196 nextAdj = adj->succ();
1198 edge e = adj->theEdge();
1199 node adjNode = adj->twinNode();
1201 if (nextAdj == adj->twin()) {
1202 nextAdj = nextAdj->
succ();
1207 if (minCostEdge[adjNode] ==
nullptr 1209 if (minCostEdge[adjNode] !=
nullptr) {
1213 minCostEdge[adjNode] = e;
1222 minCostEdge[adj->
twinNode()] =
nullptr;
1228 template<
typename T>
1234 shortestPath[v1][v2] = shortestPath[v2][v1] = min(shortestPath[v1][v2],
m_copyGraph.weight(adj->
theEdge()));
1241 if (shortestPath[v1][pivot] == numeric_limits<T>::max()
1242 || shortestPath[pivot][v2] == numeric_limits<T>::max()) {
1246 shortestPath[v1][v2] = min(shortestPath[v1][v2], shortestPath[v1][pivot] + shortestPath[pivot][v2]);
1252 template<
typename T>
1257 shortestPath[v].init(
m_copyGraph, numeric_limits<T>::max());
1263 template<
typename T>
1266 bool changed =
false;
1272 nextAdj = adj->succ();
1274 edge e = adj->theEdge();
1275 node adjNode = adj->twinNode();
1277 && shortestPath[v][adjNode] <
m_copyGraph.weight(e)) {
1286 template<
typename T>
1289 bool changed =
false;
1294 || v->degree() != 2 ) {
1299 edge eLeft = v->firstAdj()->theEdge();
1300 edge eRight = v->lastAdj()->theEdge();
1304 if (vLeft != vRight) {
1307 addNewEdge(newEdge, {v}, {eLeft, eRight},
true);
1316 template<
typename T>
1322 int componentWithTerminals = -1;
1324 if (componentWithTerminals != -1
1325 && hisConnectedComponent[v] != componentWithTerminals) {
1326 cerr <<
"terminals in different connected components!\n";
1329 componentWithTerminals = hisConnectedComponent[v];
1334 if (hisConnectedComponent[v] != componentWithTerminals) {
1342 template<
typename T>
1345 bool changed =
false;
1351 maxBottleneck = max(maxBottleneck, tprime->
weight(e));
1367 template<
typename T>
1373 distance[source] = 0;
1374 queue.
push(source, distance[source]);
1376 while (!queue.
empty()) {
1380 reachedNodes.
pushBack(currentNode);
1384 if (expandedEdges <= 0) {
1390 T possibleDistance = distance[currentNode] +
m_copyGraph.weight(e);
1392 if (
m_eps.
geq(possibleDistance, maxDistance)
1397 if (possibleDistance < distance[adjacentNode]) {
1398 distance[adjacentNode] = possibleDistance;
1399 if (queue.
contains(adjacentNode)) {
1400 queue.
decrease(adjacentNode, possibleDistance);
1402 queue.
push(adjacentNode, distance[adjacentNode]);
1409 template<
typename T>
1412 bool changed =
false;
1423 for (
node commonNode : xReachedNodes) {
1424 if (yDistance[commonNode] == numeric_limits<T>::max()) {
1434 for (
node reachedNode : xReachedNodes) {
1435 xDistance[reachedNode] = numeric_limits<T>::max();
1437 for (
node reachedNode : yReachedNodes) {
1438 yDistance[reachedNode] = numeric_limits<T>::max();
1444 template<
typename T>
1450 NodePairQueue queue;
1451 std::unordered_map<NodePair, typename NodePairQueue::Handle, steiner_tree::UnorderedNodePairHasher, steiner_tree::UnorderedNodePairEquality> qpos;
1455 closestTerminals[v].pushBack(std::make_pair(v, 0));
1459 auto getCurrentDist = [&closestTerminals](
const node currentNode,
const node sourceTerminal) {
1460 for (std::pair<node,T> currentPair : closestTerminals[currentNode]) {
1461 if (currentPair.first == sourceTerminal) {
1462 return currentPair.second;
1465 return static_cast<T
>(-1);
1468 auto setNewDist = [&closestTerminals, k](
const node currentNode,
const node sourceTerminal,
const T newDist) {
1472 for (
ListIterator<std::pair<node, T>> it = currentList.
begin(); it.valid(); ++it) {
1473 if ((*it).first == sourceTerminal) {
1474 currentList.
del(it);
1479 if (currentList.
size() == k) {
1484 if (currentList.
empty()
1485 || (*(currentList.
begin())).second >= newDist) {
1486 currentList.
pushFront(std::make_pair(sourceTerminal, newDist));
1491 while (it.
succ() != closestTerminals[currentNode].end()
1492 && (*(it.
succ())).second < newDist) {
1495 closestTerminals[currentNode].insertAfter(std::make_pair(sourceTerminal, newDist), it);
1498 while (!queue.empty()) {
1499 NodePair minDistPair = queue.topElement();
1504 T currentDist = getCurrentDist(currentNode, sourceTerminal);
1505 if (currentDist == -1) {
1517 T possibleNewDistance = currentDist +
m_copyGraph.weight(e);
1520 T currentDistToAdjacentNode = getCurrentDist(adjacentNode, sourceTerminal);
1521 if (currentDistToAdjacentNode != -1) {
1522 if (possibleNewDistance < currentDistToAdjacentNode) {
1523 queue.decrease(qpos[
NodePair(adjacentNode, sourceTerminal)], possibleNewDistance);
1524 setNewDist(adjacentNode, sourceTerminal, possibleNewDistance);
1527 if (closestTerminals[adjacentNode].size() < k
1528 || closestTerminals[adjacentNode].back().second > possibleNewDistance) {
1529 qpos[
NodePair(adjacentNode, sourceTerminal)] = queue.push(
NodePair(adjacentNode, sourceTerminal), possibleNewDistance);
1530 setNewDist(adjacentNode, sourceTerminal, possibleNewDistance);
1537 template<
typename T>
1540 bool changed =
false;
1565 template<
typename T>
1572 bool changed =
false;
1589 if (v->degree() <= 2
1590 || v->degree() > maxTestedDegree) {
1596 for (
adjEntry adj : v->adjEntries) {
1601 bool deleteNode =
true;
1602 for (neighborSubset.
begin(3, v->degree()); neighborSubset.
valid() && deleteNode; neighborSubset.
next()) {
1604 std::unordered_map<node, node> initNodeToAuxGraph;
1605 std::unordered_map<node, node> auxGraphToInitNode;
1607 T sumToSelectedAdjacentNodes = 0;
1609 for (
int i = 0; i < neighborSubset.
size(); ++i) {
1610 const adjEntry adj = neighborSubset[i];
1614 OGDF_ASSERT(initNodeToAuxGraph.find(adjacentNode) == initNodeToAuxGraph.end());
1617 initNodeToAuxGraph[adjacentNode] = newAuxGraphNode;
1618 auxGraphToInitNode[newAuxGraphNode] = adjacentNode;
1622 for (
node auxGraphNode1 : auxGraph.
nodes) {
1623 for (
node auxGraphNode2 = auxGraphNode1->
succ(); auxGraphNode2; auxGraphNode2 = auxGraphNode2->
succ()) {
1624 edge e = auxGraph.
newEdge(auxGraphNode1, auxGraphNode2);
1626 auxGraphToInitNode[auxGraphNode1],
1627 auxGraphToInitNode[auxGraphNode2],
1628 *tprime, tprimeHPD, closestTerminals);
1636 if (sumToSelectedAdjacentNodes < mstCost) {
1651 template<
typename T>
1654 isSuccessorOfMinCostEdge[currentNode] =
true;
1662 if (voronoiRegions.
predecessor(adjacentNode) == currentNode) {
1663 markSuccessors(adjacentNode, voronoiRegions, isSuccessorOfMinCostEdge);
1668 template<
typename T>
1671 if (edgesToBeAddedInSolution.
empty()) {
1674 for (
edge e : edgesToBeAddedInSolution) {
1675 node x = e->source(), y = e->target();
1687 template<
typename T>
1699 if (terminal->degree() < 2) {
1704 for(
adjEntry adj : terminal->adjEntries) {
1706 if (minCostIncidentEdge1[terminal] ==
nullptr 1708 minCostIncidentEdge2[terminal] = minCostIncidentEdge1[terminal];
1709 minCostIncidentEdge1[terminal] = e;
1711 if (minCostIncidentEdge2[terminal] ==
nullptr 1713 minCostIncidentEdge2[terminal] = e;
1721 for (
node terminal : m_copyTerminals) {
1722 if (terminal->degree() < 2) {
1725 node closestNode = minCostIncidentEdge1[terminal]->opposite(terminal);
1727 if (voronoiRegions.seed(closestNode) == terminal) {
1728 markSuccessors(closestNode, voronoiRegions, isSuccessorOfMinCostEdge);
1736 node seedX = voronoiRegions.seed(x), seedY = voronoiRegions.seed(y);
1737 if (seedX != seedY) {
1739 T distanceThroughE = voronoiRegions.distance(x) +
m_copyGraph.weight(e) + voronoiRegions.distance(y);
1741 if (isSuccessorOfMinCostEdge[x]) {
1742 distanceToClosestTerminal[seedX] = min(distanceToClosestTerminal[seedX],distanceThroughE);
1744 if (isSuccessorOfMinCostEdge[y]) {
1745 distanceToClosestTerminal[seedY] = min(distanceToClosestTerminal[seedY],distanceThroughE);
1753 for (
node terminal : m_copyTerminals) {
1754 if (terminal->degree() < 2) {
1758 const edge e1 = minCostIncidentEdge1[terminal];
1759 const node closestAdjacentNode = e1->
opposite(terminal);
1762 if (voronoiRegions.seed(closestAdjacentNode) == terminal) {
1763 distance = distanceToClosestTerminal[terminal];
1765 distance =
m_copyGraph.weight(e1) + voronoiRegions.distance(closestAdjacentNode);
1768 && !willBeAddedInSolution[e1]) {
1769 edgesToBeAddedInSolution.
pushBack(e1);
1770 willBeAddedInSolution[e1] =
true;
1777 template<
typename T>
1789 auto updateMinCostLeavingRegionsFor = [&](
node seed) {
1790 if (minCostLeavingRegionEdge1[seed] ==
nullptr 1792 minCostLeavingRegionEdge2[seed] = minCostLeavingRegionEdge1[seed];
1793 minCostLeavingRegionEdge1[seed] = e;
1795 if (minCostLeavingRegionEdge2[seed] ==
nullptr 1797 minCostLeavingRegionEdge2[seed] = e;
1801 const node seedX = voronoiRegions.seed(x), seedY = voronoiRegions.seed(y);
1802 if (seedX != seedY) {
1804 updateMinCostLeavingRegionsFor(seedX);
1805 updateMinCostLeavingRegionsFor(seedY);
1812 if (minCostLeavingRegionEdge2[terminal] ==
nullptr) {
1817 const edge e1 = minCostLeavingRegionEdge1[terminal];
1820 voronoiRegions.distance(x) +
m_copyGraph.weight(e1) + voronoiRegions.distance(y))
1821 && !willBeAddedInSolution[e1]) {
1822 edgesToBeAddedInSolution.
pushBack(e1);
1823 willBeAddedInSolution[e1] =
true;
1830 template<
typename T>
1839 node seedV = voronoiRegions.seed(v);
1840 T distanceToSeedV = voronoiRegions.distance(v);
1846 if (voronoiRegions.seed(adjacentNode) != seedV) {
1847 terminalRadius[seedV] = min(terminalRadius[seedV], distanceToSeedV +
m_copyGraph.weight(e));
1853 template<
typename T>
1856 bool changed =
false;
1859 if (
m_eps.
greater(lowerBoundWithNode[v], upperBound)) {
1867 template<
typename T>
1885 if (closestTerminals[v].size() < 2) {
1886 lowerBoundWithNode[v] = numeric_limits<T>::max();
1890 std::pair<node, T> closestTerminalPair1 = *(closestTerminals[v].get(0)), closestTerminalPair2 = *(closestTerminals[v].
get(1));
1891 T distanceToClosestTerminal1 = closestTerminalPair1.second, distanceToClosestTerminal2 = closestTerminalPair2.second;
1893 lowerBoundWithNode[v] = max(lowerBoundWithNode[v], distanceToClosestTerminal1 + distanceToClosestTerminal2 + radiusSum);
1898 Graph auxiliaryGraph;
1902 terminalInAuxiliaryGraph[terminal] = newAuxiliaryNode;
1911 std::unordered_map<NodePair, edge, steiner_tree::UnorderedNodePairHasher, steiner_tree::UnorderedNodePairEquality> edgeBetweenNodes;
1912 EdgeArray<T> edgeWeight(auxiliaryGraph, numeric_limits<T>::max());
1915 node seedX = voronoiRegions.
seed(x), seedY = voronoiRegions.
seed(y);
1916 if (seedX == seedY) {
1920 auto pair =
NodePair(terminalInAuxiliaryGraph[seedX], terminalInAuxiliaryGraph[seedY]);
1921 if (edgeBetweenNodes.find(pair) == edgeBetweenNodes.end()) {
1922 edgeBetweenNodes[pair] = auxiliaryGraph.
newEdge(terminalInAuxiliaryGraph[seedX], terminalInAuxiliaryGraph[seedY]);
1924 edge auxiliaryEdge = edgeBetweenNodes[pair];
1925 edgeWeight[auxiliaryEdge] = min(edgeWeight[auxiliaryEdge], min(voronoiRegions.
distance(x), voronoiRegions.
distance(y)) +
m_copyGraph.weight(e));
1929 T minimumSpanningTreeCost =
computeMinST(auxiliaryGraph, edgeWeight, isInTree);
1930 T longestEdgeCost = numeric_limits<T>::lowest();
1933 longestEdgeCost = max(longestEdgeCost, edgeWeight[e]);
1942 std::pair<node, T> closestTerminalPair1 = *(closestTerminals[v].get(0)), closestTerminalPair2 = *(closestTerminals[v].
get(1));
1943 T distanceToClosestTerminal1 = closestTerminalPair1.second, distanceToClosestTerminal2 = closestTerminalPair2.second;
1945 lowerBoundWithNode[v] = max(lowerBoundWithNode[v], minimumSpanningTreeCost - longestEdgeCost + distanceToClosestTerminal1 + distanceToClosestTerminal2);
1951 template<
typename T>
1954 bool changed =
false;
1957 if (
m_eps.
greater(lowerBoundWithEdge[e], upperBound)) {
1965 template<
typename T>
1973 T largestRadius1 = numeric_limits<T>::lowest(), largestRadius2 = numeric_limits<T>::lowest();
1975 radiusSum += terminalRadius[terminal];
1977 if (terminalRadius[terminal] > largestRadius1) {
1978 largestRadius2 = largestRadius1;
1979 largestRadius1 = terminalRadius[terminal];
1981 if (terminalRadius[terminal] > largestRadius2) {
1982 largestRadius2 = terminalRadius[terminal];
1986 radiusSum -= largestRadius1 + largestRadius2;
1990 template<
typename T>
2004 T distanceToClosestTerminalX = (*closestTerminals[x].
begin()).second;
2005 T distanceToClosestTerminalY = (*closestTerminals[y].
begin()).second;
2007 lowerBoundWithEdge[e] = max(lowerBoundWithEdge[e],
m_copyGraph.weight(e) + distanceToClosestTerminalX + distanceToClosestTerminalY + radiusSum);
2013 template<
typename T>
2016 bool changed =
false;
2019 if (maxDegreeTest <= 0) {
2027 for (
node v : approximatedSteinerTree->
nodes) {
2028 isInUpperBoundTree[approximatedSteinerTree->
original(v)] =
true;
2030 delete approximatedSteinerTree;
2044 if (isInUpperBoundTree[v]
2045 || v->
degree() > maxDegreeTest) {
2057 node farthestTerminal =
nullptr;
2058 T distanceToFarthestTerminal(0);
2059 T distanceToClosestTerminal1 = numeric_limits<T>::max(),
2060 distanceToClosestTerminal2 = numeric_limits<T>::max();
2062 if (distanceToFarthestTerminal < distance[terminal]) {
2063 farthestTerminal = terminal;
2064 distanceToFarthestTerminal = distance[terminal];
2067 if (distanceToClosestTerminal1 > distance[terminal]) {
2068 distanceToClosestTerminal2 = distanceToClosestTerminal1;
2069 distanceToClosestTerminal1 = distance[terminal];
2071 if (distanceToClosestTerminal2 > distance[terminal]) {
2072 distanceToClosestTerminal2 = distance[terminal];
2077 if (predecessor[farthestTerminal] ==
nullptr 2078 || distanceToClosestTerminal2 == numeric_limits<T>::max()
2079 ||
m_eps.
geq(distanceToFarthestTerminal + distanceToClosestTerminal1 + distanceToClosestTerminal2, upperBoundCost)) {
2082 if (predecessor[farthestTerminal] !=
nullptr 2083 && distanceToClosestTerminal2 != numeric_limits<T>::max()
2084 &&
m_eps.
less(distanceToFarthestTerminal + distanceToClosestTerminal1, upperBoundCost)) {
2099 template<
typename T>
2100 template<
typename LAMBDA>
2111 if (predecessor[terminal] ==
nullptr) {
2115 if (optimalTerminal1 ==
nullptr 2116 || dist(optimalTerminal1, distance) > dist(terminal, distance)) {
2117 optimalTerminal2 = optimalTerminal1;
2118 optimalTerminal1 = terminal;
2120 if (optimalTerminal2 ==
nullptr 2121 || dist(optimalTerminal2, distance) > dist(terminal, distance)) {
2122 optimalTerminal2 = terminal;
2128 OGDF_ASSERT(optimalTerminal1 != optimalTerminal2);
2131 template<
typename T>
2143 for (
node v : approximatedSteinerTree->
nodes) {
2144 isInUpperBoundTree[approximatedSteinerTree->
original(v)] =
true;
2146 delete approximatedSteinerTree;
2151 for (
adjEntry adj : terminal->adjEntries) {
2152 minCostOfAdjacentEdge[terminal] = min(minCostOfAdjacentEdge[terminal],
m_copyGraph.weight(adj->
theEdge()));
2154 cK += minCostOfAdjacentEdge[terminal];
2156 auto dist = [&minCostOfAdjacentEdge](
node terminal,
const NodeArray<T> &distance) {
2157 return distance[terminal] - minCostOfAdjacentEdge[terminal];
2161 std::set<edge> delEdges;
2167 if (isInUpperBoundTree[v]) {
2172 node vOptimalTerminal1 =
nullptr, vOptimalTerminal2 =
nullptr;
2176 if (
m_eps.
geq(cK + dist(vOptimalTerminal1, vDistance) + dist(vOptimalTerminal2, vDistance), upperBoundCost)) {
2179 for (
adjEntry adj = v->firstAdj(), adjNext; adj; adj = adjNext) {
2180 adjNext = adj->succ();
2181 node w = adj->twinNode();
2185 node wOptimalTerminal1 =
nullptr, wOptimalTerminal2 =
nullptr;
2188 node vOptimalTerminal = vOptimalTerminal1;
2189 node wOptimalTerminal = wOptimalTerminal1;
2190 if (vOptimalTerminal == wOptimalTerminal) {
2194 dist(vOptimalTerminal1, vDistance) + dist(wOptimalTerminal2, wDistance),
2195 dist(vOptimalTerminal2, vDistance) + dist(wOptimalTerminal1, wDistance))) {
2196 wOptimalTerminal = wOptimalTerminal2;
2198 vOptimalTerminal = vOptimalTerminal2;
2201 OGDF_ASSERT(vOptimalTerminal != wOptimalTerminal);
2202 if (
m_eps.
geq(cK + dist(vOptimalTerminal, vDistance) + dist(wOptimalTerminal, wDistance) +
m_copyGraph.weight(adj->theEdge()), upperBoundCost)) {
2203 delEdges.insert(adj->theEdge());
2209 bool changed =
false;
2210 for (
edge e : delEdges) {
2214 for (
node v : delNodes) {
node target() const
Returns the target node of the edge.
node lowestCommonAncestor(node x, node y) const
computes the lowest common ancestor of nodes x and y using the hpd
std::vector< std::vector< node > > chainsOfTerminals
list of chains only of terminals corresponding to the decomposition
void findClosestNonTerminals(node source, List< node > &reachedNodes, NodeArray< T > &distance, T maxDistance, int expandedEdges) const
Heuristic approach to computing the closest non-terminals for one node, such that there is no termina...
int operator()(NodePair const &v) const
void pop()
Removes the topmost element from the queue.
std::vector< std::vector< node > > chains
list of chains of nodes corresponding to the decomposition
The parameterized class Array implements dynamic arrays of type E.
bool lowerBoundBasedNodeTest()
Computes for each non-terminal a lower bound of the cost of the minimum Steiner tree containing it...
edge theEdge() const
Returns the edge associated with this adjacency entry.
std::enable_if< std::is_integral< T >::value, bool >::type leq(const T &x, const T &y) const
Compare if x is LEQ than y for integral types.
bool deleteNodesAboveUpperBound(const NodeArray< T > &lowerBoundWithNode, const T upperBound)
Deletes the nodes whose lowerBoundWithNode exceeds upperBound.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Dijkstra's single source shortest path algorithm.
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
SteinerTreePreprocessing(const EdgeWeightedGraph< T > &wg, const List< node > &terminals, const NodeArray< bool > &isTerminal)
An implementation of the HeavyPathDecomposition on trees.
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).
void push(const E &element, const P &priority)
Adds a new element to the queue.
void markSuccessors(node currentNode, const Voronoi< T > &voronoiRegions, NodeArray< bool > &isSuccessorOfMinCostEdge) const
Mark successors.
void init()
Reinitializes the array. Associates the array with no graph.
T computeMinST(const Graph &G, const EdgeArray< T > &weight, EdgeArray< bool > &isInTree)
Computes a minimum spanning tree using Prim's algorithm.
bool leastCostTest()
Performs a least cost test [DV89] computing the whole shortest path matrix.
void dfsHeavyPathDecomposition(node v, node closestSteinerUpNode)
performs the heavy path decomposition on the tree belonging to the class updates the fields of the cl...
virtual T call(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
Builds a minimum Steiner tree given a weighted graph and a list of terminals.
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).
void call(const Graph &G, const EdgeArray< T > &weight, const List< node > &sources, NodeArray< edge > &predecessor, NodeArray< T > &distance, bool directed=false)
Calculates, based on the graph G with corresponding edge costs and source nodes, the shortest paths a...
edge newEdge(node u, node v, T weight)
iterator begin()
Returns an iterator to the first element of the list.
This class implements preprocessing strategies for the Steiner tree problem.
const EdgeArray< T > & edgeWeights() const
node firstNode() const
Returns the first node in the list of all nodes.
void computeClosestKTerminals(const int k, NodeArray< List< std::pair< node, T >>> &closestTerminals) const
Computes for every non-terminal the closest k terminals such that there is no other terminal on the p...
Implementation of Mehlhorn's minimum Steiner tree 2(1-1/l)-approximation algorithm.
Implementation of the 2(1-1/l)-approximation algorithm for the minimum Steiner tree problem by Matsuy...
void makeSimple(Graph &G)
Removes all self-loops and all but one edge of each bundle of parallel edges.
NodeArray< node > closestSteinerAncestor
the highest-level Steiner ancestor of the current node
void addNewEdge(edge e, const std::vector< node > &replacedNodes, const std::vector< edge > &replacedEdges, bool deleteReplacedElements)
The function is called after a new edge is added to the copy graph during the reductions.
bool deleteLeaves()
Deletes the leaves of the graph.
List< node > m_copyTerminals
The reduced form of terminals.
bool valid() const
Is the current subset valid? If not, all subsets have already been enumerated.
A class used by the unordered_maps inside the reductions.
T makeMinimumSpanningTree(Graph &G, const EdgeArray< T > &weight)
Reduce a graph to its minimum spanning tree (MST) using Kruskal's algorithm.
void addNewNode(node v, const std::vector< node > &replacedNodes, const std::vector< edge > &replacedEdges, bool deleteReplacedElements)
Calls addNew() for a node.
node succ() const
Returns the successor in the list of all nodes.
void computeOptimalTerminals(node v, LAMBDA dist, node &optimalTerminal1, node &optimalTerminal2, NodeArray< T > &distance) const
Compute first and second best terminals according to function dist.
Defines a queue for handling prioritized elements.
Prioritized queue interface wrapper for heaps.
Compare floating point numbers with epsilons and integral numbers with normal compare operators...
std::unique_ptr< MinSteinerTreeModule< T > > m_costUpperBoundAlgorithm
Algorithm used for computing the upper bound for the cost of a minimum Steiner tree.
void popBack()
Removes the last element from the list.
ListIteratorBase< E, isConst > succ() const
Returns successor iterator.
bool nearestVertexTest()
Nearest vertex test using Voronoi regions [DV89, PV01].
bool longEdgesTest()
Long-Edges test from [DV89].
bool lowerBoundBasedEdgeTest()
Computes for each edge a lower bound of the cost of the minimum Steiner tree containing it...
std::enable_if< std::is_integral< T >::value, bool >::type less(const T &x, const T &y) const
Compare if x is LESS than y for integral types.
NodeArray< int > m_nodeSonsListIndex
It contains for each node an index i.
void del(iterator it)
Removes it from the list.
T weight(const edge e) const
const List< node > & getReducedTerminals() const
Returns the list of the terminals corresponding to the reduced graph.
NodeArray< int > chainOfNode
the index of a node's chain
node binarySearchUpmostTerminal(node v, const std::vector< node > &chainOfTerminals) const
performs a binary search on chainOfTerminals, searches for the closest node to the root on chainOfTer...
const List< node > & m_origTerminals
Const reference to the original list of terminals.
edge newEdge(node v, node w, T weight)
bool reduceFast()
Apply fast reductions iteratively (includes trivial reductions).
void append(const E &x)
Adds x at the end of queue.
void createEmpty(const Graph &wG)
T computeMinSteinerTreeUpperBound(EdgeWeightedGraphCopy< T > *&finalSteinerTree) const
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
const NodeArray< bool > & getReducedIsTerminal() const
Returns the NodeArray<bool> isTerminal corresponding to the reduced graph.
int numberOfEdges() const
Returns the number of edges in the graph.
Computes Voronoi regions in an edge weighted graph.
const E & topElement() const
Returns the topmost element in the queue.
A class used by the unordered_maps inside the reductions.
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
void deleteSteinerDegreeTwoNode(node v, const EdgeWeightedGraphCopy< T > &tprime, const HeavyPathDecomposition &tprimeHPD, const NodeArray< List< std::pair< node, T >>> &closestTerminals)
Deletes a node that is known to have degree 2 in at least one minimum Steiner tree.
EdgeWeightedGraph< T > m_copyGraph
Copy of the original graph; this copy will actually be reduced.
void begin(int low, int high)
Initialize the SubsetEnumerator to enumerate subsets of cardinalities from low to high...
void addToSolution(const int listIndex, Array< bool, int > &isInSolution) const
Helper method for computeOriginalSolution.
INDEX size() const
Returns the size (number of elements) of the array.
void computeRadiusOfTerminals(NodeArray< T > &terminalRadius) const
Compute radius of terminals.
const EdgeArray< T > & edgeWeights() const
bool terminalDistanceTest()
Simple terminal distance test [PV01].
void computeLongestDistToSteinerAncestorSegTree()
creates for every chain a segment tree built on a fictive array which keeps for every node the sum of...
std::vector< node > fatherOfChain
the first node from bottom up that does not belong to the chain
bool shortLinksTest()
Short links test using Voronoi regions [PV01].
Enumerator for k-subsets of a given type.
Doubly linked lists (maintaining the length of the list).
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
node seed(node v) const
Returns the Voronoi seed of node v.
T m_costAlreadyInserted
The cost of the already inserted in solution edges.
bool addEdgesToSolution(const List< edge > &edgesToBeAddedInSolution)
The function adds a set of edges in the solution.
bool PTmTest(const int k=3)
"Paths with many terminals" test, efficient on paths with many terminals.
void decrease(const E &element, const P &priority)
Decreases the priority of the given element.
void buildMaxSegmentTree(std::vector< T > &segmentTree, const int nodeIndex, const int left, const int right, const std::vector< T > &baseArray) const
builds a max segment tree on the baseArray
bool isLoopFree(const Graph &G)
Returns true iff G contains no self-loop.
bool NTDkTest(const int maxTestedDegree=5, const int k=3)
Non-terminals of degree k test [DV89, PV01].
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Class for the representation of edges.
NodeArray< int > positionOnChain
position of a node on his chain
bool reduceTrivial()
Apply trivial (hence amazingly fast) reductions iteratively, that is degree2Test(), makeSimple(), deleteLeaves().
NodeArray< int > weightOfSubtree
weight of the subtree rooted in one node
const EdgeWeightedGraphCopy< T > & tree
constant ref to the tree to be decomposed
T computeRadiusSum() const
Compute the sum of all radii except the two largest.
T distance(node v) const
Returns the distance between v and its Voronoi seed.
adjEntry lastAdj() const
Returns the last entry in the adjacency list.
Class for the representation of nodes.
void computeOriginalSolution(const EdgeWeightedGraphCopy< T > &reducedGraphSolution, EdgeWeightedGraphCopy< T > &correspondingOriginalSolution)
Computes the solution for the original graph, given a solution on the reduction.
Priority queue interface wrapping various heaps.
Encapsulates a pointer to a list element.
std::enable_if< std::is_integral< T >::value, bool >::type greater(const T &x, const T &y) const
Compare if x is GREATER than y for integral types.
bool reachabilityTest(int maxDegreeTest=0, const int k=3)
Performs a reachability test [DV89].
node opposite(node v) const
Returns the adjacent node different from v.
const NodeArray< bool > & m_origIsTerminal
Const reference to the original isTerminal.
NodeArray< T > distanceToRoot
the length of the edge to his father
void addNew(TWhat x, const std::vector< node > &replacedNodes, const std::vector< edge > &replacedEdges, bool deleteReplacedElements, TWhatArray &whatSonsListIndex)
Update internal data structures to let a (new) node or edge represent replaced nodes and/or edges...
const Graph & original() const
Returns a reference to the original graph.
bool degree2Test()
deletes degree-2 nodes and replaces them with one edge with the adjacent edges' sum ...
void floydWarshall(NodeArray< NodeArray< T >> &shortestPath) const
Applies the Floyd-Warshall algorithm on the m_copyGraph. The shortestPath matrix has to be already in...
This class implements the minimum Steiner tree 2-approximation algorithm by Takahashi and Matsuyama w...
NodeArray< bool > m_copyIsTerminal
The reduced form of isTerminal.
const EdgeWeightedGraph< T > & m_origGraph
Const reference to the original graph.
std::vector< std::vector< int > > m_sonsList
List with lists (corresponding to nodes and containing the indexes of their sons) ...
std::vector< std::vector< T > > longestDistToSteinerAncestorSegTree
segment tree for segment maxs on every chain
int index() const
Returns the (unique) node index.
EdgeArray< int > m_edgeSonsListIndex
See m_nodeSonsListIndex but for edges.
edge succ() const
Returns the successor in the list of all edges.
bool empty() const
Checks whether the queue is empty.
List< node > terminals
list of terminals of the desc tree
T getBottleneckSteinerDistance(node x, node y) const
computes in the bottleneck distance between terminals x and y
const NodeArray< bool > isTerminal
isTerminal of the desc tree
bool deleteComponentsWithoutTerminals()
Deletes connected components with no terminals.
void next()
Obtain the next subset if possible. The result should be checked using the valid() method...
adjEntry succ() const
Returns the successor in the adjacency list.
T computeMinSteinerTreeUpperBound() const
int size() const
Returns the number of elements in the list.
void computeBottleneckOnBranch(node x, node ancestor, T &longestPathDistance, T &fromLowestToAncestor) const
computes for the path from x to ancestor the maximum distance (sum of edges) between any two consecut...
bool makeSimple()
Deletes parallel edges keeping only the minimum cost one, and deletes self-loops. ...
iterator begin()
Returns an iterator to the first entry in the node array.
int maxNodeIndex() const
Returns the largest used node index.
HeavyPathDecomposition(const EdgeWeightedGraphCopy< T > &treeEWGraphCopy)
void recomputeTerminalsList()
Used by reductions to recompute the m_copyTerminals list, according to m_copyIsTerminal; useful when ...
EdgeWeightedGraphCopy< T > * initializeTPrime() const
bool contains(const E &element) const
Returns whether this queue contains that key.
node predecessor(node v) const
Returns the nearest node to v on the shortest path to its Voronoi seed.
node source() const
Returns the source node of the edge.
T solve(MinSteinerTreeModule< T > &mst, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
A shortcut to get the solution of a reduced instance.
bool cutReachabilityTest()
Performs a cut reachability test [DV89].
bool isSimple(const Graph &G)
Returns true iff G contains neither self-loops nor parallel edges.
int size() const
Return the cardinality of the subset.
NodeArray< int > nodeLevel
the level of a node in the tree
The namespace for all OGDF objects.
Implementation of Voronoi regions in an EdgeWeightedGraph.
Declaration and implementation of bounded queue class.
T getMaxSegmentTree(const std::vector< T > &segmentTree, const int nodeIndex, const int left, const int right, const int queryLeft, const int queryRight) const
extracts the maximum on the required interval
int maxEdgeIndex() const
Returns the largest used edge index.
std::enable_if< std::is_integral< T >::value, bool >::type geq(const T &x, const T &y) const
Compare if x is GEQ to y for integral types.
static void calculateCompleteGraph(const EdgeWeightedGraph< T > &wG, const List< node > &terminals, const Voronoi< T > &voronoi, EdgeArray< edge > &bridges, EdgeWeightedGraphCopy< T > &completeTerminalGraph)
Builds a complete terminal graph.
bool deleteEdgesAboveUpperBound(const EdgeArray< T > &lowerBoundWithEdge, const T upperBound)
Deletes the edges whose lowerBoundWithEdge exceeds upperBound.
int numberOfNodes() const
Returns the number of nodes in the graph.
Handle push(const E &element, const P &priority)
Pushes a new element with the respective priotiy to the queue.
node newNode()
Creates a new node and returns it.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
bool isConnected(const Graph &G)
Returns true iff G is connected.
int connectedComponents(const Graph &G, NodeArray< int > &component)
Computes the connected components of G.
void computeShortestPathMatrix(NodeArray< NodeArray< T >> &shortestPath) const
Computes the shortest path matrix corresponding to the m_copyGraph.
A class that allows to enumerate k-subsets of lists.
bool empty() const
Returns true iff the list is empty.
bool repeat(Fun f) const
Repeat a function until it returns false (used for iteratively applying reductions) ...
The parameterized class BoundedQueue implements queues with bounded size.
T distanceToAncestor(node v, node ancestor) const
computes the sum of all edges on the path from v to ancestor v must be in ancestor's subtree ...
Class for adjacency list elements.
void computeLongestDistToSteinerAncestorOnChain()
creates for every chain an array with the maximum of every prefix of a fictive array which keeps for ...
std::vector< std::vector< T > > longestDistToSteinerAncestorOnChain
the max of the interval 0..i for every i on chains
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
T computeBottleneckDistance(node x, node y, const EdgeWeightedGraphCopy< T > &tprime, const HeavyPathDecomposition &tprimeHPD, const NodeArray< List< std::pair< node, T >>> &closestTerminals) const
Heuristic computation [PV01] of the bottleneck Steiner distance between two nodes in a graph...
T weight(const edge e) const
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.