Originally posted by: quawarty
Hi,
I am trying to write a mathematical model for a special VRP problem.
It consists of transporting an amount of products (i.e 2 products)from a set of pickup customers to a set of a delivery customers by a vehicle with a given capacity (here it is equal to 3)available at the depot. Service at each customer (delivery or pickup customers) must start and end within a given time windows. The time windows indicate when the goods can be picked up and dropped off. In addition, I assume that a product picked up fro a pickup customer can be delivered to any delivery customer. The objective is to construct routes such that the total travel distance is minimized.
You will find below the mathematical model using OPL.
However, the result are strange! I don't know where I make mistakes.
Could you please help me?
Thank you for you help.
Model.mod
//Notation//
//----------------------------------//
int n = 5;
range P = 1..2;/* set of products*/
range N = 0..n+1;/* set of customers and depots (N.B. depot is represented by the two vertices )*/
range N0 = 1..n;/* set of customers */
range N_1 = 0..n;
range N_0 = 1..n+1;
//Parameters//
//------------------------------------//
int q
N0[P] =...; /* amount of product p provided or required by customer */
int d
i in Nj in N = rand()%(3+5+1)-5; /* travel distance between customer*/
int Q = 3;/* vehicle capacity*/
int t[N][N] = ...; /* travel time between customers*/
int Ts
N_1 = ...; /* service time at a customer*/
int e[N] =
0, 0, 0, 0, 0, 0, 0; /* lower bound of the time windows*/
int l[N] =
10, 13, 27, 34, 24, 44, 41;/* upper bound of the time windows*/
int M = 10000; /* a big number*/
//--------------------------------------------------//
//Decision variables//
//--------------------------------------------------//
dvar int+ f[N][N][P]; /* load of the vehicle by product p passing through the arc (i,j)*/
dvar int+ T[N]; /*continous variable indicationg the time at which the vehicle strats serving pickup customer*/
dvar boolean x[N][N][P];/* = 1 if the arc (i,j)*/
//--------------------------------------------------//
//Objective fucntion//
//--------------------------------------------------//
minimize
sum (i in N, j in N, k in P) d[i][j] * x[i][j][k]; /* Minimize the total distance */
/* Constraint: customer is visited exactly once*/
subject to
{
forall (i in N0, k in P)
sum (j in N) x[i][j][k] == 1;
forall (j in N0, k in P)
sum (i in N) x[i][j][k] == 1;
/* Constraint: flow conservation*/
forall(j in N0, k in P)
sum(i in N) x[i][j][k] - sum (i in N) x[j][i][k] == 0;
forall (k in P)sum(i in N) x[i][0][k] == 0;
forall (k in P)x[0]
n+1[k] == 0;
forall (k in P) sum (i in N)x
n+1[i][k] == 0;
/*Conservation flow for demands*/
forall(j in N0, k in P)
sum (i in N) f[j][i][k] - sum (i in N) f[i][j][k] == sum(k in P) q[j][k];
/*capacity constraint*/
forall(i in N, j in N, k in P)
f[i][j][k] <= Q * x[i][j][k];
/*constraints ensures that the time windows*/
forall(i in N)
e[i]<= T[i] <= l[i];
forall (j in N_0, i in N_1, k in P)
T[j] >= T[i] + Ts[i] + t[i][j] - M *(1 - x[i][j][k]);
}
data.dat
q =[
2, 1 3,0 -1, 0 -2, -1 -2, 0];
t = [
0 1 7 10 9 6 0 1 0 2 8 7 9 1 7 2 0 3 6 8 7 10 8 3 0 4 11 10 9 7 6 4 0 5 9 6 9 8 11 5 0 6 0 1 7 10 9 6 0];
Ts =
0, 1, 2, 3, 1, 1;
#DecisionOptimization#OPLusingCPLEXOptimizer