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