1

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].
ndns
  • 21
  • 3

1 Answers1

2

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];
halfer
  • 19,824
  • 17
  • 99
  • 186
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Thank you so much Alex, it works. but after that the first constraint (ct1b) get an error: cannot extract expression: ct1b: sum(k in 1..4, i in 1..11: i != j) X[] == 1. can you help me? – ndns Sep 08 '19 at 02:41
  • If you need to add `` to your paragraph text, please use backticks so it is rendered as inline code, otherwise it will be treated as (invalid) HTML. – halfer Sep 08 '19 at 10:11
  • Hi, do the same : change ct1b: sum(k in 1..4, i in 1..11: i != j) X[] == 1. into ct1b: sum(k in 1..4, i in 1..11: i != j && in route) X[] == 1. – Alex Fleischer Sep 08 '19 at 11:08
  • hi @AlexFleischer thank you so much.. but, after I changed all of the constraints, it gets a relaxed solution in every constraint except ct4 ct5 and ct6, i have edited the new code and the data in the column code, – ndns Sep 08 '19 at 16:26
  • This means your model is not feasible. You should have a look at the relaxations and conflicts – Alex Fleischer Sep 08 '19 at 17:59
  • i'm sorry @AlexFleischer , i am a beginner in cplex so i dont know what to do, can you tell me specifically what should i fix first? thank you – ndns Sep 09 '19 at 03:47
  • Hi, hard to help you in 2 lines but please have a look at IDE and OPL > CPLEX Studio IDE > IDE Tutorials / Relaxing infeasible models in the CPLEX documentation – Alex Fleischer Sep 09 '19 at 07:08