Absolute Value in Linear Programming

How to model an absolute value in Linear Programming?

Many of my students at Ghent University (for the course Applied Operations Research) or Vlerick Business School (for the courses Decision Sciences or Taking Sound Business Decisions) struggle with using absolute values in Linear Programming.

Since the use of absolute values is not linear, many of the students tend to use the big M method, but that is - although possible - not necessary. It can easily be done by defining two new so-called slack variables (I will call them s+ and s-) for each absolute value equation.

Let me give you an example with only one absolute value equation:

Suppose that the absolute value of two variables, X and Y, must be taken, as follows: |X-Y|, then the LP program can be formulated as follows:

min s+ + s-
subject to
Y - X <= s+
X - Y <= s-

Just check whether this is correct by using X = 5 and Y = 10 (absolute value = 5) or X = 10 and Y = 5 (absolute value is also = 5). The model will always give you 5 (i.e. the absolute value) in the objective, as shown below:

  • X = 5 and Y = 10 than s+ = 5 and s- = 0
  • X = 10 and Y = 5 than s+ = 0 and s- = 5

How elegant, isn't it? 

Download our free ORASTalks app to receive more tips and hints on topics like this!