Question: This is the code for deliverable A: import java.io . * ; import java.util. * ; / / Class DelivA does the work for deliverable
This is the code for deliverable A:
import java.io;
import java.util.;
Class DelivA does the work for deliverable DelivA of the Prog
public class DelivA
File inputFile;
File outputFile;
PrintWriter output;
Graph g;
public DelivA File in Graph gr
inputFile in;
g gr;
Get output file name.
String inputFileName inputFile.toString;
String baseFileName inputFileName.substring inputFileName.length; Strip off txt
String outputFileName baseFileName.concatout.txt;
outputFile new File outputFileName ;
if outputFile.exists For retests
outputFile.delete;
try
output new PrintWriteroutputFile;
catch Exception x
System.err.formatException: sn x;
System.exit;
Design of solution:
Sort the cities by value using Arrays.sort This sounds like a general thing to do so I'll do it in the Node class.
Go from city to city until done, then go back to the first city.
Print the distance.
Collections.sort ggetNodeList new Comparator
@Override
public int compare Node n Node n
return Integer.valueOf ngetValcompareTo Integer.valueOf ngetVal;
;
int totalDist ;
System.out.print "Path ; output.print "Path ;
for Node n : ggetNodeList
System.out.print ngetAbbrev; output.print ngetAbbrev;
System.out.print ggetNodeListgetgetAbbrev; output.print ggetNodeListgetgetAbbrev;
int s ggetNodeListsize;
for int i ; i s; i
Node t ggetNodeListget i ;
Node h;
if i s
h ggetNodeListget;
else
h ggetNodeListget i;
Edge e tfindEdgeTo h ; Complete graph, we know it exists.
totalDist egetDist;
System.out.println "has distance totalDist ; output.println "has distance totalDist ;
Systemout.println "DelivA: To be implemented";
outputprintln "DelivA: To be implemented";
output.flush;
Based off of this, Start with your ideally working submission of Deliverable A Read a file of the name Fbtxt This is a file of distances between cities in which the value of each city is a floating point number that lists either the latitude or longitude of each city.
Using the algorithm one or both of the papers on bitonic tours that is in DL BitonicTour Paper Reference One andor BitonicTour Paper Reference Two find the shortest bitonic tour going from the highest value to the lowest value, then back to the highest value for each set of cities.
A bitonic tour is a Traveling Salesperson Tour Deliverable A was a Traveling Salesperson problem where you start at a given city, visit every other city in order exactly once and go back home Deliverable B is a more complex Traveling Salesperson Tour in which you start with a city at one end say most northerly or westerly go in one direction southeast to the most southerlyeasterly city maybe visiting cities along the way and return home visiting every unvisited city southtonortheasttowest on the way back.
The output should look like the photo attached. Thank you!
Output:
The input will be a table of distances representing a graph, like the one below. The largest graph I will test with will have cities.
Yields output:
Shortest bitonic tour has distance
Tour is W M C S N F D W
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
