/************************************************************************* * YOU DO NOT NEED TO MODIFY THIS FILE * * Compilation: javac NearestInsertion.java * Execution: java NearestInsertion < file.txt * Dependencies: Tour.java Point.java StdIn.java * * Run nearest insertion heuristic for traveling salesperson problem * and print resulting tour to standard output. * * % java NearestInsertion < tsp100.txt | more * * *************************************************************************/ public class NearestInsertion { public static void main(String[] args) { // get dimensions and ignore since no plotting in this client int w = StdIn.readInt(); int h = StdIn.readInt(); // read in data and run nearest insertion heuristic Tour tour = new Tour(); while (!StdIn.isEmpty()) { double x = StdIn.readDouble(); double y = StdIn.readDouble(); Point p = new Point(x, y); tour.insertNearest(p); } // print results System.out.println("Tour distance = " + tour.distance()); tour.show(); } }