Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package compute;
- import java.util.Arrays;
- public class Main {
- public static void main(String[] args) {
- _stats();
- }
- static void _stats(){
- int[] vals = new int[]{5, 10, 50, 100, 1000, 5000,
- 10000, 15000, 20000, 25000, 30000, 35000, 40000};
- System.out.println("n | Brute-Force | Divide and conquer");
- for(int i =0;i<vals.length;i++){
- System.out.print(vals[i]+" | ");
- point[] pts = rand_pts(vals[i], vals[i]-vals[i]*.7);
- long t = System.currentTimeMillis();
- closestpair.naive(pts);
- System.out.print((System.currentTimeMillis()-t)+" | ");
- point[] cpts = make_copy(pts);
- t = System.currentTimeMillis();
- closestpair.divideAndConquer(cpts);
- System.out.println((System.currentTimeMillis()-t));
- }
- }
- static void _test(){
- point[] pts = rand_pts(50000, 10);
- long t = System.currentTimeMillis();
- System.out.println(Arrays.toString(closestpair.naive(pts)));
- System.out.println("brute-force: "+(System.currentTimeMillis()-t));
- point[] cpts = make_copy(pts);
- t = System.currentTimeMillis();
- System.out.println(Arrays.toString(closestpair.divideAndConquer(cpts)));
- System.out.println("divide and conquer: "+(System.currentTimeMillis()-t));
- }
- static void test(){
- point[] pts = new point[]{
- new point(1, 7.7734, 4.4243),
- new point(2, 4.2401, 6.4828),
- new point(3, 5.0661, 7.0897),
- new point(4, 4.1967, 4.7368),
- new point(5, 5.0151, 2.6063),
- new point(6, 6.5864, 6.4131),
- new point(7, 1.7985, 3.1026),
- new point(8, 7.1108, 3.0596),
- new point(9, 2.5118, 4.5105),
- new point(10, 4.9114, 4.2766),
- new point(11, 7.0471, 5.6371),
- new point(12, 4.1030, 1.3781),
- new point(13, 3.1418, 3.4415),
- new point(14, 1.8617, 1.6294)
- };
- long t = System.currentTimeMillis();
- System.out.println(Arrays.toString(closestpair.naive(pts)));
- System.out.println("brute-force: "+(System.currentTimeMillis()-t));
- point[] cpts = make_copy(pts);
- t = System.currentTimeMillis();
- System.out.println(Arrays.toString(closestpair.divideAndConquer(cpts)));
- System.out.println("divide and conquer: "+(System.currentTimeMillis()-t));
- }
- static point[] make_copy(point[] t){
- point[] r = new point[t.length];
- for(int i=0;i<r.length;i++){
- r[i] = new point(t[i]);
- }
- return r;
- }
- static point[] rand_pts(int n, double max){
- point[] r = new point[n];
- for(int i=0;i<r.length;i++){
- double x = Math.round(max*Math.random()*10000)/(double)10000;
- double y = Math.round(max*Math.random()*10000)/(double)10000;
- r[i] = new point(i+1, x, y);
- }
- return r;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment