|
What are the main goals of this assignment? You should (i) learn about the notorious traveling salesperson problem, (ii) learn to use linked lists, and (iii) get more practice with data types.
What files do I need to write? Point and Tour. The Tour data type is the most interesting one because it involves using linked structures.
How do I represent infinity in Java? Use Double.POSITIVE_INFINITY.
How long should my programs take to execute? It should take less than a minute for the 13,509 city example (substantially less if you have a fast computer), unless you're animating the results, in which case it will take considerably longer. If your code takes much much longer, try to discover why (think analysis of algorithms), and explain it in your readme file.
What is the file Tour$Node.class? When you declare a nested class like Node, the Java compiler uses the $ symbol to mark its name.
What is a NullPointerException? You can get one by initializing a variable of type Node, say x, to null and then accessing x.next or x.p. This can happen in your insertion routine if you inadvertently break up the circular linked list.
When should I create a new linked list node with the keyword new? To create a tour with N elements, you should use new exactly N times with Node, once per invocation of insert. It is unnecessary (and bad style) to use new with your list traversal variables since this allocates memory that you never use.
How can I produce an animation of the heuristic in action? It's easy and instructive - just redraw the tour after each insertion. See the instructions in SmallestInsertion.java. It could take a while on a big input file, so you might want to modify it so that it redraws only after every 20 insertions or so.
Can I use Java's built in LinkedList class? Absolutely not! One of the main goals of this assignment is to gain experience writing and using linked structures. The Java libraries can only take you so far, and you will quickly discover applications which cannot be solved without devising your own linked structures. Stay tuned.
Is this the same type of approach used in MapQuest? Similar, but not quite the same. Roughly speaking, MapQuest's problem is to find a shortest path between two distinguished points in a network where only certain pairs of points are connected by edges (roads). This problem is much better understood than the TSP,and there are remarkably efficient algorithms for solving it.
For the extra credit, how fast should my solution be? Obviously it depends on the speed of your computer, but say around 5 minutes for usa13509.txt. If your program is substantially slower, consult a preceptor for suggestions on speeding it up.
Do I have to used a linked list for the extra credit? No.
|
Input. There are many sample data files (with extension .txt) available in /u/cs126/files/tsp/. Most are taken from TSPLIB.
Debugging. A good debugging strategy for most programs is to test your code on inputs that you can easily solve by hand. Start with 1 and 2 city problems. Then, do the 4 city problem. Choose the data so that it is easy to work through the code by hand. Draw pictures. If your code does not do exactly what your hand calculations indicate, determine where they differ. Use the System.out.print method.
Compilation. Your programs must be named Tour.java and Point.java. Don't forget to hit the Run Script button on the submission system to test that it compiles cleanly.
Execution. Use the following command to execute the client NearestInsertion.java
Or, if your program has alot of output, usejava NearestInsertion < tsp10.txt
java NearestInsertion < tsp1000.txt | more
Checking your work. For usa13509.txt we get distances of 50538.33716519955 and 29710.412348094807 for nearest insertion and smallest insertion, respectively. For circuit1290.txt we get 25029.790452731024 (or 25091.6899) and 14596.097124575306. Note that there two possible correct answers with the nearest insertion heuristic because after inserting the first 3 points, there are two distinct tours that have the same length: A->B->C and A->C->B. Depending on which one your program chooses, you can end up with a different tour length (possibly better, possibly worse) down the road.
Timing. Use the client program TSPTimer.java to help you estimate the running time as a function of the input size N. It takes one command line input N, runs the two heuristics, and prints out how long each took.
|
Submission. Submit the following files: readme.txt, Tour.java, Point.java.
readme.txt. Use the following readme file template. You will lose points if you don't address these questions.
|
These are purely suggestions for how you might make progress. You do not have to follow these steps.
public Tour() { Node a = new Node(); Node b = new Node(); Node c = new Node(); Node d = new Node(); a.p = new Point(100.0, 100.0); b.p = new Point(500.0, 100.0); c.p = new Point(500.0, 500.0); d.p = new Point(100.0, 500.0); a.next = b; b.next = c; c.next = d; d.next = a; first = a; }
Test your show method on inputs with 0, 1 and 2 points to check that it still works. You can create such instances by modifying the 4-node debugging constructor.(100.0, 100.0) (500.0, 100.0) (500.0, 500.0) (100.0, 500.0)
|
Possibilities for improvement are endless. Here are some ideas. If you are shooting for an A or A+, this is a good opportunity to impress us. However, be warned, this is a difficult extra credit. If you complete the extra credit, submit a program ExtraCredit.java along with any accompanying files. You need not reuse the Tour data type or linked lists, but you should exercise good modular design.
|