Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Problems with TSP formulation

  • 1.  Problems with TSP formulation

    Posted 10/30/13 09:16 AM

    Originally posted by: MityaStiglitz


    Hi,

    I'm working on a smaller TSP for an OR course. I've already programmed a B&B alg. but I would also like to check the solution using CPLEX. It  happens this is the first time I am using CPLEX  and it doesn't like my code. It doesn't recognize the subtour constraints. I don't know how to correct it - any help is appreciated. The code is as follows:

    //Data
     int Nb = ...;
    {string} Nodi = ...;
    {string} Nodj = ...;
    {string} Arts = ...;
     int Dist[Nodi][Nodj] = ...;
    
     //Decision variables
     dvar boolean NodiToNodj[Nodi][Nodj];
     dvar float Art[Arts];
    
     //Objective function
     minimize
     sum (i in Nodi, j in Nodj )
       Dist[i][j]*NodiToNodj[i][j];
    
    //Constraints
    
    subject to {
    forall( i in Nodi )
     ctNodiHasOneNodj:
     sum( j in Nodj)
         NodiToNodj[i][j]==1;  
    
    forall( j in Nodj )
     ctNodjHasOneNodi:
     sum( i in Nodi)
       NodiToNodj[i][j]==1;
    
    forall (i in 1..(Nb-1))
     forall (j in 2..Nb)
      ctSubtourElimination:
      Art[i]-Art[j]+Nb*NodiToNodj[i][j]<=Nb-1;
    }
    
    //DATA
    Nb=12;
    Nodi={"1","2","3","4","5","6","7","8","9","10","11","12"};
    Nodj={"1","2","3","4","5","6","7","8","9","10","11","12"};
    Arts={"1","2","3","4","5","6","7","8","9","10","11","12"};
    Dist=[
    [999,7,3,999,3,999,999,999,999,999,999,999],
    [7,999,999,3,999,999,3,999,999,999,999,999],
    [3,999,999,1999,2,999,999,999,999,999,3,999],
    [999,3,1999,999,999,999,2,999,999,999,999,3],
    [3,999,2,999,999,1,999,1,999,999,999,999],
    [999,999,999,999,1,999,1,999,1,999,999,999],
    [999,3,999,2,999,1,999,999,999,1,999,999],
    [999,999,999,999,1,999,999,999,1,999,2,7],
    [999,999,999,999,999,1,999,1,999,1,7,999],
    [999,999,999,999,999,999,1,999,1,999,999,2],
    [999,999,3,999,999,999,999,2,7,999,999,10],
    [999,999,999,3,999,999,999,7,999,2,10,999]];
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Problems with TSP formulation

    Posted 10/30/13 10:41 AM

    Hi,

     

    could you try

     

    forall (i in 1..(Nb-1))
     forall (j in 2..Nb)
      ctSubtourElimination:
        Art[item(Arts,i-1)]-Art[item(Arts,j-1)]+Nb*NodiToNodj[item(Nodi,i-1)][item(Nodi,j-1)]<=Nb-1;

     

    ?

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Problems with TSP formulation

    Posted 10/30/13 12:19 PM

    Originally posted by: MityaStiglitz


    Thank you Alex! It now works.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer