13 #ifndef VRP_CONCORDE_INCLUDED
14 #define VRP_CONCORDE_INCLUDED
24 #define VRP_CONCORDE_DEBUG 0
25 #define VRP_CONCORDE_SOLVER_TINY 1
65 void init(
const int nVerts,
78 "Error: Out of Memory");
128 "Error: Out of Memory");
158 int nVerts = nCustomers + nRoutes;
160 int * edgeList = NULL;
176 for(i = 1; i < nVerts; i++){
177 for(j = 0; j < i; j++){
187 edgeList[2*edgeIndex ] = i;
188 edgeList[2*edgeIndex+1] = j;
210 const int nOrigEdges = graphLib.
n_edges;
214 const int nCustomers = nOrigVerts - 1;
222 #if VRP_CONCORDE_DEBUG > 0
223 for(i = 0; i < nOrigEdges; i++){
224 printf(
"origGraphCost[%d -> %s]: %10.5f\n",
228 const double * minElement = min_element(origGraphCost,
229 origGraphCost + nOrigEdges);
230 const double offset = min(0.0, *minElement);
231 #if VRP_CONCORDE_DEBUG > 0
232 printf(
"minElement = %10.5f offset = %10.5f\n", *minElement, -offset);
234 memcpy(origGraphCostDbl, origGraphCost, nOrigEdges *
sizeof(
double));
250 origGraphCostInt, 1.0e-3);
254 #if VRP_CONCORDE_DEBUG > 0
256 for(i = 0; i < nOrigEdges; i++){
257 printf(
"origGraphCost[%d]: %10.5f -> %10d\n",
260 origGraphCostInt[i]);
270 double bigCostDbl = 0.0;
271 int maxEdgeLen = *max_element(origGraphCostInt,
272 origGraphCostInt+nOrigEdges);
275 printf(
"WARNING: Large edge lengths!!!!\n");
276 bigCost = CCutil_MAXINT / 256;
281 while(maxEdgeLen > bigCost){
282 printf(
"maxEdgeLen=%d > bigCost=%d !!! SCALE BY 10\n",
283 maxEdgeLen, bigCost);
285 for(i = 0; i < nOrigEdges; i++){
286 origGraphCostInt[i] /= 10;
290 assert(maxEdgeLen < bigCost);
304 int u, v, d, d1, d2, origIndex, newIndex, custIndex, depot;
305 for(u = 1; u < nOrigVerts; u++){
306 for(v = 1; v < u; v++){
309 #if VRP_CONCORDE_DEBUG > 0
310 printf(
"origIndex: [%d -> %s] to newIndex: [%d -> %s]\n",
315 CoinAssert(origGraphCostInt[origIndex] < bigCost);
316 edgeValue[newIndex] = origGraphCostInt[origIndex];
319 for(u = 1; u <= nCustomers; u++){
322 origCost = origGraphCostInt[origIndex];
326 for(d = 0; d < nRoutes; d++){
327 depot = nCustomers + d;
333 #if VRP_CONCORDE_DEBUG > 0
334 printf(
"(u:%d,0) origIndex=%d origCost=%d d=%d cInd=%d nInd=%d\n",
335 u, origIndex, origCost, d,
338 edgeValue[newIndex] = origCost;
341 for(d1 = 1; d1 < nRoutes; d1++){
342 for(d2 = 0; d2 < d1; d2++){
345 edgeValue[newIndex] = bigCost;
363 vector<double> & vrpRouteEls){
411 int success, foundtour, hit_timebound;
423 int nCustomers = nOrigVerts - 1;
424 double upbound = DecompInf;
425 double optval = DecompInf;
439 for(d1 = 1; d1 < nRoutes; d1++){
440 for(d2 = 0; d2 < d1; d2++){
441 upper[
UtilIndexU(nCustomers + d1, nCustomers + d2)] = 0;
460 bool useFullSolver =
false;
462 printf(
"Search limit exceeded - let's go to full solver\n");
463 useFullSolver =
true;
478 strcpy(nameC, name.c_str());
480 #if VRP_CONCORDE_DEBUG > 0
481 printf(
"CONCORDE GRAPH:\n");
482 printf(
" nVerts=%d nEdges=%d\n",
486 printf(
"(%4d,%4d) val:%4d\n",
506 CoinAssert((success == 1) && (foundtour == 1));
509 #if VRP_CONCORDE_DEBUG > 0
510 printf(
"Optimal Route:\n");
515 vector<int> edgeListSol;
518 #if VRP_CONCORDE_DEBUG > 0
519 printf(
"(%d,%d) wt:%d\n",
542 vector<int> & vrpRouteInd,
543 vector<double> & vrpRouteEls){
554 #if VRP_CONCORDE_DEBUG > 0
555 printf(
"Optimal Route:\n");
559 u = tspEdgeList[2*i];
560 v = tspEdgeList[2*i+1];
561 u = u >= nCustomers ? 0 : u+1;
562 v = v >= nCustomers ? 0 : v+1;
572 #if VRP_CONCORDE_DEBUG > 0
573 printf(
"(%d,%d) -> %d\n", u, v,
UtilIndexU(u,v));
577 UtilFillN(vrpRouteEls, vrpRouteInd.size(), 1.0);
579 for(v = 1; v < nVerts; v++){
584 vrpRouteEls.push_back(static_cast<double>(depotEdges[v]));
585 #if VRP_CONCORDE_DEBUG > 0
586 printf(
"%d D(%d,%d) -> %d\n",
594 const int tspRouteLen,
595 vector<int> & vrpRouteInd,
596 vector<double> & vrpRouteEls){
607 #if VRP_CONCORDE_DEBUG > 0
608 printf(
"Optimal Route Nodes:");
609 for(i = 0; i < tspRouteLen; i++){
610 printf(
"%d ", tspRoute[i]);
612 printf(
"\nOptimal Route Edges:\n");
614 for(i = 0; i < tspRouteLen-1; i++){
615 u = tspRoute[i] >= nCustomers ? 0 : tspRoute[i] +1;
616 v = tspRoute[i+1] >= nCustomers ? 0 : tspRoute[i+1]+1;
627 #if VRP_CONCORDE_DEBUG > 0
628 printf(
"(%d,%d) -> %d\n", u, v,
UtilIndexU(u,v));
631 u = tspRoute[tspRouteLen-1] >= nCustomers ? 0
632 : tspRoute[tspRouteLen-1]+1;
633 v = tspRoute[0] >= nCustomers ? 0 : tspRoute[0] + 1;
644 #if VRP_CONCORDE_DEBUG > 0
645 printf(
"(%d,%d) -> %d\n", u, v,
UtilIndexU(u,v));
647 UtilFillN(vrpRouteEls, vrpRouteInd.size(), 1.0);
649 for(v = 1; v < nVerts; v++){
654 vrpRouteEls.push_back(static_cast<double>(depotEdges[v]));
655 #if VRP_CONCORDE_DEBUG > 0
656 printf(
"%d D(%d,%d) -> %d\n",
669 printf(
"Open File %s\n", fileName.c_str());
672 os <<
"NAME: " << fileName <<
"\n"
674 <<
"DIMENSION: " << nVerts <<
"\n"
675 <<
"EDGE_WEIGHT_TYPE: EXPLICIT\n"
676 <<
"EDGE_WEIGHT_FORMAT: LOWER_DIAG_ROW\n"
677 <<
"EDGE_WEIGHT_SECTION\n";
680 for(i = 1; i < nVerts; i++){
681 for(j = 0; j < i; j++){
682 os << edgeValue[edgeIndex] <<
" ";
int UtilIndexU(const int i, const int j)
int solveTSP(vector< int > &vrpRouteInd, vector< double > &vrpRouteEls)
std::string UtilStringRandom(int iLength)
void createVrpRouteFromTspRoute(const int *tspRoute, const int tspRouteLen, vector< int > &vrpRouteInd, vector< double > &vrpRouteEls)
#define CC_TINYTSP_INFEASIBLE
#define CC_TINYTSP_SEARCHLIMITEXCEEDED
int UtilNumEdgesU(const int n)
void init(const int nVerts, const int nEdges)
#define CoinAssertHint(expression, hint)
void UtilOpenFile(ifstream &fs, const char *fileName)
UtilGraphLib m_graphLib
Data for an instance from VRPLIB.
const VRP_Instance * m_vrp
int CCtsp_solve_dat(int ncount, CCdatagroup *indat, int *in_tour, int *out_tour, double *in_val, double *optval, int *success, int *foundtour, char *name, double *timebound, int *hit_timebound, int silent, CCrandstate *rstate)
void createVrpRouteFromTspEdgeList(vector< int > &tspEdgeList, vector< int > &vrpRouteInd, vector< double > &vrpRouteEls)
std::string UtilEdgeToStr(const int index)
#define CC_TINYTSP_MINIMIZE
void UtilAddOffsetArr(const int arrLen, T offset, T *arr)
void UtilFillN(T *to, const int size, const T value)
int CCutil_graph2dat_matrix(int ncount, int ecount, int *elist, int *elen, int defaultlen, CCdatagroup *dat)
void setEdgeValue(const double *edgeValue)
void buildExpandedCompleteGraph()
#define CoinAssert(expression)
void CCutil_sprand(int seed, CCrandstate *r)
void init(const VRP_Instance *vrp)
int CCtiny_bnc_msp(int ncount, int ecount, int *elist, int *elen, int depot, int *lower, int *upper, double *upperbound, int objsense, double *optval, int *xsol, int checkresult, int searchlimit)
void createTSPLIBFile(const string fileName)
int UtilScaleDblToIntArr(const int arrLen, const double *arrDbl, int *arrInt, const double oneDbl, int *oneInt, const double epstol=UtilEpsilon)
void setExpandedCost(const double *origGraphCost)