45class EdgeWeightedGraphCopy;
47namespace steiner_tree {
60 std::vector<std::vector<node>>
chains;
78 const int right,
const std::vector<T>& baseArray)
const {
80 segmentTree[nodeIndex] = baseArray[left];
84 int middle = (left + right) >> 1;
85 int leftNodeIndex = nodeIndex + nodeIndex + 1;
86 int rightNodeIndex = leftNodeIndex + 1;
91 segmentTree[nodeIndex] = max(segmentTree[leftNodeIndex], segmentTree[rightNodeIndex]);
99 const int right,
const int queryLeft,
const int queryRight)
const {
100 if (queryLeft > queryRight || left > queryRight || queryLeft > right) {
104 if (queryLeft <= left && right <= queryRight) {
105 return segmentTree[nodeIndex];
108 int middleIndex = (left + right) >> 1;
109 int leftNodeIndex = nodeIndex + nodeIndex + 1;
110 int rightNodeIndex = leftNodeIndex + 1;
113 if (queryLeft <= middleIndex) {
118 if (queryRight > middleIndex) {
121 queryLeft, queryRight));
132 if (ancestor ==
nullptr) {
145 for (
int i = 0; i < (int)
chains.size(); ++i) {
147 for (
int j = 0; j < (int)
chains[i].size(); ++j) {
165 for (
int i = 0; i < (int)
chains.size(); ++i) {
168 std::vector<T> distanceToSteinerAncestor_byPosition;
169 distanceToSteinerAncestor_byPosition.resize(
chains[i].size());
170 for (
int j = 0; j < (int)
chains[i].size(); ++j) {
171 distanceToSteinerAncestor_byPosition[j] =
176 (
int)
chains[i].size() - 1, distanceToSteinerAncestor_byPosition);
186 node heaviestSon =
nullptr;
190 edge e = adj->theEdge();
191 node son = adj->twinNode();
209 if (heaviestSon ==
nullptr) {
212 std::vector<node> new_chain;
213 chains.push_back(new_chain);
233 int left = 0, middle, right = (int)chainOfTerminals.size() - 1;
234 while (left <= right) {
235 middle = (left + right) >> 1;
244 if (left == (
int)chainOfTerminals.size()) {
247 return chainOfTerminals[left];
260 T& fromLowestToAncestor)
const {
261 node upmostTerminal = x;
276 node upmostTerminalLastChain =
279 upmostTerminalLastChain =
nullptr;
281 if (upmostTerminalLastChain !=
nullptr) {
282 upmostTerminal = upmostTerminalLastChain;
285 if (upmostTerminalLastChain !=
nullptr) {
297 :
tree {treeEWGraphCopy}
311 int numberOfChains =
static_cast<int>(
chains.size());
312 for (
int i = 0; i < numberOfChains; ++i) {
337 if (xlevelOfFatherOfChain >= ylevelOfFatherOfChain) {
355 T xLongestPathDistance = 0, yLongestPathDistance = 0;
356 T xFromLowestToLCA = 0, yFromLowestToLCA = 0;
362 T maxValue = max(xLongestPathDistance, yLongestPathDistance);
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Declaration of doubly linked lists and iterators.
Basic declarations, included by all source files.
Class for adjacency list elements.
Class for the representation of edges.
Doubly linked lists (maintaining the length of the list).
Class for the representation of nodes.
int degree() const
Returns the degree of the node (indegree + outdegree).
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
RegisteredArray for nodes, edges and adjEntries of a graph.
An implementation of the heavy path decomposition on trees.
List< node > terminals
list of terminals of the desc tree
NodeArray< int > chainOfNode
the index of a node's chain
NodeArray< int > nodeLevel
the level of a node in the tree
NodeArray< int > positionOnChain
position of a node on his chain
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
std::vector< node > fatherOfChain
the first node from bottom up that does not belong to the chain
std::vector< std::vector< T > > longestDistToSteinerAncestorOnChain
the max of the interval 0..i for every i on chains
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...
std::vector< std::vector< node > > chains
list of chains of nodes corresponding to the decomposition
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
std::vector< std::vector< node > > chainsOfTerminals
list of chains only of terminals corresponding to the decomposition
NodeArray< T > distanceToRoot
the length of the edge to his father
const EdgeWeightedGraphCopy< T > & tree
constant ref to the tree to be decomposed
NodeArray< node > closestSteinerAncestor
the highest-level Steiner ancestor of the current node
void dfsHeavyPathDecomposition(node v, node closestSteinerUpNode)
performs the heavy path decomposition on the tree belonging to the class updates the fields of the cl...
node lowestCommonAncestor(node x, node y) const
computes the lowest common ancestor of nodes x and y using the hpd
T getBottleneckSteinerDistance(node x, node y) const
computes in the bottleneck distance between terminals x and y
HeavyPathDecomposition(const EdgeWeightedGraphCopy< T > &treeEWGraphCopy)
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
const NodeArray< bool > isTerminal
isTerminal of the desc tree
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 > > longestDistToSteinerAncestorSegTree
segment tree for segment maxs on every chain
NodeArray< int > weightOfSubtree
weight of the subtree rooted in one node
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...
void computeLongestDistToSteinerAncestorSegTree()
creates for every chain a segment tree built on a fictive array which keeps for every node the sum of...
Reverse< T > reverse(T &container)
Provides iterators for container to make it easily iterable in reverse.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
void updateMax(T &max, const T &newValue)
Stores the maximum of max and newValue in max.
The namespace for all OGDF objects.
HypergraphRegistry< HypernodeElement >::iterator begin(const HypergraphRegistry< HypernodeElement > &self)
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)