Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. static double[][] times = new double[2644][2644];
  2. static Order[] orders = new Order[3000];
  3.  
  4. public static void readTimes(){
  5. BufferedReader br;
  6. int i = 0;
  7. try {
  8. br = new BufferedReader(new FileReader("times.txt"));
  9. try {
  10. String x;
  11. while ( (x = br.readLine()) != null ) {
  12. String[] split = x.split(",");
  13. for (int j = 0; j < split.length; j++){
  14. times[i][j] = Double.parseDouble(split[j]);
  15. }
  16. i++;
  17. }
  18. } catch (IOException e) {
  19. e.printStackTrace();
  20. }
  21. } catch (FileNotFoundException e) {
  22. System.out.println(e);
  23. e.printStackTrace();
  24. }
  25. }
  26. public static void readOrders(){
  27. BufferedReader br;
  28. int i = 0;
  29. try {
  30. br = new BufferedReader(new FileReader("order.csv"));
  31. try {
  32. String x;
  33. while ( (x = br.readLine()) != null ) {
  34. String[] split = x.split(",");
  35. orders[i] = new Order(Integer.parseInt(split[1]),Integer.parseInt(split[2]),Integer.parseInt(split[3]));
  36. i++;
  37. }
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. } catch (FileNotFoundException e) {
  42. System.out.println(e);
  43. e.printStackTrace();
  44. }
  45. }
  46. public class Order {
  47. public int A;
  48. public int B;
  49. public int T;
  50. public Order(int A, int B, int T){
  51. this.A = A;
  52. this.B = B;
  53. this.T = T;
  54. }
  55. }
  56.  
  57.  
  58.  
  59. public static double calcTimeForList(LinkedList<Integer> list) {
  60. if (list.size() == 0) return 0;
  61. if (list.size() == 1) {
  62. Order order = orders[list.get(0)];
  63. return times[order.A][order.B];
  64. }
  65. if (list.size() == 2) {
  66. Order order = orders[list.get(0)];
  67. Order order2 = orders[list.get(1)];
  68. double res1 = times[order.A][order.B] + times[order.B][order2.B];
  69. double res2 = times[order2.A][order2.B] + times[order.B][order2.B];
  70. if (res1 < res2) return res1;
  71. else return res2;
  72. }
  73. double min = 99999999;
  74. for (int i = 0; i < list.size(); i++) {
  75. for (int j = 0; j < list.size(); j++) {
  76. for (int k = 0; k < list.size(); k++) {
  77. if (i != j && j != k) {
  78. Order order = orders[i];
  79. Order order1 = orders[j];
  80. Order order2 = orders[k];
  81. double d = times[order.A][order.B] + times[order.B][order1.B] + times[order1.B][order2.B];
  82. if (d < min) {
  83. min = d;
  84. }
  85. }
  86. }
  87. }
  88. }
  89. return min;
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement