4 #include <sys/resource.h> 30 int i, j, Dist, Clusters = 0;
35 NewInitialTourFileName[256] = { 0 },
36 NewInputTourFileName[256] = { 0 },
37 NewSubproblemTourFileName[256] = { 0 },
38 **NewMergeTourFileName,
43 assert(NewMergeTourFileName =
46 assert(NewMergeTourFileName[i] = (
char *) malloc(256));
56 M = Clusters < 2 ? 0 : INT_MAX / 4 /
Precision;
58 sprintf(Prefix,
"%s.pid%d",
Name, getpid());
61 sprintf(ProblemFileName,
"TMP/%s.atsp", Prefix);
62 assert(ProblemFile = fopen(ProblemFileName,
"w"));
63 fprintf(ProblemFile,
"NAME : %s.gtsp\n", Prefix);
64 fprintf(ProblemFile,
"TYPE : ATSP\n");
66 fprintf(ProblemFile,
"DIMENSION : %d\n",
Dimension);
69 fprintf(ProblemFile,
"EDGE_WEIGHT_TYPE : EXPLICIT\n");
70 fprintf(ProblemFile,
"EDGE_WEIGHT_FORMAT : FULL_MATRIX\n");
71 fprintf(ProblemFile,
"EDGE_WEIGHT_SECTION\n");
78 fprintf(ProblemFile,
"999999 ");
82 To->
V == From->
V ? 2 * M :
84 From->
Next->
C[j]) + M;
85 fprintf(ProblemFile,
"%d ", Dist);
87 printff(
"*** PRECISION (= %d) is too large. ",
95 fprintf(ProblemFile,
"\n");
97 fprintf(ProblemFile,
"EOF\n");
101 sprintf(ParFileName,
"TMP/%s.par", Prefix);
102 assert(ParFile = fopen(ParFileName,
"w"));
103 fprintf(ParFile,
"PROBLEM_FILE = TMP/%s.atsp\n", Prefix);
107 fprintf(ParFile,
"BACKTRACKING = YES\n");
110 fprintf(ParFile,
"CANDIDATE_SET_TYPE = ALPHA\n");
112 fprintf(ParFile,
"EXCESS = %g\n",
Excess);
114 fprintf(ParFile,
"GAIN23 = NO\n");
116 fprintf(ParFile,
"GAIN_CRITERION = NO\n");
119 fprintf(ParFile,
"INITIAL_TOUR_ALGORITHM = %s\n",
125 sprintf(NewInitialTourFileName,
"TMP/%s.initial.tour", Prefix);
127 fprintf(ParFile,
"INITIAL_TOUR_FILE = %s\n",
128 NewInitialTourFileName);
130 fprintf(ParFile,
"INITIAL_TOUR_FRACTION = %0.3f\n",
133 sprintf(NewInputTourFileName,
"TMP/%s.input.tour", Prefix);
135 fprintf(ParFile,
"INPUT_TOUR_FILE = %s\n", NewInputTourFileName);
137 fprintf(ParFile,
"KICK_TYPE = %d\n",
KickType);
138 fprintf(ParFile,
"MAX_BREADTH = %d\n",
MaxBreadth);
141 fprintf(ParFile,
"MAX_SWAPS = %d\n",
MaxSwaps);
142 fprintf(ParFile,
"MAX_TRIALS = %d\n",
MaxTrials);
144 sprintf(NewMergeTourFileName[i],
145 "TMP/%s.merge%d.tour", Prefix, i + 1);
147 fprintf(ParFile,
"MERGE_TOUR_FILE = %s\n",
148 NewMergeTourFileName[i]);
150 fprintf(ParFile,
"MOVE_TYPE = %d\n",
MoveType);
152 fprintf(ParFile,
"NONSEQUENTIAL_MOVE_TYPE = %d\n",
155 fprintf(ParFile,
"OPTIMUM = " GainFormat "\n",
157 fprintf(ParFile,
"PATCHING_A = %d %s\n",
PatchingA,
160 fprintf(ParFile,
"PATCHING_C = %d %s\n",
PatchingC,
164 fprintf(ParFile,
"PI_FILE = %s\n",
PiFileName);
166 fprintf(ParFile,
"PRECISION = %d\n",
Precision);
168 fprintf(ParFile,
"RESTRICTED_SEARCH = NO\n");
169 fprintf(ParFile,
"RUNS = %d\n",
Runs);
170 fprintf(ParFile,
"SEED = %d\n",
Seed);
172 fprintf(ParFile,
"STOP_AT_OPTIMUM = NO\n");
174 fprintf(ParFile,
"SUBGRADIENT = NO\n");
178 sprintf(NewSubproblemTourFileName,
"TMP/%s.subproblem.tour",
181 fprintf(ParFile,
"SUBPROBLEM_TOUR_FILE = %s\n",
182 NewSubproblemTourFileName);
186 fprintf(ParFile,
"SUBSEQUENT_PATCHING = NO\n");
188 fprintf(ParFile,
"TIME_LIMIT = %0.1f\n",
TimeLimit);
189 sprintf(TourFileName,
"TMP/%s.tour", Prefix);
190 fprintf(ParFile,
"TOUR_FILE = %s\n", TourFileName);
191 fprintf(ParFile,
"TRACE_LEVEL = %d\n",
196 assert(Tour = (
int *) malloc((
DimensionSaved + 1) *
sizeof(
int)));
201 unlink(ProblemFileName);
202 unlink(NewInitialTourFileName);
203 unlink(NewInputTourFileName);
205 unlink(NewMergeTourFileName[i]);
206 unlink(NewSubproblemTourFileName);
216 while (From->
V == i);
217 assert(Used = (
int *) calloc(Clusters + 1,
sizeof(
int)));
220 GTour[++i] = From->
Id;
223 eprintf(
"Illegal g-tour: cluster entered more than once");
230 eprintf(
"Illegal g-tour: unvisited cluster(s)");
231 GTour[0] = GTour[Clusters];
241 assert(Tour = (
int *) malloc((Dimension + 1) *
sizeof(
int)));
253 while ((N = N->
Next) != To);
259 assert(i == Dimension);
int NonsequentialMoveType
double InitialTourFraction
GainType SolveTSP(int Dimension, char *ParFileName, char *TourFileName, int *Tour, GainType Optimum, GainType Deduction)
char * SubproblemTourFileName
int CandidateSetSymmetric
void printff(char *fmt,...)
void eprintf(const char *fmt,...)
static void WriteFullTour(enum TourType Type, int Dimension, char *TourFileName, int Id)
GainType SolveGTSP(int *GTour)
void WriteTour(char *FileName, int *Tour, GainType Cost)
char * InitialTourFileName
char ** CandidateFileName