0
$\begingroup$

I am trying to formulate an optimization problem with the following constraint: $y = 1$ if $x \le c$ and $y = 0$ if $x > c$ which is basically an indicator function $y = 1[x \le c]$ and $c$ would be the decision variable here (hence $y$).

I noticed that big-M is the typical way of dealing with indicator constraints but it only works for the opposite direction: e.g., if $y = 1$ then $x \le c$.

I wonder if there's a way of formulating this as an optimization constraint. Thank you!

Update: The optimization problem would be something like \begin{align*} & \max \;\; f(y) \\ & \text{s.t.} \;\; y = 1[x \le c]\\ & y = \{0,1\}, c \in \mathbb{R} \end{align*} where $x$ is a fixed parameter. The objective function is a function of $y$, so we would like to optimize the choice of $c$ (which can be thought of as a threshold) such that $f(y)$ is maximized/minimized.

$\endgroup$
5
  • $\begingroup$ Could you describe more precisely your optimization problem? In particular, what is the respective status of $c$, $x$ and $y$: which can be chosen, which is fixed, what are you optimizing, and so on... $\endgroup$
    – cs89
    Commented Apr 13, 2023 at 19:00
  • $\begingroup$ @cs89 Thanks for the reply! I've made a few edits to the original problem. Basically, x is fixed and given, c is the variable that I am optimizing. $\endgroup$
    – Juan
    Commented Apr 13, 2023 at 19:27
  • $\begingroup$ I am still missing something. You say $x$ is fixed. Let us say that $x = 0$ for example. Then you are looking for the "best" $c \in \mathbb{R}$. But $y$ can only take 2 values. So any $c < 0$ will give $f(0)$ and any $c > 0$ will give $f(1)$. So depending on whether $f(0) < f(1)$ (or the converse), the optimal choice of $c$ is any $c < 0$ (or the converse). There must be a difficulty I don't understand. $\endgroup$
    – cs89
    Commented Apr 13, 2023 at 21:57
  • $\begingroup$ @cs89 Sorry for the confusion. The actual problem I'm having has an objective function of something like $f(y_{1}, y_{2}, ..., y_{n})$ and each $y_{i} = 1[x_{i} \le c]$. A way to think of is that $x_{i}$ are the data points and we want to pick the best cutoff $c$ such that $f(y_{1}, y_{2}, ..., y_{n})$ is maximized/minimized $\endgroup$
    – Juan
    Commented Apr 14, 2023 at 18:10
  • $\begingroup$ Thanks for the clarification. If I understand correctly, up to sorting the data points $x_i$ by increasing value, there are thus at most $n$ "interesting" values of the common threshold $c$. Is testing all of them impractical? $\endgroup$
    – cs89
    Commented Apr 14, 2023 at 20:57

2 Answers 2

4
$\begingroup$

You want to enforce two implications: \begin{align} x \le c &\implies y = 1 \\ x > c &\implies y = 0 \end{align} Equivalently, you want to enforce their contrapositives: \begin{align} y = 0 &\implies x > c \tag1\label1 \\ y = 1 &\implies x \le c \tag2\label2 \end{align} Assume $L_c \le c \le U_c$ for constants $L_c$ and $U_c$. As you suggested, \eqref{2} can be enforced by a big-M constraint: $$x - c \le (x-L_c)(1-y)$$ If you introduce a small constant tolerance $\epsilon>0$, \eqref{1} can also be enforced by a big-M constraint: $$c - x + \epsilon \le (U_c-x+\epsilon)y$$


Another way to think about this is that you want $x \le c \le U_c$ if $y=1$ and $L_c \le c \le x-\epsilon$ if $y=0$. So combine these two constraints as $$xy + L_c(1-y) \le c \le U_c y + (x-\epsilon)(1-y)$$

$\endgroup$
3
  • $\begingroup$ Thanks for the reply. I think I am looking for the opposite: $x\le c \Rightarrow y = 1$ and $x > c \Rightarrow y = 0$. Is it possible to express it in a similar way? $\endgroup$
    – Juan
    Commented Apr 14, 2023 at 8:39
  • $\begingroup$ The model I proposed does both. I added some clarification to my answer. $\endgroup$
    – RobPratt
    Commented Apr 14, 2023 at 14:12
  • $\begingroup$ I see now, thank you so much! $\endgroup$
    – Juan
    Commented Apr 14, 2023 at 22:10
0
$\begingroup$

$ (1-y)L_c \le c-x \le yU_c + \epsilon(y-1)$
where $0 \gt U_c$ is ub & $ L_c \lt 0$ is lb for $c$ & $0 \lt \epsilon$ is a small number.

$\endgroup$
1
  • 1
    $\begingroup$ This has some errors. $\endgroup$
    – RobPratt
    Commented Apr 14, 2023 at 1:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .