Originally posted by: sophieTSP
Hello
I am new in OPL and I work on a mathematical model of Traveling Salesman Problem with variable customers, I would like to make the resolution with OPL CPLEX, I have seen the resolution of the classic TSP with the DFJ formulation, and in my case I wonder how I could introduce a new parameter (Scenario) since it is stochastic in the source code of the Classic TSP ( Subtour Elimination Constraincts) , the formulation is as follows:
I started writing the code but i have difficulty to integrate the scenario concept into the code
// Cities
int n = ...;
int nbScs = ...;
range Scs =1..nbScs;
range Cities = 1..n;
{int} I = {1,2,3,4,5};
range r=1.. ftoi(pow(2,card(I)));
{int} s2 [k in r] = {i | i in I: ((k div (ftoi(pow(2,(ord(I,i))))) mod 2) == 1)};
execute
{
writeln(s2);
}
// more than two elements and less than |S|-1 elements
tuple t
{
{int} set;
};
{t} res={<s2[k]> | k in r : 2<=card(s2[k])<=card(I)-1};
execute
{
writeln(res);
}
// Edges -- sparse set
int l[i in Cities][j in Cities] = ...;
int S[k in Scs][i in Cities ][j in Cities] = ...;
// Decision variables
dvar boolean y[i in Cities][j in Cities];
dvar int+ x[k in Scs][i in Cities][j in Cities] ;
// Objective
minimize sum (i in Cities, j in Cities, k in Scs: i!=j) l[i][j]* x[k][i][j];
subject to {
// Each city is linked with two other cities
forall (j in Cities)
flow_in:
sum (i in Cities : i!=j) y[i][j] ==1;
forall (j in Cities, k in Scs)
sum (i in Cities : i!=j ) x[k][i][j] ==1;
forall (i in Cities)
flow_out:
sum (j in Cities : j!=i) y[i][j] ==1;
forall (i in Cities, k in Scs)
sum (j in Cities : j!=i , k in Scs) x[k][i][j] ==1;
// Subtour elimination constraints.
forall( k in r: 1 < card(s2[k]) < card(Cities) - 1 ) {
sum(i in s2[k], j in s2[k]) y[i][j] <= card(s2[k]) - 1; }
forall(k in Scs ,c in r : card(s2[c]) > 1 && card(s2[c]) < card(I) - 1) {
sum(i in s2[c], j in s2[c],k in Scs) x[k][i][j] <= card(s2[c]) - 1;
}
forall(i in Cities, j in Cities , k in Scs){
x[k][i][j]<=y[i][j];}
};
p
please I need your help
#CPLEXOptimizers#DecisionOptimization