-3

I came across linear programming while trying to find a solution to a problem. I didn't use LP before so pardon if it is naive question. I hope this forum can help.

There are n tasks (x1, x2 .., xn) with current assigned values (r1, r2 .. rn) and new target values (t1, t2 ... tn). Each of the tasks has certain known constraint on upper and lower bound values (lbi <= xi <= ubi). There are also constraint across the task values. (See example for more details)

Objective is to minimize individual task deviation.

I tried with minimizing sum of absolute value deviation ($min \sum_i \left|x_i - t_i\right|$) but with that some tasks are more close to target value than others.


Edit1: Here is a simple example.

This is the input:

task current (r) target (t) LB (lb) UB (ub)
X1 500 1500 500 1500
X2 500 1500 500 1500
X3 5000 4000 4000 8000
X4 5000 4000 4000 8000

Update Eg constraint across task total values: $x_1 + x_2 \le 2000$

My initial approach: Here is the primary objective I initially created:

\begin{align} min \sum_i \left|x_i - t_i\right| \end{align}

Subject to: \begin{align} \text{lb}_i \le x_i \le \text{ub}_i \\ \sum_i x_i - \sum_i t_i = 0 \\ \ x_1 + x_2 \le 2000 \end{align}

This gave me results:

task current (r) target (t) LB (lb) UB (ub) result (x)
X1 500 1500 500 1500 1500
X2 500 1500 500 1500 500
X3 5000 4000 4000 8000 4000
X4 5000 4000 4000 8000 5000

I would want to optimize so that X1, X2, X3, X4 increase/decrease evenly close to the target. Result for X1, X2 should be 1000 and X3, X4 should be 4500 respectively.

Hope it helps.

Edit2: Model file for glpsol for above problem and the solution:

Note that Z is (same as what @RobPratt suggested): \begin{align} z_i + x_i &\ge t_i \\ z_i - x_i &\ge -t_i \end{align}

Minimize
 obj: TaskZ1 + TaskZ2 + TaskZ3 + TaskZ4
Subject to
 c0: TaskX1 + TaskX2 <= 2000
 c1: TaskZ1 + TaskX1 >= 1500
 c2: TaskZ1 - TaskX1 >= -1500
 c3: TaskZ2 + TaskX2 >= 1500
 c4: TaskZ2 - TaskX2 >= -1500
 c5: TaskZ3 + TaskX3 >= 4000
 c6: TaskZ3 - TaskX3 >= -4000
 c7: TaskZ4 + TaskX4 >= 4000
 c8: TaskZ4 - TaskX4 >= -4000
 c9: TaskX1 + TaskX2 + TaskX3 + TaskX4 >= 11000

Bounds 0 <= TaskZ1 <= 1000 0 <= TaskZ2 <= 1000 0 <= TaskZ3 <= 1000 0 <= TaskZ4 <= 1000 500 <= TaskX1 <= 1500 500 <= TaskX2 <= 1500 4000 <= TaskX3 <= 8000 4000 <= TaskX4 <= 8000 General TaskZ1 TaskZ2 TaskZ3 TaskZ4 TaskX1 TaskX2 TaskX3 TaskX4 End

Solution:

 Objective: 2000.0
TaskZ1 = 0.0
TaskZ2 = 1000.0
TaskZ3 = 1000.0
TaskZ4 = 0.0
TaskX1 = 1500.0
TaskX2 = 500.0
TaskX3 = 5000.0
TaskX4 = 4000.0

There are many solution to the above problem.

But the desired outcome: Get task value to evenly change to reduce variability: (objective still 2000)

TaskX1 = 1000.0
TaskX2 = 1000.0
TaskX3 = 4500.0
TaskX4 = 4500.0

How to achieve this?

Edit3: This question was marked closed due to initial limited info. I have been updating the question with more concrete examples and findings (thanks to @RobPratt). I have updated the description again to make it more valuable for folks that might be in similar situation.

Bdw, @RobPratt's last update to his response did the trick! There is subtle difference between $min \sum_i \left|z_i\right|$ and $min |z|$. Minimizing $|z|$ did the trick for me.

