1 function exportData (randomR,randomD,nearestR,nearestD,farthestR,...
\r
2 farthestD,enumR,enumD,coordMatrix,distanceMatrix)
\r
3 % Prompts the user to specify a location to save the file containing the
\r
4 % exported TSP data and then exports it to the specified file.
\r
9 [FileName,PathName] = uiputfile('*.txt','Export Data','ExportData');
\r
10 filePath = [PathName FileName];
\r
12 % Open the file in write mode
\r
13 fid = fopen(filePath, 'wt');
\r
15 % Create the header for the file
\r
16 fprintf(fid,'### TRAVELLING SALESMAN PROBLEM ###\n\n');
\r
18 % Enter the matrix data
\r
19 fprintf(fid,'=== Location Matrix ===\n\n');
\r
20 fprintf(fid,'-#-\t -X-\t -Y-\t\n\n');
\r
21 fprintf(fid,'%.0f\t %.0f\t %.0f\t\n',coordMatrix');
\r
22 fprintf(fid,'\n\n');
\r
24 fprintf(fid,'=== Distance Matrix ===\n\n');
\r
25 for i = 1:size(distanceMatrix,1)
\r
26 for j = 1:size(distanceMatrix,2)
\r
27 fprintf(fid,'%.0f\t',distanceMatrix(i,j));
\r
31 fprintf(fid,'\n\n');
\r
33 % Enter the Random Heuristic data
\r
34 fprintf(fid,'=== Random Heuristic ===\n\n');
\r
35 fprintf(fid,'Route:\t\t');
\r
36 fprintf(fid,randomR);
\r
37 fprintf(fid,'\n\n');
\r
38 fprintf(fid,'Distance:\t');
\r
39 fprintf(fid,'%.3f km\n\n',randomD);
\r
41 % Enter the Nearest Neighbour Heuristic data
\r
42 fprintf(fid,'=== Nearest Neighbour Heuristic ===\n\n');
\r
43 fprintf(fid,'Route:\t\t');
\r
44 fprintf(fid,nearestR);
\r
45 fprintf(fid,'\n\n');
\r
46 fprintf(fid,'Distance:\t');
\r
47 fprintf(fid,'%.3f km\n\n',nearestD);
\r
49 % Enter the Farthest Neighbour Heuristic data
\r
50 fprintf(fid,'=== Farthest Neighbour Heuristic ===\n\n');
\r
51 fprintf(fid,'Route:\t\t');
\r
52 fprintf(fid,farthestR);
\r
53 fprintf(fid,'\n\n');
\r
54 fprintf(fid,'Distance:\t');
\r
55 fprintf(fid,'%.3f km\n\n',farthestD);
\r
57 % Enter the Enumerative Heuristic data
\r
58 fprintf(fid,'=== Enumerative Heuristic ===\n\n');
\r
60 fprintf(fid,'Route:\t\t');
\r
62 fprintf(fid,'\n\n');
\r
63 fprintf(fid,'Distance:\t');
\r
64 fprintf(fid,'%.3f km\n',enumD);
\r
66 fprintf(fid,'Route:\t\t');
\r
67 fprintf(fid,'Not Available\n\n');
\r
68 fprintf(fid,'Distance:\t');
\r
69 fprintf(fid,'Not Available\n');
\r