CPLEX model, data seems to be correct, but when I run it I get the wrong answer

127 Views Asked by At

I started learning OPL for a university project, to program the following model, and solve it given certain data. I've programmed it, as well as the data, but I'm not getting the answer I'm supposed to get, I'm not sure what's wrong. model data

I've read my data several times, and I'm sure every number is correct, so is it something to do with I've set up the matrices? My .mod file is the folloiwng:

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] =...; //p_vij
   
range Nc=1..n; range Vc=1..v;
   float c[Vc][Nc][Nc] =...; //c_vij
   
range Nd=1..n; range Td=1..t;
   float d[Td][Nd][Nd] =...; //d_tij

range Nm=1..n; range Tm=1..t; range Vm=1..v;
   int m[Vm][Nm][Tm] =...; //m_vit
   
range NA=1..n; range VA=1..v;
   int A[VA][NA][NA] =...; //A_vij
   
range Ntau=1..n;;
   int tau[Ntau][Ntau] =...; //
   
dvar boolean x[N][N][T][V]; //x_ijtv
dvar boolean y[N][N][T][V]; //y_ijtv

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:(t-1) in T)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]; // (2)

  forall(i in N, j in N, t in T)
    sum(v in V) x[i][j][t][v] <= d[t][i][j]; //(3)

  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; //(4)

} 

and my .dat file is:

n = 6;
t = 6;
v = 2;

c = \[\[  \[0 1 2 2 2 2\]
\[1 0 2 2 2 2\]
\[2 2 0 2 1 1\]
\[2 2 2 0 1 1\]
\[2 2 1 1 0 1\]
\[2 2 1 1 1 0\]\]

\[  \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 0 0\]\]
\];

m = \[\[  \[0 0 0 0 0 0\]
\[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\]
\[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\]
\[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\]\];

When I run it, all the x values are 0 and some of the y values are 1. Given that data, I am supposed to get x5612=x5151=y6511=y6531=y1161=y5541=1, x4222=x2332=y3352=y3362=1, while the rest are 0.

1

There are 1 best solutions below

8
On

Have you tried to change

forall(i in N, t in T, v in V:(t-1) in T)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]; // (2)

into

forall(i in N, t in T, v in V:(t-1) in T)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][t-tau[k][i]][i][v] + y[k][t-tau[k][i]][i][v])-
   y[i][i][t-1][v] == m[v][i][t]; // (2)

?

This was not a good idea. You seem to be right.

Idea to debug your model.

Set your solution through

x[5][6][1][2]==1;
x[5][1][5][1]==1;

Turn your constraints to soft constraints

 forall(i in N, j in N, t in T)
    ct3:sum(v in V) x[i][j][t][v] <= d[t][i][j]; //(3)

You will get relaxations and then you can debug

relaxation