-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
118 lines (109 loc) · 4.86 KB
/
Main.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
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class Main {
private static double SIZE = 35;
private static int PARTICLES = 350;
private static double RADIUS = 3;
static int x = 0;
public static void main(String[] args) {
if (args.length > 0 && args[0].equals("test")) {
test();
} else {
Space s = new Space(SIZE);
s.setCriticalRadius(RADIUS);
// s.setRadiusLimits(1, 4);
s.initialize(PARTICLES, .5);
s.calculateCells();
s.outputInitialState();
s.outputNeighbours();
}
}
public static void test() {
final double size = 20, radius = 1, particleRadius = .25;
int gridSize, particles;
Map<Integer, Double> elapsedTimes = new TreeMap<>();
System.out.println("Starting performance test\n");
System.out.println("CELL INDEX METHOD");
// Test performance with fixed grid size as 13
System.out.println("Test performance with fixed grid size as 13");
gridSize = 13;
Space s;
for (particles = 0; particles <= 1000; particles += 100) {
List<Double> times = new ArrayList<>();
for (int i = 0; i < 50; i++) {
s = new Space(size);
s.setOutputElapsedTime(false);
s.setCriticalRadius(radius);
s.initialize(particles, particleRadius);
long start = System.nanoTime();
s.calculateCells(gridSize);
long end = System.nanoTime();
double elapsed = (end - start) / Math.pow(10, 6);
times.add(elapsed);
}
System.out.print(".");
elapsedTimes.put(particles, times.stream().mapToDouble(x -> x).average().getAsDouble());
}
System.out.println();
System.out.println("Performance with increasing particles for grid size of " + gridSize + ":");
System.out.println("Particles Elapsed Time [ms]");
elapsedTimes.forEach((k, v) -> System.out.println(String.format("%9d %12f", k, v)));
elapsedTimes.clear();
// Test performance with fixed particles as 1000
System.out.println("\n\nTest performance with fixed particles as 1000");
particles = 1000;
int maxGridSize = (int) (size / (radius + 2 * particleRadius));
for (gridSize = 1; gridSize <= maxGridSize; gridSize++) {
List<Double> times = new ArrayList<>();
for (int i = 0; i < 50; i++) {
s = new Space(size);
s.setOutputElapsedTime(false);
s.setCriticalRadius(radius);
s.initialize(particles, particleRadius);
long start = System.nanoTime();
s.calculateCells(gridSize);
long end = System.nanoTime();
double elapsed = (end - start) / Math.pow(10, 6);
times.add(elapsed);
}
System.out.print(".");
elapsedTimes.put(gridSize, times.stream().mapToDouble(x -> x).average().getAsDouble());
}
System.out.println();
System.out.println("Performance with increasing grid size for " + particles + " particles:");
System.out.println("Grid Size Elapsed Time [ms]");
elapsedTimes.forEach((k, v) -> System.out.println(String.format("%9d %12f", k, v)));
/*
* Brute Force Method
*/
elapsedTimes.clear();
System.out.println("---------------------------------------------------------");
System.out.println("---------------------------------------------------------");
System.out.println("BRUTE FORCE METHOD");
// Test performance with fixed grid size as 13
System.out.println("Test performance with fixed grid size as 13");
for (particles = 0; particles <= 1000; particles += 100) {
List<Double> times = new ArrayList<>();
for (int i = 0; i < 50; i++) {
s = new Space(size);
s.setOutputElapsedTime(false);
s.setCriticalRadius(radius);
s.initialize(particles, particleRadius);
long start = System.nanoTime();
s.calculateCellsBruteForce();
long end = System.nanoTime();
double elapsed = (end - start) / Math.pow(10, 6);
times.add(elapsed);
}
System.out.print(".");
elapsedTimes.put(particles, times.stream().mapToDouble(x -> x).average().getAsDouble());
}
System.out.println();
System.out.println("Performance with increasing particles for grid size of " + gridSize + ":");
System.out.println("Particles Elapsed Time [ms]");
elapsedTimes.forEach((k, v) -> System.out.println(String.format("%9d %12f", k, v)));
}
}