31 int *BestGTour, i, Clusters =
GTSPSets, FirstTime = 1;
35 assert(BestGTour = (
int *) malloc((Clusters + 1) *
sizeof(
int)));
36 memcpy(BestGTour, GTour, (Clusters + 1) *
sizeof(
int));
46 for (i = 1; i <= Clusters; i++)
47 GTour[i] = BestGTour[GTour[i]];
48 GTour[0] = GTour[Clusters];
49 memcpy(BestGTour, GTour, (Clusters + 1) *
sizeof(
int));
55 memcpy(GTour, BestGTour, (Clusters + 1) *
sizeof(
int));
65 memcpy(BestGTour, GTour, (Clusters + 1) *
sizeof(
int));
73 memcpy(GTour, BestGTour, (Clusters + 1) *
sizeof(
int));
93 sprintf(Prefix,
"%s.pid%d",
Name, getpid());
94 sprintf(ProblemFileName,
"TMP/%s.post.tsp", Prefix);
95 assert(ProblemFile = fopen(ProblemFileName,
"w"));
96 fprintf(ProblemFile,
"NAME : %s\n",
Name);
97 fprintf(ProblemFile,
"TYPE : %s\n",
Type);
98 fprintf(ProblemFile,
"DIMENSION : %d\n", Clusters);
101 fprintf(ProblemFile,
"EDGE_WEIGHT_FORMAT : FULL_MATRIX\n");
102 fprintf(ProblemFile,
"EDGE_WEIGHT_SECTION\n");
103 for (i = 1; i <= Clusters; i++) {
104 for (j = 1; j <= Clusters; j++)
105 fprintf(ProblemFile,
"%d ", i == j ? 99999 :
109 fprintf(ProblemFile,
"\n");
112 fprintf(ProblemFile,
"NODE_COORD_SECTION\n");
114 for (i = 1; i <= Clusters; i++) {
116 fprintf(ProblemFile,
"%d %f %f\n", i, N->
X, N->
Y);
119 for (i = 1; i <= Clusters; i++) {
121 fprintf(ProblemFile,
"%d %f %f %f\n", i, N->
X, N->
Y, N->
Z);
125 fprintf(ProblemFile,
"EOF\n");
129 sprintf(ParFileName,
"TMP/%s.post.par", Prefix);
130 assert(ParFile = fopen(ParFileName,
"w"));
131 fprintf(ParFile,
"PROBLEM_FILE = %s\n", ProblemFileName);
132 fprintf(ParFile,
"MAX_TRIALS = %d\n",
MaxTrials);
134 fprintf(ParFile,
"PRECISION = %d\n",
Precision);
135 fprintf(ParFile,
"RUNS = 1\n");
136 fprintf(ParFile,
"SEED = %d\n",
Seed);
138 fprintf(ParFile,
"SUBGRADIENT = NO\n");
139 sprintf(TourFileName,
"TMP/%s.post.tour", Prefix);
140 fprintf(ParFile,
"TOUR_FILE = %s\n", TourFileName);
147 unlink(ProblemFileName);
163 int i, j = 1,
d, MinSize, MinV, Clusters =
GTSPSets;
165 Node **First, *From, *To;
168 MinSize = MinV = INT_MAX;
170 if (Cl->
Size < MinSize) {
175 for (i = 1; i <= Clusters; i++) {
177 if (From->
V == MinV) {
182 assert(First = (
Node **) malloc(Clusters *
sizeof(
Node *)));
183 for (i = 0; i < Clusters; i++) {
197 }
while ((To = To->
Next) != First[1]);
198 for (i = 2; i < Clusters; i++) {
204 if ((
d = From->
Cost +
206 From->
C[To->
Id])) < To->
Cost) {
210 }
while ((From = From->
Next) != First[i - 1]);
211 }
while ((To = To->
Next) != First[i]);
213 From = First[Clusters - 1];
215 if ((
d = From->
Cost +
219 for (i = Clusters, To = From; To; To = To->
Dad)
222 }
while ((From = From->
Next) != First[Clusters - 1]);
225 GTour[0] = GTour[Clusters];
GainType PostOptimize(int *GTour, GainType Cost)
void printff(char *fmt,...)
static GainType KOptimize(int *GTour)
static GainType ClusterOptimize(int *GTour)
GainType SolveTSP(int Dimension, char *ParFileName, char *TourFileName, int *Tour, GainType Optimum, GainType Displacement)