207 static const char Delimiters[] =
" :=\n\t\r\f\v\xef\xbb\xbf";
209 static char *
Copy(
char *S);
233 char *Line, *Keyword;
251 for (i = 0; i < (int) strlen(Keyword); i++)
252 Keyword[i] = (
char) toupper(Keyword[i]);
253 if (!strcmp(Keyword,
"COMMENT"));
254 else if (!strcmp(Keyword,
"DEMAND_SECTION"))
255 eprintf(
"Not implemented: %s", Keyword);
256 else if (!strcmp(Keyword,
"DEPOT_SECTION"))
257 eprintf(
"Not implemented: %s", Keyword);
258 else if (!strcmp(Keyword,
"DIMENSION"))
260 else if (!strcmp(Keyword,
"DISPLAY_DATA_SECTION"))
262 else if (!strcmp(Keyword,
"DISPLAY_DATA_TYPE"))
264 else if (!strcmp(Keyword,
"EDGE_DATA_FORMAT"))
266 else if (!strcmp(Keyword,
"EDGE_DATA_SECTION"))
268 else if (!strcmp(Keyword,
"EDGE_WEIGHT_FORMAT"))
270 else if (!strcmp(Keyword,
"EDGE_WEIGHT_SECTION"))
272 else if (!strcmp(Keyword,
"EDGE_WEIGHT_TYPE"))
274 else if (!strcmp(Keyword,
"EOF"))
276 else if (!strcmp(Keyword,
"FIXED_EDGES_SECTION"))
278 else if (!strcmp(Keyword,
"GTSP_SETS"))
280 else if (!strcmp(Keyword,
"GTSP_SET_SECTION"))
282 else if (!strcmp(Keyword,
"NAME"))
284 else if (!strcmp(Keyword,
"NODE_COORD_SECTION"))
286 else if (!strcmp(Keyword,
"NODE_COORD_TYPE"))
288 else if (!strcmp(Keyword,
"TOUR_SECTION"))
290 else if (!strcmp(Keyword,
"TYPE"))
293 eprintf(
"Unknown keyword: %s", Keyword);
299 Seed = (unsigned) time(0);
355 for (i = 2; i <= n; i++) {
357 for (j = 1; j < i; j++) {
426 eprintf(
"DIMENSION < 3 or not specified");
428 eprintf(
"EDGE_WEIGHT_TYPE is missing");
430 eprintf(
"EDGE_WEIGHT_FORMAT is missing");
432 eprintf(
"Conflicting EDGE_WEIGHT_TYPE and EDGE_WEIGHT_FORMAT");
437 eprintf(
"Conflicting EDGE_WEIGHT_TYPE and EDGE_WEIGHT_FORMAT");
439 eprintf(
"Conflicting TYPE and EDGE_WEIGHT_TYPE");
441 eprintf(
"Conflicting TYPE and EDGE_WEIGHT_FORMAT");
445 (
"Illegal EDGE_WEIGHT_TYPE for CANDIDATE_SET_TYPE = DELAUNAY");
449 (
"Illegal EDGE_WEIGHT_TYPE for CANDIDATE_SET_TYPE = " 454 (
"Illegal EDGE_WEIGHT_TYPE for CANDIDATE_SET_TYPE = QUADRANT");
458 (
"Illegal EDGE_WEIGHT_TYPE for EXTRA_CANDIDATE_SET_TYPE = " 464 (
"Illegal EDGE_WEIGHT_TYPE for EXTRA_CANDIDATE_SET_TYPE = " 469 (
"Illegal EDGE_WEIGHT_TYPE for INITIAL_TOUR_ALGORITHM = " 473 (
"Illegal EDGE_WEIGHT_TYPE for INITIAL_TOUR_ALGORITHM = " 476 eprintf(
"Illegal EDGE_WEIGHT_TYPE for DELAUNAY specification");
478 eprintf(
"Illegal EDGE_WEIGHT_TYPE for KARP specification");
480 eprintf(
"Illegal EDGE_WEIGHT_TYPE for MOORE specification");
482 eprintf(
"Illegal EDGE_WEIGHT_TYPE for ROHE specification");
484 eprintf(
"Illegal EDGE_WEIGHT_TYPE for SIERPINSKI specification");
486 eprintf(
"Illegal EDGE_WEIGHT_TYPE for BORDERS specification");
493 if (!S || strlen(S) == 0)
495 assert(Buffer = (
char *) malloc(strlen(S) + 1));
502 Node *Prev = 0, *N = 0;
506 eprintf(
"DIMENSION is not positive (or not specified)");
512 eprintf(
"Dimension too large in HPP problem");
515 for (i = 1; i <=
Dimension; i++, Prev = N) {
532 eprintf(
"NAME: string expected");
539 if (!Token || !sscanf(Token,
"%d", &
Dimension))
540 eprintf(
"DIMENSION: integer expected");
554 (
"DISPLAY_DATA_SECTION conflicts with DISPLAY_DATA_TYPE: %s",
565 eprintf(
"Missing nodes in DIPLAY_DATA_SECTION");
567 eprintf(
"(DIPLAY_DATA_SECTION) Node number out of range: %d",
571 eprintf(
"(DIPLAY_DATA_SECTION) Node number occours twice: %d",
575 eprintf(
"Missing X-coordinate in DIPLAY_DATA_SECTION");
577 eprintf(
"Missing Y-coordinate in DIPLAY_DATA_SECTION");
585 eprintf(
"(DIPLAY_DATA_SECTION) No coordinates given for node %d",
596 eprintf(
"DISPLAY_DATA_TYPE: string expected");
610 eprintf(
"EDGE_DATA_FORMAT: string expected");
618 " cannot be used together with SUBPROBLEM_TOUR_FILE");
628 eprintf(
"Missing EDGE_DATA_FORMAT specification");
639 eprintf(
"(EDGE_DATA_SECTION) Node number out of range: %d",
644 eprintf(
"(EDGE_DATA_SECTION) Node number out of range: %d",
647 eprintf(
"(EDGE_DATA_SECTION) Illgal edge: %d to %d", i, j);
700 eprintf(
"(EDGE_DATA_SECTION) Node number out of range: %d",
711 (
"(EDGE_DATA_SECTION) Node number out of range: %d",
714 eprintf(
"(EDGE_DATA_SECTION) Illgal edge: %d to %d",
758 eprintf(
"(EDGE_DATA_SECTION) No EDGE_DATA_FORMAT specified");
769 eprintf(
"EDGE_WEIGHT_FORMAT: string expected");
816 assert(
CostMatrix = (
int *) calloc((
size_t) n * n,
sizeof(
int)));
826 for (i = 1; i <= n; i++) {
828 for (j = 1; j <= n; j++) {
830 eprintf(
"Missing weight in EDGE_WEIGHT_SECTION");
851 eprintf(
"Missing weight in EDGE_WEIGHT_SECTION");
859 for (j = i + 1, Nj = Ni->
Suc; j <= Dimension;
862 eprintf(
"Missing weight in EDGE_WEIGHT_SECTION");
868 for (i = 2, Ni =
FirstNode->
Suc; i <= Dimension; i++, Ni = Ni->Suc) {
869 for (j = 1; j < i; j++) {
871 eprintf(
"Missing weight in EDGE_WEIGHT_SECTION");
878 for (j = i, Nj = Ni; j <=
Dimension; j++, Nj = Nj->
Suc) {
880 eprintf(
"Missing weight in EDGE_WEIGHT_SECTION");
888 for (j = 1; j <= i; j++) {
890 eprintf(
"Missing weight in EDGE_WEIGHT_SECTION");
897 for (j = 2, Nj =
FirstNode->
Suc; j <= Dimension; j++, Nj = Nj->Suc) {
898 for (i = 1; i < j; i++) {
900 eprintf(
"Missing weight in EDGE_WEIGHT_SECTION");
907 for (i = j + 1, Ni = Nj->Suc; i <= Dimension;
910 eprintf(
"Missing weight in EDGE_WEIGHT_SECTION");
917 for (i = 1; i <= j; i++) {
919 eprintf(
"Missing weight in EDGE_WEIGHT_SECTION");
927 for (i = j, Ni = Nj; i <=
Dimension; i++, Ni = Ni->Suc) {
929 eprintf(
"Missing weight in EDGE_WEIGHT_SECTION");
945 eprintf(
"EDGE_WEIGHT_TYPE: string expected");
1015 Node *Ni, *Nj, *N, *NPrev = 0, *NNext;
1016 int i, j,
Count = 0;
1018 eprintf(
"Not implemented: FIXED_EDGES_SECTION\n");
1029 eprintf(
"(FIXED_EDGES_SECTION) Node number out of range: %d",
1034 eprintf(
"(FIXED_EDGES_SECTION) Node number out of range: %d",
1037 eprintf(
"(FIXED_EDGES_SECTION) Illgal edge: %d to %d", i, j);
1045 eprintf(
"(FIXED_EDGES_SECTION) Illegal fix: %d to %d", i, j);
1051 eprintf(
"(FIXED_EDGES_SECTION) Illegal fix: %d to %d", i, j);
1058 }
while ((N = NNext) && N != Ni);
1060 eprintf(
"(FIXED_EDGES_SECTION) Illegal fix: %d to %d", i, j);
1072 if (!Token || !sscanf(Token,
"%d", &
GTSPSets))
1073 eprintf(
"GTSP_SETS: integer expected");
1075 eprintf(
"GTSP_SETS: not greater than 1");
1080 int Clusters = 0, n, Id;
1086 eprintf(
"Missing specification of GTSP_SETS");
1091 assert(Used = (
char *) calloc(
GTSPSets + 1,
sizeof(
char)));
1094 eprintf(
"(GTSP_SET_SECTION) Set number %d of of range", Id);
1096 eprintf(
"(GTSP_SET_SECTION) Set %d specified twice", Id);
1106 eprintf(
"(GTSP_SET_SECTION) Node %d outside range", n);
1109 eprintf(
"(GTSP_SET_SECTION) Node %d occurs in two sets", n);
1129 eprintf(
"(GTSP_SET_SECTION) Node %d does not occur in any set",
1133 eprintf(
"(GTSP_SET_SECTION) Missing sets");
1144 eprintf(
"NODE_COORD_SECTION conflicts with NODE_COORD_TYPE: %s",
1153 eprintf(
"Missing nodes in NODE_COORD_SECTION");
1155 eprintf(
"(NODE_COORD_SECTION) Node number out of range: %d",
1159 eprintf(
"(NODE_COORD_SECTION) Node number occours twice: %d",
1163 eprintf(
"Missing X-coordinate in NODE_COORD_SECTION");
1165 eprintf(
"Missing Y-coordinate in NODE_COORD_SECTION");
1168 eprintf(
"Missing Z-coordinate in NODE_COORD_SECTION");
1169 if (
Name && !strcmp(
Name,
"d657")) {
1170 N->
X = (float) N->
X;
1171 N->
Y = (
float) N->
Y;
1180 eprintf(
"(NODE_COORD_SECTION) No coordinates given for node %d",
1191 eprintf(
"NODE_COORD_TYPE: string expected");
1206 Node *First = 0, *Last = 0, *N;
1216 printff(
"SUBPROBLEM_TOUR_FILE: \"%s\" ... ",
1221 printff(
"MERGE_TOUR_FILE: \"%s\" ... ",
1236 for (k = 0; k <=
GTSPSets && i != -1; k++) {
1238 eprintf(
"(TOUR_SECTION) Node number out of range: %d", i);
1241 eprintf(
"(TOUR_SECTION) Node number occours twice: %d", N->Id);
1251 (Last->SubproblemSuc = N)->SubproblemPred = Last;
1266 N->SubproblemPred != N->FixedTo1
1267 && N->SubproblemSuc != N->FixedTo1)
1268 eprintf(
"Fixed edge (%d, %d) " 1269 "does not belong to subproblem tour", N->Id,
1271 if (N->FixedTo2 && N->SubproblemPred != N->FixedTo2
1272 && N->SubproblemSuc != N->FixedTo2)
1273 eprintf(
"Fixed edge (%d, %d) " 1274 "does not belong to subproblem tour", N->Id,
1291 eprintf(
"TYPE: string expected");
1292 for (i = 0; i < strlen(
Type); i++)
1294 if (!strcmp(
Type,
"TSP"))
1296 else if (!strcmp(
Type,
"ATSP"))
1298 else if (!strcmp(
Type,
"SOP")) {
1301 }
else if (!strcmp(
Type,
"HCP"))
1303 else if (!strcmp(
Type,
"CVRP")) {
1306 }
else if (!strcmp(
Type,
"TOUR")) {
1309 }
else if (!strcmp(
Type,
"HPP"))
1311 else if (!strcmp(
Type,
"GTSP")) {
1313 strcpy(
Type,
"TSP");
1314 }
else if (!strcmp(
Type,
"AGTSP")) {
1316 strcpy(
Type,
"ATSP");
1345 char *Line, *Keyword, *Token;
1349 if (!(*File = fopen(FileName,
"r")))
1350 eprintf(
"Cannot open tour file: \"%s\"", FileName);
1354 for (i = 0; i < strlen(Keyword); i++)
1355 Keyword[i] = (
char) toupper(Keyword[i]);
1356 if (!strcmp(Keyword,
"COMMENT") ||
1357 !strcmp(Keyword,
"DEMAND_SECTION") ||
1358 !strcmp(Keyword,
"DEPOT_SECTION") ||
1359 !strcmp(Keyword,
"DISPLAY_DATA_SECTION") ||
1360 !strcmp(Keyword,
"DISPLAY_DATA_TYPE") ||
1361 !strcmp(Keyword,
"EDGE_DATA_FORMAT") ||
1362 !strcmp(Keyword,
"EDGE_DATA_SECTION") ||
1363 !strcmp(Keyword,
"EDGE_WEIGHT_FORMAT") ||
1364 !strcmp(Keyword,
"EDGE_WEIGHT_SECTION") ||
1365 !strcmp(Keyword,
"EDGE_WEIGHT_TYPE") ||
1366 !strcmp(Keyword,
"FIXED_EDGES_SECTION") ||
1367 !strcmp(Keyword,
"NAME") ||
1368 !strcmp(Keyword,
"NODE_COORD_SECTION") ||
1369 !strcmp(Keyword,
"NODE_COORD_TYPE")
1370 || !strcmp(Keyword,
"TYPE"));
1371 else if (strcmp(Keyword,
"OPTIMUM") == 0) {
1374 eprintf(
"[%s] (OPTIMUM): integer expected", FileName);
1375 }
else if (strcmp(Keyword,
"DIMENSION") == 0) {
1378 !sscanf(Token,
"%d", &Dim))
1379 eprintf(
"[%s] (DIMENSION): integer expected", FileName);
1382 (
"[%s] (DIMENSION): does not match problem dimension",
1384 }
else if (!strcmp(Keyword,
"TOUR_SECTION")) {
1387 }
else if (!strcmp(Keyword,
"EOF"))
1390 eprintf(
"[%s] Unknown Keyword: %s", FileName, Keyword);
1393 eprintf(
"Missing TOUR_SECTION in tour file: \"%s\"", FileName);
static void Read_EDGE_DATA_SECTION(void)
static void Read_GTSP_SET_SECTION(void)
int IsCandidate(const Node *ta, const Node *tb)
static void Read_FIXED_EDGES_SECTION(void)
static const char Delimiters[]
int fscanint(FILE *f, int *v)
int NonsequentialMoveType
static void Read_NODE_COORD_SECTION(void)
static void Read_EDGE_DATA_FORMAT(void)
int ExtraCandidateSetType
char * SubproblemTourFileName
static void Read_DISPLAY_DATA_TYPE(void)
static int TwoDWeightType(void)
void PrintParameters(void)
void printff(char *fmt,...)
int Distance_MAN_2D(Node *Na, Node *Nb)
int Distance_GEOM_MEEUS(Node *Na, Node *Nb)
static void Read_TYPE(void)
int Distance_SPECIAL(Node *Na, Node *Nb)
static int ThreeDWeightType(void)
void ReadTour(char *FileName, FILE **File)
int Distance_ATT(Node *Na, Node *Nb)
int Distance_ATSP(Node *Na, Node *Nb)
static void Read_TOUR_SECTION(FILE **File)
static char * Copy(char *S)
int Distance_CEIL_3D(Node *Na, Node *Nb)
static void Read_GTSP_SETS(void)
int Distance_CEIL_2D(Node *Na, Node *Nb)
int Distance_1(Node *Na, Node *Nb)
void eprintf(const char *fmt,...)
int Distance_GEOM(Node *Na, Node *Nb)
int Distance_GEO_MEEUS(Node *Na, Node *Nb)
static void Read_DIMENSION(void)
int Distance_EUC_2D(Node *Na, Node *Nb)
char * ReadLine(FILE *InputFile)
int Distance_MAX_3D(Node *Na, Node *Nb)
int Distance_MAX_2D(Node *Na, Node *Nb)
int Distance_MAN_3D(Node *Na, Node *Nb)
static void Read_NODE_COORD_TYPE(void)
int SierpinskiPartitioning
int Distance_EUC_3D(Node *Na, Node *Nb)
static void Read_NAME(void)
static void Read_EDGE_WEIGHT_FORMAT(void)
char ** MergeTourFileName
FILE * SubproblemTourFile
static void Read_EDGE_WEIGHT_SECTION(void)
static void CreateNodes(void)
static void CheckSpecificationPart(void)
int Distance_GEO(Node *Na, Node *Nb)
char * InitialTourFileName
static void Read_EDGE_WEIGHT_TYPE(void)
int Distance_EXPLICIT(Node *Na, Node *Nb)
static void Read_DISPLAY_DATA_SECTION(void)