352 static size_t max(
size_t a,
size_t b);
356 char *Line, *Keyword, *Token, *
Name;
417 eprintf(
"Cannot open PARAMETER_FILE: \"%s\"",
429 printff(
"Cannot open \"%s\". Please try again.\n",
438 if (Keyword[0] ==
'#')
440 for (i = 0; i < strlen(Keyword); i++)
441 Keyword[i] = (
char) toupper(Keyword[i]);
442 if (!strcmp(Keyword,
"ASCENT_CANDIDATES")) {
445 eprintf(
"ASCENT_CANDIDATES: integer expected");
447 eprintf(
"ASCENT_CANDIDATES: >= 2 expected");
448 }
else if (!strcmp(Keyword,
"BACKBONE_TRIALS")) {
451 eprintf(
"BACKBONE_TRIALS: integer expected");
453 eprintf(
"BACKBONE_TRIALS: non-negative integer expected");
454 }
else if (!strcmp(Keyword,
"BACKTRACKING")) {
456 eprintf(
"BACKTRACKING: YES or NO expected");
457 }
else if (!strcmp(Keyword,
"CANDIDATE_FILE")) {
459 eprintf(
"CANDIDATE_FILE: string expected");
462 (
char **) malloc(
sizeof(
char *)));
469 if (i == CandidateFiles) {
473 1) *
sizeof(
char *)));
477 }
else if (!strcmp(Keyword,
"CANDIDATE_SET_TYPE")) {
479 eprintf(
"%s",
"CANDIDATE_SET_TYPE: " 480 "ALPHA, DELAUNAY, NEAREST-NEIGHBOR, " 481 "or QUADRANT expected");
482 for (i = 0; i < strlen(Token); i++)
483 Token[i] = (
char) toupper(Token[i]);
484 if (!strncmp(Token,
"ALPHA", strlen(Token)))
486 else if (!strncmp(Token,
"DELAUNAY", strlen(Token))) {
488 }
else if (!strncmp(Token,
"NEAREST-NEIGHBOR", strlen(Token)))
490 else if (!strncmp(Token,
"QUADRANT", strlen(Token)))
493 eprintf(
"%s",
"CANDIDATE_SET_TYPE: " 494 "ALPHA, DELAUNAY, NEAREST-NEIGHBOR, " 495 "or QUADRANT expected");
498 for (i = 0; i < strlen(Token); i++)
499 Token[i] = (
char) toupper(Token[i]);
500 if (strncmp(Token,
"PURE", strlen(Token)))
501 eprintf(
"%s",
"CANDIDATE_SET_TYPE (DELAUNAY): " 502 "PURE or no token expected");
506 }
else if (!strcmp(Keyword,
"COMMENT"))
508 else if (!strcmp(Keyword,
"EOF"))
510 else if (!strcmp(Keyword,
"EXCESS")) {
512 !sscanf(Token,
"%lf", &
Excess))
513 eprintf(
"EXCESS: real expected");
515 eprintf(
"EXCESS: non-negeative real expected");
516 }
else if (!strcmp(Keyword,
"EXTRA_CANDIDATES")) {
519 eprintf(
"EXTRA_CANDIDATES: integer expected");
521 eprintf(
"EXTRA_CANDIDATES: non-negative integer expected");
523 for (i = 0; i < strlen(Token); i++)
524 Token[i] = (
char) toupper(Token[i]);
525 if (strncmp(Token,
"SYMMETRIC", strlen(Token)))
527 (
"(EXTRA_CANDIDATES) Illegal SYMMETRIC specification");
530 }
else if (!strcmp(Keyword,
"EXTRA_CANDIDATE_SET_TYPE")) {
532 eprintf(
"%s",
"EXTRA_CANDIDATE_SET_TYPE: " 533 "NEAREST-NEIGHBOR, or QUADRANT expected");
534 for (i = 0; i < strlen(Token); i++)
535 Token[i] = (
char) toupper(Token[i]);
536 if (!strncmp(Token,
"NEAREST-NEIGHBOR", strlen(Token)))
538 else if (!strncmp(Token,
"QUADRANT", strlen(Token)))
541 eprintf(
"%s",
"EXTRA_CANDIDATE_SET_TYPE: " 542 "NEAREST-NEIGHBOR or QUADRANT expected");
543 }
else if (!strcmp(Keyword,
"GAIN23")) {
545 eprintf(
"GAIN23: YES or NO expected");
546 }
else if (!strcmp(Keyword,
"GAIN_CRITERION")) {
548 eprintf(
"GAIN_CRITERION: YES or NO expected");
549 }
else if (!strcmp(Keyword,
"INITIAL_PERIOD")) {
552 eprintf(
"INITIAL_PERIOD: integer expected");
554 eprintf(
"INITIAL_PERIOD: non-negative integer expected");
555 }
else if (!strcmp(Keyword,
"INITIAL_STEP_SIZE")) {
558 eprintf(
"INITIAL_STEP_SIZE: integer expected");
560 eprintf(
"INITIAL_STEP_SIZE: positive integer expected");
561 }
else if (!strcmp(Keyword,
"INITIAL_TOUR_ALGORITHM")) {
563 eprintf(
"INITIAL_TOUR_ALGORITHM: " 564 "BORUVKA, GREEDY, MOORE, NEAREST-NEIGHBOR,\n" 565 "QUICK-BORUVKA, SIERPINSKI, or WALK expected");
566 for (i = 0; i < strlen(Token); i++)
567 Token[i] = (
char) toupper(Token[i]);
568 if (!strncmp(Token,
"BORUVKA", strlen(Token)))
570 else if (!strncmp(Token,
"GREEDY", strlen(Token)))
572 else if (!strncmp(Token,
"MOORE", strlen(Token)))
574 else if (!strncmp(Token,
"NEAREST-NEIGHBOR", strlen(Token)))
576 else if (!strncmp(Token,
"QUICK-BORUVKA", strlen(Token)))
578 else if (!strncmp(Token,
"SIERPINSKI", strlen(Token)))
580 else if (!strncmp(Token,
"WALK", strlen(Token)))
583 eprintf(
"INITIAL_TOUR_ALGORITHM: " 584 "BORUVKA, GREEDY, MOORE, NEAREST-NEIGHBOR,\n" 585 "QUICK-BORUVKA, SIERPINSKI or WALK expected");
586 }
else if (!strcmp(Keyword,
"INITIAL_TOUR_FILE")) {
588 eprintf(
"INITIAL_TOUR_FILE: string expected");
589 }
else if (!strcmp(Keyword,
"INITIAL_TOUR_FRACTION")) {
592 eprintf(
"INITIAL_TOUR_FRACTION: real expected");
593 if (InitialTourFraction < 0 || InitialTourFraction > 1)
594 eprintf(
"INITIAL_TOUR_FRACTION: >= 0 or <= 1 expected");
595 }
else if (!strcmp(Keyword,
"INPUT_TOUR_FILE")) {
597 eprintf(
"INPUT_TOUR_FILE: string expected");
598 }
else if (!strcmp(Keyword,
"KICK_TYPE")) {
601 eprintf(
"KICK_TYPE: integer expected");
603 eprintf(
"KICK_TYPE: integer >= 4 expected");
604 }
else if (!strcmp(Keyword,
"KICKS")) {
606 !sscanf(Token,
"%d", &
Kicks))
607 eprintf(
"KICKS: integer expected");
609 eprintf(
"KICKS: non-negative integer expected");
610 }
else if (!strcmp(Keyword,
"MAX_BREADTH")) {
613 eprintf(
"MAX_BREADTH: integer expected");
615 eprintf(
"MAX_BREADTH: non-negative integer expected");
616 }
else if (!strcmp(Keyword,
"MAX_CANDIDATES")) {
619 eprintf(
"MAX_CANDIDATES: integer expected");
621 eprintf(
"MAX_CANDIDATES: non-negative integer expected");
623 for (i = 0; i < strlen(Token); i++)
624 Token[i] = (
char) toupper(Token[i]);
625 if (!strncmp(Token,
"SYMMETRIC", strlen(Token)))
629 (
"(MAX_CANDIDATES) Illegal SYMMETRIC specification");
631 }
else if (!strcmp(Keyword,
"MAX_SWAPS")) {
634 eprintf(
"MAX_SWAPS: integer expected");
636 eprintf(
"MAX_SWAPS: non-negative integer expected");
637 }
else if (!strcmp(Keyword,
"MAX_TRIALS")) {
640 eprintf(
"MAX_TRIALS: integer expected");
642 eprintf(
"MAX_TRIALS: non-negative integer expected");
643 }
else if (!strcmp(Keyword,
"MERGE_TOUR_FILE")) {
645 eprintf(
"MERGE_TOUR_FILE: string expected");
648 (
char **) malloc(
sizeof(
char *)));
655 if (i == MergeTourFiles) {
659 1) *
sizeof(
char *)));
663 }
else if (!strcmp(Keyword,
"MOVE_TYPE")) {
666 eprintf(
"MOVE_TYPE: integer expected");
668 eprintf(
"MOVE_TYPE: >= 2 expected");
669 }
else if (!strcmp(Keyword,
"NONSEQUENTIAL_MOVE_TYPE")) {
672 eprintf(
"NONSEQUENTIAL_MOVE_TYPE: integer expected");
674 eprintf(
"NONSEQUENTIAL_MOVE_TYPE: >= 4 expected");
675 }
else if (!strcmp(Keyword,
"OPTIMUM")) {
678 eprintf(
"OPTIMUM: integer expected");
679 }
else if (!strcmp(Keyword,
"OUTPUT_TOUR_FILE")) {
681 eprintf(
"OUTPUT_TOUR_FILE: string expected");
682 }
else if (!strcmp(Keyword,
"PATCHING_A")) {
685 eprintf(
"PATCHING_A: integer expected");
687 eprintf(
"PATCHING_A: non-negative integer expected");
689 for (i = 0; i < strlen(Token); i++)
690 Token[i] = (
char) toupper(Token[i]);
691 if (!strncmp(Token,
"RESTRICTED", strlen(Token)))
693 else if (!strncmp(Token,
"EXTENDED", strlen(Token)))
697 "Illegal RESTRICTED or EXTENDED specification");
699 }
else if (!strcmp(Keyword,
"PATCHING_C")) {
702 eprintf(
"PATCHING_C: integer expected");
704 eprintf(
"PATCHING_C: non-negative integer expected");
706 for (i = 0; i < strlen(Token); i++)
707 Token[i] = (
char) toupper(Token[i]);
708 if (!strncmp(Token,
"RESTRICTED", strlen(Token)))
710 else if (!strncmp(Token,
"EXTENDED", strlen(Token)))
714 "Illegal RESTRICTED or EXTENDED specification");
716 }
else if (!strcmp(Keyword,
"PI_FILE")) {
718 eprintf(
"PI_FILE: string expected");
719 }
else if (!strcmp(Keyword,
"POPULATION_SIZE")) {
722 eprintf(
"POPULATION_SIZE: integer expected");
723 }
else if (!strcmp(Keyword,
"PRECISION")) {
726 eprintf(
"PRECISION: integer expected");
727 }
else if (!strcmp(Keyword,
"PROBLEM_FILE")) {
729 eprintf(
"PROBLEM_FILE: string expected");
730 }
else if (!strcmp(Keyword,
"RESTRICTED_SEARCH")) {
732 eprintf(
"RESTRICTED_SEARCH: YES or NO expected");
733 }
else if (!strcmp(Keyword,
"RUNS")) {
735 !sscanf(Token,
"%d", &
Runs))
736 eprintf(
"RUNS: integer expected");
738 eprintf(
"RUNS: positive integer expected");
739 }
else if (!strcmp(Keyword,
"SEED")) {
741 !sscanf(Token,
"%u", &
Seed))
742 eprintf(
"SEED: integer expected");
743 }
else if (!strcmp(Keyword,
"STOP_AT_OPTIMUM")) {
745 eprintf(
"STOP_AT_OPTIMUM: YES or NO expected");
746 }
else if (!strcmp(Keyword,
"SUBGRADIENT")) {
748 eprintf(
"SUBGRADIENT: YES or NO expected");
749 }
else if (!strcmp(Keyword,
"SUBPROBLEM_TOUR_FILE")) {
751 eprintf(
"SUBPROBLEM_TOUR_FILE: string expected");
752 }
else if (!strcmp(Keyword,
"SUBPROBLEM_SIZE")) {
755 eprintf(
"SUBPROBLEM_SIZE: integer expected");
757 eprintf(
"SUBPROBLEM_SIZE: >= 3 expected");
759 for (i = 0; i < strlen(Token); i++)
760 Token[i] = (
char) toupper(Token[i]);
761 if (!strncmp(Token,
"DELAUNAY", strlen(Token)))
763 else if (!strncmp(Token,
"KARP",
max(strlen(Token), 2)))
766 (Token,
"K-CENTER",
max(strlen(Token), 3)))
768 else if (!strncmp(Token,
"K-MEANS",
max(strlen(Token), 3)))
770 else if (!strncmp(Token,
"MOORE", strlen(Token)))
772 else if (!strncmp(Token,
"ROHE", strlen(Token)))
774 else if (!strncmp(Token,
"SIERPINSKI", strlen(Token)))
776 else if (!strncmp(Token,
"BORDERS", strlen(Token)))
778 else if (!strncmp(Token,
"COMPRESSED", strlen(Token)))
782 (
"(SUBPROBLEM_SIZE) Illegal DELAUNAY, KARP, K-CENTER, " 783 "K-MEANS, MOORE, ROHE,\n SIERPINSKI, " 784 "BORDERS or COMPRESSED specification");
786 for (i = 0; i < strlen(Token); i++)
787 Token[i] = (
char) toupper(Token[i]);
788 if (!strncmp(Token,
"BORDERS", strlen(Token)))
790 else if (!strncmp(Token,
"COMPRESSED", strlen(Token)))
794 (
"(SUBPROBLEM_SIZE) Illegal BORDERS or " 795 "COMPRESSED specification");
798 }
else if (!strcmp(Keyword,
"SUBSEQUENT_MOVE_TYPE")) {
801 eprintf(
"SUBSEQUENT_MOVE_TYPE: integer expected");
803 eprintf(
"SUBSEQUENT_MOVE_TYPE: 0 or >= 2 expected");
804 }
else if (!strcmp(Keyword,
"SUBSEQUENT_PATCHING")) {
806 eprintf(
"SUBSEQUENT_PATCHING: YES or NO expected");
807 }
else if (!strcmp(Keyword,
"TIME_LIMIT")) {
810 eprintf(
"TIME_LIMIT: real expected");
812 eprintf(
"TIME_LIMIT: >= 0 expected");
813 }
else if (!strcmp(Keyword,
"TOUR_FILE")) {
815 eprintf(
"TOUR_FILE: string expected");
816 }
else if (!strcmp(Keyword,
"TRACE_LEVEL")) {
819 eprintf(
"TRACE_LEVEL: integer expected");
821 eprintf(
"Unknown keyword: %s", Keyword);
822 if ((Token = strtok(0,
Delimiters)) && Token[0] !=
'#')
823 eprintf(
"Junk at end of line: %s", Token);
826 eprintf(
"Problem file name is missing");
828 eprintf(
"SUBPROBLEM_SIZE specification is missing");
830 eprintf(
"SUBPROBLEM_TOUR_FILE specification is missing");
838 char *Rest = strtok(Line,
"\n\t\r\f"), *t;
842 while (isspace(*Rest))
848 while (isspace(*Rest))
850 for (t = Rest + strlen(Rest) - 1; isspace(*t); t--)
854 assert(t = (
char *) malloc(strlen(Rest) + 1));
865 for (i = 0; i < strlen(Token); i++)
866 Token[i] = (
char) toupper(Token[i]);
867 if (!strncmp(Token,
"YES", strlen(Token)))
869 else if (!strncmp(Token,
"NO", strlen(Token)))
877 static size_t max(
size_t a,
size_t b)
879 return a > b ? a :
b;
int NonsequentialMoveType
double InitialTourFraction
int ExtraCandidateSetType
char * SubproblemTourFileName
int CandidateSetSymmetric
void printff(char *fmt,...)
static char * GetFileName(char *Line)
int SubproblemsCompressed
char * OutputTourFileName
void eprintf(const char *fmt,...)
char * ReadLine(FILE *InputFile)
static char * ReadYesOrNo(int *V)
int SierpinskiPartitioning
char ** MergeTourFileName
char * InitialTourFileName
static size_t max(size_t a, size_t b)
char ** CandidateFileName
int ExtraCandidateSetSymmetric