mramine364

Main.java

Jan 6th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1.  
  2. package compute;
  3.  
  4. import java.util.Arrays;
  5.  
  6.  
  7. public class Main {
  8.  
  9. public static void main(String[] args) {
  10.  
  11. _stats();
  12.  
  13. }
  14.  
  15. static void _stats(){
  16. int[] vals = new int[]{5, 10, 50, 100, 1000, 5000,
  17. 10000, 15000, 20000, 25000, 30000, 35000, 40000};
  18.  
  19. System.out.println("n | Brute-Force | Divide and conquer");
  20. for(int i =0;i<vals.length;i++){
  21. System.out.print(vals[i]+" | ");
  22. point[] pts = rand_pts(vals[i], vals[i]-vals[i]*.7);
  23. long t = System.currentTimeMillis();
  24. closestpair.naive(pts);
  25. System.out.print((System.currentTimeMillis()-t)+" | ");
  26.  
  27. point[] cpts = make_copy(pts);
  28. t = System.currentTimeMillis();
  29. closestpair.divideAndConquer(cpts);
  30. System.out.println((System.currentTimeMillis()-t));
  31. }
  32.  
  33. }
  34.  
  35. static void _test(){
  36. point[] pts = rand_pts(50000, 10);
  37.  
  38. long t = System.currentTimeMillis();
  39. System.out.println(Arrays.toString(closestpair.naive(pts)));
  40. System.out.println("brute-force: "+(System.currentTimeMillis()-t));
  41.  
  42. point[] cpts = make_copy(pts);
  43. t = System.currentTimeMillis();
  44. System.out.println(Arrays.toString(closestpair.divideAndConquer(cpts)));
  45. System.out.println("divide and conquer: "+(System.currentTimeMillis()-t));
  46.  
  47. }
  48.  
  49. static void test(){
  50. point[] pts = new point[]{
  51. new point(1, 7.7734, 4.4243),
  52. new point(2, 4.2401, 6.4828),
  53. new point(3, 5.0661, 7.0897),
  54. new point(4, 4.1967, 4.7368),
  55. new point(5, 5.0151, 2.6063),
  56. new point(6, 6.5864, 6.4131),
  57. new point(7, 1.7985, 3.1026),
  58. new point(8, 7.1108, 3.0596),
  59. new point(9, 2.5118, 4.5105),
  60. new point(10, 4.9114, 4.2766),
  61. new point(11, 7.0471, 5.6371),
  62. new point(12, 4.1030, 1.3781),
  63. new point(13, 3.1418, 3.4415),
  64. new point(14, 1.8617, 1.6294)
  65. };
  66.  
  67. long t = System.currentTimeMillis();
  68. System.out.println(Arrays.toString(closestpair.naive(pts)));
  69. System.out.println("brute-force: "+(System.currentTimeMillis()-t));
  70.  
  71. point[] cpts = make_copy(pts);
  72. t = System.currentTimeMillis();
  73. System.out.println(Arrays.toString(closestpair.divideAndConquer(cpts)));
  74. System.out.println("divide and conquer: "+(System.currentTimeMillis()-t));
  75.  
  76. }
  77.  
  78. static point[] make_copy(point[] t){
  79. point[] r = new point[t.length];
  80. for(int i=0;i<r.length;i++){
  81. r[i] = new point(t[i]);
  82. }
  83. return r;
  84. }
  85.  
  86. static point[] rand_pts(int n, double max){
  87. point[] r = new point[n];
  88. for(int i=0;i<r.length;i++){
  89. double x = Math.round(max*Math.random()*10000)/(double)10000;
  90. double y = Math.round(max*Math.random()*10000)/(double)10000;
  91. r[i] = new point(i+1, x, y);
  92. }
  93. return r;
  94. }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment