-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator.cpp
164 lines (133 loc) · 4.29 KB
/
generator.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
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*
*
* Copyright (c) 2016, Lutz, Clemens <[email protected]>
*/
#include "cluster_generator.hpp"
#include <cstdint>
#include <iostream>
#include <string>
#include <SystemConfig.h>
#include <boost/program_options.hpp>
// Suppress editor errors about GENERATOR_NAME not defined
#ifndef GENERATOR_NAME
#define GENERATOR_NAME ""
#endif
namespace po = boost::program_options;
class CmdOptions {
public:
int parse(int argc, char **argv) {
char help_msg[] =
"Usage: " GENERATOR_NAME " [OPTION] [OUTPUT FILE]\n"
"Options"
;
po::options_description cmdline(help_msg);
cmdline.add_options()
("help", "Produce help message")
("csv", "Generate CSV file (default output is binary)")
("size", po::value<uint64_t>(&megabytes_)->default_value(100),
"Target file size in MiB (as float-type data)")
("features", po::value<uint64_t>(&features_)->default_value(2),
"Number of features (aka. dimensions)")
("clusters", po::value<uint64_t>(&clusters_)->default_value(10),
"Number of clusters")
("radius", po::value<float>(&radius_)->default_value(10.0f),
"Cluster radius (has Gaussian distribution)")
("domain_min", po::value<float>(&domain_min_)->default_value(-100.0f),
"Domain space (minimum value for centroids)")
("domain_max", po::value<float>(&domain_max_)->default_value(100.0f),
"Domain space (maximum value for centroids)")
("divisor", po::value<uint64_t>(&multiple_)->default_value(8),
"Number of points are multiple of divisor")
;
po::options_description hidden("Hidden options");
hidden.add_options()
("output-file", po::value<std::string>(&output_file_),
"output file")
;
po::options_description visible;
visible.add(cmdline).add(hidden);
po::positional_options_description pos;
pos.add("output-file", 1);
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(visible)
.positional(pos).run(),
vm);
po::notify(vm);
if (vm.count("help")) {
std::cout << cmdline << std::endl;
return -1;
}
if (vm.count("csv")) {
csv_format_ = true;
}
else {
csv_format_ = false;
}
// Ensure we have required options
if (output_file_.empty()) {
std::cout << "Give me an output file!" << std::endl;
return -1;
}
return 1;
}
bool csv_format() const {
return csv_format_;
}
uint64_t features() const {
return features_;
}
uint64_t clusters() const {
return clusters_;
}
uint64_t bytes() const {
return megabytes_ * 1024 * 1024;
}
uint64_t multiple() const {
return multiple_;
}
float radius() const {
return radius_;
}
float domain_min() const {
return domain_min_;
}
float domain_max() const {
return domain_max_;
}
std::string output_file() const {
return output_file_;
}
private:
std::string output_file_;
bool csv_format_;
uint64_t features_;
uint64_t clusters_;
uint64_t megabytes_;
uint64_t multiple_;
float radius_;
float domain_min_;
float domain_max_;
};
int main(int argc, char **argv) {
CmdOptions options;
if (options.parse(argc, argv) < 0) {
return 1;
}
cle::ClusterGenerator generator;
generator.total_size(options.bytes());
generator.cluster_radius(options.radius());
generator.domain(options.domain_min(), options.domain_max());
generator.num_features(options.features());
generator.num_clusters(options.clusters());
generator.point_multiple(options.multiple());
if (options.csv_format()) {
generator.generate_csv(options.output_file().c_str());
}
else {
generator.generate_bin(options.output_file().c_str());
}
}