| 1 |
/*===========================================================================*/ |
| 2 |
/* */ |
| 3 |
/* This file is part of a demonstration application for use with the */ |
| 4 |
/* SYMPHONY Branch, Cut, and Price Library. This application is a solver for */ |
| 5 |
/* the Vehicle Routing Problem and the Traveling Salesman Problem. */ |
| 6 |
/* */ |
| 7 |
/* (c) Copyright 2000-2007 Ted Ralphs. All Rights Reserved. */ |
| 8 |
/* */ |
| 9 |
/* This application was developed by Ted Ralphs ([email protected]) */ |
| 10 |
/* */ |
| 11 |
/* This software is licensed under the Eclipse Public License. Please see */ |
| 12 |
/* accompanying file for terms. */ |
| 13 |
/* */ |
| 14 |
/*===========================================================================*/ |
| 15 |
|
| 16 |
/* system include files */ |
| 17 |
#include <stdlib.h> |
| 18 |
#include <stdio.h> |
| 19 |
#include <string.h> |
| 20 |
#include <math.h> |
| 21 |
|
| 22 |
/* SYMPHONY include files */ |
| 23 |
#include "sym_macros.h" |
| 24 |
#include "sym_types.h" |
| 25 |
#include "sym_master_u.h" |
| 26 |
#include "sym_lp_params.h" |
| 27 |
|
| 28 |
/* VRP include files */ |
| 29 |
#include "vrp_io.h" |
| 30 |
#include "vrp_types.h" |
| 31 |
#include "vrp_const.h" |
| 32 |
#include "vrp_macros.h" |
| 33 |
#include "compute_cost.h" |
| 34 |
#include "small_graph.h" |
| 35 |
|
| 36 |
/*===========================================================================*/ |
| 37 |
|
| 38 |
/*===========================================================================*\ |
| 39 |
* This file contains the user I/O functions for the master process. |
| 40 |
\*===========================================================================*/ |
| 41 |
|
| 42 |
/*===========================================================================*\ |
| 43 |
* This first function reads in the data instance. |
| 44 |
\*===========================================================================*/ |
| 45 |
|
| 46 |
void vrp_io(vrp_problem *vrp, char *infile) |
| 47 |
{ |
| 48 |
static char keywords[KEY_NUM][22] = { |
| 49 |
"NAME", |
| 50 |
"NAME:", /* This section lists the names of the */ |
| 51 |
"TYPE", /* possible fields in the data file */ |
| 52 |
"TYPE:", |
| 53 |
"COMMENT", |
| 54 |
"COMMENT:", |
| 55 |
"DIMENSION", |
| 56 |
"DIMENSION:", |
| 57 |
"CAPACITY", |
| 58 |
"CAPACITY:", |
| 59 |
"EDGE_WEIGHT_TYPE", |
| 60 |
"EDGE_WEIGHT_TYPE:", |
| 61 |
"EDGE_WEIGHT_FORMAT", |
| 62 |
"EDGE_WEIGHT_FORMAT:", |
| 63 |
"DISPLAY_DATA_TYPE", |
| 64 |
"DISPLAY_DATA_TYPE:", |
| 65 |
"EDGE_WEIGHT_SECTION", |
| 66 |
"EDGE_WEIGHT_SECTION:", |
| 67 |
"DISPLAY_DATA_SECTION", |
| 68 |
"DISPLAY_DATA_SECTION:", |
| 69 |
"NODE_COORD_SECTION", |
| 70 |
"NODE_COORD_SECTION:", |
| 71 |
"NODE_COORD_TYPE", |
| 72 |
"NODE_COORD_TYPE:", |
| 73 |
"DEPOT_SECTION", |
| 74 |
"DEPOT_SECTION:", |
| 75 |
"CAPACITY_VOL", |
| 76 |
"CAPACITY_VOL:", |
| 77 |
"DEMAND_SECTION", |
| 78 |
"DEMAND_SECTION:", |
| 79 |
"TIME_WINDOW_SECTION", |
| 80 |
"TIME_WINDOW_SECTION:", |
| 81 |
"STANDTIME_SECTION", |
| 82 |
"STANDTIME_SECTION:", |
| 83 |
"PICKUP_SECTION", |
| 84 |
"PICKUP_SECTION:", |
| 85 |
"EOF", |
| 86 |
"EOF.", |
| 87 |
"NUMBER_OF_TRUCKS", |
| 88 |
"NUMBER_OF_TRUCKS:", |
| 89 |
"", |
| 90 |
"", |
| 91 |
"NO_MORE_TYPE" |
| 92 |
}; |
| 93 |
|
| 94 |
#define NCTYPE_NUM 3 |
| 95 |
|
| 96 |
static char nctypes[NCTYPE_NUM][14] = { |
| 97 |
"TWOD_COORDS", |
| 98 |
"THREED_COORDS", /*This section lists the possible node*/ |
| 99 |
"NO_COORDS" /*coordinate data types */ |
| 100 |
}; |
| 101 |
|
| 102 |
#define WTYPE_NUM 10 |
| 103 |
|
| 104 |
static char wtypes[WTYPE_NUM][9] = { |
| 105 |
"EXPLICIT", |
| 106 |
"EUC_2D", /*This is a list of the possible data types for */ |
| 107 |
"EUC_3D", /*edge weights */ |
| 108 |
"MAX_2D", |
| 109 |
"MAX_3D", |
| 110 |
"MAN_2D", |
| 111 |
"MAN_3D", |
| 112 |
"CEIL_2D", |
| 113 |
"GEO", |
| 114 |
"ATT" |
| 115 |
}; |
| 116 |
|
| 117 |
#define WFORMAT_NUM 9 |
| 118 |
|
| 119 |
static char wformats[WFORMAT_NUM][20] = { |
| 120 |
"UPPER_ROW", |
| 121 |
"LOWER_ROW", /*This is a list of the possible formats that*/ |
| 122 |
"UPPER_DIAG_ROW", /*the edge weight matrix could be given in */ |
| 123 |
"LOWER_DIAG_ROW", /*if it is given explicitly */ |
| 124 |
"UPPER_COL", |
| 125 |
"LOWER_COL", |
| 126 |
"UPPER_DIAG_COL", |
| 127 |
"LOWER_DIAG_COL", |
| 128 |
"FULL_MATRIX" |
| 129 |
}; |
| 130 |
|
| 131 |
#define DTYPE_NUM 3 |
| 132 |
|
| 133 |
static char dtypes[DTYPE_NUM][14] = { |
| 134 |
"COORD_DISPLAY", |
| 135 |
"TWOD_DISPLAY", /*This is a list of the various display data*/ |
| 136 |
"NO_DISPLAY" /*types */ |
| 137 |
}; |
| 138 |
|
| 139 |
char line[LENGTH], line1[LENGTH], key[30], tmp[80]; |
| 140 |
int wformat=-1, dtype=-1, nctype=-1; |
| 141 |
double fdummy; |
| 142 |
int i, j = 0; |
| 143 |
int l, m, *coef2; |
| 144 |
FILE *f; |
| 145 |
int node; |
| 146 |
double deg, min, coord_x, coord_y, coord_z; |
| 147 |
double x, y; |
| 148 |
int capacity_vol = FALSE; |
| 149 |
int k; |
| 150 |
register int vertnum = 0; |
| 151 |
distances *dist = &vrp->dist; |
| 152 |
|
| 153 |
if (!strcmp(infile, "")){ |
| 154 |
printf("\nVrp I/O: No problem data file specified\n\n"); |
| 155 |
exit(1); |
| 156 |
} |
| 157 |
|
| 158 |
if ((f = fopen(infile, "r")) == NULL){ |
| 159 |
fprintf(stderr, "Vrp I/O: file '%s' can't be opened\n", infile); |
| 160 |
exit(1); |
| 161 |
} |
| 162 |
|
| 163 |
/*This loop reads in the next line of the data file and compares it |
| 164 |
to the list of possible keywords to determine what data will follow. |
| 165 |
It then reads the data into the appropriate field and iterates */ |
| 166 |
|
| 167 |
while(NULL != fgets( line1, LENGTH, f)){ |
| 168 |
strcpy(key,""); |
| 169 |
sscanf(line1,"%s",key); /*read in next keyword*/ |
| 170 |
|
| 171 |
for (k = 0; k < KEY_NUM; k++) /*which data field comes next?*/ |
| 172 |
if (strcmp(keywords[k], key) == 0) break; |
| 173 |
|
| 174 |
if (k == KEY_NUM){ |
| 175 |
continue; |
| 176 |
fprintf(stderr, "Unknown keyword! bye.\n"); |
| 177 |
exit(1); /*error check for acceptable data field*/ |
| 178 |
} |
| 179 |
|
| 180 |
k >>= 1; /* This is a bit shift operation that divides k by 2 */ |
| 181 |
/* since in the list of keywords, there are two possible*/ |
| 182 |
/* formats for the keyword */ |
| 183 |
|
| 184 |
if (strchr(line1,':')){ |
| 185 |
strcpy(line, strchr(line1, ':')+1); |
| 186 |
} |
| 187 |
|
| 188 |
switch (k){ |
| 189 |
|
| 190 |
case 0: /* NAME */ |
| 191 |
if (!sscanf(line, "%s", vrp->name)) |
| 192 |
fprintf(stderr, "\nVrp I/O: error reading NAME\n\n"); |
| 193 |
printf("PROBLEM NAME: \t\t%s\n", vrp->name); |
| 194 |
break; |
| 195 |
case 1 : /*TYPE*/ |
| 196 |
sscanf(line, "%s", tmp); |
| 197 |
if (strcmp("CVRP", tmp) != 0){ |
| 198 |
if (strcmp("TSP", tmp) == 0){ |
| 199 |
vrp->par.tsp_prob = TRUE; |
| 200 |
/*__BEGIN_EXPERIMENTAL_SECTION__*/ |
| 201 |
}else if (strcmp("BPP", tmp) == 0){ |
| 202 |
vrp->par.bpp_prob = TRUE; |
| 203 |
/*___END_EXPERIMENTAL_SECTION___*/ |
| 204 |
}else{ |
| 205 |
fprintf(stderr, "This is not a recognized file type!\n"); |
| 206 |
exit(1); |
| 207 |
} |
| 208 |
} |
| 209 |
printf("TYPE: \t\t\t%s\n", tmp); |
| 210 |
case 2 : /*COMMENT*/ |
| 211 |
#if 0 |
| 212 |
if (!strncpy(tmp, line, 80)) |
| 213 |
fprintf(stderr, "\nVrp I/O: error reading COMMENT\n\n"); |
| 214 |
printf("DESCRIPTION: \t\t%s\n", tmp); |
| 215 |
#endif |
| 216 |
break; |
| 217 |
case 3 : /* DIMENSION */ |
| 218 |
if (!sscanf(line, "%i", &k)){ |
| 219 |
fprintf(stderr, "Vrp I/O: error reading DIMENSION\n\n"); |
| 220 |
exit(1); |
| 221 |
} |
| 222 |
vertnum = vrp->vertnum = (int) k; |
| 223 |
vrp->edgenum = (int) vertnum * (vertnum - 1)/2; |
| 224 |
printf("DIMENSION: \t\t%i\n", k); |
| 225 |
break; |
| 226 |
case 4 : /*CAPACITY*/ |
| 227 |
if (!sscanf(line, "%i", &k)){ |
| 228 |
fprintf(stderr, "Vrp I/O: error reading CAPACITY\n\n"); |
| 229 |
exit(1); |
| 230 |
} |
| 231 |
vrp->capacity = (int) k; |
| 232 |
break; |
| 233 |
case 5 : /* EDGE_WEIGHT_TYPE */ |
| 234 |
sscanf(line, "%s", tmp); |
| 235 |
for (dist->wtype = 0; dist->wtype < WTYPE_NUM; (dist->wtype)++) |
| 236 |
if (strcmp(wtypes[dist->wtype], tmp) == 0) break; |
| 237 |
if (dist->wtype == WTYPE_NUM) { |
| 238 |
fprintf(stderr, "Unknown weight type : %s !!!\n", tmp); |
| 239 |
exit(1); |
| 240 |
} |
| 241 |
break; |
| 242 |
case 6 : /* EDGE_WEIGHT_FORMAT */ |
| 243 |
sscanf(line, "%s", tmp); |
| 244 |
for (wformat = 0; wformat < WFORMAT_NUM; wformat++) |
| 245 |
if (strcmp(wformats[wformat], tmp) == 0) break; |
| 246 |
if (wformat == WFORMAT_NUM) { |
| 247 |
fprintf(stderr, "Unknown weight type : %s !!!\n", tmp); |
| 248 |
exit(1); |
| 249 |
} |
| 250 |
break; |
| 251 |
case 7 : /* DISPLAY_DATA_TYPE */ |
| 252 |
sscanf(line, "%s", tmp); |
| 253 |
for (dtype = 0; dtype < DTYPE_NUM; dtype++) |
| 254 |
if (strcmp(dtypes[dtype], tmp) == 0) break; |
| 255 |
if (dtype == DTYPE_NUM) { |
| 256 |
fprintf(stderr, "Unknown display type : %s !!!\n", tmp); |
| 257 |
exit(1); |
| 258 |
} |
| 259 |
break; |
| 260 |
case 8: /* EDGE_WEIGHT_SECTION */ |
| 261 |
/*------------------------break if not EXPLICIT -*/ |
| 262 |
if (dist->wtype != _EXPLICIT) break; |
| 263 |
dist->cost = (int *) malloc (vrp->edgenum*sizeof(int)); |
| 264 |
switch (wformat){ |
| 265 |
case 1 : /* LOWER_ROW */ |
| 266 |
case 4 : /* UPPER_COL */ |
| 267 |
case 3 : /* LOWER_DIAG_ROW */ |
| 268 |
case 6 : /* UPPER_DIAG_COL */ |
| 269 |
for (i=0, coef2=dist->cost; i<vertnum; i++){ |
| 270 |
for (j=0; j<i; j++, coef2++){ |
| 271 |
if (!fscanf(f,"%lf", &fdummy)){ |
| 272 |
fprintf(stderr, "Not enough data -- DIMENSION or " |
| 273 |
"EDGE_WEIGHT_TYPE declared wrong\n"); |
| 274 |
exit(1); |
| 275 |
} |
| 276 |
else *coef2 = (int) fdummy; |
| 277 |
} |
| 278 |
if ((wformat==3 || wformat==6) && |
| 279 |
!fscanf(f,"%lf", &fdummy)){ |
| 280 |
fprintf(stderr, "Not enough data -- DIMENSION or " |
| 281 |
"EDGE_WEIGHT_TYPE declared wrong\n"); |
| 282 |
exit(1); |
| 283 |
} |
| 284 |
} |
| 285 |
if (fscanf(f,"%lf", &fdummy)){ |
| 286 |
fprintf(stderr, "Too much data -- DIMENSION or " |
| 287 |
"EDGE_WEIGHT_TYPE declared wrong\n"); |
| 288 |
exit(1); |
| 289 |
} |
| 290 |
break; |
| 291 |
case 0 : /* UPPER_ROW */ |
| 292 |
case 5 : /* LOWER_COL */ |
| 293 |
case 2 : /* UPPER_DIAG_ROW */ |
| 294 |
case 7 : /* LOWER_DIAG_COL */ |
| 295 |
for (i=0, coef2=dist->cost; i<vertnum; i++){ |
| 296 |
if (wformat==2 || wformat==7) |
| 297 |
if (!fscanf(f,"%lf", &fdummy)){ |
| 298 |
fprintf(stderr, "Not enough data -- DIMENSION or " |
| 299 |
"EDGE_WEIGHT_TYPE declared wrong"); |
| 300 |
exit(1); |
| 301 |
} |
| 302 |
for (j=i+1; j<vertnum; j++){ |
| 303 |
if (!fscanf(f,"%lf", &fdummy)){ |
| 304 |
fprintf(stderr, "Not enough data -- DIMENSION or " |
| 305 |
"EDGE_WEIGHT_TYPE declared wrong"); |
| 306 |
exit(1); |
| 307 |
} |
| 308 |
else coef2[j*(j-1)/2+i] = (int) fdummy; |
| 309 |
} |
| 310 |
} |
| 311 |
if (fscanf(f,"%lf", &fdummy)){ |
| 312 |
fprintf(stderr, "Too much data -- DIMENSION or " |
| 313 |
"EDGE_WEIGHT_TYPE declared wrong\n"); |
| 314 |
exit(1); |
| 315 |
} |
| 316 |
break; |
| 317 |
case 8 : /* FULL_MATRIX */ |
| 318 |
for (i=0, coef2=dist->cost; i<vertnum; i++){ |
| 319 |
for (j=0; j<=i; j++) |
| 320 |
if(!fscanf(f,"%lf", &fdummy)){ |
| 321 |
fprintf(stderr, "Not enough data -- DIMENSION or " |
| 322 |
"EDGE_WEIGHT_TYPE declared wrong"); |
| 323 |
exit(1); |
| 324 |
} |
| 325 |
for (j=i+1; j<vertnum; j++){ |
| 326 |
if(!fscanf(f,"%lf", &fdummy)){ |
| 327 |
fprintf(stderr, "Not enough data -- DIMENSION or " |
| 328 |
"EDGE_WEIGHT_TYPE declared wrong"); |
| 329 |
exit(1); |
| 330 |
} |
| 331 |
coef2[j*(j-1)/2+i] = (int) fdummy; |
| 332 |
} |
| 333 |
} |
| 334 |
if (fscanf(f,"%lf", &fdummy)){ |
| 335 |
fprintf(stderr, "Too much data -- DIMENSION or " |
| 336 |
"EDGE_WEIGHT_TYPE declared wrong\n"); |
| 337 |
exit(1); |
| 338 |
} |
| 339 |
break; |
| 340 |
} |
| 341 |
break; |
| 342 |
case 9 : /* DISPLAY_DATA_SECTION */ |
| 343 |
/*--------------------- break if NO_DISPLAY -*/ |
| 344 |
if (dtype != 1){ |
| 345 |
fprintf(stderr, "DISPLAY_DATA_SECTION exists" |
| 346 |
"but not TWOD_DISPLAY!\n"); |
| 347 |
exit(1); |
| 348 |
} |
| 349 |
/* posx, posy -*/ |
| 350 |
vrp->posx = (int *) malloc (vertnum*sizeof(int)); |
| 351 |
vrp->posy = (int *) malloc (vertnum*sizeof(int)); |
| 352 |
for (i=0; i<vertnum; i++){ |
| 353 |
if ((k = fscanf(f,"%i%lf%lf", &node, &x, &y)) != 3){ |
| 354 |
fprintf(stderr, "\nVrp I/O: error reading DISPLAY_DATA\n"); |
| 355 |
break; |
| 356 |
} |
| 357 |
vrp->posx[node-1] = (int)(x + 0.5); |
| 358 |
vrp->posy[node-1] = (int)(y + 0.5); |
| 359 |
} |
| 360 |
if (fscanf(f,"%lf", &fdummy)){ |
| 361 |
fprintf(stderr, "\nVrp I/O: too much display data\n"); |
| 362 |
break; |
| 363 |
} |
| 364 |
break; |
| 365 |
case 10 : /* NODE_COORD_SECTION */ |
| 366 |
if (nctype == -1) nctype = 0; /*if not given: TWOD_COORDS*/ |
| 367 |
if (dtype == -1 && ((dist->wtype == _EUC_2D) || /*display type*/ |
| 368 |
(dist->wtype == _MAX_2D) || /*not defd yet*/ |
| 369 |
(dist->wtype == _MAN_2D) ))/*&& can disp.*/ |
| 370 |
dtype = 0; /* COORD_DISPLAY */ |
| 371 |
if (dtype == 0){ |
| 372 |
vrp->posx = (int *) malloc (vertnum*sizeof(int)); |
| 373 |
vrp->posy = (int *) malloc (vertnum*sizeof(int)); |
| 374 |
} |
| 375 |
dist->coordx = (double *) malloc (vertnum*sizeof(double)); |
| 376 |
dist->coordy = (double *) malloc (vertnum*sizeof(double)); |
| 377 |
if (nctype == 1) |
| 378 |
dist->coordz = (double *) malloc (vertnum*sizeof(double)); |
| 379 |
for (i=0; i<vertnum; i++){ |
| 380 |
if (nctype == 0) /* TWOD_COORDS */ |
| 381 |
if (fscanf(f,"%i%lf%lf", &node, &coord_x, &coord_y) != 3){ |
| 382 |
fprintf(stderr, "\nVrp I/O: error reading NODE_COORD\n\n"); |
| 383 |
exit(1); |
| 384 |
} |
| 385 |
if (nctype == 1) /* THREED_COORDS */ |
| 386 |
if (fscanf(f,"%i%lf%lf%lf", &node, &coord_x, &coord_y, |
| 387 |
&coord_z) != 4){ |
| 388 |
fprintf(stderr, "\nVrp I/O: error reading NODE_COORD\n\n"); |
| 389 |
exit(1); |
| 390 |
} |
| 391 |
dist->coordx[node-1] = coord_x; |
| 392 |
dist->coordy[node-1] = coord_y; |
| 393 |
/*since position is an integer and coord is a double, I must |
| 394 |
round off here if dtype is EXPLICIT*/ |
| 395 |
if (dtype == 0){ |
| 396 |
vrp->posx[node-1] = (int)coord_x; |
| 397 |
vrp->posy[node-1] = (int)coord_y; |
| 398 |
} |
| 399 |
if (nctype == 1) dist->coordz[node-1] = coord_z; |
| 400 |
if (dist->wtype == _GEO){ /* GEO */ |
| 401 |
/*--- latitude & longitude for node ------------*/ |
| 402 |
deg = (int)(dist->coordx[node-1]); |
| 403 |
min = dist->coordx[node-1] - deg; |
| 404 |
dist->coordx[node-1] = MY_PI * (deg + 5.0*min/3.0 ) / 180.0; |
| 405 |
deg = (int)(dist->coordy[node-1]); |
| 406 |
min = dist->coordy[node-1] - deg; |
| 407 |
dist->coordy[node-1] = MY_PI * (deg + 5.0*min/3.0 ) / 180.0; |
| 408 |
} |
| 409 |
} |
| 410 |
if (fscanf(f,"%i%lf%lf%lf", &node, &coord_x, &coord_y, &coord_z)){ |
| 411 |
fprintf(stderr, "\nVrp I/O: too much data in NODE_COORD\n\n"); |
| 412 |
exit(1); |
| 413 |
} |
| 414 |
break; |
| 415 |
case 11: /* NODE_COORD_TYPE */ |
| 416 |
sscanf(line, "%s", tmp); |
| 417 |
for (nctype = 0; nctype < NCTYPE_NUM; nctype++) |
| 418 |
if (strcmp(nctypes[nctype], tmp) == 0) break; |
| 419 |
if (nctype == NCTYPE_NUM) { |
| 420 |
fprintf(stderr, "Unknown node_coord_type : %s !!!\n", tmp); |
| 421 |
exit(1); |
| 422 |
} |
| 423 |
break; |
| 424 |
case 12: /*DEPOT_SECTION*/ |
| 425 |
fscanf(f, "%i", &k); |
| 426 |
if (k != 1){ |
| 427 |
fprintf(stderr, "Error in data: depot must be node 1"); |
| 428 |
exit(1); |
| 429 |
} |
| 430 |
vrp->depot = k - 1; |
| 431 |
while (-1 != k) fscanf(f, "%i", &k); |
| 432 |
break; |
| 433 |
case 13: /*CAPACITY_VOL*/ |
| 434 |
sscanf(line, "%i", &k); |
| 435 |
capacity_vol = TRUE; |
| 436 |
break; |
| 437 |
case 14: /*DEMAND_SECTION*/ |
| 438 |
vrp->demand = (int *) malloc(vertnum*sizeof(int)); |
| 439 |
for (i = 0; i < vertnum; i++){ |
| 440 |
if (capacity_vol){ |
| 441 |
if (fscanf(f, "%i%i%i", &k, &l, &m) != 3){ |
| 442 |
fprintf(stderr,"\nVrp I/O: error reading DEMAND_SECTION\n\n"); |
| 443 |
exit(1); |
| 444 |
} |
| 445 |
} |
| 446 |
else if (fscanf(f, "%i%i", &k, &l) != 2){ |
| 447 |
fprintf(stderr, "\nVrp I/O: error reading DEMAND_SECTION\n\n"); |
| 448 |
exit(1); |
| 449 |
} |
| 450 |
vrp->demand[k-1] = l; |
| 451 |
vrp->demand[0] += l; |
| 452 |
} |
| 453 |
if (fscanf(f, "%i%i", &k, &l)){ |
| 454 |
fprintf(stderr, "\nVrp I/O: too much data in DEMAND_SECTION\n\n"); |
| 455 |
exit(1); |
| 456 |
} |
| 457 |
break; |
| 458 |
case 15: /*TIME_WINDOW_SECTION*/ /*These sections are not used*/ |
| 459 |
while (fscanf(f, "%d %*d:%*d %*d:%*d", &k)); |
| 460 |
break; |
| 461 |
case 16: /*STANDTIME_SECTION*/ |
| 462 |
while (fscanf(f, "%d%*d", &k)); |
| 463 |
break; |
| 464 |
case 17: /*PICKUP_SECTION*/ |
| 465 |
while (fscanf(f, "%d%*d%*d", &k)); |
| 466 |
break; |
| 467 |
case 18: /* EOF */ |
| 468 |
break; |
| 469 |
case 19: /* NUMBER_OF_TRUCKS */ |
| 470 |
if (!sscanf(line, "%i", &k)){ |
| 471 |
fprintf(stderr, "Vrp I/O: error reading NO_OF_TRUCKS\n\n"); |
| 472 |
exit(1); |
| 473 |
} |
| 474 |
vrp->numroutes = (int) k; |
| 475 |
default: |
| 476 |
break; |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
if (f != stdin) |
| 481 |
fclose(f); |
| 482 |
|
| 483 |
/*calculate all the distances explcitly and then use distance type EXPLICIT*/ |
| 484 |
|
| 485 |
/*__BEGIN_EXPERIMENTAL_SECTION__*/ |
| 486 |
if (vrp->par.bpp_prob){ |
| 487 |
dist->cost = (int *) calloc (vrp->edgenum, sizeof(int)); |
| 488 |
for (i = 1, k = 0; i < vertnum; i++){ |
| 489 |
for (j = 0; j < i; j++){ |
| 490 |
dist->cost[k++] = vrp->demand[i]+vrp->demand[j]; |
| 491 |
} |
| 492 |
} |
| 493 |
dist->wtype = _EXPLICIT; |
| 494 |
} |
| 495 |
/*___END_EXPERIMENTAL_SECTION___*/ |
| 496 |
if (dist->wtype != _EXPLICIT){ |
| 497 |
dist->cost = (int *) calloc (vrp->edgenum, sizeof(int)); |
| 498 |
for (i = 1, k = 0; i < vertnum; i++){ |
| 499 |
for (j = 0; j < i; j++){ |
| 500 |
dist->cost[k++] = ICOST(dist, i, j); |
| 501 |
} |
| 502 |
} |
| 503 |
dist->wtype = _EXPLICIT; |
| 504 |
} |
| 505 |
|
| 506 |
if (vrp->par.tsp_prob){ |
| 507 |
vrp->capacity = vertnum; |
| 508 |
vrp->numroutes = 1; |
| 509 |
vrp->demand = (int *) malloc (vertnum * ISIZE); |
| 510 |
vrp->demand[0] = vertnum; |
| 511 |
for (i = vertnum - 1; i > 0; i--) |
| 512 |
vrp->demand[i] = 1; |
| 513 |
vrp->cg_par.tsp_prob = TRUE; |
| 514 |
if (!vrp->cg_par.which_tsp_cuts) |
| 515 |
vrp->cg_par.which_tsp_cuts = ALL_TSP_CUTS; |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
/*===========================================================================*/ |
| 520 |
|
| 521 |
/*===========================================================================*\ |
| 522 |
* This second function reads in the parameters from the parameter file. |
| 523 |
\*===========================================================================*/ |
| 524 |
|
| 525 |
void vrp_readparams(vrp_problem *vrp, char *filename, int argc, char **argv) |
| 526 |
{ |
| 527 |
int i, j, k; |
| 528 |
char line[LENGTH], key[50], value[50], c, tmp; |
| 529 |
/*__BEGIN_EXPERIMENTAL_SECTION__*/ |
| 530 |
int col_size = 0; |
| 531 |
char v0[10], v1[10]; |
| 532 |
/*___END_EXPERIMENTAL_SECTION___*/ |
| 533 |
FILE *f = NULL; |
| 534 |
str_int colgen_str[COLGEN_STR_SIZE] = COLGEN_STR_ARRAY; |
| 535 |
|
| 536 |
vrp_params *par = &vrp->par; |
| 537 |
#ifdef COMPILE_HEURS |
| 538 |
heur_params *heur_par = &vrp->heur_par; |
| 539 |
lb_params *lb_par = &vrp->lb_par; |
| 540 |
#endif |
| 541 |
vrp_lp_params *lp_par = &vrp->lp_par; |
| 542 |
vrp_cg_params *cg_par = &vrp->cg_par; |
| 543 |
|
| 544 |
if (!strcmp(filename, "")) |
| 545 |
goto EXIT; |
| 546 |
|
| 547 |
if ((f = fopen(filename, "r")) == NULL){ |
| 548 |
printf("VRP Readparams: file %s can't be opened\n", filename); |
| 549 |
exit(1); /*error check for existence of parameter file*/ |
| 550 |
} |
| 551 |
|
| 552 |
while(NULL != fgets( line, LENGTH, f)){ /*read in parameter settings*/ |
| 553 |
strcpy(key, ""); |
| 554 |
sscanf(line, "%s%s", key, value); |
| 555 |
|
| 556 |
if (strcmp(key, "input_file") == 0){ |
| 557 |
par->infile[MAX_FILE_NAME_LENGTH] = 0; |
| 558 |
strncpy(par->infile, value, MAX_FILE_NAME_LENGTH); |
| 559 |
} |
| 560 |
#ifdef COMPILE_HEURS |
| 561 |
else if (strcmp(key, "rand_seed") == 0){ |
| 562 |
par->rand_seed = (int *) calloc (NUM_RANDS, sizeof(int)); |
| 563 |
if (sscanf(line, "%*s%i%i%i%i%i%i", &par->rand_seed[0], |
| 564 |
&par->rand_seed[1], &par->rand_seed[2], |
| 565 |
&par->rand_seed[3], &par->rand_seed[4], |
| 566 |
&par->rand_seed[5]) != 6) |
| 567 |
READPAR_ERROR(key); |
| 568 |
} |
| 569 |
else if (strcmp(key, "tours_to_keep") == 0){ |
| 570 |
READ_INT_PAR(par->tours_to_keep); |
| 571 |
} |
| 572 |
else if (strcmp(key, "do_heuristics") == 0){ |
| 573 |
READ_INT_PAR(par->do_heuristics); |
| 574 |
} |
| 575 |
else if (strcmp(key, "ub_time_out") == 0){ |
| 576 |
READ_INT_PAR(par->time_out.ub); |
| 577 |
} |
| 578 |
else if (strcmp(key, "lb_time_out") == 0){ |
| 579 |
READ_INT_PAR(par->time_out.lb); |
| 580 |
} |
| 581 |
#endif |
| 582 |
else if (strcmp(key, "k_closest") == 0){ |
| 583 |
READ_INT_PAR(par->k_closest); |
| 584 |
} |
| 585 |
else if (strcmp(key, "k_closest_minimum") == 0){ |
| 586 |
READ_INT_PAR(par->min_closest); |
| 587 |
} |
| 588 |
else if (strcmp(key, "k_closest_maximum") == 0){ |
| 589 |
READ_INT_PAR(par->max_closest); |
| 590 |
} |
| 591 |
else if (strcmp(key, "add_all_edges") == 0){ |
| 592 |
READ_INT_PAR(par->add_all_edges); |
| 593 |
} |
| 594 |
else if (strcmp(key, "base_variable_selection") == 0){ |
| 595 |
READ_INT_PAR(par->base_variable_selection); |
| 596 |
} |
| 597 |
else if (strcmp(key, "use_small_graph") == 0){ |
| 598 |
READ_INT_PAR(par->use_small_graph); |
| 599 |
if (par->use_small_graph){ |
| 600 |
if (fgets( line, LENGTH, f) == NULL){ |
| 601 |
printf("No small graph file!/n/n"); |
| 602 |
exit(1); |
| 603 |
} |
| 604 |
strcpy(key, ""); |
| 605 |
sscanf(line, "%s%s", key, value); |
| 606 |
if (strcmp(key, "small_graph_file_name") != 0){ |
| 607 |
printf("Need small_graph_file_name next!!!/n/n"); |
| 608 |
exit(1); |
| 609 |
} |
| 610 |
strcpy(par->small_graph_file, value); |
| 611 |
#ifdef COMPILE_HEURS |
| 612 |
if (par->use_small_graph == LOAD_SMALL_GRAPH) |
| 613 |
par->do_heuristics = FALSE; |
| 614 |
#endif |
| 615 |
} |
| 616 |
} |
| 617 |
else if (strcmp(key, "colgen_in_first_phase") == 0 || |
| 618 |
strcmp(key, "TM_colgen_in_first_phase") == 0){ |
| 619 |
READ_INT_PAR(par->colgen_strat[0]); |
| 620 |
} |
| 621 |
else if (strcmp(key, "colgen_in_second_phase") == 0 || |
| 622 |
strcmp(key, "TM_colgen_in_second_phase") == 0){ |
| 623 |
READ_INT_PAR(par->colgen_strat[1]); |
| 624 |
} |
| 625 |
else if (strcmp(key, "colgen_in_first_phase_str") == 0 || |
| 626 |
strcmp(key, "TM_colgen_in_first_phase_str") == 0){ |
| 627 |
READ_STRINT_PAR(par->colgen_strat[0], |
| 628 |
colgen_str, COLGEN_STR_SIZE, value); |
| 629 |
} |
| 630 |
else if (strcmp(key, "colgen_in_second_phase_str") == 0 || |
| 631 |
strcmp(key, "TM_colgen_in_second_phase_str") == 0){ |
| 632 |
READ_STRINT_PAR(par->colgen_strat[1], |
| 633 |
colgen_str, COLGEN_STR_SIZE, value); |
| 634 |
} |
| 635 |
else if (strcmp(key, "numroutes") == 0){ |
| 636 |
READ_INT_PAR(j); |
| 637 |
vrp->numroutes = j; |
| 638 |
} |
| 639 |
|
| 640 |
#ifdef COMPILE_HEURS |
| 641 |
/******************** heuristics parameters ****************************/ |
| 642 |
|
| 643 |
else if (strcmp(key, "sweep_trials") == 0){ |
| 644 |
READ_INT_PAR(heur_par->sweep_trials); |
| 645 |
} |
| 646 |
else if (strcmp(key, "savings_grid_size") == 0){ |
| 647 |
READ_INT_PAR(heur_par->savings_par.grid_size); |
| 648 |
} |
| 649 |
else if (strcmp(key, "savings_lamda") == 0){ |
| 650 |
READ_FLOAT_PAR(heur_par->savings_par.lamda); |
| 651 |
} |
| 652 |
else if (strcmp(key, "savings_mu") == 0){ |
| 653 |
READ_FLOAT_PAR(heur_par->savings_par.mu); |
| 654 |
} |
| 655 |
else if (strcmp(key, "savings3_grid_size") == 0){ |
| 656 |
READ_INT_PAR(heur_par->savings3_par.grid_size); |
| 657 |
} |
| 658 |
else if (strcmp(key, "savings3_lamda") == 0){ |
| 659 |
READ_FLOAT_PAR(heur_par->savings3_par.lamda); |
| 660 |
} |
| 661 |
else if (strcmp(key, "savings3_mu") == 0){ |
| 662 |
READ_FLOAT_PAR(heur_par->savings3_par.mu); |
| 663 |
} |
| 664 |
else if (strcmp(key, "route_opt1") == 0){ |
| 665 |
READ_INT_PAR(heur_par->route_opt1); |
| 666 |
} |
| 667 |
else if (strcmp(key, "fini_ratio") == 0){ |
| 668 |
READ_FLOAT_PAR(heur_par->fini_ratio); |
| 669 |
} |
| 670 |
else if (strcmp(key, "ni_trials") == 0){ |
| 671 |
READ_INT_PAR(heur_par->ni_trials); |
| 672 |
} |
| 673 |
else if (strcmp(key, "fi_trials") == 0){ |
| 674 |
READ_INT_PAR(heur_par->fi_trials); |
| 675 |
} |
| 676 |
else if (strcmp(key, "fini_trials") == 0){ |
| 677 |
READ_INT_PAR(heur_par->fini_trials); |
| 678 |
} |
| 679 |
else if (strcmp(key, "savings_trials") == 0){ |
| 680 |
READ_INT_PAR(heur_par->savings_par.savings_trials); |
| 681 |
} |
| 682 |
else if (strcmp(key, "savings2_trials") == 0){ |
| 683 |
READ_INT_PAR(heur_par->savings_par.savings2_trials); |
| 684 |
} |
| 685 |
else if (strcmp(key, "savings3_trials") == 0){ |
| 686 |
READ_INT_PAR(heur_par->savings3_par.savings_trials); |
| 687 |
} |
| 688 |
else if (strcmp(key, "near_cluster_trials") == 0){ |
| 689 |
READ_INT_PAR(heur_par->near_cluster_trials); |
| 690 |
} |
| 691 |
else if (strcmp(key, "tsp_fi_trials") == 0){ |
| 692 |
READ_INT_PAR(heur_par->tsp.fi_trials); |
| 693 |
} |
| 694 |
else if (strcmp(key, "tsp_ni_trials") == 0){ |
| 695 |
READ_INT_PAR(heur_par->tsp.ni_trials); |
| 696 |
} |
| 697 |
else if (strcmp(key, "tsp_fini_trials") == 0){ |
| 698 |
READ_INT_PAR(heur_par->tsp.fini_trials); |
| 699 |
} |
| 700 |
else if (strcmp(key, "tsp_num_starts") == 0){ |
| 701 |
READ_INT_PAR(heur_par->tsp.num_starts); |
| 702 |
} |
| 703 |
else if (strcmp(key, "exchange") == 0){ |
| 704 |
READ_INT_PAR(heur_par->exchange); |
| 705 |
} |
| 706 |
else if (strcmp(key, "exchange2") == 0){ |
| 707 |
READ_INT_PAR(heur_par->exchange2); |
| 708 |
} |
| 709 |
else if (strcmp(key, "route_opt2") == 0){ |
| 710 |
READ_INT_PAR(heur_par->route_opt2); |
| 711 |
} |
| 712 |
else if (strcmp(key, "route_opt3") == 0){ |
| 713 |
READ_INT_PAR(heur_par->route_opt3); |
| 714 |
} |
| 715 |
else if (strcmp(key, "lower_bound") == 0){ |
| 716 |
READ_INT_PAR(lb_par->lower_bound); |
| 717 |
} |
| 718 |
else if (strcmp(key, "lb_max_iter") == 0){ |
| 719 |
READ_INT_PAR(lb_par->lb_max_iter); |
| 720 |
} |
| 721 |
else if (strcmp(key, "lb_penalty_mult") == 0){ |
| 722 |
READ_INT_PAR(lb_par->lb_penalty_mult); |
| 723 |
} |
| 724 |
#endif |
| 725 |
|
| 726 |
/********************** executable names *******************************/ |
| 727 |
|
| 728 |
/*__BEGIN_EXPERIMENTAL_SECTION__*/ |
| 729 |
else if (strcmp(key, "winprog_executable_name") == 0){ |
| 730 |
strcpy(par->executables.winprog, value); |
| 731 |
} |
| 732 |
/*___END_EXPERIMENTAL_SECTION___*/ |
| 733 |
#ifdef COMPILE_HEURS |
| 734 |
else if (strcmp(key, "heuristics_executable_name") == 0){ |
| 735 |
strcpy(par->executables.heuristics, value); |
| 736 |
} |
| 737 |
#endif |
| 738 |
|
| 739 |
/******************** debugging parameters *****************************/ |
| 740 |
|
| 741 |
/*__BEGIN_EXPERIMENTAL_SECTION__*/ |
| 742 |
else if (strcmp(key, "winprog_debug") == 0){ |
| 743 |
READ_INT_PAR(par->debug.winprog); |
| 744 |
CHECK_DEBUG_PAR(par->debug.winprog, key); |
| 745 |
} |
| 746 |
/*___END_EXPERIMENTAL_SECTION___*/ |
| 747 |
#ifdef COMPILE_HEURS |
| 748 |
else if (strcmp(key, "heuristics_debug") == 0){ |
| 749 |
READ_INT_PAR(par->debug.heuristics); |
| 750 |
CHECK_DEBUG_PAR(par->debug.heuristics, key); |
| 751 |
} |
| 752 |
#endif |
| 753 |
|
| 754 |
/************************ lp parameters *******************************/ |
| 755 |
else if (strcmp(key, "branching_rule") == 0){ |
| 756 |
READ_INT_PAR(lp_par->branching_rule); |
| 757 |
} |
| 758 |
else if (strcmp(key, "branch_on_cuts") == 0){ |
| 759 |
READ_INT_PAR(lp_par->branch_on_cuts); |
| 760 |
} |
| 761 |
else if (strcmp(key, "strong_branching_cand_num") == 0){ |
| 762 |
READ_INT_PAR(lp_par->strong_branching_cand_num_max); |
| 763 |
lp_par->strong_branching_cand_num_min = |
| 764 |
lp_par->strong_branching_cand_num_max; |
| 765 |
lp_par->strong_branching_red_ratio = 0; |
| 766 |
} |
| 767 |
else if (strcmp(key, "strong_branching_cand_num_min") == 0){ |
| 768 |
READ_INT_PAR(lp_par->strong_branching_cand_num_min); |
| 769 |
} |
| 770 |
else if (strcmp(key, "strong_branching_cand_num_max") == 0){ |
| 771 |
READ_INT_PAR(lp_par->strong_branching_cand_num_max); |
| 772 |
} |
| 773 |
else if (strcmp(key, "strong_branching_red_ratio") == 0){ |
| 774 |
READ_INT_PAR(lp_par->strong_branching_red_ratio); |
| 775 |
} |
| 776 |
else if (strcmp(key, "child_compar_obj_tol") == 0){ |
| 777 |
READ_FLOAT_PAR(lp_par->child_compar_obj_tol); |
| 778 |
} |
| 779 |
else if (strcmp(key, "detect_tailoff") == 0){ |
| 780 |
READ_INT_PAR(lp_par->detect_tailoff); |
| 781 |
} |
| 782 |
|
| 783 |
/************************* cutgen parameters ***************************/ |
| 784 |
|
| 785 |
else if (strcmp(key, "verbosity") == 0){ |
| 786 |
READ_INT_PAR(par->verbosity); |
| 787 |
lp_par->verbosity = cg_par->verbosity = par->verbosity; |
| 788 |
} |
| 789 |
else if (strcmp(key, "do_greedy") == 0){ |
| 790 |
READ_INT_PAR(cg_par->do_greedy); |
| 791 |
} |
| 792 |
else if (strcmp(key, "greedy_num_trials") == 0){ |
| 793 |
READ_INT_PAR(cg_par->greedy_num_trials); |
| 794 |
} |
| 795 |
else if (strcmp(key, "do_extra_in_root") == 0){ |
| 796 |
READ_INT_PAR(cg_par->do_extra_in_root); |
| 797 |
} |
| 798 |
else if (strcmp(key, "which_tsp_cuts") == 0){ |
| 799 |
READ_INT_PAR(cg_par->which_tsp_cuts); |
| 800 |
} |
| 801 |
/*__BEGIN_EXPERIMENTAL_SECTION__*/ |
| 802 |
else if (strcmp(key, "do_mincut") == 0){ |
| 803 |
READ_INT_PAR(cg_par->do_mincut); |
| 804 |
} |
| 805 |
else if (strcmp(key, "always_do_mincut") == 0){ |
| 806 |
READ_INT_PAR(cg_par->always_do_mincut); |
| 807 |
} |
| 808 |
else if (strcmp(key, "update_contr_above") == 0){ |
| 809 |
READ_INT_PAR(cg_par->update_contr_above); |
| 810 |
} |
| 811 |
else if (strcmp(key, "shrink_one_edges") == 0){ |
| 812 |
READ_INT_PAR(cg_par->shrink_one_edges); |
| 813 |
} |
| 814 |
else if (strcmp(key, "do_extra_checking") == 0){ |
| 815 |
READ_INT_PAR(cg_par->do_extra_checking); |
| 816 |
} |
| 817 |
/*___END_EXPERIMENTAL_SECTION___*/ |
| 818 |
#if defined(CHECK_CUT_VALIDITY) || defined(TRACE_PATH) |
| 819 |
else if (strcmp(key, "feasible_solution_edges") == 0){ |
| 820 |
READ_INT_PAR(vrp->feas_sol_size); |
| 821 |
if (vrp->feas_sol_size){ |
| 822 |
vrp->feas_sol = (int *)calloc(vrp->feas_sol_size, sizeof(int)); |
| 823 |
for (i=0; i<vrp->feas_sol_size; i++){ |
| 824 |
if (!fgets( line, LENGTH, f)){ |
| 825 |
fprintf(stderr, |
| 826 |
"\nVrp I/O: error reading in feasible solution\n\n"); |
| 827 |
exit(1); |
| 828 |
} |
| 829 |
strcpy(key, ""); |
| 830 |
sscanf(line, "%s%s", key, value); |
| 831 |
if (strcmp(key, "edge")){ |
| 832 |
fprintf(stderr, |
| 833 |
"\nVrp I/O: error reading in feasible solution\n\n"); |
| 834 |
exit(1); |
| 835 |
} |
| 836 |
if (sscanf(value, "%i", vrp->feas_sol+i) != 1){ |
| 837 |
fprintf(stderr, |
| 838 |
"\nVrp I/O: error reading in feasible solution %s\n\n", |
| 839 |
key); |
| 840 |
exit(1); |
| 841 |
} |
| 842 |
} |
| 843 |
} |
| 844 |
} |
| 845 |
else if (strcmp(key, "feasible_solution_nodes") == 0){ |
| 846 |
READ_INT_PAR(vrp->feas_sol_size); |
| 847 |
if (vrp->feas_sol_size){ |
| 848 |
int cur_node, prev_node = 0; |
| 849 |
|
| 850 |
vrp->feas_sol = (int *)calloc(vrp->feas_sol_size, sizeof(int)); |
| 851 |
for (i=0; i<vrp->feas_sol_size; i++){ |
| 852 |
if (!fgets( line, LENGTH, f)){ |
| 853 |
fprintf(stderr, |
| 854 |
"\nVrp I/O: error reading in feasible solution\n\n"); |
| 855 |
exit(1); |
| 856 |
} |
| 857 |
sscanf(line, "%s", value); |
| 858 |
if (sscanf(value, "%i", &cur_node) != 1){ |
| 859 |
fprintf(stderr, |
| 860 |
"\nVrp I/O: error reading in feasible solution %s\n\n", |
| 861 |
key); |
| 862 |
exit(1); |
| 863 |
}else{ |
| 864 |
vrp->feas_sol[i] = INDEX(prev_node, cur_node); |
| 865 |
prev_node = cur_node; |
| 866 |
} |
| 867 |
} |
| 868 |
} |
| 869 |
} |
| 870 |
#endif |
| 871 |
else if (strcmp(key, "which_connected_routine") == 0){ |
| 872 |
READ_INT_PAR(cg_par->which_connected_routine); |
| 873 |
} |
| 874 |
else if (strcmp(key, "max_num_cuts_in_shrink") == 0){ |
| 875 |
READ_INT_PAR(cg_par->max_num_cuts_in_shrink); |
| 876 |
} |
| 877 |
/*__BEGIN_EXPERIMENTAL_SECTION__*/ |
| 878 |
#ifdef COMPILE_DECOMP |
| 879 |
else if (strcmp(key, "allow_one_routes_in_bfm") == 0){ |
| 880 |
READ_INT_PAR(cg_par->allow_one_routes_in_bfm); |
| 881 |
} |
| 882 |
else if (strcmp(key, "follow_one_edges") == 0){ |
| 883 |
READ_INT_PAR(cg_par->follow_one_edges); |
| 884 |
} |
| 885 |
else if (strcmp(key, "col_gen_grid_size") == 0){ |
| 886 |
READ_INT_PAR(cg_par->col_gen_par.grid_size); |
| 887 |
} |
| 888 |
else if (strcmp(key, "col_gen_lamda") == 0){ |
| 889 |
READ_FLOAT_PAR(cg_par->col_gen_par.lambda); |
| 890 |
} |
| 891 |
else if (strcmp(key, "col_gen_mu") == 0){ |
| 892 |
READ_FLOAT_PAR(cg_par->col_gen_par.mu); |
| 893 |
} |
| 894 |
else if (strcmp(key, "max_num_columns") == 0){ |
| 895 |
READ_INT_PAR(cg_par->max_num_columns); |
| 896 |
} |
| 897 |
#endif |
| 898 |
#ifdef COMPILE_OUR_DECOMP |
| 899 |
else if (strcmp(key, "generate_farkas_cuts") == 0){ |
| 900 |
READ_INT_PAR(cg_par->generate_farkas_cuts); |
| 901 |
} |
| 902 |
else if (strcmp(key, "generate_capacity_cuts") == 0){ |
| 903 |
READ_INT_PAR(cg_par->generate_capacity_cuts); |
| 904 |
} |
| 905 |
else if (strcmp(key, "generate_no_cols_cuts") == 0){ |
| 906 |
READ_INT_PAR(cg_par->generate_no_cols_cuts); |
| 907 |
} |
| 908 |
else if (strcmp(key, "decomp_decompose") == 0){ |
| 909 |
READ_INT_PAR(cg_par->decomp_decompose); |
| 910 |
} |
| 911 |
else if (strcmp(key, "feasible_tours_only") == 0){ |
| 912 |
READ_INT_PAR(cg_par->feasible_tours_only); |
| 913 |
} |
| 914 |
else if (strcmp(key, "graph_density_threshold") == 0){ |
| 915 |
READ_FLOAT_PAR(cg_par->graph_density_threshold); |
| 916 |
} |
| 917 |
else if (strcmp(key, "gap_threshold") == 0){ |
| 918 |
READ_FLOAT_PAR(cg_par->gap_threshold); |
| 919 |
} |
| 920 |
else if (strcmp(key, "do_our_decomp") == 0){ |
| 921 |
READ_INT_PAR(cg_par->do_our_decomp); |
| 922 |
} |
| 923 |
else if (strcmp(key, "do_decomp_once") == 0){ |
| 924 |
READ_INT_PAR(cg_par->do_decomp_once); |
| 925 |
} |
| 926 |
#endif |
| 927 |
/******************** sol pool **************************/ |
| 928 |
else if (strcmp(key, "sol_pool_col_size") == 0){ |
| 929 |
READ_INT_PAR(col_size); |
| 930 |
} |
| 931 |
else if (strcmp(key, "sol_pool_col_num") == 0){ |
| 932 |
if (col_size == 0){ |
| 933 |
fprintf(stderr, "Column size is 0 -- exiting\n\n"); |
| 934 |
exit(1); |
| 935 |
} |
| 936 |
READ_INT_PAR(vrp->sol_pool_col_num); |
| 937 |
vrp->sol_pool_cols = (int *) calloc (2*vrp->sol_pool_col_num*col_size, |
| 938 |
sizeof(int)); |
| 939 |
vrp->sol_pool_col_num = 0; |
| 940 |
} |
| 941 |
else if (strcmp(key, "sol_pool_col") == 0){ |
| 942 |
if (col_size == 0){ |
| 943 |
fprintf(stderr, "Column size is 0 -- exiting\n\n"); |
| 944 |
exit(1); |
| 945 |
} |
| 946 |
for(i = vrp->sol_pool_col_num*2*col_size; |
| 947 |
i < (vrp->sol_pool_col_num+1)*2*col_size; |
| 948 |
i+=2){ |
| 949 |
if (!fgets( line, LENGTH, f)){ |
| 950 |
fprintf(stderr, |
| 951 |
"\nVrp I/O: error reading in feasible solution\n\n"); |
| 952 |
exit(1); |
| 953 |
} |
| 954 |
strcpy(key,""); |
| 955 |
sscanf(line,"%s%s%s", key, v0, v1); |
| 956 |
if (strcmp(key,"edge")){ |
| 957 |
fprintf(stderr, |
| 958 |
"\nVrp I/O: error reading in feasible solution\n\n"); |
| 959 |
exit(1); |
| 960 |
} |
| 961 |
if (sscanf(v0, "%i", vrp->sol_pool_cols+i) != 1){ |
| 962 |
fprintf(stderr, "\nVrp I/O: error reading in solution %s\n\n", |
| 963 |
key); |
| 964 |
exit(1); |
| 965 |
} |
| 966 |
if (sscanf(v1, "%i", vrp->sol_pool_cols+i+1) != 1){ |
| 967 |
fprintf(stderr, "\nVrp I/O: error reading in solution %s\n\n", |
| 968 |
key); |
| 969 |
exit(1); |
| 970 |
} |
| 971 |
} |
| 972 |
vrp->sol_pool_col_num++; |
| 973 |
} |
| 974 |
/*___END_EXPERIMENTAL_SECTION___*/ |
| 975 |
} |
| 976 |
|
| 977 |
EXIT: |
| 978 |
|
| 979 |
for (i = 1; i < argc; i++){ |
| 980 |
sscanf(argv[i], "%c %c", &tmp, &c); |
| 981 |
if (tmp != '-') |
| 982 |
continue; |
| 983 |
switch (c) { |
| 984 |
case 'H': |
| 985 |
user_usage(); |
| 986 |
exit(0); |
| 987 |
case 'E': |
| 988 |
par->add_all_edges = FALSE; |
| 989 |
break; |
| 990 |
case 'S': |
| 991 |
strncpy(par->small_graph_file, argv[++i], MAX_FILE_NAME_LENGTH); |
| 992 |
par->use_small_graph = LOAD_SMALL_GRAPH; |
| 993 |
break; |
| 994 |
case 'F': |
| 995 |
strncpy(par->infile, argv[++i], MAX_FILE_NAME_LENGTH); |
| 996 |
break; |
| 997 |
case 'B': |
| 998 |
sscanf(argv[++i], "%i", &lp_par->branching_rule); |
| 999 |
break; |
| 1000 |
case 'A': |
| 1001 |
sscanf(argv[++i], "%i", &par->base_variable_selection); |
| 1002 |
break; |
| 1003 |
case 'V': |
| 1004 |
sscanf(argv[++i], "%i", &par->verbosity); |
| 1005 |
break; |
| 1006 |
case 'K': |
| 1007 |
sscanf(argv[++i], "%i", &par->k_closest); |
| 1008 |
break; |
| 1009 |
case 'N': |
| 1010 |
sscanf(argv[++i], "%i", &vrp->numroutes); |
| 1011 |
break; |
| 1012 |
case 'R': |
| 1013 |
par->tsp_prob = TRUE; |
| 1014 |
break; |
| 1015 |
case 'C': |
| 1016 |
sscanf(argv[++i], "%i", &vrp->capacity); |
| 1017 |
break; |
| 1018 |
case 'T': |
| 1019 |
par->test = TRUE; |
| 1020 |
if(i+1 < argc){ |
| 1021 |
sscanf(argv[i+1], "%c", &tmp); |
| 1022 |
if(tmp != '-'){ |
| 1023 |
strncpy(par->test_dir, argv[++i],MAX_FILE_NAME_LENGTH); |
| 1024 |
} |
| 1025 |
} |
| 1026 |
break; |
| 1027 |
}; |
| 1028 |
} |
| 1029 |
|
| 1030 |
if (f) |
| 1031 |
fclose(f); |
| 1032 |
|
| 1033 |
#ifdef COMPILE_HEURS |
| 1034 |
if (!par->rand_seed){ |
| 1035 |
par->rand_seed = (int *) calloc (NUM_RANDS, sizeof(int)); |
| 1036 |
for (k = 0; k<NUM_RANDS; k++) |
| 1037 |
par->rand_seed[k] = k+12; |
| 1038 |
} |
| 1039 |
|
| 1040 |
if (heur_par->route_opt1 < 0) |
| 1041 |
heur_par->route_opt1 = par->tours_to_keep; |
| 1042 |
if (heur_par->route_opt2 < 0) |
| 1043 |
heur_par->route_opt2 = par->tours_to_keep; |
| 1044 |
if (heur_par->route_opt3 < 0) |
| 1045 |
heur_par->route_opt3 = par->tours_to_keep; |
| 1046 |
if (heur_par->exchange < 0) |
| 1047 |
heur_par->exchange = par->tours_to_keep; |
| 1048 |
if (heur_par->exchange2 < 0) |
| 1049 |
heur_par->exchange2 = par->tours_to_keep; |
| 1050 |
#endif |
| 1051 |
} |
| 1052 |
|
| 1053 |
/*===========================================================================*/ |
| 1054 |
|
| 1055 |
void vrp_set_defaults(vrp_problem *vrp) |
| 1056 |
{ |
| 1057 |
vrp_params *par = &vrp->par; |
| 1058 |
#ifdef COMPILE_HEURS |
| 1059 |
heur_params *heur_par = &vrp->heur_par; |
| 1060 |
lb_params *lb_par = &vrp->lb_par; |
| 1061 |
#endif |
| 1062 |
vrp_lp_params *lp_par = &vrp->lp_par; |
| 1063 |
vrp_cg_params *cg_par = &vrp->cg_par; |
| 1064 |
|
| 1065 |
/*vrp->numroutes = 0;*/ |
| 1066 |
#if defined(CHECK_CUT_VALIDITY) || defined(TRACE_PATH) |
| 1067 |
vrp->feas_sol_size = 0; |
| 1068 |
vrp->feas_sol = NULL; |
| 1069 |
#endif |
| 1070 |
par->tsp_prob = FALSE; |
| 1071 |
#ifdef COMPILE_HEURS |
| 1072 |
par->rand_seed = NULL; |
| 1073 |
par->tours_to_keep = 15; |
| 1074 |
par->do_heuristics = FALSE; |
| 1075 |
#endif |
| 1076 |
par->k_closest = -1; |
| 1077 |
par->min_closest = 4; |
| 1078 |
par->max_closest = 10; |
| 1079 |
par->add_all_edges = TRUE; |
| 1080 |
par->base_variable_selection = SOME_ARE_BASE; |
| 1081 |
par->use_small_graph = FALSE; |
| 1082 |
par->colgen_strat[0] = 0; |
| 1083 |
par->colgen_strat[1] = 0; |
| 1084 |
par->verbosity = 9; |
| 1085 |
/*__BEGIN_EXPERIMENTAL_SECTION__*/ |
| 1086 |
par->debug.winprog = 0; |
| 1087 |
/*___END_EXPERIMENTAL_SECTION___*/ |
| 1088 |
#ifdef COMPILE_HEURS |
| 1089 |
par->debug.heuristics = 0; |
| 1090 |
par->time_out.ub = 60; |
| 1091 |
par->time_out.lb = 60; |
| 1092 |
heur_par->no_of_machines = 3; |
| 1093 |
heur_par->sweep_trials = 1000; /*default parameter settings*/ |
| 1094 |
heur_par->savings_par.savings_trials = 0; |
| 1095 |
heur_par->savings_par.savings2_trials = 1; |
| 1096 |
heur_par->savings_par.grid_size = 1; |
| 1097 |
heur_par->savings_par.mu = 1; |
| 1098 |
heur_par->savings_par.lamda = 2; |
| 1099 |
heur_par->savings3_par.savings_trials = 1; |
| 1100 |
heur_par->savings3_par.grid_size = 1; |
| 1101 |
heur_par->savings3_par.mu = 1; |
| 1102 |
heur_par->savings3_par.lamda = 2; |
| 1103 |
heur_par->route_opt1 = -1; |
| 1104 |
heur_par->route_opt2 = -1; |
| 1105 |
heur_par->route_opt3 = -1; |
| 1106 |
heur_par->fini_ratio = 0; |
| 1107 |
heur_par->ni_trials = 1; |
| 1108 |
heur_par->fi_trials = 1; |
| 1109 |
heur_par->fini_trials = 1; |
| 1110 |
heur_par->near_cluster_trials = 1; |
| 1111 |
heur_par->tsp.fi_trials = 3; |
| 1112 |
heur_par->tsp.ni_trials = 3; |
| 1113 |
heur_par->tsp.fini_trials = 3; |
| 1114 |
heur_par->tsp.num_starts = 1000; |
| 1115 |
heur_par->exchange = -1; |
| 1116 |
heur_par->exchange2 = -1; |
| 1117 |
lb_par->lower_bound = 0; |
| 1118 |
lb_par->lb_max_iter = 200; |
| 1119 |
lb_par->lb_penalty_mult = 100; |
| 1120 |
vrp->lb = (low_bd *) calloc (1, sizeof(low_bd)); |
| 1121 |
strcpy(par->executables.heuristics, "vrp_heuristics"); |
| 1122 |
#endif |
| 1123 |
|
| 1124 |
lp_par->verbosity = 0; |
| 1125 |
lp_par->branching_rule = 2; |
| 1126 |
lp_par->branch_on_cuts = FALSE; |
| 1127 |
lp_par->strong_branching_cand_num_max = 7; |
| 1128 |
lp_par->strong_branching_cand_num_min = 7; |
| 1129 |
lp_par->strong_branching_red_ratio = 0; |
| 1130 |
lp_par->detect_tailoff = 0; |
| 1131 |
lp_par->child_compar_obj_tol = .01; |
| 1132 |
|
| 1133 |
cg_par->verbosity = 0; |
| 1134 |
cg_par->do_greedy = 1; |
| 1135 |
cg_par->greedy_num_trials = 5; |
| 1136 |
cg_par->do_extra_in_root = FALSE; |
| 1137 |
cg_par->which_tsp_cuts = NO_TSP_CUTS; |
| 1138 |
cg_par->which_connected_routine = BOTH; |
| 1139 |
cg_par->max_num_cuts_in_shrink = 200; |
| 1140 |
/*__BEGIN_EXPERIMENTAL_SECTION__*/ |
| 1141 |
cg_par->do_mincut = 0; |
| 1142 |
cg_par->always_do_mincut = 0; |
| 1143 |
cg_par->update_contr_above = 0; |
| 1144 |
cg_par->shrink_one_edges = 1; |
| 1145 |
cg_par->do_extra_checking = 0; |
| 1146 |
#ifdef COMPILE_DECOMP |
| 1147 |
cg_par->generate_farkas_cuts = TRUE; |
| 1148 |
cg_par->generate_no_cols_cuts = TRUE; |
| 1149 |
cg_par->generate_capacity_cuts = TRUE; |
| 1150 |
cg_par->decomp_decompose = FALSE; |
| 1151 |
cg_par->allow_one_routes_in_bfm = TRUE; |
| 1152 |
cg_par->follow_one_edges = TRUE; |
| 1153 |
cg_par->max_num_columns = 1000; |
| 1154 |
cg_par->col_gen_par.grid_size = 1; |
| 1155 |
cg_par->col_gen_par.lambda = 2; |
| 1156 |
cg_par->col_gen_par.mu = 1; |
| 1157 |
#endif |
| 1158 |
#ifdef COMPILE_OUR_DECOMP |
| 1159 |
cg_par->feasible_tours_only = FALSE; |
| 1160 |
cg_par->graph_density_threshold = 10; |
| 1161 |
cg_par->gap_threshold = -1; |
| 1162 |
cg_par->do_our_decomp = FALSE; |
| 1163 |
cg_par->do_decomp_once = TRUE; |
| 1164 |
#endif |
| 1165 |
/*___END_EXPERIMENTAL_SECTION___*/ |
| 1166 |
|
| 1167 |
return; |
| 1168 |
} |
| 1169 |
|
| 1170 |
/*===========================================================================*/ |
| 1171 |
/*===========================================================================*/ |
| 1172 |
|
| 1173 |
void vrp_create_instance(void *user, int vertnum, int numroutes, int capacity, |
| 1174 |
int *demand, int *cost, small_graph *g) |
| 1175 |
{ |
| 1176 |
vrp_problem *vrp = (vrp_problem *)user; |
| 1177 |
int edgenum = vertnum*(vertnum-1)/2; |
| 1178 |
|
| 1179 |
vrp->vertnum = vertnum; |
| 1180 |
vrp->numroutes = numroutes; |
| 1181 |
vrp->capacity = capacity; |
| 1182 |
vrp->demand = (int *) malloc(vertnum*ISIZE); |
| 1183 |
memcpy(vrp->demand, demand, vertnum*ISIZE); |
| 1184 |
vrp->dist.cost = (int *) malloc(edgenum*ISIZE); |
| 1185 |
memcpy(vrp->dist.cost, cost, edgenum*ISIZE); |
| 1186 |
vrp->dist.wtype = _EXPLICIT; |
| 1187 |
if (g){ |
| 1188 |
vrp->g = (small_graph *) malloc(sizeof(small_graph)); |
| 1189 |
memcpy(vrp->g, g, sizeof(small_graph)); |
| 1190 |
vrp->g->edges = (edge_data *) malloc (vrp->g->edgenum*sizeof(edge_data)); |
| 1191 |
memcpy(vrp->g->edges, g->edges, vrp->g->edgenum*sizeof(edge_data)); |
| 1192 |
} |
| 1193 |
|
| 1194 |
strcpy(vrp->par.infile, ""); |
| 1195 |
|
| 1196 |
return; |
| 1197 |
} |