| 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 |
#define COMPILING_FOR_MASTER |
| 17 |
|
| 18 |
/*===========================================================================*/ |
| 19 |
|
| 20 |
/*===========================================================================*\ |
| 21 |
* This file contains the main() for the master process. |
| 22 |
\*===========================================================================*/ |
| 23 |
|
| 24 |
#ifdef USE_OSI_INTERFACE |
| 25 |
|
| 26 |
#include "OsiSymSolverInterface.hpp" |
| 27 |
|
| 28 |
int main(int argc, char **argv) |
| 29 |
{ |
| 30 |
OsiSymSolverInterface si; |
| 31 |
|
| 32 |
//si.setSymParam(OsiSymVerbosity, 3); |
| 33 |
si.setSymParam(OsiSymGranularity, 0.9999); |
| 34 |
si.setSymParam("generate_cgl_cuts", FALSE); |
| 35 |
si.setSymParam("lp_executable_name", "vrp_lp_cg"); |
| 36 |
si.setSymParam("cp_executable_name", "vrp_cp"); |
| 37 |
|
| 38 |
/* Parse the command line */ |
| 39 |
si.parseCommandLine(argc, argv); |
| 40 |
|
| 41 |
/* Read in the problem */ |
| 42 |
si.loadProblem(); |
| 43 |
|
| 44 |
/* Find a priori problem bounds */ |
| 45 |
si.findInitialBounds(); |
| 46 |
|
| 47 |
/* Solve the problem */ |
| 48 |
si.branchAndBound(); |
| 49 |
|
| 50 |
return(0); |
| 51 |
} |
| 52 |
|
| 53 |
#else |
| 54 |
|
| 55 |
#include "symphony.h" |
| 56 |
#include "sym_master.h" |
| 57 |
#include "vrp_types.h" |
| 58 |
#include "vrp_const.h" |
| 59 |
|
| 60 |
int vrp_test(sym_environment *env, int argc, char **argv); |
| 61 |
|
| 62 |
int main(int argc, char **argv) |
| 63 |
{ |
| 64 |
vrp_problem *vrp; |
| 65 |
|
| 66 |
sym_environment *env = sym_open_environment(); |
| 67 |
|
| 68 |
sym_version(); |
| 69 |
|
| 70 |
sym_parse_command_line(env, argc, argv); |
| 71 |
|
| 72 |
sym_get_user_data(env, (void**)&vrp); |
| 73 |
|
| 74 |
if (vrp->par.test){ |
| 75 |
|
| 76 |
vrp_test(env, argc, argv); |
| 77 |
|
| 78 |
} else { |
| 79 |
|
| 80 |
sym_load_problem(env); |
| 81 |
|
| 82 |
sym_find_initial_bounds(env); |
| 83 |
|
| 84 |
sym_set_str_param(env, "lp_executable_name", "vrp_lp_cg"); |
| 85 |
sym_set_str_param(env, "cp_executable_name", "vrp_cp"); |
| 86 |
sym_set_int_param(env, "generate_cgl_cuts", FALSE); |
| 87 |
|
| 88 |
sym_solve(env); |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
sym_close_environment(env); |
| 93 |
|
| 94 |
return(0); |
| 95 |
} |
| 96 |
|
| 97 |
/*===========================================================================*/ |
| 98 |
/*===========================================================================*/ |
| 99 |
|
| 100 |
int vrp_test(sym_environment *env, int argc, char **argv) |
| 101 |
{ |
| 102 |
|
| 103 |
int termcode, i, file_num = 34; |
| 104 |
char input_files[34][MAX_FILE_NAME_LENGTH +1] = {"A/A-n34-k5", |
| 105 |
"A/A-n32-k5", |
| 106 |
"A/A-n33-k5", |
| 107 |
"E/E-n13-k4", |
| 108 |
"E/E-n22-k4", |
| 109 |
"E/E-n23-k3", |
| 110 |
"E/E-n30-k3", |
| 111 |
"E/E-n33-k4", |
| 112 |
"V/att-n48-k4", |
| 113 |
"E/E-n51-k5", |
| 114 |
"A/A-n33-k6", |
| 115 |
"A/A-n36-k5", |
| 116 |
"A/A-n37-k5", |
| 117 |
"A/A-n38-k5", |
| 118 |
"A/A-n39-k5", |
| 119 |
"A/A-n39-k6", |
| 120 |
"A/A-n45-k6", |
| 121 |
"A/A-n46-k7", |
| 122 |
"B/B-n31-k5", |
| 123 |
"B/B-n34-k5", |
| 124 |
"B/B-n35-k5", |
| 125 |
"B/B-n38-k6", |
| 126 |
"B/B-n39-k5", |
| 127 |
"B/B-n41-k6", |
| 128 |
"B/B-n43-k6", |
| 129 |
"B/B-n44-k7", |
| 130 |
"B/B-n45-k5", |
| 131 |
"B/B-n50-k7", |
| 132 |
"B/B-n51-k7", |
| 133 |
"B/B-n52-k7", |
| 134 |
"B/B-n56-k7", |
| 135 |
"B/B-n64-k9", |
| 136 |
"A/A-n48-k7", |
| 137 |
"A/A-n53-k7"}; |
| 138 |
|
| 139 |
double sol[34] = {778, 784, 661, 247, 375, 569, 534, 835, 40002, 521, 742, |
| 140 |
799, 669, 730, 822, 831, 944, 914, 672, 788, 955, 805, |
| 141 |
549, 829, 742, 909, 751, 741, 1032, 747, 707, 861, |
| 142 |
1073, 1010}; |
| 143 |
|
| 144 |
char *input_dir = (char*)malloc(CSIZE*(MAX_FILE_NAME_LENGTH+1)); |
| 145 |
char *infile = (char*)malloc(CSIZE*(MAX_FILE_NAME_LENGTH+1)); |
| 146 |
char *sgfile = (char*)malloc(CSIZE*(MAX_FILE_NAME_LENGTH+1)); |
| 147 |
double *obj_val = (double *)calloc(DSIZE,file_num); |
| 148 |
double tol = 1e-06, ub; |
| 149 |
|
| 150 |
vrp_problem *vrp = (vrp_problem *) env->user; |
| 151 |
|
| 152 |
if (strcmp(vrp->par.test_dir, "") == 0){ |
| 153 |
strcpy(input_dir, "../../../VRPLIB"); |
| 154 |
} else{ |
| 155 |
strcpy(input_dir, vrp->par.test_dir); |
| 156 |
} |
| 157 |
|
| 158 |
for(i = 0; i<file_num; i++){ |
| 159 |
|
| 160 |
strcpy(infile, ""); |
| 161 |
strcpy(sgfile, ""); |
| 162 |
sprintf(infile, "%s%s%s%s", input_dir, "/", input_files[i], ".vrp"); |
| 163 |
sprintf(sgfile, "%s%s%s", "./small_graph/", input_files[i], ".sg"); |
| 164 |
|
| 165 |
|
| 166 |
strcpy(vrp->par.infile, infile); |
| 167 |
strcpy(vrp->par.small_graph_file, sgfile); |
| 168 |
vrp->par.use_small_graph = LOAD_SMALL_GRAPH; |
| 169 |
|
| 170 |
sym_load_problem(env); |
| 171 |
|
| 172 |
sym_find_initial_bounds(env); |
| 173 |
|
| 174 |
printf("Solving %s...\n", input_files[i]); |
| 175 |
|
| 176 |
sym_solve(env); |
| 177 |
|
| 178 |
sym_get_obj_val(env, &obj_val[i]); |
| 179 |
|
| 180 |
if((obj_val[i] < sol[i] + tol) && |
| 181 |
(obj_val[i] > sol[i] - tol)){ |
| 182 |
printf("Success!\n"); |
| 183 |
} else { |
| 184 |
printf("Failure!(%f, %f) \n", obj_val[i], sol[i]); |
| 185 |
} |
| 186 |
|
| 187 |
if(i+1 < file_num){ |
| 188 |
sym_close_environment(env); |
| 189 |
|
| 190 |
env = sym_open_environment(); |
| 191 |
sym_parse_command_line(env, argc, argv); |
| 192 |
} |
| 193 |
|
| 194 |
} |
| 195 |
return (0); |
| 196 |
} |
| 197 |
|
| 198 |
#endif |