40 namespace steiner_tree {
59 : terminal(t), cutIterators(graph, nullptr), inCut(graph, false) {}
74 for (;
it != m_terminals.
end(); ++
it) {
75 if ((*it).cut.size() < (*bestIt).cut.size()) {
91 td.
references.push({t, m_inTerminalCut[t].pushBack(it)});
96 if (m_eps.
equal(m_reducedCost[adj], T(0))) {
111 if (cutAdjIt != td.
cut.end()) {
112 td.
cut.del(cutAdjIt);
122 if (!(*it).inCut[w]) {
131 for (
auto ref : (*it).references) {
132 m_inTerminalCut[ref.v].del(ref.it);
146 node v = adj->theNode();
147 node w = adj->twinNode();
148 for (
auto it = m_inTerminalCut[v].begin();
it.valid();) {
163 T cost = std::numeric_limits<T>::max();
176 m_reducedCost[adj] -= delta;
178 if (m_eps.
leq(m_reducedCost[adj], T(0))) {
197 m_reducedCost(m_graph),
198 m_inTerminalCut(m_graph) {
204 for (
node t : terminals) {
223 while (!m_terminals.
empty()) {
233 return m_reducedCost[adj];
253 int m_repetitions = 1;
282 orig[uv] = orig[vu] = e;
289 sssp.
call(network, weights, copy[root], pred, distance,
true);
292 lbNodes.
init(graph, alg.
get());
293 lbEdges.
init(graph, alg.
get());
298 lbNodes[
v] += distance[copy[
v]];
302 lbArcs[a] += distance[a->
source()] + weights[a];
310 for (
node t : terminals) {
315 sssp.
call(network, weights, nonRootTerminals, pred, distance,
true);
319 lbNodes[
v] += distance[copy[
v]];
323 lbArcs[a] += distance[a->
source()];
340 for (
node root : terminals) {
342 if (++i >= m_repetitions) {
354 if (m_repetitions <= 1) {
356 compute(graph, terminals, terminals.
front(), lbNodes, lbEdges);
358 lbNodes.
init(graph, 0);
359 lbEdges.
init(graph, 0);
361 for (
node root : terminals) {
364 compute(graph, terminals, root, nodes, edges);
371 if (++i >= m_repetitions) {
node target() const
Returns the target node of the edge.
void compute()
Computes the lower bound.
T call(const EdgeWeightedGraph< T > &graph, const List< node > &terminals)
Calls the algorithm and returns the lower bound.
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.
Dijkstra's single source shortest path algorithm.
Implementation of a dual-ascent-based lower bound heuristic for Steiner tree problems.
void init()
Reinitializes the array. Associates the array with no graph.
std::enable_if< std::is_integral< T >::value, bool >::type equal(const T &x, const T &y) const
Compare if x is EQUAL to y for integral types.
iterator pushBack(const E &x)
Adds element x at the end of the list.
Data type for general directed graphs (adjacency list representation).
AdjEntryArray< T > m_reducedCost
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
void init()
Reinitializes the array. Associates the array with no graph.
void removeTerminalData(ListIterator< TerminalData > it)
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...
iterator begin()
Returns an iterator to the first element of the list.
void push(E e)
Puts a new element in the buffer.
An array that keeps track of the number of inserted elements; also usable as an efficient stack...
Dynamic arrays indexed with adjacency entries.
Dynamic arrays indexed with edges.
bool addNode(ListIterator< TerminalData > &it, node t)
Adds a node to the cut and add neighbors recursively.
bool addNodeChecked(ListIterator< TerminalData > &it, node w)
Compare floating point numbers with epsilons and integral numbers with normal compare operators...
List< TerminalData > m_terminals
LowerBoundDualAscent(const EdgeWeightedGraph< T > &graph, const List< node > &terminals, double eps=1e-6)
Initializes the algorithm (and takes the first terminal as root)
void del(iterator it)
Removes it from the list.
T weight(const edge e) const
const EdgeWeightedGraph< T > & m_graph
T compute(const EdgeWeightedGraph< T > &graph, const List< node > &terminals, node root)
void updateMin(T &min, const T &newValue)
Stores the minimum of min and newValue in min.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Implementation of Dijkstra's single source shortest path algorithm.
NodeArray< List< ListIterator< TerminalData > > > m_inTerminalCut
Mapping of nodes to the cuts they are in.
T get() const
Returns the lower bound.
static void copy(const T &from, T &to)
const_reference front() const
Returns a const reference to the first element.
void extendCut(adjEntry adj)
Assumes that the reduced cost of arc adj is zeroed and hence updates (in relevant cuts) the set of ar...
Doubly linked lists (maintaining the length of the list).
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
iterator end()
Returns an iterator to one-past-last element of the list.
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Class for the representation of edges.
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Declaration of class EdgeWeightedGraph.
LowerBoundDualAscent(const EdgeWeightedGraph< T > &graph, const List< node > &terminals, node root, double eps=1e-6)
Initializes the algorithm.
void call(const EdgeWeightedGraph< T > &graph, const List< node > &terminals, NodeArray< T > &lbNodes, EdgeArray< T > &lbEdges)
Compute the lower bounds under the assumption nodes or edges are included in the solution.
ListIterator< ListIterator< TerminalData > > it
void setRepetitions(int num)
Sets the number of repeated calls to the lower bound algorithm (runs with different roots) ...
Class for the representation of nodes.
Encapsulates a pointer to a list element.
void update(TerminalData &td, T delta)
Updates reduced costs and cut data.
void compute(const EdgeWeightedGraph< T > &graph, const List< node > &terminals, node root, NodeArray< T > &lbNodes, EdgeArray< T > &lbEdges)
TerminalData(const EdgeWeightedGraph< T > &graph, node t)
T reducedCost(adjEntry adj) const
Returns the reduced cost of the arc given by adj.
AdjEntryArray< ListIterator< adjEntry > > cutIterators
node source() const
Returns the source node of the edge.
The namespace for all OGDF objects.
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.
T findCheapestCutArcCost(const TerminalData &td) const
Finds the cheapest arc in cut and returns its cost.
void reverseAllEdges()
Reverses all edges in the graph.
node newNode()
Creates a new node and returns it.
void updateMax(T &max, const T &newValue)
Stores the maximum of max and newValue in max.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
bool isConnected(const Graph &G)
Returns true iff G is connected.
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
bool empty() const
Returns true iff the list is empty.
Class for adjacency list elements.
ListIterator< TerminalData > chooseTerminal()
Finds the terminal with the smallest cut arc set (of the last iteration)
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Computes lower bounds for minimum Steiner tree instances.
ArrayBuffer< TerminalDataReference > references
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.