forked from YangKai-NEU/TED
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe_query_set.hpp
183 lines (163 loc) · 5.79 KB
/
e_query_set.hpp
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
#ifndef __EQUERY_SET_HPP__
#define __EQUERY_SET_HPP__
#include "e_graphic.hpp"
#include "e_tool.hpp"
#define random(x) (rand() % x)
const int INIT_PART_NUM = 6;
double randf() {
double t = (double)(rand() / (double)RAND_MAX);
return t;
}
class QuerySet {
public:
int tSetSize;
Node gLL, ur;
QuerySet(int size) { tSetSize = size; }
int Convert2int(Node *p) {
int tGridNum = pow(4, INIT_PART_NUM);
int lineNum = sqrt(tGridNum);
double latWidth = (ur.GetLatitude() - gLL.GetLatitude()) / lineNum;
double lngWidth = (ur.GetLongitude() - gLL.GetLongitude()) / lineNum;
return (int)(lineNum * (p->GetLatitude() - gLL.GetLatitude()) / latWidth) +
(int)((p->GetLongitude() - gLL.GetLongitude()) / lngWidth);
}
void initArea() {
gLL.SetLatitude(10000);
gLL.SetLongitude(10000);
ur.SetLatitude(-10000);
ur.SetLongitude(-10000);
for (int i = 0; i < gGraph->GetNodeNumber(); i++) {
if (gLL.GetLatitude() > gGraph->GetNodeById(i)->GetLatitude())
gLL.SetLatitude(gGraph->GetNodeById(i)->GetLatitude());
if (gLL.GetLongitude() > gGraph->GetNodeById(i)->GetLongitude())
gLL.SetLongitude(gGraph->GetNodeById(i)->GetLongitude());
if (ur.GetLatitude() < gGraph->GetNodeById(i)->GetLatitude())
ur.SetLatitude(gGraph->GetNodeById(i)->GetLatitude());
if (ur.GetLongitude() < gGraph->GetNodeById(i)->GetLongitude())
ur.SetLongitude(gGraph->GetNodeById(i)->GetLongitude());
}
}
void GetWhenSet(FileWriter *writer) {
int i;
writer->WriteInt(tSetSize);
for (i = 0; i < tSetSize; i++) {
int a = random(gGraph->GetEdgeNumber());
writer->WriteInt(a);
double b = randf() * gGraph->GetEdgeById(a)->GetLength();
writer->WriteDouble(b);
}
}
void GetWhereSet(FileWriter *writer) {
int i;
writer->WriteInt(tSetSize);
for (i = 0; i < tSetSize; i++) {
int a = random(24 * 3600);
writer->WriteInt(a);
}
}
void GetDistanceSet(FileWriter *writer) {
int i;
writer->WriteInt(tSetSize);
for (i = 0; i < tSetSize; i++) {
int a1 = random(24 * 3600);
int a2 = random(24 * 3600);
if (a1 > a2) {
int t = a1;
a1 = a2;
a2 = t;
}
writer->WriteInt(a1);
writer->WriteInt(a2);
}
}
void GetHowlongSet(FileWriter *writer) {
int i;
writer->WriteInt(tSetSize);
for (i = 0; i < tSetSize; i++) {
int a1 = random(gGraph->GetEdgeNumber());
writer->WriteInt(a1);
double b1 = randf() * gGraph->GetEdgeById(a1)->GetLength();
writer->WriteDouble(b1);
int a2 = random(gGraph->GetEdgeNumber());
writer->WriteInt(a2);
double b2 = randf() * gGraph->GetEdgeById(a2)->GetLength();
writer->WriteDouble(b2);
}
}
void GetWindowSet(FileWriter *writer) {
initArea();
int i;
writer->WriteInt(tSetSize);
for (i = 0; i < tSetSize; i++) {
double lat =
gLL.GetLatitude() + randf() * (ur.GetLatitude() - gLL.GetLatitude());
double lng = gLL.GetLongitude() +
randf() * (ur.GetLongitude() - gLL.GetLongitude());
int tGridNum = pow(4, INIT_PART_NUM);
int lineNum = sqrt(tGridNum);
double latWidth = (ur.GetLatitude() - gLL.GetLatitude()) / lineNum;
double lngWidth = (ur.GetLongitude() - gLL.GetLongitude()) / lineNum;
writer->WriteDouble(((int)((lat - gLL.GetLatitude()) / latWidth)) *
latWidth +
gLL.GetLatitude());
writer->WriteDouble(((int)((lng - gLL.GetLongitude()) / lngWidth)) *
lngWidth +
gLL.GetLongitude());
writer->WriteDouble(((int)((lat - gLL.GetLatitude()) / latWidth) + 1) *
latWidth +
gLL.GetLatitude());
writer->WriteDouble(((int)((lng - gLL.GetLongitude()) / lngWidth) + 1) *
lngWidth +
gLL.GetLongitude());
}
}
void GetKNNSet(FileWriter *writer) {
initArea();
int i;
writer->WriteInt(tSetSize);
for (i = 0; i < tSetSize; i++) {
double lat =
gLL.GetLatitude() + randf() * (ur.GetLatitude() - gLL.GetLatitude());
double lng = gLL.GetLongitude() +
randf() * (ur.GetLongitude() - gLL.GetLongitude());
writer->WriteDouble(lat);
writer->WriteDouble(lng);
}
}
void GetCountSet(FileWriter *writer) {
initArea();
int i;
writer->WriteInt(tSetSize);
for (i = 0; i < tSetSize; i++) {
double lat =
gLL.GetLatitude() + randf() * (ur.GetLatitude() - gLL.GetLatitude());
double lng = gLL.GetLongitude() +
randf() * (ur.GetLongitude() - gLL.GetLongitude());
int tGridNum = pow(4, INIT_PART_NUM);
int lineNum = sqrt(tGridNum);
double latWidth = (ur.GetLatitude() - gLL.GetLatitude()) / lineNum;
double lngWidth = (ur.GetLongitude() - gLL.GetLongitude()) / lineNum;
writer->WriteDouble(((int)((lat - gLL.GetLatitude()) / latWidth)) *
latWidth +
gLL.GetLatitude());
writer->WriteDouble(((int)((lng - gLL.GetLongitude()) / lngWidth)) *
lngWidth +
gLL.GetLongitude());
writer->WriteDouble(((int)((lat - gLL.GetLatitude()) / latWidth) + 1) *
latWidth +
gLL.GetLatitude());
writer->WriteDouble(((int)((lng - gLL.GetLongitude()) / lngWidth) + 1) *
lngWidth +
gLL.GetLongitude());
}
}
void GetDistanceSingleSet(FileWriter *writer) {
int i;
writer->WriteInt(tSetSize);
for (i = 0; i < tSetSize; i++) {
int a = random(24 * 3600);
writer->WriteInt(a);
}
}
};
#endif