-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
139 lines (107 loc) · 5.7 KB
/
Main.java
File metadata and controls
139 lines (107 loc) · 5.7 KB
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
import java.util.ArrayList;
public class Main {
private static Tree tree = new Tree(new TreeNode(Double.MAX_VALUE, Double.MIN_VALUE, Double.MAX_VALUE, Double.MIN_VALUE));
public static void main(String[] args) throws Exception {
ArrayList<Location> locations = null;
Tree sKNN = new Tree();
//διάβασμα του αρχείου osm
LoadOSM osm = new LoadOSM();
osm.load_osmlife();
//διάβασμα του αρχείου datafile
LoadData data = new LoadData();
locations = data.read_data();
//δημιουργία καταλόγου
System.out.println("\nMaking index");
long beginning= System.currentTimeMillis();
tree.read_from_file();
tree.setTotal_records(data.getTotal_entries());
tree.read_from_file();
long ending= System.currentTimeMillis() - beginning ;
System.out.println("Time needed: " + ending + "ms");
//αρχικοποίηση τιμών για να τρέξουν τα ερωτήματα
int k = 5; //κοντινότεροι γείτονες
double lat = 38.444235; //x
double lon = 23.853263; //y
double range = 10; //ακτίνα
long id =35836525; //id τοποθεσίας
//προσθήκη καινούργιου στοιχείου
Location newLocation = new Location(id, lat, lon);
System.out.println("\nInsert new element " + newLocation.toString());
long startTime = System.currentTimeMillis();
int size = locations.size();
LoadOSM osm2 = new LoadOSM();
osm2.add_location(newLocation, locations);
LoadData data2 = new LoadData();
locations = data2.read_data();
if(size !=locations.size())
System.out.println("Location added.");
else
System.out.println("Location not added.");
long endTime = System.currentTimeMillis() - startTime;
System.out.println("Time needed: " + endTime + "ms");
//διαγραφή στοιχείου
System.out.println("\nDelete element " + newLocation.toString());
startTime = System.currentTimeMillis();
size = locations.size();
tree.delete_from_tree(id,locations);
if(size !=locations.size())
System.out.println("Location deleted.");
else
System.out.println("Location not deleted.");
endTime = System.currentTimeMillis() - startTime;
System.out.println("Time needed: " + endTime + "ms");
//ερώτημα περιοχής χωρίς τη βοήθεια του καταλόγου
System.out.println("\nRange query without index for range=" + range + " lat: " + lat + " lon: " + lon );
startTime = System.currentTimeMillis();
ArrayList<Location> locations_in_range = sKNN.range_query_without_index(new Location(-1, lat, lon), range, locations);
int count1 = 0;
for (Location neighbor : locations_in_range)
count1++;
//System.out.println(neighbor.toString());
endTime = System.currentTimeMillis() - startTime;
System.out.println("Time needed: " + endTime + "ms");
//ερώτημα περιοχής με τη βοήθεια του καταλόγου
System.out.println();
System.out.println("\nRange query with index for range=" + range + " lat: " + lat + " lon: " + lon );
startTime = System.currentTimeMillis();
ArrayList<Location> CloseAreasA = tree.range_query_with_index(new Point(lat, lon), range);
for (Location neighbor : CloseAreasA)
count1++;
//System.out.println(neighbor.toString());
endTime = System.currentTimeMillis() - startTime;
System.out.println("Time needed: " + endTime + "ms");
//ερώτημα k κοντινότερων γειτόνων χωρίς τη βοήθεια καταλόγου
System.out.println("\nKNN without index for k=" + k + " lat: " + lat + " lon: " + lon );
Location middle = new Location(-1, lat, lon);
startTime = System.currentTimeMillis();
ArrayList<Location> distances = sKNN.knn_without_index(locations, middle, k);
for (Location neighbor : distances)
System.out.println(neighbor.toString());
endTime = System.currentTimeMillis() - startTime;
System.out.println("Time needed: " + endTime + "ms");
//ερώτημα k κοντινότερων γειτόνων με τη βοήθεια καταλόγου
System.out.println("\nKNN with index for k=" + k + " lat: " + lat + " lon: " + lon );
Point point = new Point(lat, lon);
startTime = System.currentTimeMillis();
ArrayList<Location> Neighbors = tree.knn_with_index(point, k);
for (Location neighbor : Neighbors)
System.out.println(neighbor.toString());
endTime = System.currentTimeMillis() - startTime;
System.out.println("Time needed: " + endTime + "ms");
//ερώτημα κορυφογραμμής
System.out.println("\nSkyline");
startTime = System.currentTimeMillis();
Skyline skl = new Skyline();
ArrayList<SkylineNode> results = skl.skyline(tree);
System.out.println("Skyline result: \n" + results);
endTime = System.currentTimeMillis() - startTime;
System.out.println("Time needed: " + endTime + "ms");
//μαζική κατασκευή του δέντρου
System.out.println("\nMaking bottom up");
beginning= System.currentTimeMillis();
BottomUp b = new BottomUp();
b.build();
ending= System.currentTimeMillis() - beginning ;
System.out.println("Time needed: " + ending + "ms");
}
}