Jeroen
Jeroen

Reputation: 1

How do I formulate these ConVRP constraints in CPLEX?

I am trying to build a conVRP model with hard time window constraints. However, I am stuck with the inflow and outflow constraints.

I have four sets:

range N = 1..20 // set of Nodes

range P = 1..19 // set of customers

range D = 1..5 // set of Days

range K = 1..2 // set of Vehicles

Then I have some other input parameters

int q[D][N] = ...; //demand matrix of 5*20

int cap = ...; // capacity of a truck

Three decision variables:

dvar boolean x[N][N][D][K]; //= one if node i visits node j on day d with vehicle k

dvar float+ y[N][D][K]; // arrival time 

dvar boolean z[N][K]; // = one if node n is visisted by vehicle k

//objective

minimize sum(i,j in N, d in D, k in K) x[i][j][d][k] * c[i][j]; 

The constraints I am having trouble with are:

forall(d in D, i in N: q[i][d]>=1)
   sum (j in N, k in K) x[i][j][k][d] == 1; //outflow 

forall(d in D, j in N : q[j][d]>=1)
  sum(i in N, k in K) x[j][i][k][d] == 1; //inflow

I get these error messages:

Image

I would love to know how to fix this problem. Your help would be appreciated!

Upvotes: 0

Views: 98

Answers (1)

Daniel Junglas
Daniel Junglas

Reputation: 5930

You get an index out of bound error. This is because you have this definition

int q[D][N] = ...; //demand matrix of 5*20

but then do

forall(d in D, i in N: q[i][d]>=1)

It looks like you swapped the indices for q here. According to your definition, d should be the first and i should be the second index. Note that the same problem seems to exist for the last two indices for x.

Upvotes: 2

Related Questions