Exemple #1
0
  public void solveTSP(String file, int numNodes) {
    InputFileProcessor processor = new InputFileProcessor(file, numNodes);

    try {
      int adjMatrix[][] = processor.initializeMatrix();

      GreedyTSP greedy = new GreedyTSP(adjMatrix);
      ArrayList<Integer> path = greedy.shortestPath();

      TwoOpt optimizer = new TwoOpt(path, adjMatrix);
      ArrayList<Integer> newPath = optimizer.optimize();
      newPath.forEach(x -> System.out.print(x + " "));

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemple #2
0
  public static void main(String args[]) {

    String input = "/Users/Emma/GitHub/TSP/input/input.txt";
    InputFileProcessor processor = new InputFileProcessor(input, 4);

    try {
      int adjMatrix[][] = processor.initializeMatrix();

      GreedyTSP greedy = new GreedyTSP(adjMatrix);
      ArrayList<Integer> path = greedy.shortestPath();
      path.forEach(x -> System.out.print(x + " "));
      System.out.println();

      TwoOpt optimizer = new TwoOpt(path, adjMatrix);
      ArrayList<Integer> newPath = optimizer.optimize();
      newPath.forEach(x -> System.out.print(x + " "));

    } catch (Exception e) {
      e.printStackTrace();
    }
  }