# How to write constraint with sum of absolutes in Integer Programming?

I found a solution for just one term here

How can we formulate constraints of the form

$$\sum_{i=1}^n |x_i -a_i| \ge K$$

in Mixed Integer Linear Programming ?

• or.stackexchange.com/search?q=linearize+absolute+value+ Aug 18, 2022 at 11:05
• None of those actually help, since the abs in those occurs in the objective which is minimized. Here one a needs a small epsilon approach to prevent one term from growing larger then abs and thereby fulfilling the inequality when it should no be fullfilled. Aug 18, 2022 at 11:47
• Here is a very explicit reference. fico.com/fico-xpress-optimization/docs/latest/mipform/dhtml/… Then sum of the y's >= R Aug 18, 2022 at 12:42
• That one works. Did big M over small epsilon. Neat. Do you wanna write up an answer post? Aug 18, 2022 at 13:32
• Not really. That's why I wrote a comment. Have at it. Actually needs to be modified a bit to introduce a lower bound which might not be 0 as was assumed in the link. Aug 18, 2022 at 14:05

In CPLEX you can use the absolute value. For instance with the OPL API you can write

int n=5;
range r=1..n;

int K=10;

int a[i in r]=i;
dvar int x[r];

subject to
{
sum (i in r) abs(x[i]-a[i])>=K;
}