Main Page
Namespaces
Classes
Files
File List
File Members
src
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
}
27
ReadParameters
();
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;
37
Dimension
=
ProblemType
!=
ATSP
?
GTSPSets
: 2 *
GTSPSets
;
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;
45
Dimension
=
ProblemType
!=
ATSP
?
GTSPSets
: 2 *
GTSPSets
;
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
}
PostOptimize
GainType PostOptimize(int *GTour, GainType Cost)
Definition:
PostOptimize.c:29
Dimension
int Dimension
Definition:
LKH.h:190
ReadProblem
void ReadProblem(void)
Definition:
ReadProblem.c:230
GTSPSets
int GTSPSets
Definition:
LKH.h:209
printff
void printff(char *fmt,...)
Definition:
printff.c:10
CostSum
static GainType CostSum
Definition:
Statistics.c:4
MINUS_INFINITY
#define MINUS_INFINITY
Definition:
GainType.h:21
Optimum
GainType Optimum
Definition:
LKH.h:241
main
int main(int argc, char *argv[])
Definition:
GLKH_EXPmain.c:14
OutputTourFileName
char * OutputTourFileName
Definition:
LKH.h:284
ATSP
Definition:
LKH.h:41
ReadParameters
void ReadParameters(void)
Definition:
ReadParameters.c:354
TraceLevel
int TraceLevel
Definition:
LKH.h:274
LKH.h
SolveGTSP
GainType SolveGTSP(int *GTour)
Definition:
SolveGTSP.c:28
Seed
unsigned Seed
Definition:
LKH.h:259
TourFileName
char * TourFileName
Definition:
LKH.h:284
Run
int Run
Definition:
LKH.h:257
ParameterFileName
char * ParameterFileName
Definition:
LKH.h:284
ProblemType
int ProblemType
Definition:
LKH.h:290
WriteTour
void WriteTour(char *FileName, int *Tour, GainType Cost)
Definition:
WriteTour.c:16
GainFormat
#define GainFormat
Definition:
GainType.h:22
GainType
long long GainType
Definition:
GainType.h:13
GetTimeUsage
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