-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup_TSPLIB.m
More file actions
155 lines (144 loc) · 5.46 KB
/
setup_TSPLIB.m
File metadata and controls
155 lines (144 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
% This script performs the files setup for the TSP Problem. The data is
% automatically downloaded from
% http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/
webFile = 'http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/tsp/ALL_tsp.tar.gz';
filesPath = fullfile(fileparts(fileparts(which('tsphopfieldnet.m'))),'data');
fprintf(1,'\nDownloading TSPLIB library...\n');
tempFile = 'ALL_tsp.tar.gz';
try
websave(fullfile(filesPath,tempFile), webFile);
catch me
fprintf(1,'Please, make sure you have Internet connection\n');
end
fprintf(1,'TSPLIB files downloaded!\n');
TSPFilesDir = fullfile(filesPath,'TSPFiles');
TSPToursDir = fullfile(TSPFilesDir,'TSPTours');
untar(fullfile(filesPath,tempFile),TSPFilesDir)
gunzip(fullfile(TSPFilesDir,'*.gz'),TSPFilesDir);
delete(fullfile(TSPFilesDir,'*.gz'));
delete(fullfile(filesPath,tempFile));
mkdir(TSPToursDir)
movefile(fullfile(TSPFilesDir,'*.tour'),TSPToursDir)
% The missing optimum tour are downloaded
missingTours = 'http://www.akira.ruc.dk/~keld/research/LKH/LKH-1.2/TOURS/';
fprintf(1,'\nDownloading missing TSPLIB Tours from alternative repository...\n');
missingFiles = {'ali535.opt.tour',...
'att532.opt.tour',...
'bier127.opt.tour',...
'brazil58.opt.tour',...
'brd14051.469388.tour',...
'burma14.opt.tour',...
'd1291.opt.tour',...
'd15112.opt.tour',...
'd1655.opt.tour',...
'd18512.645244.tour',...
'd198.opt.tour',...
'd2103.opt.tour',...
'd493.opt.tour',...
'd657.opt.tour',...
'dantzig42.opt.tour',...
'dsj1000.opt.tour',...
'fl1400.opt.tour',...
'fl1577.opt.tour',...
'fl3795.opt.tour',...
'fl417.opt.tour',...
'fnl4461.opt.tour',...
'gil262.opt.tour',...
'gr137.opt.tour',...
'gr17.opt.tour',...
'gr21.opt.tour',...
'gr229.opt.tour',...
'gr431.opt.tour',...
'hk48.opt.tour',...
'kroA150.opt.tour',...
'kroA200.opt.tour',...
'kroB100.opt.tour',...
'kroB150.opt.tour',...
'kroB200.opt.tour',...
'kroE100.opt.tour',...
'lin318.opt.tour',...
'linhp318.opt.tour',...
'nrw1379.opt.tour',...
'p654.opt.tour',...
'pcb1173.opt.tour',...
'pcb3038.opt.tour',...
'pla33810.66050599.tour',...
'pla7397.opt.tour',...
'pla85900.142393738.tour',...
'pr107.opt.tour',...
'pr124.opt.tour',...
'pr136.opt.tour',...
'pr144.opt.tour',...
'pr152.opt.tour',...
'pr226.opt.tour',...
'pr264.opt.tour',...
'pr299.opt.tour',...
'pr439.opt.tour',...
'rat195.opt.tour',...
'rat575.opt.tour',...
'rat783.opt.tour',...
'rat99.opt.tour',...
'rd400.opt.tour',...
'rl11849.opt.tour',...
'rl1304.opt.tour',...
'rl1323.opt.tour',...
'rl1889.opt.tour',...
'rl5915.opt.tour',...
'rl5934.opt.tour',...
'si1032.opt.tour',...
'si175.opt.tour',...
'si535.opt.tour',...
'swiss42.opt.tour',...
'ts225.opt.tour',...
'u1060.opt.tour',...
'u1432.opt.tour',...
'u159.opt.tour',...
'u1817.opt.tour',...
'u2152.opt.tour',...
'u2319.opt.tour',...
'u574.opt.tour',...
'u724.opt.tour',...
'usa13509.opt.tour',...
'vm1084.opt.tour',...
'vm1748.opt.tour'};
try
for f = 1:length(missingFiles)
websave(fullfile(TSPToursDir,missingFiles{f}), [missingTours,missingFiles{f}]);
end
catch me
fprintf(1,'Please, make sure you have Internet connection\n');
end
fprintf(1,'Missing TSPLIB Tour files downloaded!\n');
fprintf(1,'\nParsing files to match repositories...\n');
for f = 1:length(missingFiles)
fid = fopen(fullfile(TSPToursDir,missingFiles{f}));
fid2 = fopen(fullfile(TSPToursDir,[missingFiles{f},'_dupped']),'w');
while ~feof(fid)
str = fgetl(fid);
if strncmp(str,'TOUR_SECTION',12)
str = 'TOUR_SECTION';
end
fprintf(fid2,[str,'\n']);
end
fclose(fid);
fclose(fid2);
movefile(fullfile(TSPToursDir,[missingFiles{f},'_dupped']),fullfile(TSPToursDir,missingFiles{f}))
end
tspFiles = dir(fullfile(TSPFilesDir,'*.tsp'));
tspFiles = {tspFiles.name}';
for f = 1:length(tspFiles)
fid = fopen(fullfile(TSPFilesDir,tspFiles{f}));
fid2 = fopen(fullfile(TSPFilesDir,[tspFiles{f},'_dupped']),'w');
while ~feof(fid)
str = fgetl(fid);
if strncmp(str,'NODE_COORD_SECTION',18)
str = 'NODE_COORD_SECTION';
end
fprintf(fid2,[str,'\n']);
end
fclose(fid);
fclose(fid2);
movefile(fullfile(TSPFilesDir,[tspFiles{f},'_dupped']),fullfile(TSPFilesDir,tspFiles{f}))
end
fprintf(1,'All files parsed.\n');
fprintf(1,'\nTSPLIB library is ready to be used.\n');