41 namespace steiner_tree {
43 #define OGDF_FULLCOMPONENTSTORE_REMOVE_IN_GRAPH_REPRESENTATION_ALSO // unnecessary but may save memory 48 template<
typename T,
typename ExtraDataType =
void>
60 template<
class Y,
class Enable =
void>
90 , m_terminals(terminals)
91 , m_isTerminal(isTerminal)
95 for (
node v : m_terminals) {
112 Metadata<ExtraDataType> data;
121 data.terminals.
grow(1, vO);
132 T weight = comp.
weight(e);
135 if (m_isTerminal[uO]) {
138 if (m_isTerminal[vO]) {
144 for (
node vO : tempUse) {
148 m_components.
push(data);
153 #ifdef OGDF_FULLCOMPONENTSTORE_REMOVE_IN_GRAPH_REPRESENTATION_ALSO 155 auto &comp = m_components[id];
156 if (comp.terminals.size() == 2) {
157 m_graph.
delEdge(comp.start->theEdge());
160 stack.
push(comp.start->twinNode());
161 m_graph.
delEdge(comp.start->theEdge());
162 while (!stack.empty()) {
163 const node v = stack.pop();
173 if (m_components.
size() ==
id + 1) {
176 m_components[id] = m_components.
popRet();
183 return m_components.
size();
189 return m_components.
empty();
197 return m_components[id].terminals;
205 return m_components[id].terminals.
linearSearch(t) != -1;
210 return m_isTerminal[m_nodeOrig[v]];
218 return m_components[i].cost;
225 return m_components[i].start;
236 return m_nodeOrig[v];
239 template<
typename Fun>
243 int size = m_components[i].terminals.
size();
251 while (!stack.
empty()) {
263 template<
typename Fun>
273 template<
typename Fun>
285 template<
typename Fun>
297 v = pred[u][v]->opposite(v);
316 template<
typename T,
typename ExtraDataType>
331 const ExtraDataType &
extra(
int i)
const 367 if (!m_lossTerminal[u]
369 m_lossTerminal[u] = findLossTerminal(pred[u]->opposite(u), pred);
372 return m_lossTerminal[u];
388 m_lossTerminal[sC] = s;
392 m_lossTerminal[vC] = v;
402 for (
edge e : zeroEdges) {
407 for (
int id = 0;
id < this->
size(); ++id) {
410 if (!isLossEdge[e]) {
411 this->extra(
id).bridges.pushBack(e);
412 findLossTerminal(e->source(), pred);
413 findLossTerminal(e->target(), pred);
415 this->extra(
id).loss += this->
m_graph.weight(e);
424 return this->extra(
id).loss;
430 return this->extra(
id).bridges;
442 return m_lossTerminal[v];
node target() const
Returns the target node of the edge.
ArrayBuffer< Metadata< ExtraDataType > > m_components
List of full components (based on metadata)
void foreachEdge(int id, const NodeArray< NodeArray< edge >> &pred, Fun f) const
INDEX linearSearch(const E &x) const
Performs a linear search for element x.
edge theEdge() const
Returns the edge associated with this adjacency entry.
void pop()
Removes the newest element from the buffer.
const List< edge > & lossBridges(int id) const
Returns a list of non-loss edges (that are bridges between the Loss components) of full component wit...
iterator pushBack(const E &x)
Adds element x at the end of the list.
virtual void delNode(node v)
Removes node v and all incident edges from the graph.
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
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.
NodeArray< node > m_nodeOrig
Mapping of m_graph nodes to original nodes.
const Array< node > & terminals(int id) const
Returns the list of terminals in the full component with given id.
virtual void delEdge(edge e)
Removes edge e from the graph.
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...
Extends the GraphCopy concept to weighted graphs.
const List< node > & m_terminals
The terminal list of the original Steiner instance.
Declaration and implementation of bounded stack class.
void quicksort()
Sorts buffer using Quicksort.
node lossTerminal(node v) const
Returns the terminal (in the original graph) that belongs to a given node v (in the store) according ...
void computeAllLosses()
Compute the loss, both edge set and value, of all full components.
adjEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
bool isTerminal(int id, node t) const
checks if a given node t is a terminal in the full component with given id
NodeArray< node > m_nodeCopy
Mapping of original terminals to m_graph nodes.
EdgeWeightedGraph< T > m_graph
Our graph representation for the full component store.
edge newEdge(node v, node w, T weight)
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
bool empty() const
Returns true if the buffer is empty, false otherwise.
INDEX size() const
Returns the size (number of elements) of the array.
A data structure to store full components.
Doubly linked lists (maintaining the length of the list).
The parameterized class BoundedStack implements stacks with bounded size.
void insert(const EdgeWeightedGraphCopy< T > &comp)
void grow(INDEX add, const E &x)
Enlarges the array by add elements and sets new elements to x.
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.
A data structure to store full components with additional "loss" functionality.
node findLossTerminal(const node u, const NodeArray< edge > &pred)
Starting from a Steiner node find the nearest terminal along a shortest path.
Class for the representation of nodes.
bool valid() const
Returns true iff the array is associated with a graph.
Declaration and implementation of NodeArray class.
node original(node v) const
Encapsulates a pointer to a list element.
INDEX size() const
Returns number of elements in the buffer.
const Graph & original() const
Returns a reference to the original graph.
void foreachNode(int id, const NodeArray< NodeArray< edge >> &pred, Fun f) const
The IndexComparer compares entities like nodes, edges, adjacency entries, based on their index...
E popRet()
Removes the newest element from the buffer and returns it.
IndexComparer definition.
bool isEmpty() const
Checks if the store does not contain any full components.
bool isTerminal(node v) const
E pop()
Removes the top-most element from the stack and returns it.
NodeArray< node > m_lossTerminal
Indicates which Steiner node is connected to which terminal through the loss edges, indexed by the Steiner node.
FullComponentStore(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal)
T loss(int id) const
Returns the loss value of full component with given id.
adjEntry start(int i) const
bool isTree(const Graph &G)
Returns true iff G is a tree, i.e. contains no undirected cycle and is connected. ...
const EdgeWeightedGraph< T > & m_originalGraph
The original Steiner instance.
node source() const
Returns the source node of the edge.
const NodeArray< bool > & m_isTerminal
Incidence vector for terminal nodes.
const EdgeWeightedGraph< T > & graph() const
The namespace for all OGDF objects.
T cost(int i) const
Returns the sum of edge costs of this full component.
void foreachAdjEntry(int i, Fun f) const
int numberOfNodes() const
Returns the number of nodes in the graph.
int size() const
Returns the number of full components in the store.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
void foreachNode(int id, Fun f) const
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
bool empty() const
Returns true iff the graph is empty, i.e., contains no nodes.
node theNode() const
Returns the node whose adjacency list contains this element.
Class for adjacency list elements.
bool empty()
Returns true iff the stack is empty.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
void push(const E &x)
Adds element x as top-most element to the stack.
T weight(const edge e) const
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.