R. V.
  • 7
  • 3
  • In your example, the $\sum_i x_i - \sum_i t_i =0$ constraint is violated. – RobPratt Mar 02 '24 at 00:45
  • Sorry, I was hand-typing values. Updated to add X4. Thanks for pointing. – R. V. Mar 02 '24 at 00:46
  • Your lb values do not match in the two tables. – RobPratt Mar 02 '24 at 00:51
  • Fixed. Thanks again! – R. V. Mar 02 '24 at 01:02
  • OK, but now $x_i=t_i$ is optimal. – RobPratt Mar 02 '24 at 01:04
  • Yes, it is optimal based on sum of deviation but that's one of the objective. The optimization I am looking is to reduce variation or also minimize individual $\text|{x}_i - \text{t}_i|$ deviation. Like in above eg, X1, X2 to be evenly increasing and X3,X4 to be evenly decreasing. Is there any way to achieve that? One way I am thinking is to rerun same LP again but with different target which could be either mean or std dev from previous LP $\text{x}_i$ result. – R. V. Mar 02 '24 at 01:17
  • The optimal solution for the problem you specified does not match the values in your result column but is instead $x=(1500,1500,4000,4000)$, which already satisfies $x_1=x_2$ and $x_3=x_4$. – RobPratt Mar 02 '24 at 01:24
  • Added critical constraint which i missed while simplifying example $x_1 + x_2 \le 2000$. – R. V. Mar 02 '24 at 02:16
  • OK, with that additional constraint, minimizing $\max_i |x_i-t_i|$ yields the optimal solution you want: $x=(1000,1000,4500,4500)$. – RobPratt Mar 02 '24 at 02:51
  • How to construct such an objective or what additional constraint I may have to add? Can it be done using single LP problem? I am using glpsol if it matters. – R. V. Mar 02 '24 at 03:23
  • I updated my answer with a linearization. – RobPratt Mar 02 '24 at 04:08
  • Well, thats what i did which gave me the solution i posted. It is not maximizing deviation. – R. V. Mar 02 '24 at 04:37
  • The solution you posted has objective value 1000 instead of the optimal objective value 500. – RobPratt Mar 02 '24 at 05:13
  • Optimal value is 2000. Even with x = (1000, 1000, 4500, 4500), |1500-1000| + |1500-1000| + |4500 - 4000| + |4500 - 4000| = 2000. Am I missing anything? – R. V. Mar 02 '24 at 06:09
  • Updated question with glpsol input and output. – R. V. Mar 02 '24 at 06:33
  • I was suggesting to linearize objective (4) with a single $z$ variable, but you linearized objective (2) with multiple $z_i$ variables. I updated my answer to show the difference. For your example data, objective (4) gives your desired solution in one step. – RobPratt Mar 02 '24 at 14:46

2 Answers2

2

An alternative linearizable objective is to minimize the maximum absolute difference. Your original objective function is the $L_1$ norm, and this alternative is the $L_\infty$ norm. You can also combine the two by first minimizing one of them (primary objective), then imposing a constraint (objective cut) that the primary objective value must be no more than this minimum, then minimizing the other (secondary) objective.


I guess there are actually four main linearizable objective functions to consider: \begin{align} \sum_i \left|x_i - r_i\right| \tag1\label1 \\ \sum_i \left|x_i - t_i\right| \tag2\label2 \\ \max_i \left|x_i - r_i\right| \tag3\label3 \\ \max_i \left|x_i - t_i\right| \tag4\label4 \\ \end{align} You can minimize one of them or some combination. From your problem description, it sounds like you might have been minimizing the sum of \eqref{1} and \eqref{2} rather than $\sum_i |r_i - t_i|$, which is a constant. If $\text{lb}_i \le t_i \le \text{ub}_i$ for all $i$, then you can make both \eqref{2} and \eqref{4} zero by taking $x_i=t_i$.

To linearize \eqref{2}, introduce new decision variable $z_i$ and minimize $\sum_i z_i$ subject to additional constraints \begin{align} z_i&\ge x_i-t_i \\ z_i&\ge t_i-x_i \end{align}

To linearize \eqref{4}, introduce a new decision variable $z$ and minimize $z$ subject to additional constraints \begin{align} z&\ge x_i-t_i \\ z&\ge t_i-x_i \end{align}

RobPratt
  • 45,619
  • Thanks for the response. If the primary minimization is minimize absolute difference. How to formulate secondary objective? Would it be minimize deviation from mean to reduce variability? – R. V. Mar 01 '24 at 07:21
  • Wow. \eqref{4} did the trick. I need to $minimize |z|$ and not $minmize \sum_i \left|z_i\right|$. Thank you @RobPratt. I have been going crazy to find optimal solution. You saved my day! :D – R. V. Mar 02 '24 at 20:20
-1

I was able to achieve the desired outcome using two LP. Pending test for all corner cases. Also, not sure if this is optimal solution but better than before.

  1. First LP, Minimize the absolute sum. Same objective as posted in the question.

\begin{align} min \sum_i \left|x_i - t_i\right| \end{align}

Subject to: \begin{align} \text{lb}_i \le x_i \le \text{ub}_i \\ \sum_i x_i - \sum_i t_i = 0 \\ \ x_1 + x_2 \le 2000 \end{align}

  1. Calculate two standard deviation $sd_i$ from the first LP results $x_i$.

    • one for the tasks whose current value is less than target.
    • second for the tasks whose current value is greater than target.
  2. Second LP, Add new constraint to have absolute value within calculated sd to reduce variability.

\begin{align} min \sum_i \left|x_i - t_i\right| \end{align}

Subject to: \begin{align} \text{lb}_i \le x_i \le \text{ub}_i \\ \sum_i x_i - \sum_i t_i = 0 \\ \ x_1 + x_2 \le 2000 \\ \left|x_i - t_i\right| \le sd_i \\ \end{align}

This is the outcome I got:

TaskX1 = 1000.0
TaskX2 = 1000.0
TaskX3 = 4500.0
TaskX4 = 4500.0
R. V.
  • 7
  • 3