Reputation: 1
I have to use absolute value in the cost function of some linear problem. Part that bother me like this
for (t=0;t<T;t++)
for (i=0;i<I; i++){
for (j=1;j<J; j++)
Sum += |x[i][j][t]-x[i][j][t-1]|*L/2;
Sum += |x[i][0][t]-x[i][0][t-1]|*V/2;
}
I am writing my code in c++ and I don't know how to implement absolute value. x is integer value. I have tried with cplex.getValue(x[i][j][t])-cplex.getValue(x[i][j][t-1]) >0 but it couldn't work.
Upvotes: 0
Views: 1749
Reputation: 250
Since the absolute value function is nonlinear ( the reason is explained in this math question ) you need to linearize the objective function first.
Basically, you need to express each absolute-valued-term of that summation with a new variable and optimize the sum of these new variables (subject to some additional constraints). The method is explained in detail in Section 7.2 of Linear Programming textbook of Thomas S. Ferguson.
Upvotes: 1