Reputation: 21
I get this error,"opl cannot extract expression", for dexpr and the first constraint when I am running the code in CPLEX. What can be the reason behind this error? How can I solve it? If you can help me, I will be really glad.
The dexpr get an error "OPL cannot extract the expression X[]*Ok[k]" in : dexpr float fromdepot=sum(m in M, j in C, k in K) X[]*Ok[k];
and the error I get is: OPL cannot extract the expression X[] and index out of bond for array "x":<1,4,1> for the first constraint: forall (j in C) ct1b: sum (k in K, i in V: i!=j) X[]==1;
My code is as follow:
//depot
int m=...;
range M=1..m;
//customer
int n=...;
range C=m+1..m+n; //mulai dari 4-11
int c=...;
range V=1..c;
//vehicle
int k=...;
range K=1..k;
int q=...; //vehicle capacity
int U=...;//limits the number of vehicle u
//operating cost between pairs of depots and customers
tuple Cij{
int i;
int j;
}
setof (Cij) operatingcost={<i,j> | i,j in C: i!=j};//diganti
//tuple route
tuple xijk{
int i;
int j;
int k;
}
setof (xijk) route={<i,j,k> | i,j in C: i!=j, k in K};
float fm[M]=...;
float cij[operatingcost]=...;
float di[C]=...;
float Ok[K]=...;
float Qm[M]=...;
//decision variable
dvar boolean X[route];
dvar boolean Y[M];
dexpr float depotestablish=sum(m in M) fm[m]*Y[m];
dexpr float fromdepot=sum(m in M, j in C, k in K) X[<m,j,k>]*Ok[k];
dexpr float travelcost=sum(i,j in C: i!=j, k in K) cij[<i,j>]*X[<i,j,k>];
//objective functions:
minimize (depotestablish+fromdepot+travelcost);
subject to{
forall (j in C)
ct1b: sum (k in K, i in V: i!=j && <i,j,k> in route) X[<i,j,k>]==1;
forall (i in C)
ct1: sum (k in K, j in V: j!=i && <i,j,k> in route) X[<i,j,k>]==1;
forall (m in M, k in K)
ct2: sum (j in V: j!=m && <m,j,k> in route) X[<m,j,k>] == 1;
forall (m in M, k in K)
ct3: sum (i in V: i!=m && <i,m,k> in route) X[<i,m,k>] == 1;
forall (h in V, k in K)
ct4: sum(i in V: i!=h && <i,h,k> in route) X[<i,h,k>] - sum (j in V: j!=h&& <h,j,k> in route) X[<h,j,k>]==0 ;
forall (k in K)
ct5: sum(i in C) di[i]*sum(j in V: j!=i&& <i,j,k> in route) X[<i,j,k>]<= q;
forall (m in M)
ct6: sum(k in K, i in C) di[i]*sum(j in V: j!=i&& <i,j,k> in route) X[<i,j,k>]==Qm[m]*Y[m];
ct7: sum (m in M, j in C, k in K:<m,j,k> in route) X[<m,j,k>]-U==0;
}
DATA:
n=8; //customer
k=4; //vehicle
m=3; //depot
c=11;
q=400;
U=4;
Qm=[534 534 534];
Ok=[2000 2000 2000 2000];
fm=[150000000, 150000000, 150000000];
cij=[3 40 20 60 50 786 54 627 29 29
30 20 21 14 40 28 5 631 23 23
4 5 40 89 28 288 9 947 96 96
627 29 54 12 288 937 104 786 97 97
631 23 5 631 937 282 85 28 53 53
947 96 9 947 96 104];
di=[200 250 150 170 225 180 220 200];
the result:
OPL cannot extract expression: X[<m,j,k>]*Ok[k].
Upvotes: 1
Views: 599
Reputation: 10059
In this code:
dexpr float fromdepot=sum(m in M, j in C, k in K) X[<m,j,k>]*Ok[k];
You could have some <m,j,k>
that are not in route
Can you change that into this?
dexpr float fromdepot=sum(m in M, j in C, k in K:<m,j,k> in route) X[<m,j,k>]*Ok[k];
Upvotes: 2