25 char Command[256], Key[256],
Buffer[256], *Line, *Keyword;
26 char Delimiters[] =
" :=\n\t\r\f\v\xef\xbb\xbf";
28 sprintf(Command,
"rosrun lkh_solver lkh_solver %s", ParFileName);
29 assert(p = popen(Command,
"r"));
31 while (fgets(Buffer,
sizeof(Buffer), p)) {
34 if (sscanf(Buffer,
"%s", Key) > 0) {
38 if (!strcmp(Key,
"Cost.min")) {
39 char *cp = strchr(Buffer + strlen(Key),
'=');
43 if (!strcmp(Key,
"Run")) {
44 char *cp = Buffer + strlen(Key);
45 sscanf(cp + 1,
"%d", &
Run);
46 sscanf(cp + 1,
"%d", &LocalTrial);
47 cp = strchr(cp + 1,
'=');
49 LocalCost -= Deduction;
50 cp = strchr(cp + 1,
'T');
51 cp = strchr(cp + 1,
'=');
52 sscanf(cp + 1,
"%lf", &LocalTime);
56 printf(
"Gap = %0.4f%%, ",
57 100.0 * (LocalCost - Optimum) / Optimum);
58 printff(
"Time = %0.2f sec.\n\n", LocalTime);
59 }
else if (!strcmp(Key,
"*")) {
60 char *cp = Buffer + strlen(Key);
61 if (sscanf(cp + 1,
"%d", &LocalTrial) > 0) {
62 cp = strchr(cp + 1,
'=');
64 LocalCost -= Deduction;
65 cp = strchr(cp + 1,
'T');
66 cp = strchr(cp + 1,
'=');
67 sscanf(cp + 1,
"%lf", &LocalTime);
69 LocalTrial, LocalCost);
71 printf(
"Gap = %0.4f%%, ",
72 100.0 * (LocalCost - Optimum) / Optimum);
73 printff(
"Time = %0.2f sec.\n", LocalTime);
76 }
else if (!strcmp(Key,
"Run")) {
77 char *cp = Buffer + strlen(Key);
78 sscanf(cp + 1,
"%d", &
Run);
83 TourFile = fopen(TourFileName,
"r");
86 while ((Line =
ReadLine(TourFile))) {
87 if (!(Keyword = strtok(Line, Delimiters)))
89 for (i = 0; i < strlen(Keyword); i++)
90 Keyword[i] = (
char) toupper(Keyword[i]);
91 if (!strcmp(Keyword,
"TOUR_SECTION"))
95 fscanf(TourFile,
"%d", &Tour[i]);
void printff(char *fmt,...)
char * ReadLine(FILE *InputFile)
GainType SolveTSP(int Dimension, char *ParFileName, char *TourFileName, int *Tour, GainType Optimum, GainType Deduction)