/************************************************************************* * YOU DO NOT NEED TO MODIFY THIS FILE * * Compilation: javac NearestInsertionDraw.java * Execution: java NearestInsertionDraw < file.txt * Dependencies: Tour.java Point.java StdIn.java StdDraw.java * * Run smallest insertion heuristic for traveling salesperson problem * and plot results. * * % java NearestInsertionDraw < tsp1290.txt * *************************************************************************/ public class NearestInsertionDraw { public static void main(String[] args) { // get dimensions int w = StdIn.readInt(); int h = StdIn.readInt(); StdDraw.setCanvasSize(w, h); StdDraw.setXscale(0, w); StdDraw.setYscale(0, h); // turn on animation mode StdDraw.show(0); // run smallest 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); // uncomment the 4 lines below to animate // StdDraw.clear(); // tour.draw(); // StdDraw.text(100, 0, "" + tour.distance()); // StdDraw.show(50); } tour.show(); tour.draw(); StdDraw.text(100, 0, "" + tour.distance()); StdDraw.show(0); } }