# Decision Optimization

View Only

## Cannot Extract Expression Error

• #### 1.  Cannot Extract Expression Error

Posted Wed September 13, 2023 10:47 AM

Hi everyone,

I am new to Cplex and trying to learn and code at same time. Currently I am trying to code a location routing problem. I took some examples from my friends and I wrote the code same way they did. However I get Cannot Extract Expression error and ı cannot understand the root cause. I share my code below:

---- Code:

// Sets

{int} D = ...; //Demand points
{int} P = ...; // Potential depot Locations
int K = 2; // Car Number
int M = 9999999; // A Big Number

int dabs = 7; // Number of demand points

// arcs
tuple Route {
int i;
int j;
}

{Route} Routes = ...;

//parameters

float t[Routes] = ...; // transfer time i - j

// variables

dvar boolean X[Routes]; // route decision
dvar boolean Y[P]; // location openning dec.
dvar boolean Z[P][D]; // if node j covers node i's demand
dvar int+ U[P union D]; // visit order

// OBJ func.

minimize
sum (i in P union D, j in P union D) X[<i,j>] * t[<i,j>] + sum (i in D, j in D) Z[i][j] * t[<i,j>];

// subject to
subject to {

// cons 1

forall (i in P){
sum (j in D, <i,j> in Routes) X [<i,j>] == Y[i];

// cons 2

forall (i in P) {
sum(j in D, <i,j> in Routes) X[<j,i>] == Y[i];
}

// cons 3
forall (j in D) {
sum(i in P union D, <i,j> in Routes) X[<i,j>] == sum(i in P union D, <i,j> in Routes) X [<j,i>];
}

// cons 4

forall(i in D) {
sum (j in P union D, <i,j> in Routes) X[<i,j>] == Z [i][i];
}

// Cons5
forall(i in D){
sum(j in D) Z [i][j] == 1;
}

// cons 6
forall(<i,j> in Routes){
U[i] - U[j] + (1-X[<i,j>]) * M <= 0;
}

// cons7
forall(i in D){
1 <= U[i]<= dabs+1;
}

// cons 8

sum(i in P) Y[i] <= K;

}

I use Excel for data and I did not get any error from .dat
Could you help or point out the root cause ?
Thank you very much.

------------------------------
Kaan Kılıç
------------------------------

• #### 2.  RE: Cannot Extract Expression Error

IBM Champion
Posted Wed September 13, 2023 11:07 AM

In the last term of your objective function, you are summing over i in D. Should that be i in P?

------------------------------
Paul Rubin
Professor Emeritus
Michigan State University
------------------------------