38 namespace steiner_tree {
40 #define OGDF_FULLCOMPONENTSTORE_REMOVE_IN_GRAPH_REPRESENTATION_ALSO // unnecessary but may save memory 43 template<
typename T,
typename ExtraDataType =
void>
55 template<
class Y,
class Enable =
void>
84 while (
m_nodeCopy[uO] ==
nullptr && !m_isTerminal[uO]) {
88 edge e2 = adj->theEdge();
98 for (
node v : nonterminals) {
99 for (
adjEntry adj : comp.
copy(m_nodeOrig[v])->adjEntries) {
100 edge e = adj->theEdge();
112 if (m_isTerminal[uO]) {
130 T weight = comp.
weight(e);
133 if (m_isTerminal[uO]) {
136 if (m_isTerminal[vO]) {
145 , m_terminals(terminals)
146 , m_isTerminal(isTerminal)
148 , m_nodeOrig(m_graph)
150 for (
node v : m_terminals) {
168 Metadata<ExtraDataType> data;
169 bool existNoncritical =
false;
178 nonterminals.push(vC);
180 existNoncritical =
true;
183 data.terminals.
grow(1, vO);
190 if (existNoncritical) {
191 if (nonterminals.empty()) {
195 data.cost += comp.
weight(e);
208 for (
node vC : nonterminals) {
212 m_components.
push(data);
218 #ifdef OGDF_FULLCOMPONENTSTORE_REMOVE_IN_GRAPH_REPRESENTATION_ALSO 219 auto &comp = m_components[id];
220 if (comp.terminals.size() == 2) {
221 m_graph.
delEdge(comp.start->theEdge());
224 stack.
push(comp.start->twinNode());
225 m_graph.
delEdge(comp.start->theEdge());
226 while (!stack.empty()) {
227 const node v = stack.popRet();
237 if (m_components.
size() ==
id + 1) {
240 m_components[id] = m_components.
popRet();
247 return m_components.
size();
253 return m_components.
empty();
261 return m_components[id].terminals;
269 return m_components[id].terminals.
linearSearch(t) != -1;
274 return m_isTerminal[m_nodeOrig[v]];
282 return m_components[i].cost;
289 return m_components[i].start;
300 return m_nodeOrig[v];
303 template<
typename Fun>
307 int size = m_components[i].terminals.
size();
315 while (!stack.
empty()) {
327 template<
typename Fun>
337 template<
typename Fun>
349 template<
typename Fun>
361 v = pred[u][v]->opposite(v);
380 template<
typename T,
typename ExtraDataType>
395 const ExtraDataType &
extra(
int i)
const 431 if (!m_lossTerminal[u]
433 m_lossTerminal[u] = findLossTerminal(pred[u]->opposite(u), pred);
436 return m_lossTerminal[u];
452 m_lossTerminal[sC] = s;
456 m_lossTerminal[vC] = v;
466 for (
edge e : zeroEdges) {
471 for (
int id = 0;
id < this->
size(); ++id) {
474 if (!isLossEdge[e]) {
475 this->extra(
id).bridges.pushBack(e);
476 findLossTerminal(e->source(), pred);
477 findLossTerminal(e->target(), pred);
479 this->extra(
id).loss += this->
m_graph.weight(e);
488 return this->extra(
id).loss;
494 return this->extra(
id).bridges;
506 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
void traverseOverDegree2Nonterminals(node &uO, T &weight, EdgeArray< bool > &marked, adjEntry adj, const EdgeWeightedGraphCopy< T > &comp) const
Traverse over degree-2 nonterminals.
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.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
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.
int degree() const
Returns the degree of the node (indegree + outdegree).
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.
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).
void insert(const EdgeWeightedGraphCopy< T > &comp)
Inserts a component. Note that comp is copied and degree-2 nodes are removed.
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.
void copyEdgesWithSimplifiedPaths(Metadata< ExtraDataType > &data, const EdgeWeightedGraphCopy< T > &comp, const ArrayBuffer< node > &nonterminals)
Copy edges from comp into our representation, traversing variant to ignore degree-2 nodes...
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
E popRet()
Removes the newest element from the buffer and returns it.
int index() const
Returns the (unique) node index.
bool isEmpty() const
Checks if the store does not contain any full components.
bool isTerminal(node v) const
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 copyEdges(Metadata< ExtraDataType > &data, const EdgeWeightedGraphCopy< T > &comp)
Copy edges from comp into our representation.
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.
Compare elements based on a single comparable attribute.
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.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
T weight(const edge e) const
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.