import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;

class OptimalTSP {

  private static LinkedHashMap<Integer,Integer> vertices;

	public static void main(String[] args) {

    try {
      checkErrorConditions(args);
    } catch (IllegalArgumentException e) {
      System.out.println(e.getMessage());
    }

    int n = Integer.parseInt(args[0]);
    int seed = Integer.parseInt(args[1]);

    generateVertices(n, seed);

    if (n <= 10) {
      printCoordinates();
    }
    
	}

  private static void checkErrorConditions(String[] args) throws IllegalArgumentException {

    if (args.length != 2) {
      throw new IllegalArgumentException("Usage: java OptimalTSP n seed");
    }

    for (int i = 0; i < 2; i++) {
      try {
        Integer.parseInt(args[i]);
      } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Command line args must be integers");
      }
    }

    Integer n = Integer.parseInt(args[0]);
    if (n < 1 || n > 13) {
      throw new IllegalArgumentException("Number of vertices must be between 1 and 13");
    }
  }

  private static void generateVertices(int n, int seed) {
    
    Random randomX = new Random(seed);
    Random randomY = new Random(seed*2);
    vertices = new LinkedHashMap<Integer,Integer>(n);

    while (vertices.size() < n) {
      int x = randomX.nextInt(n);
      int y = randomY.nextInt(n);

      if (vertices.containsKey(x)) {
        continue;
      } else {
        vertices.put(x, y);
      }
    }
  }

  private static void printCoordinates() {

    System.out.println("X-Y Coordinates:");

    int index = 0;
    for (Map.Entry<Integer, Integer> entry : vertices.entrySet()) {
      System.out.format("v%d: (%d,%d) ", index, entry.getKey(), entry.getValue());
      index++;
    }

    System.out.println();
  }
}
@@ -1,24 +1,84 @@
+import java.text.DecimalFormat;%0Aimport java.util.ArrayList;%0A
 import java.util.LinkedH
@@ -81,24 +81,47 @@
 kedHashMap;%0A
+import java.util.List;%0A
 import java.
@@ -233,16 +233,53 @@
 ertices;
+%0A  private static double%5B%5D%5B%5D adjMtrx;
 %0A%0A%09publi
@@ -440,24 +440,46 @@
 Message());%0A
+      System.exit(0);%0A
     %7D%0A%0A    i
@@ -585,16 +585,47 @@
 , seed);
+%0A    generateAdjacencyMatrix();
 %0A%0A    if
@@ -663,22 +663,53 @@
 ates();%0A
+      printAdjacencyMatrix();%0A
     %7D%0A
+%0A
     %0A%09%7D%0A
@@ -1712,32 +1712,1133 @@
    %7D%0A    %7D%0A  %7D%0A%0A
+  private static void generateAdjacencyMatrix() %7B%0A%0A    List%3CMap.Entry%3CInteger, Integer%3E%3E entries =%0A      new ArrayList%3CMap.Entry%3CInteger, Integer%3E%3E(vertices.entrySet());%0A    adjMtrx = new double%5Bentries.size()%5D%5Bentries.size()%5D;%0A%0A    for (int x = 0; x %3C entries.size(); x++) %7B%0A      for (int y = 0; y %3C entries.size(); y++) %7B%0A        adjMtrx%5Bx%5D%5By%5D = calculateVertexDistance(entries.get(x), entries.get(y));%0A        adjMtrx%5By%5D%5Bx%5D = adjMtrx%5Bx%5D%5By%5D;%0A      %7D%0A    %7D%0A  %7D%0A%0A  private static Double calculateVertexDistance(Map.Entry%3CInteger,Integer%3E v1, Map.Entry%3CInteger,Integer%3E v2) %7B%0A    %0A    int x1 = v1.getKey();%0A    int x2 = v2.getKey();%0A    int y1 = v1.getValue();%0A    int y2 = v2.getValue();%0A%0A    return Math.sqrt(Math.pow(x2-x1, 2) + Math.pow(y2-y1, 2)) ; %0A  %7D%0A%0A  private static void printAdjacencyMatrix() %7B%0A%0A    System.out.println(%22Adjacency matrix of graph weights:%5Cn%22);%0A%0A    DecimalFormat df = new DecimalFormat(%220.00%22);%0A    for (double%5B%5D row : adjMtrx) %7B%0A      for (double distance : row) %7B%0A        System.out.printf(%22%25s%5Ct%22, df.format(distance));%0A      %7D%0A      System.out.println(%22%5Cn%22);%0A    %7D%0A  %7D%0A%0A
   private static
@@ -3098,24 +3098,24 @@
 x++;%0A    %7D%0A%0A
-
     System.o
@@ -3125,16 +3125,20 @@
 println(
+%22%5Cn%22
 );%0A  %7D%0A%7D

generate adjacency matrix; matrix printing