forked from johannesgerer/jburkardt-f
-
Notifications
You must be signed in to change notification settings - Fork 1
/
select.html
322 lines (289 loc) · 8.41 KB
/
select.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
<html>
<head>
<title>
SELECT - Nijenhuis and Wilf Combinatorial Selection Algorithm
</title>
</head>
<body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">
<h1 align = "center">
SELECT <br> Nijenhuis and Wilf <br> Combinatorial Selection Algorithm
</h1>
<hr>
<p>
<b>SELECT</b>
is a FORTRAN90 library which
implements the Nijenhuis and Wilf Combinatorial Selection Algorithm.
</p>
<p>
In the reference, Nijenhuis and Wilf presented particular
algorithms to rank, unrank, enumerate, sequentially generate,
or randomly generate objects from a variety of combinatorial
families, such as K-subsets of an N-set, permutations,
partitions, and so on.
</p>
<p>
In the course of this development, they come across a number
of cases where, to determine the number B(N,K) of objects of size
K in a family of maximum size N, a recurrence is used of the form
<blockquote>
B(N,K) = PHI(N,K) * B(N1,K1) + PSI(N,K) * B(N2,K2)
</blockquote>
Typically, but not always, it is the case that:
<pre>
N1 = N - 1
N2 = N - 1
K1 = K
K2 = K - 1
</pre>
and the values of the coefficient functions PHI and PSI
depended on the family.
</p>
<p>
This pattern suggested that a single abstract approach could
be used to carry out the usual tasks for a variety of combinatorial
families. The result was a subroutine called <b>SELECT</b> which
while not optimized for a particular family, displays their
common underlying structure, and allows new families to be
added easily.
</p>
<p>
The combinatorial families are indicated by the value of the
variable <b>FAMILY</b>, and characterized by a "big" size <b>N</b>
and a smaller size <b>K</b>:
<ol>
<li>
K subsets of an N set;
</li>
<li>
Partitions of N objects into K classes;
</li>
<li>
Permutations of N objects with K cycles;
</li>
<li>
Vector subspaces of dimension K over N-dimensional space
over the field of order Q (where Q is currently set to 2 );
</li>
<li>
Permutations of N letters with K runs;
</li>
<li>
Partitions of N whose largest part is K;
</li>
<li>
Compositions of N into K parts.
</li>
</ol>
</p>
<p>
The combinatorial tasks, indicated by the value of the
variable <b>TASK</b>, include
<ol>
<li>
Present each object of the family, one at a time.
</li>
<li>
Rank a given object of the family.
</li>
<li>
Produce an object of given rank.
</li>
<li>
Select an object at random.
</li>
<li>
Enumerate the objects.
</li>
</ol>
</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>SELECT</b> is available in
<a href = "../../f77_src/select/select.html">a FORTRAN77 version</a> and
<a href = "../../f_src/select/select.html">a FORTRAN90 version</a>.
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../f_src/combo/combo.html">
COMBO</a>,
a FORTRAN90 library which
carries out various combinatorial tasks.
</p>
<p>
<a href = "../../f77_src/lamp/lamp.html">
LAMP</a>,
a FORTRAN77 library which
solves linear assignment and matching problems.
</p>
<p>
<a href = "../../f_src/subset/subset.html">
SUBSET</a>,
a FORTRAN90 library which
contains the individual Nijenhuis and Wilf routines.
</p>
<h3 align = "center">
Reference:
</h3>
<p>
<ol>
<li>
Albert Nijenhuis, Herbert Wilf,<br>
Combinatorial Algorithms,<br>
Academic Press, 1978, second edition.
</li>
</ol>
</p>
<h3 align = "center">
Source Code:
</h3>
<p>
<ul>
<li>
<a href = "select.f90">select.f90</a>, the source code.
</li>
<li>
<a href = "select.sh">select.sh</a>,
commands to compile the source code.
</li>
</ul>
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
<ul>
<li>
<a href = "select_prb.f90">select_prb.f90</a>,
a sample calling program.
</li>
<li>
<a href = "select_prb.sh">select_prb.sh</a>,
commands to compile and run the sample program.
</li>
<li>
<a href = "select_prb_output.txt">select_prb_output.txt</a>,
the output file.
</li>
</ul>
</p>
<h3 align = "center">
List of Routines:
</h3>
<p>
<ul>
<li>
<b>BNEW</b> returns either of two values needed to compute B(N,K).
</li>
<li>
<b>CODE_TO_COMPOSITION</b> decodes a composition.
</li>
<li>
<b>CODE_TO_PARTITION_NUM</b> decodes a numeric partition.
</li>
<li>
<b>CODE_TO_PARTITION_SET</b> decodes a set partition.
</li>
<li>
<b>CODE_TO_PERM_CYCLE</b> decodes a permutation of N objects with K cycles.
</li>
<li>
<b>CODE_TO_PERM_RUNS</b> decodes a permutation of N objects with K runs.
</li>
<li>
<b>CODE_TO_SUBSET</b> decodes a subset.
</li>
<li>
<b>CODE_TO_SUBSPACE</b> decodes a subspace.
</li>
<li>
<b>COMPOSITION_TO_STRING</b> writes a character representation of a composition.
</li>
<li>
<b>DIGIT_TO_CH</b> returns the character representation of a decimal digit.
</li>
<li>
<b>FAMILY_ENUMERATE</b> produces an enumeration table for a given family.
</li>
<li>
<b>FAMILY_NEXT</b> carries out a task for a combinatorial family of order N, K.
</li>
<li>
<b>FAMILY_RANK</b> returns the rank of an object of a given family.
</li>
<li>
<b>FAMILY_SAMPLE</b> produces a sample object of a given family.
</li>
<li>
<b>FAMILY_UNRANK</b> produces an object of given rank of a given family.
</li>
<li>
<b>I4_TO_S_LEFT</b> converts an integer to a left-justified string.
</li>
<li>
<b>I4_UNIFORM</b> returns a scaled pseudorandom I4.
</li>
<li>
<b>I4MAT_PRINT</b> prints an integer matrix.
</li>
<li>
<b>I4MAT_PRINT_SOME</b> prints some of an integer matrix.
</li>
<li>
<b>I4VEC_PRINT</b> prints an integer vector.
</li>
<li>
<b>PARTITION_NUM_TO_STRING</b> represents a numeric partition.
</li>
<li>
<b>PARTITION_SET_TO_STRING</b> writes a character representation of a set partition.
</li>
<li>
<b>PERM_CYCLE_TO_STRING</b> makes a string out of a permutation in cycle form.
</li>
<li>
<b>PHI</b> returns the coefficient PHI(N,K) in the recurrence.
</li>
<li>
<b>PSI</b> returns the coefficient PSI(N,K) in the recurrence.
</li>
<li>
<b>R8_UNIFORM_01</b> returns a unit pseudorandom R8.
</li>
<li>
<b>SELECT</b> carries out a task for a combinatorial family of order N, K.
</li>
<li>
<b>SUBSET_TO_STRING</b> writes a character representation of a subset.
</li>
<li>
<b>TIMESTAMP</b> prints the current YMDHMS date as a time stamp.
</li>
<li>
<b>XNEW</b> returns an index for the recursive enumeration of a family.
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../f_src.html">
the FORTRAN90 source codes</a>.
</p>
<hr>
<i>
Last revised on 30 August 2005.
</i>
<!-- John Burkardt -->
</body>
<!-- Initial HTML skeleton created by HTMLINDEX. -->
</html>