44 #if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER) 61 #define VERBOSE MSG_INFO 70 #define MAX_PATH_LEN PATH_MAX 71 #elif defined(_MAX_PATH) 72 #define MAX_PATH_LEN _MAX_PATH 73 #elif defined(_POSIX_PATH_MAX) 74 #define MAX_PATH_LEN _POSIX_PATH_MAX 76 #define MAX_PATH_LEN 1024 83 #define MAX_LINE_LEN 1024 84 #define MAX_KEYWORD_LEN 64 85 #define MAX_STRING_LEN 256 86 #define MAX_ARGUMENTS 8 95 #define KEY_SECTION 0001 99 #define KEY_COMMENT_NAME 1001 100 #define KEY_COMMENT_DATE 1002 101 #define KEY_COMMENT_CREATOR 1003 102 #define KEY_COMMENT_PROBLEM 1004 103 #define KEY_COMMENT_REMARK 1005 105 #define KEY_GRAPH_NODES 2001 106 #define KEY_GRAPH_EDGES 2002 107 #define KEY_GRAPH_E 2003 108 #define KEY_GRAPH_A 2004 109 #define KEY_GRAPH_AA 2005 110 #define KEY_GRAPH_OBSTACLES 2006 111 #define KEY_GRAPH_HOPLIMIT 2007 113 #define KEY_TERMINALS_END 3001 114 #define KEY_TERMINALS_TERMINALS 3002 115 #define KEY_TERMINALS_T 3003 116 #define KEY_TERMINALS_TP 3004 117 #define KEY_TERMINALS_ROOT 3005 118 #define KEY_TERMINALS_ROOTP 3006 119 #define KEY_TERMINALS_TG 3007 120 #define KEY_TERMINALS_GROUPS 3008 121 #define KEY_TERMINALS_TR 3009 123 #define KEY_COORDINATES_DD 4001 124 #define KEY_COORDINATES_DDD 4002 125 #define KEY_COORDINATES_DDDD 4003 126 #define KEY_COORDINATES_DDDDD 4004 127 #define KEY_COORDINATES_DDDDDD 4005 128 #define KEY_COORDINATES_DDDDDDD 4006 129 #define KEY_COORDINATES_DDDDDDDD 4007 131 #define KEY_COORDINATES_END 4011 132 #define KEY_COORDINATES_GRID 4012 134 #define KEY_SOLUTION_VALUE 4021 135 #define KEY_SOLUTION_DATE 4022 136 #define KEY_SOLUTION_TIME 4023 137 #define KEY_SOLUTION_STEINER 4024 138 #define KEY_SOLUTION_S 4025 140 #define KEY_PRESOLVE_DATE 5001 141 #define KEY_PRESOLVE_FIXED 5002 142 #define KEY_PRESOLVE_LOWER 5003 143 #define KEY_PRESOLVE_UPPER 5004 144 #define KEY_PRESOLVE_TIME 5005 145 #define KEY_PRESOLVE_EA 5006 146 #define KEY_PRESOLVE_EC 5007 147 #define KEY_PRESOLVE_ED 5008 148 #define KEY_PRESOLVE_ES 5009 151 #define KEY_NODEWEIGHTS_NW 6000 152 #define KEY_NODEWEIGHTS_END 6001 154 #define KEY_MAXDEGS_MD 8000 156 #define KEY_OBSTACLES_RR 9000 157 #define KEY_OBSTACLES_END 9001 159 #define KEY_HOPCONS_LIM 10000 160 #define KEY_HOPCONS_FACTOR 10001 162 #define KEY_TREE_S 11000 174 {
"comment.end",
KEY_END, NULL },
193 {
"graph.end",
KEY_END, NULL },
201 {
"maximumdegrees.end",
KEY_END, NULL },
214 {
"presolve.end",
KEY_END, NULL },
218 {
"presolve.orgnodes",
KEY_EOF,
"n" },
223 {
"solution.end",
KEY_END, NULL },
250 #define FLAG_OPTIONAL 1 251 #define FLAG_REQUIRED 2 253 #define SECTION_MISSING 0 254 #define SECTION_EXISTEND 1 304 for( t = s; *s !=
'\0'; s++ )
305 *s = (
char)tolower(*s);
325 const char* intro[] = {
"Fatal Error",
"Error ",
"Warning ",
328 const char* header =
"*** %s File \"%s\" line %05d: ";
330 assert(type <
sizeof(intro) /
sizeof(
char*));
331 assert(curf !=
NULL);
333 assert(curf->
line >= 0);
336 va_start(params, msg);
340 (void)fprintf(stderr, header, intro[type], curf->
filename, curf->
line);
341 (void)vfprintf(stderr, msg, params);
342 (void)fputc(
'\n', stderr);
358 assert(elem !=
NULL);
359 assert(((
const struct key*)elem)->
keyword !=
NULL);
361 return(strcmp((
const char*)key, ((
const struct key*)elem)->
keyword));
375 assert(section !=
NULL);
376 assert(((
const struct section*)section)->name !=
NULL);
378 return(strcmp((
const char*)key, ((
const struct section*)section)->name));
394 const char* err_missmatch_v =
"Wrong Syntax";
395 const char* msg_hello_ss =
"get_arguments(\"%s\", \"%s\")";
397 int missmatch =
FALSE;
401 assert(format !=
NULL);
403 assert(para !=
NULL);
409 while((*s !=
'\0') && (*format !=
'\0') && !missmatch)
418 while((*s !=
'\0') && !isdigit(*s) && (*s !=
'.') && (*s !=
'-') )
426 assert(isdigit(*s) || (*s ==
'.') || (*s ==
'-'));
433 while(isdigit(*s) || (*s ==
'.') || (*s ==
'-'))
439 else if( decimal_spaces != -1 )
440 para->
n = para->
n +
pow(10.0, (
double) -(++decimal_spaces)) * (*s -
'0');
442 para->
n = para->
n * 10 + (*s -
'0');
446 para->
n = (-1) * para->
n;
453 while((*s !=
'\0') && (*s !=
'\"'))
503 unsigned char main_file
506 const char* err_cantopen_s =
"%s.";
507 const char* err_noheader_v =
"Wrong file header.";
508 const char* err_nomagic_d =
"Wrong Magic-Number %d.";
509 const char* err_wrongtype_ss =
"Wrong file type. Found %s, expected %s.";
510 const char* msg_version_dd =
"Format Version %d.%d.";
518 assert(curf !=
NULL);
532 (void)sprintf(fillname_gr,
"%s.%s",
536 if ((curf->
fp = fopen(fillname_gr,
"r")) !=
NULL)
538 (void)sprintf(curf->
filename,
"%s", fillname_gr);
545 (void) sprintf(fillname_stp,
"%s.%s", curf->
filename,
"stp");
547 if ((curf->
fp = fopen(fillname_stp,
"r")) ==
NULL)
552 (void)sprintf(curf->
filename,
"%s", fillname_stp);
559 if (!main_file && (curf->
fp = fopen(curf->
filename,
"r")) ==
NULL)
564 else if (fscanf(curf->
fp,
"%8x %3s File, STP Format Version %2d.%2d \n",
565 &magic, type, &version_major, &version_minor) != 4)
598 const char* pathname,
599 const char* basename,
604 const char* err_missing_v =
"Section name missing";
605 const char* err_badsect_s =
"Unknown section name [%s]";
606 const char* err_required_s =
"Can't access required file [%s]";
615 assert(pathname !=
NULL);
616 assert(basename !=
NULL);
617 assert(curf !=
NULL);
618 assert(save !=
NULL);
626 if( (tokens = sscanf(s,
"%63s %63s %s", sectname, dummy, inclname)) < 1 )
632 if( strcmp(
strlower(sectname),
"comments") == 0 )
646 if( tokens == 1 || (tokens == 2 && strcmp(
strlower(sectname),
"tree") == 0) )
654 (void)sprintf(temp.
filename,
"%s%s%c%s",
656 (*inclname ==
'\0') ? basename : inclname,
659 #if defined(_MSC_VER) 673 temp.
section = §ion_table[0];
699 double*** coordinates,
708 if( *coordinates ==
NULL )
711 assert(termcount !=
NULL);
712 assert(grid_dim !=
NULL);
713 assert(*termcount == 0);
721 for( i = 0; i < dim; i++ )
725 for( i = 0; i < dim; i++ )
726 (*coordinates)[i][*termcount] = (double)para[i + 1].n;
745 length = (int) strlen(str_number);
749 for( i = 0; i < length; i++ )
751 if( str_number[length - i - 1] !=
'0' )
756 for( i = 0; i < length; i++ )
763 order = length - ints - trail_zeroes - 1;
772 double** coordinates,
773 int*** scaled_coords,
785 assert(coordinates !=
NULL);
787 assert(grid_dim > 1);
791 for( i = 0; i < grid_dim; i++ )
792 for( j = 0; j <
nnodes; j++ )
796 if( max_order < tmp )
802 *scale_order = max_order;
803 scale_factor = (int)
pow(10.0, (
double) max_order);
805 for( i = 0; i < grid_dim; i++ )
808 for( j = 0; j <
nnodes; j++ )
810 (*scaled_coords)[i][j] = (int) (coordinates[i][j] * scale_factor);
828 const char* err_unknown_s =
"Unknown keyword [%s]";
829 const char* err_include_v =
"Include in included file";
830 const char* err_missing_s =
"Required section %s missing";
831 const char* msg_newsect_s =
"Processing Section %s";
832 const char* msg_keyword_sd =
"Found Keyword \"%s\", code = %d";
833 const char* err_badedge_ddd =
"Bad edge %d-%d (%d nodes)";
834 const char* err_badroot_dd =
"Bad root %d (%d nodes)";
835 const char* err_baddeg_dd =
"More degree constraints (%d) than nodes (%d)";
836 const char* msg_finish_dddd =
"Nodes: %d Edges: %d Terminals: %d Source=%d\n";
838 const char* endofline =
"#;\n\r";
839 const char* separator =
" \t:=";
852 int stop_input =
FALSE;
857 double** coordinates =
NULL;
873 int obstacle_counter = 0;
874 int** scaled_coordinates =
NULL;
875 int** obstacle_coords =
NULL;
878 assert(file != NULL);
882 for( i = 1; i < (int)(
sizeof(section_table) /
sizeof(section_table[0])); i++ )
887 (void)strcpy(pathname, file);
891 if( (s = strrchr(pathname,
DIRSEP[0])) == NULL )
895 (void)strcpy(basename, pathname);
903 (void)strcpy(basename, s);
909 if ((s = strrchr(basename,
EXTSEP)) != NULL)
914 curf.
section = §ion_table[0];
925 while((curf.
fp != NULL) && !stop_input)
929 if ((s = fgets(buffer, (
int)
sizeof(buffer), curf.
fp)) == NULL)
933 (void)fclose(curf.
fp);
958 if ((t = strpbrk(s, endofline)) != NULL)
970 i = (int)strlen(keyword);
976 keyword[i] = (
char)tolower(*s);
982 while((*s !=
'\0') && (strchr(separator, *s) != NULL))
985 if( strcmp(keyword,
"comments") == 0 )
986 keyword[i - 1] =
'\0';
990 p = (
struct key*)bsearch(keyword, keyword_table,
991 sizeof(keyword_table) /
sizeof(
struct key),
992 sizeof(struct key), key_cmp);
998 char newformat[5] =
"";
1006 strcpy(newformat,
"nn");
1008 strcpy(newformat,
"nnnn");
1010 if( p->
format == NULL || !
get_arguments(&curf, (
const char*)( newformat[0] !=
'\0' ? newformat : p->
format ), s, para) )
1017 if (save.
fp == NULL)
1029 curf.
section = §ion_table[0];
1038 for(i = 0; (unsigned)i <
sizeof(section_table) /
sizeof(
struct section); i++)
1052 (void)printf(
"Problem: [%s]\n", para[0].s);
1053 if( strcmp(para[0].s,
"SPG") == 0 )
1055 else if( strcmp(para[0].s,
"PCSPG") == 0
1056 || strcmp(para[0].s,
"Prize-Collecting Steiner Problem in Graphs") == 0 )
1058 else if( strcmp(para[0].s,
"RPCST") == 0
1059 || strcmp(para[0].s,
"Rooted Prize-Collecting Steiner Problem in Graphs") == 0 )
1061 else if( strcmp(para[0].s,
"NWSPG") == 0 )
1063 else if( strcmp(para[0].s,
"DCST") == 0 )
1065 else if( strcmp(para[0].s,
"RSMT") == 0 )
1067 else if( strcmp(para[0].s,
"OARSMT") == 0 )
1069 else if( strcmp(para[0].s,
"Maximum Node Weight Connected Subgraph") == 0
1070 || strcmp(para[0].s,
"MWCS") == 0 )
1072 else if( strcmp(para[0].s,
"Rooted Maximum Node Weight Connected Subgraph") == 0
1073 || strcmp(para[0].s,
"RMWCS") == 0 )
1075 else if( strcmp(para[0].s,
"HCDST") == 0 )
1077 else if( strcmp(para[0].s,
"SAP") == 0 )
1079 else if( strcmp(para[0].s,
"GSTP") == 0 )
1083 (void)printf(
"Comment: [%s]\n", para[0].s);
1084 if( strcmp(para[0].s,
"Transformed") == 0 )
1088 assert(para != NULL);
1089 nodes = (int)para[0].n;
1092 nobstacles = (int)para[0].n;
1093 if( nobstacles > 0 )
1097 hoplimit = (int)para[0].n;
1101 edges = (int)para[0].n;
1106 if( (
int)para[0].
n > nodes || (int)para[1].n > nodes )
1109 (
int)para[0].n, (
int)para[1].n, nodes);
1124 for( i = 0; i < nodes; i++ )
1136 tail = (int)para[0].n - 1;
1137 head = (int)para[1].n - 1;
1140 if( g->
tail[i] == tail )
1145 g->
cost[i] = (double)para[2].n;
1148 else if( stp_type ==
STP_SAP )
1150 graph_edge_add(scip, g, (
int)para[0].n - 1, (
int)para[1].n - 1, (
double)para[2].n, (
double)para[3].n);
1154 graph_edge_add(scip, g, (
int)para[0].n - 1, (
int)para[1].n - 1, 0.0, 0.0);
1162 : (
double)para[3].
n);
1167 assert((
int)para[0].n >= 0);
1169 if( degcount < nodes )
1176 g->
maxdeg[degcount++] = (int)para[0].n;
1186 nodeweight = (double) para[0].n;
1188 assert(presol != NULL);
1194 presol->
fixed += nodeweight;
1198 g->
cost[i] += nodeweight;
1202 curf.
section = §ion_table[0];
1205 assert(nobstacles > 0);
1206 if( obstacle_coords == NULL )
1208 assert(obstacle_counter == 0);
1210 for( i = 0; i < 4; i++ )
1213 for( i = 0; i < 4; i++ )
1214 obstacle_coords[i][obstacle_counter] = (
int)para[i].
n;
1218 curf.
section = §ion_table[0];
1220 if( obstacle_counter != nobstacles )
1222 message(
MSG_FATAL, &curf,
"obstacle number does not match coordinates \n");
1226 if( scaled_coordinates == NULL )
1235 message(
MSG_FATAL, &curf,
"Obstacle avoiding RSMT problems are currently not supported in this format \n");
1239 if( obstacle_coords != NULL )
1240 for( i = 3; i >= 0; i-- )
1245 if( transformed == 0 )
1249 assert(nodes == termcount);
1263 assert(nodes == termcount);
1284 curf.
section = §ion_table[0];
1287 terms = (int)para[0].n;
1292 assert(terms == nodes);
1294 if( g->
prize == NULL )
1300 tgroups = (int)para[0].n;
1301 presol->
fixed -= tgroups * 1e+8;
1302 for( i = 0; i < tgroups; i++ )
1310 if ((
int)para[0].n <= nodes)
1312 g->
source = (int)para[0].n - 1;
1318 (
int)para[0].n, nodes);
1325 g->
source = (int)para[0].n - 1;
1328 if( g->
prize == NULL )
1337 assert(g->
prize != NULL);
1338 g->
prize[(int)para[0].n - 1] = (
double)para[1].
n;
1339 if(
SCIPisGT(scip, (
double)para[1].n, 0.0) )
1340 presol->
fixed -= (
double)para[1].
n;
1348 assert(tgroups > 0);
1349 graph_edge_add(scip, g, (
int)para[0].n - 1, g->
knots - tgroups + (
int)para[1].
n - 1, 1e+8, 1e+8);
1355 if( g->
prize == NULL )
1361 g->
prize[(int)para[0].n - 1] = (
double)para[1].
n;
1367 assert(g->
prize != NULL);
1369 presol->
fixed -= (double)para[1].n;
1403 assert(grid_dim > 1);
1405 curf.
section = §ion_table[0];
1406 if( termcount != nodes )
1416 if( coordinates != NULL )
1417 for( i = 0; i < grid_dim; i++ )
1433 presol->
fixed += (double)para[0].n;
1436 (void)printf(
"Found presolve information %s\n",
1441 presol->
lower = (double)para[0].n;
1445 presol->
upper = (double)para[0].n;
1449 presol->
time = (int)para[0].n;
1471 if( save.
fp != NULL )
1472 (void)fclose(save.
fp);
1477 if( curf.
fp != NULL )
1478 (void)fclose(curf.
fp);
1486 for( i = 0; i < g->
knots; i++ )
1487 if ((g->
term[i] == 0)
1500 (void)printf(msg_finish_dddd,
1508 if( obstacle_coords != NULL )
1510 for( i = 0; i < 4; i++ )
#define KEY_COMMENT_CREATOR
#define KEY_NODEWEIGHTS_NW
SCIP_RETCODE graph_pc_2mw(SCIP *, GRAPH *, SCIP_Real *)
SCIP_RETCODE graph_pc_init(SCIP *, GRAPH *, int, int)
static SCIP_RETCODE scale_coords(double **coordinates, int ***scaled_coords, int *scale_order, int nnodes, int grid_dim)
#define KEY_NODEWEIGHTS_END
#define SCIPfreeMemoryArrayNull(scip, ptr)
static void message(unsigned int type, const CURF *curf, const char *msg,...)
SCIP_RETCODE graph_load(SCIP *scip, GRAPH **graph, const char *file, PRESOL *presol)
SCIP_Bool graph_valid(const GRAPH *)
SCIPInterval pow(const SCIPInterval &x, const SCIPInterval &y)
static int sec_cmp(const void *key, const void *section)
#define SCIPallocMemoryArray(scip, ptr, num)
SCIP_RETCODE graph_obstgrid_create(SCIP *, GRAPH **, int **, int **, int, int, int, int)
#define KEY_OBSTACLES_END
#define KEY_COMMENT_REMARK
static SCIP_RETCODE init_coordinates(SCIP *scip, GRAPH *g, PARA *para, double ***coordinates, int *grid_dim, int *termcount, int dim, int nodes)
#define KEY_SOLUTION_DATE
static char * strlower(char *s)
enum SCIP_Retcode SCIP_RETCODE
#define KEY_TERMINALS_ROOTP
#define KEY_PRESOLVE_LOWER
char filename[MAX_PATH_LEN]
#define KEY_COORDINATES_END
void graph_knot_chg(GRAPH *, int, int)
static int open_file(CURF *curf, unsigned char main_file)
#define KEY_SOLUTION_VALUE
SCIP_RETCODE graph_pc_2rmw(SCIP *, GRAPH *)
#define KEY_TERMINALS_ROOT
#define KEY_COORDINATES_DD
#define KEY_PRESOLVE_DATE
#define KEY_COORDINATES_DDDDDDDD
SCIP_RETCODE graph_pc_2rpc(SCIP *, GRAPH *)
#define KEY_HOPCONS_FACTOR
#define SCIPfreeBufferArrayNull(scip, ptr)
#define KEY_TERMINALS_TERMINALS
#define KEY_COORDINATES_DDDD
static int get_scale_order(SCIP_Real number)
#define KEY_COORDINATES_DDDDD
#define KEY_PRESOLVE_UPPER
#define SCIPallocBufferArray(scip, ptr, num)
#define KEY_SOLUTION_TIME
#define KEY_COORDINATES_DDDDDD
#define KEY_SOLUTION_STEINER
static const struct key keyword_table[]
static struct section section_table[]
#define KEY_GRAPH_HOPLIMIT
static int get_arguments(const CURF *curf, const char *format, const char *s, PARA *para)
includes various files containing graph methods used for Steiner tree problems
#define KEY_TERMINALS_END
static int start_section(const char *pathname, const char *basename, CURF *curf, CURF *save, const char *s)
#define KEY_PRESOLVE_TIME
int SCIPsnprintf(char *t, int len, const char *s,...)
#define KEY_COMMENT_PROBLEM
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define KEY_PRESOLVE_FIXED
void graph_knot_add(GRAPH *, int)
#define KEY_GRAPH_OBSTACLES
#define KEY_COORDINATES_GRID
#define KEY_COORDINATES_DDDDDDD
SCIP_RETCODE graph_pc_2pc(SCIP *, GRAPH *)
#define KEY_COORDINATES_DDD
#define KEY_TERMINALS_GROUPS
void graph_edge_add(SCIP *, GRAPH *, int, int, double, double)
static int key_cmp(const void *key, const void *elem)
SCIP_RETCODE graph_grid_create(SCIP *, GRAPH **, int **, int, int, int)
SCIP_RETCODE graph_init(SCIP *, GRAPH **, int, int, int)