-
Notifications
You must be signed in to change notification settings - Fork 0
/
skyline.cpp
208 lines (190 loc) · 4.45 KB
/
skyline.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
#include "skyline.h"
extern unordered_map<long int, RtreeNode*> ramTree;
float minDist(float p1[], float p2[], int dimen)
{
float mindist = 0;
for (int i = 0; i < dimen; i++)
{
float dist = p1[i] - p2[i];
mindist += (dist * dist);
}
return (float)sqrt(mindist);
}
bool dominatedByK(const int dimen, const float pt[], vector<long> &kskyband, float* PG[], int k)
{
// see if pt is dominated by k options of kskyband
if (kskyband.empty())
return false;
int count = 0;
for (vector<long>::iterator iter = kskyband.begin(); iter != kskyband.end(); iter++)
{
long pid = *iter;
bool dominated = true;
for (int i = 0; i < dimen; i++)
{
if (PG[pid][i] + SIDELEN < pt[i])
{
dominated = false;
break;
}
}
if (dominated) {
count++;
if(count>=k){
return true;
}
}
}
return false;
}
bool dominatedByK_noSL(const int dimen, const float pt[], vector<long> &kskyband, float* PG[], int k)
{
if (kskyband.empty())
return false;
int count = 0;
for (vector<long>::iterator iter = kskyband.begin(); iter != kskyband.end(); iter++)
{
long pid = *iter;
bool dominated = true;
for (int i = 0; i < dimen; i++)
{
if (PG[pid][i]< pt[i])
{
dominated = false;
break;
}
}
if (dominated) {
count++;
if(count>=k){
return true;
}
}
}
return false;
}
void aggregateRecords(Rtree& a_rtree)
{
queue<long int> H;
RtreeNode* node;
H.push(a_rtree.m_memory.m_rootPageID);
long int pageID;
while (!H.empty())
{
pageID = H.front();
H.pop();
node = a_rtree.m_memory.loadPage(pageID);
if (node->isLeaf() == false)
{
for (int i = 0; i < node->m_usedspace; i++)
{
node->m_entry[i]->num_records = countRecords(a_rtree, node->m_entry[i]->m_id);
H.push(node->m_entry[i]->m_id);
}
}
a_rtree.m_memory.writePage(pageID, node);
}
}
int countRecords(Rtree& a_rtree, int pageID)
{
int sumRecords = 0;
RtreeNode* node = a_rtree.m_memory.loadPage(pageID);
if (node->isLeaf())
{
sumRecords = node->m_usedspace;
}
else
{
for (int i = 0; i < node->m_usedspace; i++)
{
sumRecords += countRecords(a_rtree, node->m_entry[i]->m_id);
}
}
delete node;
return sumRecords;
}
void kskyband(const int dimen, Rtree& a_rtree, vector<long int>& kskyband, float* PG[], const int k)
{
RtreeNode* node;
multimap<float, int> heap;
multimap<float, int>::iterator heapIter;
float pt[MAXDIMEN];
float ORIGNIN[MAXDIMEN];
float mindist;
for (int i = 0; i < dimen; i++)
ORIGNIN[i] = 1;
int pageID;
float dist_tmp;
heap.emplace(INFINITY, a_rtree.m_memory.m_rootPageID);
while (!heap.empty())
{
heapIter = heap.begin();
dist_tmp = heapIter->first;
pageID = heapIter->second;
heap.erase(heapIter);
if (pageID > MAXPAGEID)
{
for (int d = 0; d < dimen; d++)
pt[d] = (PG[pageID - MAXPAGEID][d] + PG[pageID - MAXPAGEID][d + dimen])/2;
if (!dominatedByK(dimen, pt, kskyband, PG, k))
{
kskyband.push_back(pageID - MAXPAGEID);
}
}
else
{
//node = a_rtree.m_memory.loadPage(pageID);
node = ramTree[pageID];
if (node->isLeaf())
{
for (int i = 0; i < node->m_usedspace; i++)
{
for (int d = 0; d < dimen; d++)
{
pt[d] = node->m_entry[i]->m_hc.getLower()[d] + SIDELEN;
}
if (!dominatedByK(dimen, pt, kskyband, PG, k))
{
mindist = minDist(pt, ORIGNIN, dimen);
heap.emplace(mindist, node->m_entry[i]->m_id + MAXPAGEID);
}
}
}
else
{
for (int i = 0; i < node->m_usedspace; i++)
{
for (int d = 0; d < dimen; d++)
pt[d] = node->m_entry[i]->m_hc.getUpper()[d];
if (!dominatedByK(dimen, pt, kskyband, PG, k))
{
mindist = minDist(pt, ORIGNIN, dimen);
heap.emplace(mindist, node->m_entry[i]->m_id);
}
}
}
}
}
}
void rtreeRAM(Rtree& rt, unordered_map<long int, RtreeNode*>& ramTree)
{
ramTree.clear();
queue<long int> H;
RtreeNode* node;
H.push(rt.m_memory.m_rootPageID);
long int pageID;
while (!H.empty())
{
pageID = H.front();
H.pop();
node = rt.m_memory.loadPage(pageID);
ramTree[pageID] = node;
if (node->isLeaf() == false)
{
for (int i = 0; i < node->m_usedspace; i++)
{
H.push(node->m_entry[i]->m_id);
}
}
}
}