* filename,
82vector<vector<int> >& dist
85 static const stringDIMENSION =
"DIMENSION";
86 static const stringDEMAND_SECTION =
"DEMAND_SECTION";
87 static const stringDEPOT_SECTION =
"DEPOT_SECTION";
88 static const stringEDGE_WEIGHT_TYPE =
"EDGE_WEIGHT_TYPE";
89 static const stringEUC_2D =
"EUC_2D";
90 static const stringEXPLICIT =
"EXPLICIT";
91 static const stringLOWER_DIAG_ROW =
"LOWER_DIAG_ROW";
92 static const stringEDGE_WEIGHT_FORMAT =
"EDGE_WEIGHT_FORMAT";
93 static const stringEDGE_WEIGHT_SECTION =
"EDGE_WEIGHT_SECTION";
94 static const stringNODE_COORD_SECTION =
"NODE_COORD_SECTION";
95 static const stringCAPACITY =
"CAPACITY";
97ifstream file(filename);
101cerr <<
"Cannot open file "<< filename << endl;
105 stringedge_weight_type =
"";
106 stringedge_weight_format =
"";
119 if( key == DIMENSION )
124demand.resize(num_nodes, 0);
125dist.resize(num_nodes);
126 for(
inti = 0; i < num_nodes; ++i)
127dist[i].resize(i, 0);
130 if( key == CAPACITY )
135 else if( key == EDGE_WEIGHT_TYPE )
138file >> edge_weight_type;
139 if( edge_weight_type != EUC_2D && edge_weight_type != EXPLICIT )
141cerr <<
"Wrong "<< EDGE_WEIGHT_TYPE <<
" "<< edge_weight_type << endl;
144 if( edge_weight_type == EUC_2D )
146 x.resize(num_nodes, 0);
147 y.resize(num_nodes, 0);
150 else if( key == EDGE_WEIGHT_FORMAT )
153file >> edge_weight_format;
155 else if( key == EDGE_WEIGHT_FORMAT +
":")
157file >> edge_weight_format;
159 else if( key == EDGE_WEIGHT_SECTION )
161 if( edge_weight_type != EXPLICIT || edge_weight_format != LOWER_DIAG_ROW )
163cerr <<
"Error. Unsupported edge length type."<< endl;
166 for(
inti = 0; i < num_nodes; ++i)
168 for(
intj = 0; j < i; ++j)
176 else if( key == NODE_COORD_SECTION )
178 if( edge_weight_type != EUC_2D )
180cerr <<
"Error. Data file contains "<< EDGE_WEIGHT_TYPE <<
" "<< edge_weight_type <<
" and "<< NODE_COORD_SECTION << endl;
183 for(
inti = 0; i < num_nodes; ++i)
191cerr <<
"Error reading "<< NODE_COORD_SECTION << endl;
197 for(
inti = 0; i < num_nodes; ++i)
199 for(
intj = 0; j < i; ++j)
201 intdx =
x[i] -
x[j];
202 intdy =
y[i] -
y[j];
203dist[i][j] = int( sqrt((
double)dx*dx + dy*dy) + 0.5 );
207 else if( key == DEMAND_SECTION )
209 for(
inti = 0; i < num_nodes; ++i)
216cerr <<
"Error reading "<< DEMAND_SECTION << endl;
222 else if( key == DEPOT_SECTION )
224 for(
inti = 0; i != -1 ;)
227 if( i != -1 && i != 1 )
229cerr <<
"Error: This file specifies other depots than 1."<< endl;
236(void) getline(file, dummy);
250cout <<
"Solving the vehicle routing problem using SCIP."<< endl;
251cout <<
"Implemented by Andreas Bley."<< endl << endl;
253 if( argc != 2 && argc != 3 )
255cerr <<
"Usage: vrp [-h] datafile"<< endl;
256cerr <<
"Options:"<< endl;
257cerr <<
" -h Uses hop limit instead of capacity limit for tours."<< endl;
266 static const char* VRP_PRICER_NAME =
"VRP_Pricer";
268vector<vector<int> > dist;
273 if(
read_problem(argv[argc-1], num_nodes, capacity, demand, dist) )
275cerr <<
"Error reading data file "<< argv[argc-1] << endl;
279cout <<
"Number of nodes: "<< num_nodes << endl;
283 if(
string(
"-h") != argv[1] )
285cerr <<
"Unknow option "<< argv[2] << endl;
289 inttotal_demand = 0;
290 for(
inti = 1; i< num_nodes; ++i)
291total_demand += demand[i];
293 if( total_demand == 0.0 )
295cerr <<
"Total demand is zero!"<< endl;
299capacity = (num_nodes - 1) * capacity / total_demand;
300demand.assign(num_nodes, 1);
302cout <<
"Max customers per tour: "<< capacity << endl << endl;
305cout <<
"Max demand per tour: "<< capacity << endl << endl;
333vector< vector<SCIP_VAR*> > arc_var( num_nodes );
334 for(
inti = 0; i < num_nodes; ++i)
337 for(
intj = 0; j < i; ++j)
359vector< vector<SCIP_CONS*> > arc_con( num_nodes );
360 for(
inti = 0; i < num_nodes; ++i)
363 for(
intj = 0; j < i; ++j)
388 for(
inti = 1; i < num_nodes; ++i)
406 for(
intj = 0; j < num_nodes; ++j)
417vector<SCIP_CONS*> part_con(num_nodes, (
SCIP_CONS*)
NULL);
418 for(
inti = 1; i < num_nodes; ++i)
441arc_var, arc_con, part_con);
472 for(
inti = 0; i < num_nodes; ++i)
478 for(
intj = 0; j < i; ++j)
493int main(
intargc,
char** argv)
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
SCIP_RETCODE SCIPfree(SCIP **scip)
SCIP_RETCODE SCIPcreate(SCIP **scip)
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPcreateProb(SCIP *scip, const char *name, SCIP_DECL_PROBDELORIG((*probdelorig)), SCIP_DECL_PROBTRANS((*probtrans)), SCIP_DECL_PROBDELTRANS((*probdeltrans)), SCIP_DECL_PROBINITSOL((*probinitsol)), SCIP_DECL_PROBEXITSOL((*probexitsol)), SCIP_DECL_PROBCOPY((*probcopy)), SCIP_PROBDATA *probdata)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
void SCIPprintVersion(SCIP *scip, FILE *file)
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
SCIP_PRICER * SCIPfindPricer(SCIP *scip, const char *name)
SCIP_RETCODE SCIPactivatePricer(SCIP *scip, SCIP_PRICER *pricer)
SCIP_RETCODE SCIPprintBestSol(SCIP *scip, FILE *file, SCIP_Bool printzeros)
SCIP_RETCODE SCIPsolve(SCIP *scip)
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
SCIP_RETCODE SCIPcreateVar(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype, SCIP_Bool initial, SCIP_Bool removable, SCIP_DECL_VARDELORIG((*vardelorig)), SCIP_DECL_VARTRANS((*vartrans)), SCIP_DECL_VARDELTRANS((*vardeltrans)), SCIP_DECL_VARCOPY((*varcopy)), SCIP_VARDATA *vardata)
int SCIPsnprintf(char *t, int len, const char *s,...)
int main(int argc, char **argv)
static SCIP_RETCODE execmain(int argc, char **argv)
static int read_problem(const char *filename, int &num_nodes, int &capacity, vector< int > &demand, vector< vector< int > > &dist)
#define BMScheckEmptyMemory()
SCIP_RETCODE SCIPincludeObjPricer(SCIP *scip, scip::ObjPricer *objpricer, SCIP_Bool deleteobject)
C++ wrapper classes for SCIP.
C++ wrapper for default SCIP plugins.
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
enum SCIP_Retcode SCIP_RETCODE
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4