forked from johannesgerer/jburkardt-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
treepack.html
359 lines (324 loc) · 10.4 KB
/
treepack.html
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<html>
<head>
<title>
TREEPACK - Computations using Tree Graphs
</title>
</head>
<body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">
<h1 align = "center">
TREEPACK <br> Computations using Tree Graphs
</h1>
<hr>
<p>
<b>TREEPACK</b>
is a C++ library which
performs common calculations involving a special kind of graph
known as a tree.
</p>
<p>
A graph is a collection of objects or "nodes", such that any (unordered) pair of
nodes is connected or not connected. If a pair of nodes <b>i</b> and <b>j</b>
are connected, we say there is an "edge" between them, and we may describe
the edge as <b>(i,j)</b>. A graph can be represented by a drawing
of dots with lines connecting some of the dots.
</p>
<p>
A tree is a minimally connected graph; more precisely, it is a graph
with two additional properties:
<ul>
<li>
it is <i>connected</i>, that is, given any two pair of nodes <b>i</b>
and <b>j</b>, there is a sequence of edges <b>(na,nb),(nb,nc),...(nx,ny),(ny,nz)</b>
such that <b>na=i</b> and <b>nz=j</b>;
</li>
<li>
if any edge is removed from the graph, it is no longer connected.
</li>
</ul>
Note that a tree using <b>N</b> nodes will have exactly <b>N-1</b> edges.
</p>
<p>
There are several ways to represent a graph on the computer.
</p>
<p>
For the <b>TREE_ARC</b> representation, we simply store a list of the edges
of the tree, that is, pairs of nodes.
</p>
<p>
For the <b>TREE_PRUEFER</b> representation, a tree of <b>N</b> nodes
is represented by a sequence of <b>N-2</b> integers known as the
Pruefer code.
</p>
<p>
For the <b>TREE_PARENT</b> representation, a tree of <b>N</b> nodes
is represented by a list of nodes PARENT, such that, for I = 1 to N - 1,
the I-th edge of the tree connects node I to node PARENT(I).
</p>
<p>
For the <b>TREE_ROOTED</b> representation, a tree is assumed to have the additional
property that one node has been designated as the "root".
</p>
<p>
For the <b>TREE_RB</b> representation, a tree is assumed to have the additional
properties that one node has been designated as the "root", and that every node
has exactly 1 or 2 edges.
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The computer code and data files described and made available on this web page
are distributed under
<a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
</p>
<h3 align = "center">
Languages:
</h3>
<p>
<b>TREEPACK</b> is available in
<a href = "../../c_src/treepack/treepack.html">a C version</a> and
<a href = "../../cpp_src/treepack/treepack.html">a C++ version</a> and
<a href = "../../f77_src/treepack/treepack.html">a FORTRAN77 version</a> and
<a href = "../../f_src/treepack/treepack.html">a FORTRAN90 version</a> and
<a href = "../../m_src/treepack/treepack.html">a MATLAB version</a>.
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../cpp_src/combo/combo.html">
COMBO</a>,
a C++ library which
includes routines for ranking, unranking, enumerating and
randomly selecting balanced sequences, cycles, graphs, Gray codes,
subsets, partitions, permutations, restricted growth functions,
Pruefer codes and trees.
</p>
<p>
<a href = "../../data/graph_representation/graph_representation.html">
GRAPH_REPRESENTATION</a>,
a data directory which
contains examples of ways of representing abstract
mathematical graphs
</p>
<p>
<a href = "../../cpp_src/subset/subset.html">
SUBSET</a>,
a C++ library which
generates, ranks and unranks various combinatorial objects.
</p>
<h3 align = "center">
Reference:
</h3>
<p>
<ol>
<li>
Alan Gibbons,<br>
Algorithmic Graph Theory,<br>
Cambridge University Press, 1985,<br>
ISBN: 0-5212-8881-9,<br>
LC: QA166.G53.
</li>
<li>
Hang Tong Lau,<br>
Combinatorial Heuristic Algorithms with FORTRAN,<br>
Springer, 1986,<br>
ISBN: 3540171614,<br>
LC: QA402.5.L37.
</li>
<li>
Albert Nijenhuis, Herbert Wilf,<br>
Combinatorial Algorithms for Computers and Calculators,<br>
Second Edition,<br>
Academic Press, 1978,<br>
ISBN: 0-12-519260-6,<br>
LC: QA164.N54.
</li>
<li>
Robert Sedgewick,<br>
Algorithms in C,<br>
Addison-Wesley, 1990,<br>
ISBN: 0-201-51425-7,<br>
LC: QA76.73.C15S43.
</li>
<li>
Dennis Stanton, Dennis White,<br>
Constructive Combinatorics,<br>
Springer, 1986,<br>
ISBN: 0387963472,<br>
LC: QA164.S79.
</li>
<li>
Krishnaiyan Thulasiraman, M Swamy,<br>
Graphs: Theory and Algorithms,<br>
John Wiley, 1992,<br>
ISBN: 0471513563,<br>
LC: QA166.T58.
</li>
</ol>
</p>
<h3 align = "center">
Source Code:
</h3>
<p>
<ul>
<li>
<a href = "treepack.cpp">treepack.cpp</a>, the source code;
</li>
<li>
<a href = "treepack.hpp">treepack.hpp</a>, the include file.
</li>
<li>
<a href = "treepack.sh">treepack.sh</a>,
commands to compile the source code;
</li>
</ul>
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
<ul>
<li>
<a href = "treepack_prb.cpp">treepack_prb.cpp</a>, the calling
program;
</li>
<li>
<a href = "treepack_prb.sh">treepack_prb.sh</a>,
commands to compile, link and run the calling program;
</li>
<li>
<a href = "treepack_prb_output.txt">treepack_prb_output.txt</a>,
the output file.
</li>
</ul>
</p>
<h3 align = "center">
List of Routines:
</h3>
<p>
<ul>
<li>
<b>CATALAN</b> computes the Catalan numbers, from C(0) to C(N).
</li>
<li>
<b>GRAPH_ADJ_EDGE_COUNT</b> counts the number of edges in a graph.
</li>
<li>
<b>GRAPH_ADJ_IS_NODE_CONNECTED</b> determines if a graph is nodewise connected.
</li>
<li>
<b>GRAPH_ADJ_IS_TREE</b> determines whether a graph is a tree.
</li>
<li>
<b>GRAPH_ARC_DEGREE</b> determines the degree of the nodes of a graph.
</li>
<li>
<b>GRAPH_ADJ_IS_TREE</b> determines whether a graph is a tree.
</li>
<li>
<b>GRAPH_ARC_NODE_COUNT</b> counts the number of nodes in a graph.
</li>
<li>
<b>GRAPH_ARC_PRINT</b> prints out a graph from an edge list.
</li>
<li>
<b>GRAPH_ARC_TO_GRAPH_ADJ</b> converts an arc list graph to an adjacency graph.
</li>
<li>
<b>I4_UNIFORM_AB</b> returns a scaled pseudorandom I4 between A and B.
</li>
<li>
<b>I4VEC_HEAP_D</b> reorders an I4VEC into an descending heap.
</li>
<li>
<b>I4VEC_INDICATOR</b> sets an I4VEC to the indicator vector.
</li>
<li>
<b>I4VEC_PRINT</b> prints an I4VEC.
</li>
<li>
<b>I4VEC_SORT_HEAP_A</b> ascending sorts an I4VEC using heap sort.
</li>
<li>
<b>I4VEC_SORTED_UNIQUE_COUNT</b> counts the unique elements in a sorted I4VEC.
</li>
<li>
<b>PRUEFER_TO_TREE_ARC</b> is given a Pruefer code, and computes the tree.
</li>
<li>
<b>PRUEFER_TO_TREE_2</b> produces the edge list of a tree from its Pruefer code.
</li>
<li>
<b>R8_UNIFORM_01</b> returns a unit pseudorandom R8.
</li>
<li>
<b>TIMESTAMP</b> prints the current YMDHMS date as a time stamp.
</li>
<li>
<b>TREE_ARC_CENTER</b> computes the center, eccentricity, and parity of a tree.
</li>
<li>
<b>TREE_ARC_DIAM</b> computes the "diameter" of a tree.
</li>
<li>
<b>TREE_ARC_RANDOM</b> selects a random labeled tree and its Pruefer code.
</li>
<li>
<b>TREE_ARC_TO_PRUEFER</b> is given a labeled tree, and computes its Pruefer code.
</li>
<li>
<b>TREE_ENUM</b> enumerates the labeled trees on NNODE nodes.
</li>
<li>
<b>TREE_PARENT_NEXT</b> generates, one at a time, all labeled trees.
</li>
<li>
<b>TREE_PARENT_TO_ARC</b> converts a tree from parent to arc representation.
</li>
<li>
<b>TREE_RB_ENUM</b> returns the number of rooted binary trees with N nodes.
</li>
<li>
<b>TREE_RB_LEX_NEXT</b> generates rooted binary trees in lexicographic order.
</li>
<li>
<b>TREE_RB_TO_PARENT</b> converts rooted binary tree to parent node representation.
</li>
<li>
<b>TREE_RB_YULE</b> adds two nodes to a rooted binary tree using the Yule model.
</li>
<li>
<b>TREE_ROOTED_CODE</b> returns the code of a rooted tree.
</li>
<li>
<b>TREE_ROOTED_CODE_COMPARE</b> compares a portion of the code for two rooted trees.
</li>
<li>
<b>TREE_ROOTED_DEPTH</b> returns the depth of a rooted tree.
</li>
<li>
<b>TREE_ROOTED_ENUM</b> counts the number of unlabeled rooted trees.
</li>
<li>
<b>TREE_ROOTED_RANDOM</b> selects a random unlabeled rooted tree.
</li>
<li>
<b>VEC_NEXT</b> generates all N-vectors of integers modulo a given base.
</li>
<li>
<b>VEC_RANDOM</b> selects a random N-vector of integers modulo a given base.
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../cpp_src.html">
the C++ source codes</a>.
</p>
<hr>
<i>
Last revised on 05 August 2013.
</i>
<!-- John Burkardt -->
</body>
</html>