I have a problem in building the expression for transportation costs in CPLEX. In particular, it is a piecewise linear function of the flow of material, reflecting economies of scale. Consider the transportation cost from Plant to Warehouse, we denote T[f][j][m] and Qf1[f][j][m][r] as the baseline transportation cost for transporting the product of family f from plant j to warehouse m and the flow of material of product family f from plant j to warehouse m, respectively. r stands for the range to which the flow belongs. This is the code
sum(f in Fa, j in Pl, m in Wh, r in ra)
piecewise(t in 1..NbPieces-1) {Coef[t]*T[f][j][m] -> Breakpoint[t]; Coef[NbPieces]*T[f][j][m]} Qf1[f][j][m][r];
This is my .dat file
NbPieces=4;
Coef=[1, 0.95, 0.89, 0.8];
Breakpoint=[40, 100, 1000];
However, the program cannot extract the expression. Can someone help me solve this error?
Edit: Thanks, Alex Fleischer! I fixed the above one. However, the optimal solution is still not achieved. I think I did make other mistakes. When I added constraints to make sure that the sum of flow of products in each products family must be equal to the flow of that product family from one stage to another stage, I am not sure whether it is right or not.
This is my code of that constraint, Q2 is the rate of flow of product i from warehouse m to distribution center k and Qf2 is the rate of flow of product family f from warehouse m to distribution center k. Family 1 includes products 1-6, 10. Family 2: 7-9, Family 3: 11-14.
forall (i in pr, m in Wh, k in DC)
sum(i in pr:i<=6 || i==10) Q2[i][m][k] == sum(r in ra,f in Fa:f==1)Qf2[f][m][k][r];
forall (i in pr, m in Wh, k in DC)
sum(i in pr:i<=9 || i>=7) Q2[i][m][k] == sum(r in ra,f in Fa:f==2)Qf2[f][m][k][r];
forall (i in pr, m in Wh, k in DC)
sum(i in pr:i>=11) Q2[i][m][k] == sum(r in ra,f in Fa:f==3)Qf2[f][m][k][r];
You have out of bounds errors but if you change
sum(f in Fa, k in DC, l in CZ, r in ra)
piecewise(t in 1..NbPieces-1) {Coef[t]*T3[f][k][l] -> Breakpoint[t]; Coef[NbPieces]*T3[f][k][l]} Qf2[f][k][l][r];
into
sum(f in Fa, k in DC, l in CZ, r in ra)
piecewise(t in 1..NbPieces-1) {Coef[t]*T3[f][k][l] -> Breakpoint[t]; Coef[NbPieces]*T3[f][k][l]} Qf3[f][k][l][r];
Then it works. Are you sure about Qf2 here ? Qf3 works fine