import java.util.*; import java.io.*; /** * A TSP object is a representation of a traveling salesman problem * and provides methods to display the TSP, display a tour of that tsp * and to get inter-city distances and the total cost of a tour * where a tour is an integer array containg a permutation of the integers 0 to n-1 */ public class TSP { private ArrayList X,Y; private double[][] Cost; private int xMin,xMax,yMin,yMax; private int n; private double pointSize; private String fname; public TSP(String fname) throws IOException { X = new ArrayList(); Y = new ArrayList(); this.fname = fname; pointSize = 1.0; Scanner sc = new Scanner(new File(fname)); xMin = yMin = Integer.MAX_VALUE; xMax = yMax = Integer.MIN_VALUE; n = 0; while (sc.hasNext()){ int x = sc.nextInt(); int y = sc.nextInt(); xMin = Math.min(xMin,x); xMax = Math.max(xMax,x); yMin = Math.min(yMin,y); yMax = Math.max(yMax,y); X.add(x); Y.add(y); n++; } sc.close(); makeCostMatrix(); } private void makeCostMatrix(){ Cost = new double[n][n]; double x,y; for (int i=0;i