-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_supermarble.cpp
79 lines (64 loc) · 1.8 KB
/
gen_supermarble.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
/*****************************************************
* IST - ASA 23/24 - Super Marble instance generator *
*****************************************************/
#include <iostream>
using namespace std;
// Dimensions
int _N;
int _M;
int _P; // # pieces
//-----------------------------------------------------------------------------
void printUsage(char *progname) {
cerr << "Usage: " << progname << " <N> <M> <P> <seed>" << endl;
cerr << " N: number of rows" << endl;
cerr << " M: number of columns" << endl;
cerr << " P: number of pieces (dimensions 1 to N x 1 to M)" << endl;
cerr << " seed: random seed number (optional)" << endl;
exit(1);
}
void parseArgs(int argc, char *argv[]) {
int seed = 0;
if (argc < 3 || argc > 5) {
cerr << "ERROR: Wrong number of arguments" << endl;
printUsage(argv[0]);
}
sscanf(argv[1], "%d", &_N);
if (_N < 1) {
cerr << "ERROR: N rows must be >= 1" << endl;
printUsage(argv[0]);
}
sscanf(argv[2], "%d", &_M);
if (_M < 1) {
cerr << "ERROR: M columns must be >= 1" << endl;
printUsage(argv[0]);
}
sscanf(argv[3], "%d", &_P);
if (_P < 1) {
cerr << "ERROR: P pieces must be >= 1" << endl;
printUsage(argv[0]);
}
if (argc == 5) {
sscanf(argv[4], "%d", &seed);
srand(seed);
} else { // pseudo-random seed
srand((unsigned int)time(NULL));
}
}
inline int randomValue(int max) {
return rand() % max; // [0, max - 1]
}
int main(int argc, char *argv[]) {
parseArgs(argc, argv);
// Print dimensions
cout << _N << " " << _M << endl;
// Print number of pieces
cout << _P << endl;
// Print matrix
for (int i = 0; i < _P; i++) {
int x = randomValue(_N) + 1;
int y = randomValue(_M) + 1;
int v = randomValue(2 * x * y) + 1;
cout << x << " " << y << " " << v << endl;
}
return 0;
}