15 #ifndef VRP_CONCORDE_INCLUDED 
   16 #define VRP_CONCORDE_INCLUDED 
   26 #define VRP_CONCORDE_DEBUG       0 
   27 #define VRP_CONCORDE_SOLVER_TINY 1 
   67    void init(
const int nVerts,
 
   80                         "Error: Out of Memory");
 
  130              "Error: Out of Memory");
 
  160       int       nVerts               = nCustomers + nRoutes;
 
  162       int     * edgeList             = NULL;
 
  178       for(i = 1; i < nVerts; i++){
 
  179          for(j = 0; j < i; j++){
 
  189                edgeList[2*edgeIndex  ]  = i;
 
  190                edgeList[2*edgeIndex+1]  = j;
 
  212       const int            nOrigEdges       = graphLib.
n_edges;
 
  216       const int            nCustomers       = nOrigVerts - 1;
 
  224 #if VRP_CONCORDE_DEBUG > 0   
  225       for(i = 0; i < nOrigEdges; i++){
 
  226          printf(
"origGraphCost[%d -> %s]: %10.5f\n", 
 
  230       const double * minElement = min_element(origGraphCost, 
 
  231                           origGraphCost + nOrigEdges);
 
  232       const double   offset     = min(0.0, *minElement);
 
  233 #if VRP_CONCORDE_DEBUG > 0 
  234       printf(
"minElement = %10.5f offset = %10.5f\n", *minElement, -offset);
 
  236       memcpy(origGraphCostDbl, origGraphCost, nOrigEdges * 
sizeof(
double));
 
  252                            origGraphCostInt, 1.0e-3);
 
  256 #if VRP_CONCORDE_DEBUG > 0 
  258       for(i = 0; i < nOrigEdges; i++){
 
  259          printf(
"origGraphCost[%d]: %10.5f -> %10d\n", 
 
  262                 origGraphCostInt[i]);
 
  272       double bigCostDbl = 0.0;
 
  273       int    maxEdgeLen = *max_element(origGraphCostInt,
 
  274                                        origGraphCostInt+nOrigEdges);
 
  277          printf(
"WARNING: Large edge lengths!!!!\n");
 
  278          bigCost = CCutil_MAXINT / 256;         
 
  283       while(maxEdgeLen > bigCost){
 
  284          printf(
"maxEdgeLen=%d > bigCost=%d !!! SCALE BY 10\n",
 
  285                 maxEdgeLen, bigCost);
 
  287          for(i = 0; i < nOrigEdges; i++){
 
  288             origGraphCostInt[i] /= 10;
 
  292       assert(maxEdgeLen < bigCost);
 
  306       int u, v, d, d1, d2, origIndex, newIndex, custIndex, depot;
 
  307       for(u = 1; u < nOrigVerts; u++){
 
  308      for(v = 1; v < u; v++){
 
  311 #if VRP_CONCORDE_DEBUG > 0 
  312         printf(
"origIndex: [%d -> %s] to newIndex: [%d -> %s]\n",
 
  317             CoinAssert(origGraphCostInt[origIndex] < bigCost);
 
  318         edgeValue[newIndex] = origGraphCostInt[origIndex];
 
  321       for(u = 1; u <= nCustomers; u++){
 
  324          origCost  = origGraphCostInt[origIndex];
 
  328      for(d = 0; d < nRoutes; d++){
 
  329         depot    = nCustomers + d; 
 
  335 #if VRP_CONCORDE_DEBUG > 0 
  336             printf(
"(u:%d,0) origIndex=%d origCost=%d d=%d cInd=%d nInd=%d\n",
 
  337                    u, origIndex, origCost, d, 
 
  340         edgeValue[newIndex] = origCost;
 
  343       for(d1 = 1; d1 < nRoutes; d1++){
 
  344      for(d2 = 0; d2 < d1; d2++){
 
  347             edgeValue[newIndex] = bigCost;
 
  365         vector<double> & vrpRouteEls,
 
  414       int success, foundtour, hit_timebound;
 
  426       int    nCustomers = nOrigVerts - 1;
 
  427       double upbound    = infinity;
 
  428       double optval     = infinity;      
 
  442       for(d1 = 1; d1 < nRoutes; d1++){
 
  443      for(d2 = 0; d2 < d1; d2++){
 
  444         upper[
UtilIndexU(nCustomers + d1, nCustomers + d2)] = 0;
 
  463       bool useFullSolver = 
false;
 
  465      printf(
"Search limit exceeded - let's go to full solver\n");
 
  466      useFullSolver = 
true;
 
  481      strcpy(nameC, name.c_str());
 
  483 #if VRP_CONCORDE_DEBUG > 0 
  484      printf(
"CONCORDE GRAPH:\n");
 
  485      printf(
"   nVerts=%d nEdges=%d\n", 
 
  489         printf(
"(%4d,%4d) val:%4d\n",
 
  509      CoinAssert((success == 1) && (foundtour == 1));
 
  512 #if VRP_CONCORDE_DEBUG > 0     
  513       printf(
"Optimal Route:\n");
 
  518      vector<int> edgeListSol;
 
  521 #if VRP_CONCORDE_DEBUG > 0 
  522            printf(
"(%d,%d) wt:%d\n", 
 
  545                                       vector<int>    & vrpRouteInd,
 
  546                                       vector<double> & vrpRouteEls){
 
  557 #if VRP_CONCORDE_DEBUG > 0     
  558       printf(
"Optimal Route:\n");
 
  562          u = tspEdgeList[2*i];
 
  563          v = tspEdgeList[2*i+1];
 
  564      u = u >= nCustomers ? 0 : u+1;  
 
  565      v = v >= nCustomers ? 0 : v+1;
 
  575 #if VRP_CONCORDE_DEBUG > 0     
  576             printf(
"(%d,%d) -> %d\n", u, v, 
UtilIndexU(u,v));
 
  580       UtilFillN(vrpRouteEls, vrpRouteInd.size(), 1.0);
 
  582       for(v = 1; v < nVerts; v++){
 
  587         vrpRouteEls.push_back(static_cast<double>(depotEdges[v]));
 
  588 #if VRP_CONCORDE_DEBUG > 0     
  589             printf(
"%d D(%d,%d) -> %d\n", 
 
  597                    const int        tspRouteLen,
 
  598                    vector<int>    & vrpRouteInd,
 
  599                    vector<double> & vrpRouteEls){
 
  610 #if VRP_CONCORDE_DEBUG > 0     
  611       printf(
"Optimal Route Nodes:");
 
  612       for(i = 0; i < tspRouteLen; i++){
 
  613          printf(
"%d ", tspRoute[i]);
 
  615       printf(
"\nOptimal Route Edges:\n");
 
  617       for(i = 0; i < tspRouteLen-1; i++){
 
  618      u = tspRoute[i]   >= nCustomers ? 0 : tspRoute[i]  +1;  
 
  619      v = tspRoute[i+1] >= nCustomers ? 0 : tspRoute[i+1]+1;
 
  630 #if VRP_CONCORDE_DEBUG > 0     
  631      printf(
"(%d,%d) -> %d\n", u, v, 
UtilIndexU(u,v));   
 
  634       u = tspRoute[tspRouteLen-1] >= nCustomers ? 0 
 
  635      : tspRoute[tspRouteLen-1]+1;    
 
  636       v = tspRoute[0] >= nCustomers ? 0 : tspRoute[0] + 1;
 
  647 #if VRP_CONCORDE_DEBUG > 0         
  648       printf(
"(%d,%d) -> %d\n", u, v, 
UtilIndexU(u,v));
 
  650       UtilFillN(vrpRouteEls, vrpRouteInd.size(), 1.0);
 
  652       for(v = 1; v < nVerts; v++){
 
  657         vrpRouteEls.push_back(static_cast<double>(depotEdges[v]));
 
  658 #if VRP_CONCORDE_DEBUG > 0     
  659             printf(
"%d D(%d,%d) -> %d\n", 
 
  672       printf(
"Open File %s\n", fileName.c_str());
 
  675       os << 
"NAME: " << fileName << 
"\n" 
  677      << 
"DIMENSION: " << nVerts << 
"\n" 
  678      << 
"EDGE_WEIGHT_TYPE: EXPLICIT\n" 
  679      << 
"EDGE_WEIGHT_FORMAT: LOWER_DIAG_ROW\n" 
  680      << 
"EDGE_WEIGHT_SECTION\n";
 
  683       for(i = 1; i < nVerts; i++){
 
  684      for(j = 0; j < i; j++){
 
  685         os << edgeValue[edgeIndex] << 
" ";
 
int UtilIndexU(const int i, const int j)
 
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. 
 
int solveTSP(vector< int > &vrpRouteInd, vector< double > &vrpRouteEls, double infinity)
 
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)