-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_data.cpp
235 lines (195 loc) · 7.24 KB
/
generate_data.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
/*
Copyright 2017 InitialDLab
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <iostream>
#include <vector>
#include <fstream>
#include <random>
#include <limits>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <functional>
#include <boost/lexical_cast.hpp>
#include <boost/timer/timer.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include "mongo_types.h"
#include "rtree/rtree.h"
#include "level_sampling/level_sampling.h"
//using entry = mongo_types::entry;
//using sample_entry = mongo_types::sample_entry;
//using point = mongo_types::point3d;
//using box = mongo_types::box3d;
//using rtree_t = rtree::rtree<
// entry,
// sample_entry,
// box,
// 256, // node sample count
// 256, // leaf size
// 16 // internal size
//>;
template<typename Iter>
void generate_entries(size_t element_count, Iter iter)
{
std::default_random_engine rng;
std::uniform_int_distribution<unsigned int> lat_dist(0, 180L * 10000000);
std::uniform_int_distribution<unsigned int> lon_dist(0, 360L * 10000000);
std::uniform_int_distribution<int> timestamp_dist(0, std::numeric_limits<int>::max());
static const char * id_list = "0123456789abcdef";
std::uniform_int_distribution<int> id_dist(0, 15);
char id_buffer[2 * mongo_types::OID::oid_len + 1];
id_buffer[2*mongo_types::OID::oid_len] = 0;
for(size_t i = 0; i < element_count; ++i)
{
for(int j = 0; j < 2 * mongo_types::OID::oid_len; ++j)
{
id_buffer[j] = id_list[id_dist(rng)];
}
*iter++ = mongo_types::entry(
((double)(lat_dist(rng))) / 10000000.0 - 90,
((double)(lon_dist(rng))) / 10000000.0 - 180,
timestamp_dist(rng),
id_buffer
);
}
}
void generate(size_t element_count, std::string const& filename)
{
std::vector<mongo_types::entry> entries;
entries.reserve(element_count);
generate_entries(element_count, std::back_inserter(entries));
{
std::cerr << "bbox: ";
mongo_types::box3d bbox;
boost::geometry::assign_inverse(bbox);
for(auto & v : entries)
boost::geometry::expand(bbox, v.get_point());
dump_box(std::cerr, bbox);
std::cerr << std::endl;
}
using entry = mongo_types::entry;
using sample_entry = mongo_types::sample_entry;
using point = mongo_types::point3d;
using box = mongo_types::box3d;
rtree::IOLayersParameters parameters;
parameters.max_top_layer_io_node_count = 1024;
constexpr size_t NODE_SAMPLE_SIZE = 256;
constexpr size_t MAX_FANOUT = 16;
rtree::rtree<
entry,
sample_entry,
box,
NODE_SAMPLE_SIZE,
MAX_FANOUT
>::build_io_layers(entries.begin(), entries.end(), filename + "-rtree");
parameters.max_top_layer_io_node_count *= NODE_SAMPLE_SIZE;
parameters.max_top_layer_io_node_count /= MAX_FANOUT;
level_sampling::level_sampling<
entry,
sample_entry,
box,
MAX_FANOUT
>::build(entries.begin(), entries.end(), filename + "-ls", parameters);
}
void test()
{
using entry = mongo_types::entry;
using sample_entry = mongo_types::sample_entry;
using point = mongo_types::point3d;
using box = mongo_types::box3d;
rtree::IOLayersParameters parameters;
constexpr size_t NODE_SAMPLE_SIZE = 256;
constexpr size_t MAX_FANOUT = 16;
parameters.max_top_layer_io_node_count *= NODE_SAMPLE_SIZE;
parameters.max_top_layer_io_node_count /= MAX_FANOUT;
std::function<entry(const std::string&)> GeoLife_converter =
[](const std::string& str)
{
float x_val;
float y_val;
int time;
char OIDvalue[32];
int ret = sscanf(str.c_str(), "%24s %f %f %d", OIDvalue, &x_val, &y_val, &time);
return mongo_types::entry(x_val, y_val, time, OIDvalue);
};
level_sampling::level_sampling<
entry,
sample_entry,
box,
MAX_FANOUT
>::build("raw/GeoLifeDataNormalized.txt",
"test/1",
GeoLife_converter,
1024*1024*1024,
parameters);
}
int main(int argc, char ** argv)
{
//// THIS IS A TEMP MAIN FUNCTION FOR TESTING PURPOSES FOR BULK LOADING WITHOUT NEED FOR THE ENTIRE
//// DATA SET TO FIT INTO MAIN MEMORY.
//std::string inputfilename = "/uusoc/scratch/magpie2/robertc/data/GeoLifeDataAdded.txt";
//std::string outputfilename = "output";
//using entry = mongo_types::entry;
//using sample_entry = mongo_types::sample_entry;
//using point = mongo_types::point3d;
//using box = mongo_types::box3d;
//boost::posix_time::ptime epoch = boost::posix_time::from_iso_string("1970-01-01T00:00:00Z");
////std::function<entry(const std::string&)> convert =
//// [](const std::string& str){
//// float x_val = 0.0f;
//// float y_val = 0.0f;
//// int time = 0;
//// char OIDvalue[32];
////
//// int ret = sscanf(str.c_str(), "%24s %f %f %f", OIDvalue, &x_val, &y_val, &time);
////
//// return mongo_types::entry(x_val, y_val, time, OIDvalue);
////};
//std::function<entry(const std::string&)> convert =
// [&epoch](const std::string& str){
// float x_val = 0.0f;
// float y_val = 0.0f;
// int user = 0;
// char OIDvalue[32];
// char timestr[32];
// int ret = sscanf(str.c_str(), "%f %f %d %21s %24s", &x_val, &y_val, &time, &user, timestr, OIDvalue);
// boost::posix_time::ptime entry_time = boost::posix_time::from_iso_string(timestr);
// int time = boost::posix_time::time_period(epoch, entry_time).length().total_seconds();
// return mongo_types::entry(x_val, y_val, time, OIDvalue);
//};
//rtree::rtree<
// entry,
// sample_entry,
// box,
// 256, // node sample count
// 256, // leaf size
// 16 // internal size
//>::build_io_layers(inputfilename, outputfilename,
// convert, 1024 * 1024 * 1024);
test();
return 0;
if(argc != 3)
{
std::cerr << "argument: <entry count> <output filename>" << std::endl;
return -1;
}
size_t element_count = boost::lexical_cast<size_t>(argv[1]);
const char * filename = argv[2];
generate(element_count, filename);
return 0;
}