-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSBSingleCNN.java
128 lines (107 loc) · 3.96 KB
/
SBSingleCNN.java
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
package skylinebreaker;
import java.util.ArrayList;
import skylinebreaker.LSDAbstractTree.BucketNode;
import skylinebreaker.LSDAbstractTree.DirectoryNode;
import skylinebreaker.LSDAbstractTree.Node;
import flatlc.levels.FlatLevelCombination;
public class SBSingleCNN {
private final LSDAbstractTree tree;
static SBBase.NearestNeighborOfZero nnzero = null;
final int processes;
public SBSingleCNN(final LSDAbstractTree tree, int processes)
{
this.tree = tree;
this.processes = processes;
}
public FlatLevelCombination[] computeSkyline() throws InterruptedException
{
final LSDAbstractTree.Node root = tree.getRoot();
Node n = root;
int depth = 0;
while( !(n instanceof BucketNode))
{
DirectoryNode nc = (DirectoryNode) n;
n = nc.left;
++depth;
}
final BucketNode bn = (BucketNode) n;
FlatLevelCombination[] zeroLocalSkyline = bn.computeLocalSkyline();
{
int nearestToZeroNorm = Integer.MAX_VALUE;
FlatLevelCombination nearestToZero = null;
for(final FlatLevelCombination element : zeroLocalSkyline)
{
final int l1n = tree.getOverallLevel(element);
if(nearestToZeroNorm > l1n) { nearestToZero = element; nearestToZeroNorm = l1n; }
}
synchronized(nnzero)
{
if(nnzero.norm > nearestToZeroNorm)
{
nnzero.norm = nearestToZeroNorm;
nnzero.neighbor = nearestToZero;
}
++nnzero.threadCount;
nnzero.notifyAll();
while(nnzero.threadCount < processes)
nnzero.wait();
if(tree instanceof LSDPruningTree) ((LSDPruningTree)tree).computeOverallLevel(nnzero.neighbor); // hash the value of nnzero
}
}
ArrayList<FlatLevelCombination[]> localSkylines = new ArrayList<FlatLevelCombination[]>();
for(int i = 0; i < tree.dimensions-1; ++i)
{
final DirectoryNode dn = n.getParent(); --depth;
if(dn == null) break;
localSkylines.add(computeBucketSkyline(dn.left == n ? dn.right : dn.left));
n = dn;
}
if(n != root)
{
while(n != root)
{
final DirectoryNode dn = n.getParent(); --depth;
assert (dn.right != n) : "Upward going not on the left side";
if(dn.right instanceof BucketNode) localSkylines.add(computeBucketSkyline(dn.right));
else
{
final int[] minlevels = new int[tree.dimensions];
final int dim = tree.getSplitAxis(depth);
minlevels[dim] = dn.location;
pruneBuckets( (DirectoryNode)dn.right, depth+1, minlevels, localSkylines);
}
n = dn;
//minlevels[getSplitAxis(depth)] = 0;
}
}
for(final FlatLevelCombination[] localSkyline : localSkylines)
zeroLocalSkyline = SBBase.combineLocalSkyline(localSkyline, zeroLocalSkyline);
return zeroLocalSkyline;
}
private void pruneBuckets(final LSDAbstractTree.DirectoryNode dn, final int depth, final int[] minlevels, ArrayList<FlatLevelCombination[]> localSkylines)
{
final int dim = tree.getSplitAxis(depth);
final int oldvalue = minlevels[dim];
minlevels[dim] = dn.location;
boolean greater = true;
for(int i = 0; i < tree.dimensions; ++i) if(minlevels[i] <= tree.getLevel(nnzero.neighbor, i)) { greater = false; break; }
minlevels[dim] = oldvalue;
if(dn.left instanceof LSDAbstractTree.BucketNode) localSkylines.add( ((LSDAbstractTree.BucketNode) dn.left).computeLocalSkyline());
else pruneBuckets( ((LSDAbstractTree.DirectoryNode)dn.left), depth+1, minlevels, localSkylines);
if(!greater){
final int[] rightminlevels = minlevels.clone();
rightminlevels[dim] = dn.location;
if(dn.right instanceof LSDAbstractTree.BucketNode) localSkylines.add( ((LSDAbstractTree.BucketNode) dn.right).computeLocalSkyline());
else pruneBuckets( ((LSDAbstractTree.DirectoryNode)dn.right), depth+1, rightminlevels, localSkylines);
}
}
static FlatLevelCombination[] computeBucketSkyline(final Node n)
{
if(n instanceof BucketNode) return ((BucketNode)n).computeLocalSkyline();
else
{
final DirectoryNode dn = (DirectoryNode) n;
return SBBase.combineLocalSkyline(computeBucketSkyline(dn.left),computeBucketSkyline(dn.right));
}
}
}