GLKH_CHECKmain.c
Go to the documentation of this file.
1 #include "LKH.h"
2 
3 int main(int argc, char *argv[])
4 {
5  GainType Cost;
6  Cluster *Cl;
7  Node *From;
8  int *GTour, *Used, Clusters = 0, i;
9  FILE *GTourFile;
10  char *GTourFileName, *Line, *Keyword, Buf1[256], Buf2[256];
11  char Delimiters[] = " :=\n\t\r\f\v\xef\xbb\xbf";
12 
13  /* Read the specification of the problem */
14 
15  sprintf(Buf1, "GTSPLIB/%s.gtsp", argv[1]);
16  ProblemFileName = Buf1;
17  sprintf(Buf2, "G-TOURS/%s.%s.tour", argv[1], argv[2]);
18  GTourFileName = Buf2;
20  ReadProblem();
21  for (Cl = FirstCluster; Cl; Cl = Cl->Next) {
22  Clusters++;
23  From = Cl->First;
24  do
25  From->V = Clusters;
26  while ((From = From->Next) != Cl->First);
27  }
28  if (!(GTourFile = fopen(GTourFileName, "r")))
29  eprintf("Cannot find %s\n", GTourFileName);
30  while ((Line = ReadLine(GTourFile))) {
31  if (!(Keyword = strtok(Line, Delimiters)))
32  continue;
33  for (i = 0; i < strlen(Keyword); i++)
34  Keyword[i] = (char) toupper(Keyword[i]);
35  if (!strcmp(Keyword, "TOUR_SECTION"))
36  break;
37  if (Optimum == 0 && !strcmp(Keyword, "COMMENT")) {
38  Keyword = strtok(0, Delimiters);
39  Keyword = strtok(0, Delimiters);
40  Optimum = atoi(Keyword);
41  } else {
42  if (!strcmp(Keyword, "DIMENSION")) {
43  int n;
44  Keyword = strtok(0, Delimiters);
45  n = atoi(Keyword);
46  if (n != Clusters)
47  eprintf("Wrong number of clusters");
48  }
49  }
50  }
51  assert(GTour = (int *) malloc((Clusters + 1) * sizeof(int)));
52  for (i = 1; i <= Clusters; i++)
53  fscanf(GTourFile, "%d", &GTour[i]);
54  GTour[0] = GTour[Clusters];
55  assert(Used = (int *) calloc(Clusters + 1, sizeof(int)));
56  Cost = 0;
57  for (i = 1; i <= Clusters; i++) {
58  Cost += ProblemType != ATSP ?
59  Distance(&NodeSet[GTour[i - 1]], &NodeSet[GTour[i]]) :
60  NodeSet[GTour[i - 1]].C[GTour[i]];
61  if (Used[NodeSet[GTour[i]].V])
62  eprintf("Cluster entered more than once");
63  Used[NodeSet[GTour[i]].V] = 1;
64  }
65  for (i = 1; i <= Clusters; i++)
66  if (!Used[i])
67  eprintf("Unvisited cluster(s)");
68  if (Cost != Optimum)
69  eprintf("Cost = %lld != Optimum = %lld\n", Cost, Optimum);
70  printff("OK. Cost = %lld\n", Cost);
71  free(Used);
72  return 0;
73 }
char * ProblemFileName
Definition: LKH.h:284
int main(int argc, char *argv[])
Definition: GLKH_CHECKmain.c:3
void ReadProblem(void)
Definition: ReadProblem.c:230
void printff(char *fmt,...)
Definition: printff.c:10
Definition: LKH.h:68
Definition: LKH.h:162
CostFunction Distance
Definition: LKH.h:304
GainType Optimum
Definition: LKH.h:241
Node * NodeSet
Definition: LKH.h:235
Definition: LKH.h:41
Cluster * Next
Definition: LKH.h:164
static char Delimiters[]
void eprintf(const char *fmt,...)
Definition: eprintf.c:8
int * C
Definition: LKH.h:88
int V
Definition: LKH.h:75
char * ReadLine(FILE *InputFile)
Definition: ReadLine.c:23
Node * Next
Definition: LKH.h:96
Cluster * FirstCluster
Definition: LKH.h:200
int ProblemType
Definition: LKH.h:290
int MaxMatrixDimension
Definition: LKH.h:226
long long GainType
Definition: GainType.h:13
Node * First
Definition: LKH.h:163


glkh_solver
Author(s): Francisco Suarez-Ruiz
autogenerated on Mon Jun 10 2019 13:50:26