Question: Please reference this program ( deliverable B ) to answer the question: import java.io . * ; import java.util. * ; public class DeliverableB {
Please reference this program deliverable B to answer the question:
import java.io;
import java.util.;
public class DeliverableB
File inputFile;
File outputFile;
PrintWriter output;
Graph g;
initialize the input file and graph
public DeliverableB File in Graph gr
inputFile in;
g gr;
setting up the output file
String inputFileName inputFile.toString;
String baseFileName inputFileName.substring inputFileName.length;
String outputFileName baseFileName.concatbitoniout.txt;
outputFile new FileoutputFileName;
if the output file already exists, delete it
ifoutputFileexists
outputFile.delete;
try
output new PrintWriteroutputFile;
catch Exception x
System.err.format Exception: sn x;
System.exit;
sort the cities based on values longitude latitude
Collections.sortggetNodeList new Comparator
@Override
public int compareNode n Node n
return Double.comparengetVal ngetVal;
;
calculate the shortest bitonic tour
int numCities ggetNodeListsize;
distance matrix
double distance new doublenumCitiesnumCities;
table for dp
double dp new double numCitiesnumCities;
int path new intnumCitiesnumCities;
intialize the distance matrix
for int i ; i numCities; i
forint j i; j numCities; i
distanceij ggetNodeListgetifindEdgeToggetNodeList;
distanceji distanceij;
initializing dp table
for int i ; i numCities; i
for int j ; j numCities; j
dpij Double.POSITIVEINFINITY;
begin from the first city, set distance to
dp;
fill out DP table with bitonic tour algorithm
for int j ; j numCities; j
for int i ; i j; i
if i j
for int k ; k i; k
if dpki distancekj dpij
dpij dpki distancekj;
add previous city to the path
pathij k;
else
dpij dpij distancej j;
add current city to the path
pathij i;
the trip from the last city to origin
double minTourLength dpnumCities numCities distancenumCities numCities ;
int endCity numCities ;
int endCity numCities ;
output the total distance travelled of the bitonic tour
System.out.printlnShortest bitonic tour has distance minTourLength;
List tour new ArrayList;
reconstructPathpath endCity endCity g tour;
output tour info
System.out.printTour is ;
for Node node : tour
System.out.printnodegetAbbrev;
output.printnodegetAbrrev;
private void reconstructPathint path, int i int j Graph g List tour
ifi j
reconstructPathpath pathij i g tour;
add cities i and j to the path
tour.addggetNodeListgeti;
tour.addggetNodeListgetj;
Start with your ideally working submission of Deliverable B Read a file of the name Fctxt This is a file of distances between cities in which the value of each city is either
S Starting city
G Goal city
~ neither starting nor goal city
Perform a depthfirst branchandbound search, beginning with the starting city, to find the nearest goal city. Report the nearest goal city, and the distance to it in the format listed below.
Algorithm:
The depthfirstsearch algorithm is described in the powerpoint slides and video Search III DFS and its use for branchandbound is described in Search VII Bounded DFS comments This is consistent I think with Chapter of the CLFS textbook and Chapter of the P&M textbook. The details of the algorithm are the same as they were for the Homework on this topic:
Measure the depth bound in terms of total distance to the goal node as measured by edge lengths.
When choosing which node to visit next, visit the nearest unvisited node. Break ties alphabetically.
Output:
The input will be a table of distances representing a graph.
Example Fc:
Source is B goal is E I may test with this file, with same or different source node andor goal nodes
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
