Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static double[][] times = new double[2644][2644];
- static Order[] orders = new Order[3000];
- public static void readTimes(){
- BufferedReader br;
- int i = 0;
- try {
- br = new BufferedReader(new FileReader("times.txt"));
- try {
- String x;
- while ( (x = br.readLine()) != null ) {
- String[] split = x.split(",");
- for (int j = 0; j < split.length; j++){
- times[i][j] = Double.parseDouble(split[j]);
- }
- i++;
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (FileNotFoundException e) {
- System.out.println(e);
- e.printStackTrace();
- }
- }
- public static void readOrders(){
- BufferedReader br;
- int i = 0;
- try {
- br = new BufferedReader(new FileReader("order.csv"));
- try {
- String x;
- while ( (x = br.readLine()) != null ) {
- String[] split = x.split(",");
- orders[i] = new Order(Integer.parseInt(split[1]),Integer.parseInt(split[2]),Integer.parseInt(split[3]));
- i++;
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (FileNotFoundException e) {
- System.out.println(e);
- e.printStackTrace();
- }
- }
- public class Order {
- public int A;
- public int B;
- public int T;
- public Order(int A, int B, int T){
- this.A = A;
- this.B = B;
- this.T = T;
- }
- }
- public static double calcTimeForList(LinkedList<Integer> list) {
- if (list.size() == 0) return 0;
- if (list.size() == 1) {
- Order order = orders[list.get(0)];
- return times[order.A][order.B];
- }
- if (list.size() == 2) {
- Order order = orders[list.get(0)];
- Order order2 = orders[list.get(1)];
- double res1 = times[order.A][order.B] + times[order.B][order2.B];
- double res2 = times[order2.A][order2.B] + times[order.B][order2.B];
- if (res1 < res2) return res1;
- else return res2;
- }
- double min = 99999999;
- for (int i = 0; i < list.size(); i++) {
- for (int j = 0; j < list.size(); j++) {
- for (int k = 0; k < list.size(); k++) {
- if (i != j && j != k) {
- Order order = orders[i];
- Order order1 = orders[j];
- Order order2 = orders[k];
- double d = times[order.A][order.B] + times[order.B][order1.B] + times[order1.B][order2.B];
- if (d < min) {
- min = d;
- }
- }
- }
- }
- }
- return min;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement