-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhammersley_dataset.cpp
330 lines (282 loc) · 9.22 KB
/
hammersley_dataset.cpp
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
# include <cstdlib>
# include <cmath>
# include <ctime>
# include <iostream>
# include <iomanip>
# include <fstream>
# include <cstring>
using namespace std;
# include "hammersley.H"
int main ( void );
//****************************************************************************80
int main ( void )
//****************************************************************************80
//
// Purpose:
//
// MAIN is the main program for HAMMERSLEY_DATASET.
//
// Discussion:
//
// HAMMERSLEY_DATASET generates a Hammersley dataset and writes it to a file.
//
// This program is meant to be used interactively. It's also
// possible to prepare a simple input file beforehand and use it
// in batch mode.
//
// The program requests input values from the user:
//
// * DIM_NUM, the spatial dimension,
// * N, the number of points to generate,
// * STEP, the index of the first subsequence element to be computed.
// * SEED(1:DIM_NUM), the sequence index corresponding to STEP = 0.
// * LEAP(1:DIM_NUM), the successive jumps in the sequence.
// * BASE(1:DIM_NUM), the bases (usually distinct primes or -N).
//
// The program generates the data, writes it to the file
//
// hammersley_DIM_NUM_N.txt
//
// where "DIM_NUM" and "N" are the numeric values specified by the user,
// and then asks the user for more input. To indicate that no further
// computations are desired, it is enough to input a nonsensical
// value, such as -1.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 12 April 2007
//
// Author:
//
// John Burkardt
//
{
int *base;
char command[80];
char file_out_name[80];
int i;
int *leap;
int n;
int dim_num;
double *r;
int *seed;
int step;
char *string;
timestamp ( );
cout << "\n";
cout << "HAMMERSLEY_DATASET\n";
cout << " C++ version\n";
cout << "\n";
cout << " Compiled on " << __DATE__ << " at " << __TIME__ << ".\n";
cout << "\n";
cout << " Generate a Hammersley dataset.\n";
cout << "\n";
cout << " This program is meant to be used interactively.\n";
cout << " It is also possible to prepare a simple input\n";
cout << " file beforehand and use it in batch mode.\n";
cout << "\n";
cout << " The program requests input values from the user:\n";
cout << "\n";
cout << " * DIM_NUM, the spatial dimension,\n";
cout << " * N, the number of points to generate,\n";
cout << " * STEP, the index of the first subsequence element.\n";
cout << " * SEED(1:DIM_NUM),the sequence element corresponding to STEP = 0\n";
cout << " * LEAP(1:DIM_NUM), the succesive jumps in the sequence.\n";
cout << " * BASE(1:DIM_NUM), the bases, usually distinct primes\n";
cout << " or -N (to generate values like I/N).\n";
cout << "\n";
cout << " The program generates the data, writes it to the file\n";
cout << "\n";
cout << " hammersley_DIM_NUM_N.txt\n";
cout << "\n";
cout << " where ""DIM_NUM"" and ""N"" are the numeric values specified\n";
cout << " by the user, and then asks the user for more input.\n";
cout << "\n";
cout << " To indicate that no further computations are\n";
cout << " desired, it is enough to input a nonsensical value,\n";
cout << " such as -1.\n";
for ( ; ; )
{
cout << " *\n";
cout << " *\n";
cout << "* Ready to generate a new dataset:\n";
cout << " *\n";
cout << " *\n";
cout << "\n";
cout << " Enter DIM_NUM, the spatial dimension:\n";
cout << " (Try '2' if you have no preference.)\n";
cout << " (0 or any negative value terminates execution).\n";
cin >> dim_num;
if ( cin.rdstate ( ) )
{
cin.clear ( );
cout << "\n";
cout << "HAMMERSLEY_DATASET - Fatal error!\n";
cout << " An I/O error occurred while trying to read DIM_NUM.\n";
cout << " Abnormal end of execution.\n";
break;
}
if ( !halham_dim_num_check ( dim_num ) )
{
cout << "\n";
cout << "HAMMERSLEY_DATASET\n";
cout << " The input value of DIM_NUM = " << dim_num << "\n";
cout << " is interpreted as a request for termination.\n";
cout << " Normal end of execution.\n";
break;
}
cout << "\n";
cout << " Enter N, the number of points to generate:\n";
cout << " (Try '25' if you have no preference.)\n";
cout << " (0 or any negative value terminates execution).\n";
cin >> n;
if ( cin.rdstate ( ) )
{
cin.clear ( );
cout << "\n";
cout << "HAMMERSLEY_DATASET - Fatal error!\n";
cout << " An I/O error occurred while trying to read N.\n";
cout << " Abnormal end of execution.\n";
break;
}
if ( !halham_n_check ( n ) )
{
cout << "\n";
cout << "HAMMERSLEY_DATASET\n";
cout << " The input value of N = " << n << "\n";
cout << " is interpreted as a request for termination.\n";
cout << " Normal end of execution.\n";
break;
}
cout << "\n";
cout << " Enter STEP, the index of the first subsequence element:\n";
cout << " (Try '0' or '1' if you have no preference.)\n";
cout << " (Any negative value terminates execution).\n";
cin >> step;
if ( cin.rdstate ( ) )
{
cin.clear ( );
cout << "\n";
cout << "HAMMERSLEY_DATASET - Fatal error!\n";
cout << " An I/O error occurred while trying to read STEP.\n";
cout << " Abnormal end of execution.\n";
break;
}
if ( !halham_step_check ( step ) )
{
cout << "\n";
cout << "HAMMERSLEY_DATASET\n";
cout << " The input value of STEP = " << step << "\n";
cout << " is interpreted as a request for termination.\n";
cout << " Normal end of execution.\n";
break;
}
base = new int[dim_num];
leap = new int[dim_num];
r = new double[dim_num*n];
seed = new int[dim_num];
cout << "\n";
cout << " Enter SEED(1:DIM_NUM), the starting element index\n";
cout << " for each coordinate\n";
cout << " (Try '0 0 ... 0' if you have no preference.)\n";
cout << " (a negative value terminates execution.)\n";
for ( i = 0; i < dim_num; i++ )
{
cin >> seed[i];
if ( cin.rdstate ( ) )
{
cin.clear ( );
cout << "\n";
cout << "HAMMERSLEY_DATASET - Fatal error!\n";
cout << " An I/O error occurred trying to read SEED[" << i << "].\n";
cout << " Abnormal end of execution.\n";
break;
}
}
i4vec_transpose_print ( dim_num, seed, " User input:" );
if ( !halham_seed_check ( dim_num, seed ) )
{
cout << "\n";
cout << "HAMMERSLEY_DATASET\n";
cout << " The input value of SEED\n";
cout << " is interpreted as a request for termination.\n";
cout << " Normal end of execution.\n";
break;
}
cout << "\n";
cout << " Enter LEAP(1:DIM_NUM), the leaping multiplier\n";
cout << " for each coordinate\n";
cout << " (Try '1 1 ... 1' if you have no preference.)\n";
cout << " (another choice is any prime larger than all the bases).\n";
cout << " (any value of 0 or less terminates execution.)\n";
for ( i = 0; i < dim_num; i++ )
{
cin >> leap[i];
if ( cin.rdstate ( ) )
{
cin.clear ( );
cout << "\n";
cout << "HAMMERSLEY_DATASET - Fatal error!\n";
cout << " An I/O error occurred trying to read LEAP[" << i << "].\n";
cout << " Abnormal end of execution.\n";
break;
}
}
i4vec_transpose_print ( dim_num, leap, " User input:" );
if ( !halham_leap_check ( dim_num, leap ) )
{
cout << "\n";
cout << "HAMMERSLEY_DATASET\n";
cout << " The input value of LEAP\n";
cout << " is interpreted as a request for termination.\n";
cout << " Normal end of execution.\n";
break;
}
cout << "\n";
cout << " Enter BASE(1:DIM_NUM), the bases, usually distinct \n";
cout << " primes, but any NEGATIVE base generates\n";
cout << " values I/BASE.";
cout << " (Try '-N 2 3 5 7 11 ...' if you have no preference.)\n";
cout << " (any value of 0 or 1 terminates execution.)\n";
for ( i = 0; i < dim_num; i++ )
{
cin >> base[i];
if ( cin.rdstate ( ) )
{
cin.clear ( );
cout << "\n";
cout << "HAMMERSLEY_DATASET - Fatal error!\n";
cout << " An I/O error occurred trying to read BASE[" << i << "].\n";
cout << " Abnormal end of execution.\n";
break;
}
}
i4vec_transpose_print ( dim_num, base, " User input:" );
if ( !hammersley_base_check ( dim_num, base ) )
{
cout << "\n";
cout << "HAMMERSLEY_DATASET\n";
cout << " The input value of BASE\n";
cout << " is interpreted as a request for termination.\n";
cout << " Normal end of execution.\n";
break;
}
i4_to_hammersley_sequence ( dim_num, n, step, seed, leap, base, r );
sprintf ( file_out_name, "hammersley_%d_%d.txt", dim_num, n );
halham_write ( dim_num, n, step, seed, leap, base, r, file_out_name );
delete [] base;
delete [] leap;
delete [] r;
delete [] seed;
cout << "\n";
cout << " The data was written to the file \""
<< file_out_name << "\".\n";
}
cout << "\n";
timestamp ( );
return 0;
}