|
|
Go to the documentation of this file. 51 #define VERBOSE MSG_INFO 60 #define MAX_PATH_LEN PATH_MAX 61 #elif defined(_MAX_PATH) 62 #define MAX_PATH_LEN _MAX_PATH 63 #elif defined(_POSIX_PATH_MAX) 64 #define MAX_PATH_LEN _POSIX_PATH_MAX 66 #define MAX_PATH_LEN 1024 73 #define MAX_LINE_LEN 1024 74 #define MAX_KEYWORD_LEN 64 75 #define MAX_STRING_LEN 256 76 #define MAX_ARGUMENTS 8 85 #define KEY_SECTION 0001 89 #define KEY_COMMENT_NAME 1001 90 #define KEY_COMMENT_DATE 1002 91 #define KEY_COMMENT_CREATOR 1003 92 #define KEY_COMMENT_PROBLEM 1004 93 #define KEY_COMMENT_REMARK 1005 95 #define KEY_GRAPH_NODES 2001 96 #define KEY_GRAPH_EDGES 2002 97 #define KEY_GRAPH_E 2003 98 #define KEY_GRAPH_A 2004 99 #define KEY_GRAPH_AA 2005 100 #define KEY_GRAPH_OBSTACLES 2006 101 #define KEY_GRAPH_HOPLIMIT 2007 103 #define KEY_TERMINALS_END 3001 104 #define KEY_TERMINALS_TERMINALS 3002 105 #define KEY_TERMINALS_T 3003 106 #define KEY_TERMINALS_TP 3004 107 #define KEY_TERMINALS_ROOT 3005 108 #define KEY_TERMINALS_ROOTP 3006 109 #define KEY_TERMINALS_TG 3007 110 #define KEY_TERMINALS_GROUPS 3008 112 #define KEY_COORDINATES_DD 4001 113 #define KEY_COORDINATES_DDD 4002 114 #define KEY_COORDINATES_DDDD 4003 115 #define KEY_COORDINATES_DDDDD 4004 116 #define KEY_COORDINATES_DDDDDD 4005 117 #define KEY_COORDINATES_DDDDDDD 4006 118 #define KEY_COORDINATES_DDDDDDDD 4007 120 #define KEY_COORDINATES_END 4011 121 #define KEY_COORDINATES_GRID 4012 123 #define KEY_SOLUTION_VALUE 4021 124 #define KEY_SOLUTION_DATE 4022 125 #define KEY_SOLUTION_TIME 4023 126 #define KEY_SOLUTION_STEINER 4024 127 #define KEY_SOLUTION_S 4025 129 #define KEY_PRESOLVE_DATE 5001 130 #define KEY_PRESOLVE_FIXED 5002 131 #define KEY_PRESOLVE_LOWER 5003 132 #define KEY_PRESOLVE_UPPER 5004 133 #define KEY_PRESOLVE_TIME 5005 134 #define KEY_PRESOLVE_EA 5006 135 #define KEY_PRESOLVE_EC 5007 136 #define KEY_PRESOLVE_ED 5008 137 #define KEY_PRESOLVE_ES 5009 140 #define KEY_NODEWEIGHTS_NW 6000 141 #define KEY_NODEWEIGHTS_END 6001 143 #define KEY_MAXDEGS_MD 8000 145 #define KEY_OBSTACLES_RR 9000 146 #define KEY_OBSTACLES_END 9001 148 #define KEY_HOPCONS_LIM 10000 149 #define KEY_HOPCONS_FACTOR 10001 151 #define KEY_PRIZECOLL_E 11000 163 { "comment.end", KEY_END, NULL }, 182 { "graph.end", KEY_END, NULL }, 190 { "maximumdegrees.end", KEY_END, NULL }, 203 { "presolve.end", KEY_END, NULL }, 207 { "presolve.orgnodes", KEY_EOF, "n" }, 214 { "solution.end", KEY_END, NULL }, 238 #define FLAG_OPTIONAL 1 239 #define FLAG_REQUIRED 2 241 #define SECTION_MISSING 0 242 #define SECTION_EXISTEND 1 291 for( t = s; *s != '\0'; s++ ) 292 *s = ( char)tolower(*s); 312 const char* intro[] = { "Fatal Error", "Error ", "Warning ", 315 const char* header = "*** %s File \"%s\" line %05d: "; 317 assert(type < sizeof(intro) / sizeof( char*)); 318 assert(curf != NULL); 320 assert(curf-> line >= 0); 323 va_start(params, msg); 327 (void)fprintf(stderr, header, intro[type], curf-> filename, curf-> line); 328 (void)vfprintf(stderr, msg, params); 329 (void)fputc( '\n', stderr); 345 assert(elem != NULL); 346 assert((( const struct key*)elem)-> keyword != NULL); 348 (void)fprintf(stderr, "key [%s] elem [%s]\n", 349 ( const char*)key, (( const struct key*)elem)->keyword); 351 return(strcmp(( const char*)key, (( const struct key*)elem)->keyword)); 365 assert(section != NULL); 366 assert((( const struct section*)section)->name != NULL); 368 return(strcmp(( const char*)key, (( const struct section*)section)->name)); 384 const char* err_missmatch_v = "Wrong Syntax"; 385 const char* msg_hello_ss = "get_arguments(\"%s\", \"%s\")"; 387 int missmatch = FALSE; 390 SCIP_Bool is_negative; 391 assert(format != NULL); 393 assert(para != NULL); 399 while((*s != '\0') && (*format != '\0') && !missmatch) 408 while((*s != '\0') && !isdigit(*s) && (*s != '.') && (*s != '-') ) 416 assert(isdigit(*s) || (*s == '.') || (*s == '-')); 423 while(isdigit(*s) || (*s == '.') || (*s == '-')) 429 else if( decimal_spaces != -1 ) 430 para-> n = para-> n + pow(10.0, ( double) -(++decimal_spaces)) * (*s - '0'); 432 para-> n = para-> n * 10 + (*s - '0'); 436 para-> n = (-1) * para-> n; 443 while((*s != '\0') && (*s != '\"')) 494 const char* err_cantopen_s = "%s."; 495 const char* err_noheader_v = "Wrong file header."; 496 const char* err_nomagic_d = "Wrong Magic-Number %d."; 497 const char* err_wrongtype_ss = "Wrong file type. Found %s, expected %s."; 498 const char* msg_version_dd = "Format Version %d.%d."; 506 assert(curf != NULL); 517 if ((curf-> fp = fopen(curf-> filename, "r")) == NULL) 522 else if (fscanf(curf-> fp, "%8x %3s File, STP Format Version %2d.%2d \n", 523 &magic, type, &version_major, &version_minor) != 4) 556 const char* pathname, 557 const char* basename, 562 const char* err_missing_v = "Section name missing"; 563 const char* err_badsect_s = "Unknown section name [%s]"; 564 const char* err_required_s = "Can't access required file [%s]"; 573 assert(pathname != NULL); 574 assert(basename != NULL); 575 assert(curf != NULL); 576 assert(save != NULL); 584 if( (tokens = sscanf(s, "%63s %63s %s", sectname, dummy, inclname)) < 1 ) 590 if( strcmp( strlower(sectname), "comments") == 0 ) 616 (void)sprintf(temp. filename, "%s%s%c%s", 618 (*inclname == '\0') ? basename : inclname, 632 temp. section = §ion_table[0]; 658 double*** coordinates, 667 if( *coordinates == NULL ) 670 assert(termcount != NULL); 671 assert(grid_dim != NULL); 672 assert(*termcount == 0); 678 SCIP_CALL( SCIPallocMemoryArray(scip, coordinates, dim) ); 680 for( i = 0; i < dim; i++ ) 681 SCIP_CALL( SCIPallocMemoryArray(scip, &((*coordinates)[i]), nodes) ); 684 for( i = 0; i < dim; i++ ) 685 (*coordinates)[i][*termcount] = (double)para[i + 1].n; 702 char str_number[SCIP_MAXSTRLEN]; 703 (void)SCIPsnprintf(str_number, SCIP_MAXSTRLEN, "%f", number); 704 length = (int) strlen(str_number); 705 if( SCIP_MAXSTRLEN < length ) 706 length = (int) SCIP_MAXSTRLEN; 708 for( i = 0; i < length; i++ ) 710 if( str_number[length - i - 1] != '0' ) 715 for( i = 0; i < length; i++ ) 722 order = length - ints - trail_zeroes - 1; 731 double** coordinates, 732 int*** scaled_coords, 744 assert(coordinates != NULL); 746 assert(grid_dim > 1); 748 SCIP_CALL( SCIPallocMemoryArray(scip, scaled_coords, grid_dim) ); 750 for( i = 0; i < grid_dim; i++ ) 751 for( j = 0; j < nnodes; j++ ) 755 if( max_order < tmp ) 761 *scale_order = max_order; 762 scale_factor = (int) pow(10.0, ( double) max_order); 764 for( i = 0; i < grid_dim; i++ ) 766 SCIP_CALL( SCIPallocMemoryArray(scip, &((*scaled_coords)[i]), nnodes) ); 767 for( j = 0; j < nnodes; j++ ) 769 (*scaled_coords)[i][j] = (int) (coordinates[i][j] * scale_factor); 787 const char* err_unknown_s = "Unknown keyword [%s]"; 788 const char* err_include_v = "Include in included file"; 789 const char* err_missing_s = "Required section %s missing"; 790 const char* msg_newsect_s = "Processing Section %s"; 791 const char* msg_keyword_sd = "Found Keyword \"%s\", code = %d"; 792 const char* err_badedge_ddd = "Bad edge %d-%d (%d nodes)"; 793 const char* err_badroot_dd = "Bad root %d (%d nodes)"; 794 const char* err_baddeg_dd = "More degree constraints (%d) than nodes (%d)"; 795 const char* msg_finish_dddd = "Nodes: %d Edges: %d Terminals: %d Source=%d\n"; 797 const char* endofline = "#;\n\r"; 798 const char* separator = " \t:="; 800 static CURF curf_null = { "", 0, NULL, NULL }; 811 int stop_input = FALSE; 816 double** coordinates = NULL; 832 int is_gridgraph = FALSE; 833 int has_coordinates = FALSE; 834 int obstacle_counter = 0; 835 int** scaled_coordinates = NULL; 836 int** obstacle_coords = NULL; 839 assert(file != NULL); 843 for( i = 1; i < (int)( sizeof(section_table) / sizeof(section_table[0])); i++ ) 848 (void)strcpy(pathname, file); 852 if( (s = strrchr(pathname, DIRSEP[0])) == NULL ) 856 (void)strcpy(basename, pathname); 864 (void)strcpy(basename, s); 870 if ((s = strrchr(basename, EXTSEP)) != NULL) 875 curf. section = §ion_table[0]; 878 (void)sprintf(curf. filename, "%s%s.%s", 889 while((curf. fp != NULL) && !stop_input) 893 if ((s = fgets(buffer, ( int) sizeof(buffer), curf. fp)) == NULL) 897 (void)fclose(curf. fp); 922 if ((t = strpbrk(s, endofline)) != NULL) 934 i = (int)strlen(keyword); 940 keyword[i] = ( char)tolower(*s); 946 while((*s != '\0') && (strchr(separator, *s) != NULL)) 949 if( strcmp(keyword, "comments") == 0 ) 950 keyword[i - 1] = '\0'; 954 p = ( struct key*)bsearch(keyword, keyword_table, 955 sizeof(keyword_table) / sizeof( struct key), 956 sizeof(struct key), key_cmp); 972 format = ( char*) "nn"; 974 format = ( char*) "nn"; 979 format = ( char*) "nnnn"; 1002 curf. section = §ion_table[0]; 1010 for(i = 0; (unsigned)i < sizeof(section_table) / sizeof( struct section); i++) 1024 (void)printf( "Problem: [%s]\n", para[0].s); 1025 if( strcmp(para[0].s, "SPG") == 0 ) 1027 else if( strcmp(para[0].s, "PCSPG") == 0 1028 || strcmp(para[0].s, "Prize-Collecting Steiner Problem in Graphs") == 0 ) 1030 else if( strcmp(para[0].s, "RPCST") == 0 1031 || strcmp(para[0].s, "Rooted Prize-Collecting Steiner Problem in Graphs") == 0 ) 1033 else if( strcmp(para[0].s, "NWSPG") == 0 ) 1035 else if( strcmp(para[0].s, "DCST") == 0 ) 1037 else if( strcmp(para[0].s, "RSMT") == 0 ) 1039 else if( strcmp(para[0].s, "OARSMT") == 0 ) 1041 else if( strcmp(para[0].s, "Maximum Node Weight Connected Subgraph") == 0 1042 || strcmp(para[0].s, "MWCS") == 0 ) 1044 else if( strcmp(para[0].s, "HCDST") == 0 ) 1046 else if( strcmp(para[0].s, "SAP") == 0 ) 1048 else if( strcmp(para[0].s, "GSTP") == 0 ) 1052 (void)printf( "Comment: [%s]\n", para[0].s); 1053 if( strcmp(para[0].s, "Transformed") == 0 ) 1057 nodes = (int)para[0].n; 1060 nobstacles = (int)para[0].n; 1061 if( nobstacles > 0 ) 1065 hoplimit = (int)para[0].n; 1069 edges = (int)para[0].n; 1074 if( ( int)para[0]. n > nodes || (int)para[1].n > nodes ) 1077 ( int)para[0].n, ( int)para[1].n, nodes); 1084 if( stp_type == GSTP ) 1085 SCIP_CALL( graph_init(scip, graph, nodes * 2, edges * 2 + nodes * nodes, 1, 0) ); 1087 SCIP_CALL( graph_init(scip, graph, nodes, edges * 2, 1, 0) ); 1091 for( i = 0; i < nodes; i++ ) 1103 tail = (int)para[0].n - 1; 1104 head = (int)para[1].n - 1; 1107 if( g-> tail[i] == tail ) 1112 g-> cost[i] = (double)para[2].n; 1117 graph_edge_add(scip, g, ( int)para[0].n - 1, ( int)para[1].n - 1, ( double)para[2].n, ( double)para[3].n); 1121 graph_edge_add(scip, g, ( int)para[0].n - 1, ( int)para[1].n - 1, 0.0, 0.0); 1129 : ( double)para[3]. n); 1134 assert(( int)para[0].n >= 0); 1136 if( degcount < nodes ) 1140 SCIP_CALL( SCIPallocMemoryArray(scip, &(g-> maxdeg), nodes ) ); 1143 g-> maxdeg[degcount++] = (int)para[0].n; 1153 nodeweight = (double) para[0].n; 1155 assert(presol != NULL); 1161 presol-> fixed += nodeweight; 1165 g-> cost[i] += nodeweight; 1169 curf. section = §ion_table[0]; 1172 assert(nobstacles > 0); 1173 if( obstacle_coords == NULL ) 1175 assert(obstacle_counter == 0); 1176 SCIP_CALL( SCIPallocBufferArray(scip, &obstacle_coords, 4) ); 1177 for( i = 0; i < 4; i++ ) 1178 SCIP_CALL( SCIPallocBufferArray(scip, &(obstacle_coords[i]), nobstacles) ); 1180 for( i = 0; i < 4; i++ ) 1181 obstacle_coords[i][obstacle_counter] = ( int)para[i]. n; 1185 curf. section = §ion_table[0]; 1187 if( obstacle_counter != nobstacles ) 1189 message( MSG_FATAL, &curf, "obstacle number does not match coordinates \n"); 1193 if( scaled_coordinates == NULL ) 1200 SCIP_CALL( graph_obstgrid_create(scip, graph, scaled_coordinates, obstacle_coords, nodes, grid_dim, nobstacles, scale_order) ); 1202 if( obstacle_coords != NULL ) 1203 for( i = 3; i >= 0; i-- ) 1204 SCIPfreeBufferArrayNull(scip, &(obstacle_coords[i])); 1205 SCIPfreeBufferArrayNull(scip, &(obstacle_coords)); 1208 if( transformed == 0 ) 1212 assert(nodes == termcount); 1242 curf. section = §ion_table[0]; 1245 terms = (int)para[0].n; 1250 assert(terms == nodes); 1252 if( g-> prize == NULL ) 1253 SCIP_CALL( SCIPallocMemoryArray(scip, &(g-> prize), terms) ); 1257 assert(stp_type == GSTP); 1258 tgroups = (int)para[0].n; 1259 presol-> fixed -= tgroups * 1e+8; 1260 for( i = 0; i < tgroups; i++ ) 1268 if (( int)para[0].n <= nodes) 1270 g-> source[0] = (int)para[0].n - 1; 1276 ( int)para[0].n, nodes); 1283 g-> source[0] = (int)para[0].n - 1; 1286 if( g-> prize == NULL ) 1287 SCIP_CALL( SCIPallocMemoryArray(scip, &(g-> prize), nodes) ); 1294 assert(g-> prize != NULL); 1295 g-> prize[(int)para[0].n - 1] = ( double)para[1]. n; 1296 if( SCIPisGT(scip, ( double)para[1].n, 0.0) ) 1297 presol-> fixed -= ( double)para[1]. n; 1306 assert(tgroups > 0); 1307 graph_edge_add(scip, g, ( int)para[0].n - 1, g-> knots - tgroups + ( int)para[1]. n - 1, 1e+8, 1e+8); 1313 if( g-> prize == NULL ) 1317 SCIP_CALL( SCIPallocMemoryArray(scip, &(g-> prize), nodes) ); 1319 g-> prize[(int)para[0].n - 1] = ( double)para[1]. n; 1330 SCIP_CALL( init_coordinates(scip, g, para, &coordinates, &grid_dim, &termcount, 2, nodes) ); 1333 SCIP_CALL( init_coordinates(scip, g, para, &coordinates, &grid_dim, &termcount, 3, nodes) ); 1336 SCIP_CALL( init_coordinates(scip, g, para, &coordinates, &grid_dim, &termcount, 4, nodes) ); 1339 SCIP_CALL( init_coordinates(scip, g, para, &coordinates, &grid_dim, &termcount, 5, nodes) ); 1342 SCIP_CALL( init_coordinates(scip, g, para, &coordinates, &grid_dim, &termcount, 6, nodes) ); 1345 SCIP_CALL( init_coordinates(scip, g, para, &coordinates, &grid_dim, &termcount, 7, nodes) ); 1348 SCIP_CALL( init_coordinates(scip, g, para, &coordinates, &grid_dim, &termcount, 8, nodes) ); 1352 assert(grid_dim > 1); 1354 curf. section = §ion_table[0]; 1355 if( termcount != nodes ) 1363 SCIP_CALL( scale_coords(coordinates, &scaled_coordinates, &scale_order, nodes, grid_dim) ); 1365 if( coordinates != NULL ) 1366 for( i = 0; i < grid_dim; i++ ) 1367 SCIPfreeMemoryArrayNull(scip, &(coordinates[i])); 1369 SCIPfreeMemoryArrayNull(scip, &coordinates); 1373 SCIP_CALL( graph_grid_create(scip, graph, scaled_coordinates, nodes, grid_dim, scale_order) ); 1379 is_gridgraph = TRUE; 1383 presol-> fixed += (double)para[0].n; 1386 (void)printf( "Found presolve information %s\n", 1391 presol-> lower = (double)para[0].n; 1395 presol-> upper = (double)para[0].n; 1399 presol-> time = (int)para[0].n; 1421 if (save. fp != NULL) 1422 (void)fclose(save. fp); 1427 if (curf. fp != NULL) 1428 (void)fclose(curf. fp); 1436 for(i = 0; i < g-> knots; i++) 1437 if ((g-> term[i] == 0) 1452 (void)printf(msg_finish_dddd, 1460 if( obstacle_coords != NULL ) 1462 for( i = 0; i < 4; i++ ) 1463 SCIPfreeBufferArrayNull(scip, &(obstacle_coords[i])); 1464 SCIPfreeBufferArrayNull(scip, &(obstacle_coords)); 1466 return SCIP_READERROR;
#define KEY_COMMENT_CREATOR
#define KEY_NODEWEIGHTS_NW
int graph_valid(const GRAPH *)
static SCIP_RETCODE scale_coords(double **coordinates, int ***scaled_coords, int *scale_order, int nnodes, int grid_dim)
#define GRAPH_HAS_COORDINATES
#define KEY_NODEWEIGHTS_END
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)
static int sec_cmp(const void *key, const void *section)
SCIP_RETCODE graph_obstgrid_create(SCIP *, GRAPH **, int **, int **, int, int, int, int)
#define KEY_OBSTACLES_END
SCIP_RETCODE graph_rootprize_transform(SCIP *, GRAPH *)
#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)
#define KEY_TERMINALS_ROOTP
#define KEY_PRESOLVE_LOWER
char filename[MAX_PATH_LEN]
#define KEY_COORDINATES_END
void graph_knot_chg(GRAPH *, int, int)
#define KEY_SOLUTION_VALUE
#define STP_OBSTACLES_GRID
#define KEY_TERMINALS_ROOT
#define KEY_COORDINATES_DD
#define KEY_PRESOLVE_DATE
#define KEY_COORDINATES_DDDDDDDD
#define KEY_HOPCONS_FACTOR
#define KEY_TERMINALS_TERMINALS
#define KEY_COORDINATES_DDDD
static int open_file(CURF *curf)
SCIP_RETCODE graph_MwcsToSap(SCIP *, GRAPH *, SCIP_Real *)
static int get_scale_order(SCIP_Real number)
#define STP_MAX_NODE_WEIGHT
#define KEY_COORDINATES_DDDDD
#define KEY_PRESOLVE_UPPER
SCIP_RETCODE graph_PcToSap(SCIP *, GRAPH *)
#define KEY_SOLUTION_TIME
#define KEY_COORDINATES_DDDDDD
#define KEY_SOLUTION_STEINER
static const struct key keyword_table[]
#define STP_PRIZE_COLLECTING
SCIP_RETCODE graph_init(SCIP *, GRAPH **, int, int, int, int)
static struct section section_table[]
#define KEY_GRAPH_HOPLIMIT
SCIP_RETCODE graph_maxweight_transform(SCIP *, GRAPH *, SCIP_Real *)
static int get_arguments(const CURF *curf, const char *format, const char *s, PARA *para)
void graph_flags(GRAPH *, int)
includes various files containing graph methods used for Steiner problems
#define KEY_TERMINALS_END
static int start_section(const char *pathname, const char *basename, CURF *curf, CURF *save, const char *s)
SCIP_RETCODE graph_prize_transform(SCIP *, GRAPH *)
#define GRAPH_IS_GRIDGRAPH
#define KEY_PRESOLVE_TIME
#define STP_ROOTED_PRIZE_COLLECTING
#define KEY_COMMENT_PROBLEM
#define KEY_PRESOLVE_FIXED
void graph_knot_add(GRAPH *, int)
#define KEY_GRAPH_OBSTACLES
#define KEY_COORDINATES_GRID
#define KEY_COORDINATES_DDDDDDD
#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)
|