GLKH_EXPmain.c
Go to the documentation of this file.
1 #include "LKH.h"
2 #include <unistd.h>
3 #include <sys/time.h>
4 #include <sys/resource.h>
5 
6 GainType SolveGTSP(int *GTour);
7 GainType PostOptimize(int *GTour, GainType Cost);
8 static double GetTimeUsage(int who);
9 
10 /*
11  * This file contains the main function of the program.
12  */
13 
14 int main(int argc, char *argv[])
15 {
16  int Exp, Experiments = 10;
17  GainType Cost, CostSum = 0;
18  int *GTour, RunSum = 0, Opt = 0;
19  double Time = 0;
20 
21  /* Read the specification of the problem */
22  if (argc >= 2) {
23  ParameterFileName = argv[1];
24  if (argc >= 3)
25  Experiments = atoi(argv[2]);
26  }
28  ReadProblem();
29  assert(GTour = (int *) malloc((GTSPSets + 1) * sizeof(int)));
30  for (Exp = 1; Exp <= Experiments; Exp++, Seed++) {
31  Cost = SolveGTSP(GTour);
32  RunSum += Run;
33  Cost = PostOptimize(GTour, Cost);
34  if (OutputTourFileName) {
35  int OldTraceLevel = TraceLevel, OldDimension = Dimension;
36  TraceLevel = 1;
38  WriteTour(OutputTourFileName, GTour, Cost);
39  TraceLevel = OldTraceLevel;
40  Dimension = OldDimension;
41  }
42  if (TourFileName && (Optimum == MINUS_INFINITY || Cost < Optimum)) {
43  int OldTraceLevel = TraceLevel, OldDimension = Dimension;
44  TraceLevel = 1;
46  WriteTour(TourFileName, GTour, Cost);
47  TraceLevel = OldTraceLevel;
48  Dimension = OldDimension;
49  }
50  if (TraceLevel > 0)
51  printff("* Performed %d out of %d experiments\n\n",
52  Exp, Experiments);
53  CostSum += Cost;
54  if (Cost == Optimum)
55  Opt++;
56  else if (Cost < Optimum) {
57  Optimum = Cost;
58  Opt = 1;
59  }
60  }
61  Time = GetTimeUsage(RUSAGE_SELF) + GetTimeUsage(RUSAGE_CHILDREN);
62  printff
63  ("Opt = " GainFormat ", Value = %0.1f, Error = %0.2f%%\n"
64  "Opt = %0.0f%%, Time = %0.1fs, Runs = %0.1f\n\n",
65  Optimum, (double) CostSum / Experiments,
66  ((double) CostSum / Experiments - Optimum) / Optimum * 100.0,
67  Opt * 100.0 / Experiments, Time / Experiments,
68  (double) RunSum / Experiments);
69  return 0;
70 }
71 
72 static double GetTimeUsage(int who)
73 {
74  struct rusage ru;
75  getrusage(who, &ru);
76  return ru.ru_utime.tv_sec + ru.ru_utime.tv_usec / 1000000.0;
77 }
GainType PostOptimize(int *GTour, GainType Cost)
Definition: PostOptimize.c:29
int Dimension
Definition: LKH.h:190
void ReadProblem(void)
Definition: ReadProblem.c:230
int GTSPSets
Definition: LKH.h:209
void printff(char *fmt,...)
Definition: printff.c:10
static GainType CostSum
Definition: Statistics.c:4
#define MINUS_INFINITY
Definition: GainType.h:21
GainType Optimum
Definition: LKH.h:241
int main(int argc, char *argv[])
Definition: GLKH_EXPmain.c:14
char * OutputTourFileName
Definition: LKH.h:284
Definition: LKH.h:41
void ReadParameters(void)
int TraceLevel
Definition: LKH.h:274
GainType SolveGTSP(int *GTour)
Definition: SolveGTSP.c:28
unsigned Seed
Definition: LKH.h:259
char * TourFileName
Definition: LKH.h:284
int Run
Definition: LKH.h:257
char * ParameterFileName
Definition: LKH.h:284
int ProblemType
Definition: LKH.h:290
void WriteTour(char *FileName, int *Tour, GainType Cost)
Definition: WriteTour.c:16
#define GainFormat
Definition: GainType.h:22
long long GainType
Definition: GainType.h:13
static double GetTimeUsage(int who)
Definition: GLKH_EXPmain.c:72


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