0

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!

Xavier Nodet
  • 5,033
  • 2
  • 37
  • 48
Jeroen
  • 1
  • 1
  • I still have one more question. – Jeroen Apr 03 '20 at 12:35
  • I also need to define a set of arcs which will be all the possible combinations of i,j where i is not j and where q[i][d]>=1. How do I create this set? Could you help me with that? – Jeroen Apr 03 '20 at 12:37

1 Answers1

2

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.

Daniel Junglas
  • 5,830
  • 1
  • 5
  • 22