1
$\begingroup$

Let $K$ and $Q$ be two variables, and $Q_\min$ and $Q_\max$ be two parameters. I need a series of linear constraints to define $Q$ vis-a-vis the value of $K$ based on the following rules:

  1. If $K \le Q_\min$ then $Q = Q_\min$
  2. If $K \ge Q_\max$ then $Q = Q_\max$
  3. If $Q_\min \le K \le Q_\max$ then $Q = K$
$\endgroup$
2
  • 1
    $\begingroup$ Do you have lower and upper bounds on $K$? Are $K$ and $Q$ integer variables or continuous? $\endgroup$
    – RobPratt
    Mar 1, 2023 at 21:12
  • $\begingroup$ @RobPratt The variable are continuous, and we should be able to define bounds on $K$ in the form of big $M$. $\endgroup$
    – Iman
    Mar 2, 2023 at 4:37

1 Answer 1

2
$\begingroup$

Assume $K_\min \le K \le K_\max$, and introduce binary decision variables $x_i$ for the three cases (reordered as 1, 3, 2), together with linear constraints \begin{align} \sum_{i=1}^3 x_i &= 1 \tag1\label1 \\ K_\min x_1 + Q_\min x_2 + Q_\max x_3 \le K &\le Q_\min x_1 + Q_\max x_2 + K_\max x_3 \tag2\label2 \\ Q_\min \le Q &\le Q_\min x_1 + Q_\max(1-x_1) \tag3\label3 \\ (Q_\min-K_\max)(1-x_2) \le Q - K &\le (Q_\max-K_\min)(1-x_2) \tag4\label4 \\ Q_\max x_3 + Q_\min(1-x_3) \le Q &\le Q_\max \tag5\label5 \end{align} Constraint \eqref{1} selects exactly one case. Constraint \eqref{2} enforces the bounds on $K$ for each case. Constraints \eqref{3} through \eqref{5} enforce the value of $Q$ for each case.


You could alternatively replace \eqref{3} through \eqref{5} with indicator constraints: \begin{align} x_1 = 1 &\implies Q = Q_\min \\ x_2 = 1 &\implies Q = K \\ x_3 = 1 &\implies Q = Q_\max \end{align}


Yet another approach is to recognize that $Q$ is a nonconvex and nonconcave continuous piecewise linear function of $K$ and use any formulation for that, such as the ones recommended in the answers to How to linearize specific range constraints?.

$\endgroup$
3
  • $\begingroup$ Rob, the RHS of (3) and the LHS of (5) are kaput. $\endgroup$
    – prubin
    Mar 1, 2023 at 23:51
  • $\begingroup$ @prubin Somehow my comment was deleted, but I did correct these. $\endgroup$
    – RobPratt
    Mar 2, 2023 at 13:24
  • $\begingroup$ I saw your comment before it was deleted (by SecretAgentMan, for unknown reasons). $\endgroup$
    – prubin
    Mar 2, 2023 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.