3 int main(
int argc,
char *argv[])
8 int *GTour, *Used, Clusters = 0, i;
10 char *GTourFileName, *Line, *Keyword, Buf1[256], Buf2[256];
11 char Delimiters[] =
" :=\n\t\r\f\v\xef\xbb\xbf";
15 sprintf(Buf1,
"GTSPLIB/%s.gtsp", argv[1]);
17 sprintf(Buf2,
"G-TOURS/%s.%s.tour", argv[1], argv[2]);
28 if (!(GTourFile = fopen(GTourFileName,
"r")))
29 eprintf(
"Cannot find %s\n", GTourFileName);
30 while ((Line =
ReadLine(GTourFile))) {
31 if (!(Keyword = strtok(Line, Delimiters)))
33 for (i = 0; i < strlen(Keyword); i++)
34 Keyword[i] = (
char) toupper(Keyword[i]);
35 if (!strcmp(Keyword,
"TOUR_SECTION"))
37 if (
Optimum == 0 && !strcmp(Keyword,
"COMMENT")) {
38 Keyword = strtok(0, Delimiters);
39 Keyword = strtok(0, Delimiters);
42 if (!strcmp(Keyword,
"DIMENSION")) {
44 Keyword = strtok(0, Delimiters);
47 eprintf(
"Wrong number of clusters");
51 assert(GTour = (
int *) malloc((Clusters + 1) *
sizeof(
int)));
52 for (i = 1; i <= Clusters; i++)
53 fscanf(GTourFile,
"%d", >our[i]);
54 GTour[0] = GTour[Clusters];
55 assert(Used = (
int *) calloc(Clusters + 1,
sizeof(
int)));
57 for (i = 1; i <= Clusters; i++) {
62 eprintf(
"Cluster entered more than once");
65 for (i = 1; i <= Clusters; i++)
67 eprintf(
"Unvisited cluster(s)");
70 printff(
"OK. Cost = %lld\n", Cost);
int main(int argc, char *argv[])
void printff(char *fmt,...)
void eprintf(const char *fmt,...)
char * ReadLine(FILE *InputFile)