Hello! I started with CPLEX 2 days ago, to develop a university project, without having any prior knowledge. Needless to say, it's been hard to learn everything in this little timeframe. The objective is to program the following model, and run it with certain given data.
This is my .mod:
int n=...; //set of terminals
range N=1..n;
int t=...; //set of time periods
range T=1..t;
int v=...; //set of vehicles
range V=1..v;
range Np=1..n; range Vp=1..v;
float p[Vp][Np][Np] =...;
range Nc=1..n; range Vc=1..v;
float c[Vc][Nc][Nc] =...;
range Nd=1..n; range Td=1..t;
float d[Td][Nd][Nd] =...;
range Nm=1..n; range Tm=1..t; range Vm=1..v;
int m[Vm][Nm][Tm] =...;
range NA=1..n; range VA=1..v;
int A[VA][NA][NA] =...;
range Ntau=1..n;;
int tau[Ntau][Ntau] =...;
dvar boolean x[N][N][T][V]; //π₯πππ‘π£ βΆ takes the value of 1 if vehicle π£ β π start moving a load from terminal π to terminal π beginning at time π‘ to satisfy the demand ππππ‘, βπ β π, π β π and π‘ β π , and 0 otherwise;
dvar boolean y[N][N][T][V]; //π¦πππ‘π£ βΆ takes the value of 1 if vehicle π£ β π start moving empty from terminal π to terminal π beginning at time π‘, βπ β π, π β π and π‘ β π , and 0 otherwise.
dexpr float f=sum(i in N,j in N:i!=j,t in T, v in V)(p[v][i][j]*x[i][j][t][v] - c[v][i][j]*y[i][j][t][v]);
maximize f;
subject to {
forall(i in N, t in T, v in V)sum(j in N)(x[i][j][t][v] + y[i][j][t][v])- sum(k in N: k != i, t_ in T: t_ > tau[k][i])(x[k][i][t_-tau[k][i]][v] + y[k][i][t_-tau[k][i]][v])- y[i][i][t-1][v] == m[v][i][t];
forall(i in N, j in N, t in T)
sum(v in V) x[i][j][t][v] <= d[t][i][j];
forall(i in N, j in N, t in T, v in V)
A[v][i][j] == 0 => x[i][j][t][v] == 0 && y[i][j][t][v] == 0;
forall(i in N, j in N, t in T, v in V)
x[i][j][t][v] >= 0 && x[i][j][t][v] <= 1 && y[i][j][t][v] >= 0 && y[i][j][t][v] <= 1;
}
and this is my .dat:
n = 6;
t = 6;
v = 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 0] //m_itv
[0 0 0 0 0 0]
[0 0 0 0 0 0]
[0 0 0 0 0 0]
[0 0 0 0 0 0]
[1 0 0 0 0 0]]
[ [0 0 0 0 0 0]
[0 0 0 0 0 0]
[0 0 0 0 0 0]
[0 1 0 0 0 0]
[0 0 0 0 0 0]
[0 0 0 0 0 0]]
];
A = [[ [1 0 1 1 1 1] //A_ijv
[0 1 1 1 1 1]
[1 1 1 1 1 1]
[1 1 1 1 1 1]
[1 1 1 1 1 1]
[1 1 1 1 1 1]]
[[1 0 1 1 1 1]
[0 1 1 1 1 1]
[1 1 1 1 1 1]
[1 1 1 1 1 1]
[1 1 1 1 1 1]
[1 1 1 1 1 1]]
];
tau = [[1 2 1 1 1 2] //tau_ij
[2 1 2 1 2 3]
[1 2 1 1 3 2]
[1 1 1 1 1 3]
[1 2 3 1 1 1]
[2 3 2 3 1 1]];
I'm sure there are easier and more efficient ways to do what I'm trying to do, but I would like to know what's wrong with my code?
All of these errors are happening on constraint (2), so I'm not sure if there's anything else wrong.
Thanks!
------------------------------
TomΓ‘s Bandeira
------------------------------