File: DynamicBCTree.h

package info (click to toggle)
tulip 4.8.0dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 179,264 kB
  • ctags: 64,517
  • sloc: cpp: 600,444; ansic: 36,311; makefile: 22,136; python: 1,304; sh: 946; yacc: 522; xml: 337; pascal: 157; php: 66; lex: 55
file content (326 lines) | stat: -rw-r--r-- 13,673 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
 * $Revision: 2584 $
 *
 * last checkin:
 *   $Author: gutwenger $
 *   $Date: 2012-07-12 02:38:07 +0200 (Thu, 12 Jul 2012) $
 ***************************************************************/

/** \file
 * \brief Declaration of class DynamicBCTree
 *
 * \author Jan Papenfuß
 *
 * \par License:
 * This file is part of the Open Graph Drawing Framework (OGDF).
 *
 * \par
 * Copyright (C)<br>
 * See README.txt in the root directory of the OGDF installation for details.
 *
 * \par
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * Version 2 or 3 as published by the Free Software Foundation;
 * see the file LICENSE.txt included in the packaging of this file
 * for details.
 *
 * \par
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * \par
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * \see  http://www.gnu.org/copyleft/gpl.html
 ***************************************************************/


#ifdef _MSC_VER
#pragma once
#endif

#ifndef OGDF_DYNAMIC_BC_TREE_H
#define OGDF_DYNAMIC_BC_TREE_H

#include <ogdf/decomposition/BCTree.h>

namespace ogdf {

/**
 * \brief Dynamic BC-trees.
 *
 * This class provides dynamic BC-trees.\n
 * The main difference of the dynamic BC-tree structure compared to the static
 * one implemented by the class BCTree is, that B- and C-components are not any
 * longer represented by single vertices of a BC-tree graph structure but by
 * root vertices of UNION/FIND-trees. This allows path condensation within the
 * BC-tree, when edges are inserted into the original graph. Path condensation
 * is done by gathering BC-tree-vertices into a UNION/FIND-tree. However, the
 * original vertices of the BC-tree remain in the \e m_B graph, but only those
 * being the roots of their respective UNION/FIND-tree are proper representants
 * of the biconnected components of the original graph.
 */
class OGDF_EXPORT DynamicBCTree : public BCTree {

friend class PlanarAugmentation;
friend class PlanarAugmentationFix;

protected:

/**
 * \brief Array that contains for each BC-tree-vertex its parent in its
 * UNION/FIND-tree structure.
 *
 * For each vertex \e vB of the BC-tree structure:
 * - If \e vB is representing a biconnected component, then
 *   m_bNode_owner[\e vB] points to the vertex \e vB itself.
 * - If \e vB is not any longer representing a biconnected component due to
 *   path condensation, then m_bNode_owner[\e vB] points to the parent of \e vB
 *   in its UNION/FIND-tree.
 */
	mutable NodeArray<node> m_bNode_owner;
/**
 * \brief Array that contains for each proper BC-tree-vertex its degree.
 *
 * For each vertex \e vB of the BC-tree structure:
 * - If \e vB is representing a biconnected component, then
 *   m_bNode_degree[\e vB] is the degree of the vertex of the BC-tree.
 * - If \e vB is not any longer representing a biconnected component due to
 *   path condensation, then m_bNode_degree[\e vB] is undefined.
 * This array is necessary, because the edges of the BC-tree are not updated
 * during path condensation for efficiency reasons. Thus, <em>vB</em>->degree()
 * != m_bNode_degree[\e vB]
 */
	NodeArray<int> m_bNode_degree;

/** @{
 * \brief Initialization of \e m_bNode_owner and \e m_bNode_degree.
 */
	void init ();

/** @} @{
 * \brief The UNION function of the UNION/FIND structure.
 * \param uB is a vertex of the BC-tree representing a B-component.
 * \param vB is a vertex of the BC-tree representing a C-component.
 * \param wB is a vertex of the BC-tree representing a B-component.
 * \pre \a uB and \a vB and \a wB have to be proper representants of their
 * B-components, i.e. they have to be the root vertices of their respective
 * UNION/FIND-trees.
 * \pre \a uB and \a wB have to be adjacent to \a vB.
 * \return the vertex properly representing the condensed B-component.
 */
	node unite (node uB, node vB, node wB);
/**
 * \brief The FIND function of the UNION/FIND structure.
 * \param vB is any vertex of \e m_B.
 * \return the owner of \a vB properly representing a biconnected component,
 * i.e. the root of the UNION/FIND-tree of \a vB.
 */
	node find (node vB) const;

/** @} @{
 * \brief returns the parent of a given BC-tree-vertex.
 * \param vB is any vertex of \e m_B or \e NULL.
 * \return the parent of \a vB in the BC-tree structure, if \a vB is not the
 * root of the BC-tree, and \e NULL, if \a vB is \e NULL or the root of the
 * BC-tree. The UNION/FIND-tree structures are considered.
 */
	node parent (node vB) const;
/**
 * \brief performs path condensation.
 *
 * This member function condenses the path from bcproper(\a sG) to
 * bcproper(\a tG) in the BC-tree into one single B-component by calling
 * findPath() and subsequently unite().
 * \param sG is a vertex of the original graph.
 * \param tG is a vertex of the original graph.
 * \return the proper representant of the resulting B-component.
 */
	node condensePath (node sG, node tG);

public:

/** @} @{
 * \brief A constructor.
 *
 * This constructor does only call BCTree::BCTree() and DynamicBCTree::init().
 * DynamicBCTree(\a G) is equivalent to DynamicBCTree(<em>G</em>,
 * <em>G</em>.firstNode()).
 * \param G is the original graph.
 * \param callInitConnected decides which init is called, default call is init().
 */
	DynamicBCTree (Graph& G, bool callInitConnected = false) : BCTree(G, callInitConnected) { init(); }
/**
 * \brief A constructor.
 *
 * This constructor does only call BCTree::BCTree() and DynamicBCTree::init().
 * \param G is the original graph.
 * \param vG is the vertex of the original graph which the DFS algorithm starts with.
 * \param callInitConnected decides which init is called, default call is init().
 */
	DynamicBCTree (Graph& G, node vG, bool callInitConnected = false) : BCTree(G,vG, callInitConnected) { init(); }

/** @} @{
 * \brief returns a BC-tree-vertex representing a biconnected component which a
 * given vertex of the original graph is belonging to.
 * \param vG is a vertex of the original graph.
 * \return a vertex of the BC-tree:
 * - If \a vG is not a cut-vertex, then typeOfGNode(\a vG) returns the very
 *   vertex of the BC-tree representing the unambiguous B-component which \a vG
 *   is belonging to.
 * - If \a vG is a cut-vertex, then typeOfGNode(\a vG) returns the very vertex
 *   of the BC-tree representing the unambiguous C-component which \a vG is
 *   belonging to.
 *
 * The difference between BCTree::bcproper() and DynamicBCTree::bcproper() is,
 * that the latter one considers the UNION/FIND-tree structures.
 */
	node bcproper (node vG) const;
/**
 * \brief returns the BC-tree-vertex representing the biconnected component
 * which a given edge of the original graph is belonging to.
 * \param eG is an edge of the original graph.
 * \return the vertex of the BC-tree representing the B-component which \a eG
 * is belonging to.
 *
 * The difference between BCTree::bcproper() and DynamicBCTree::bcproper() is,
 * that the latter one considers the UNION/FIND-tree structures.
 */
	node bcproper (edge eG) const;

/** @} @{
 * \brief returns a vertex of the biconnected components graph corresponding to
 * a given vertex of the original graph and belonging to the representation of
 * a certain biconnected component given by a vertex of the BC-tree.
 * \param uG is a vertex of the original graph.
 * \param vB is any vertex of \e m_B.
 * \return a vertex of the biconnected components graph:
 * - If \a uG is belonging to the biconnected component represented by \a vB,
 *   then rep(\a uG,\a vB) returns the very vertex of the biconnected
 *   components graph corresponding to \a uG within the representation of
 *   \a vB.
 * - Otherwise, \e NULL is returned.
 *
 * The difference between BCTree::repVertex() and DynamicBCTree::repVertex()
 * is, that the latter one considers the UNION/FIND-tree structures.
 */
	node repVertex (node uG, node vB) const { return BCTree::repVertex(uG,find(vB)); }
/**
 * \brief returns the copy of a cut-vertex in the biconnected components graph
 * which belongs to a certain B-component and leads to another B-component.
 *
 * If two BC-tree-vertices are neighbours, then the biconnected components
 * represented by them have exactly one cut-vertex in common. But there are
 * several copies of this cut-vertex in the biconnected components graph,
 * namely one copy for each biconnected component which the cut-vertex is
 * belonging to. The member function rep() had been designed for returning the
 * very copy of the cut-vertex belonging to the copy of the unambiguous
 * C-component which it is belonging to, whereas this member function is
 * designed to return the very copy of the cut-vertex connecting two
 * biconnected components which belongs to the copy of the second one.
 * \param uB is any vertex of \e m_B.
 * \param vB is any vertex of \e m_B.
 * \return a vertex of the biconnected components graph:
 * - If \a uB == \a vB and they are representing a B-component, then
 *   cutVertex(\a uB,\a vB) returns \e NULL.
 * - If \a uB == \a vB and they are representing a C-component, then
 *   cutVertex(\a uB,\a vB) returns the single isolated vertex in the
 *   biconnected components graph which is the copy of the C-component.
 * - If \a uB and \a vB are \e neighbours in the BC-tree, then there exists
 *   a cut-vertex leading from the biconnected component represented by \a vB
 *   to the biconnected component represented by \a uB. cutVertex(\a uB,\a vB)
 *   returns the very copy of this vertex within the biconnected components
 *   graph which belongs to the copy of the biconnected component represented
 *   by \a vB.
 * - Otherwise, cutVertex(\a uB,\a vB) returns \e NULL.
 *
 * The difference between BCTree::cutVertex() and DynamicBCTree::cutVertex()
 * is, that the latter one considers the UNION/FIND-tree structures.
 */
	node cutVertex (node uB, node vB) const { return BCTree::cutVertex(find(uB),find(vB)); }

/** @} @{
 * \brief Update of the dynamic BC-tree after edge insertion into the original
 * graph.
 *
 * This member function performs on-line maintenance of the dynamic BC-tree
 * according to J. Westbrook and R. E. Tarjan, Maintaining Bridge-Connected and
 * Biconnected Components On-Line, Algorithmica (1992) 7:433-464.
 * \param eG is a newly inserted edge of the original graph.
 *
 * After a new edge has been inserted into the original graph by calling
 * Graph::newEdge(), this member function updates the corresponding BC-tree in
 * \f$O(\alpha(k,n))\f$ amortized time and the coponents graph in
 * \f$O(1 + n/k)\f$ amortized time per insertEdge() operation, where k is the
 * number of such operations.
 * \return the new edge of the original graph.
 */
	virtual edge updateInsertedEdge (edge eG);
/**
 * \brief Update of the dynamic BC-tree after vertex insertion into the
 * original graph.
 *
 * This member function performs on-line maintenance of the dynamic BC-tree
 * according to J. Westbrook and R. E. Tarjan, Maintaining Bridge-Connected and
 * Biconnected Components On-Line, Algorithmica (1992) 7:433-464.
 * \param eG is the incoming edge of the newly inserted vertex which has been
 * generated by a Graph::split() operation.
 * \param fG is the outgoing edge of the newly inserted vertex which has been
 * generated by a Graph::split() operation.
 *
 * After a new vertex has been inserted into an edge of the original graph by
 * splitting the edge, all data structures of the DynamicBCTree class are
 * updated by this member funtion. It takes \f$O(1)\f$ time.
 * \return the new vertex of the original graph.
 */
	virtual node updateInsertedNode (edge eG, edge fG);

/**
 * \brief inserts a new edge into the original graph and updates the BC-tree.
 *
 * This member function inserts a new edge between \a sG and \a tG into the
 * original graph and then calls updateInsertedEdge().
 * \param sG is a vertex of the original graph.
 * \param tG is a vertex of the original graph.
 * \return the new edge of the original graph.
 */
	edge insertEdge (node sG, node tG) { return updateInsertedEdge(m_G.newEdge(sG,tG)); }
/**
 * \brief inserts a new vertex into the original graph and updates the BC-tree.
 *
 * This member function inserts a new vertex into the original graph by
 * splitting the edge \a eG and then calls updateInsertedNode().
 * \param eG is an edge of the original graph.
 * \return the new vertex of the original graph.
 */
	node insertNode (edge eG) { return updateInsertedNode(eG,m_G.split(eG)); }

/** @} @{
 * \brief returns the BC-tree-vertex representing the B-component which two
 * given vertices of the original graph are belonging to.
 * \param uG is a vertex of the original graph.
 * \param vG is a vertex of the original graph.
 * \return If \a uG and \a vG are belonging to the same B-component, the very
 * vertex of the BC-tree representing this B-component is returned. Otherwise,
 * \e NULL is returned. This member function returns the representant of the
 * correct B-component even if \a uG or \a vG or either are cut-vertices and
 * are therefore belonging to C-components, too.
 *
 * The difference between BCTree::bComponent() and DynamicBCTree::bComponent()
 * is, that the latter one considers the UNION/FIND-tree structures.
 */
node bComponent (node uG, node vG) const;

/** @}
 */
};

}

#endif