How can I create constraints to make sure $x=1$ if $k\geq 0$ and $x=0$ if $k<0$, where $x\in \{0,1\}$ and $k\in \mathbb{R}$?

Here is my attempt: \begin{equation}\label{cons:1} \begin{aligned} k\leq Mx \end{aligned} \end{equation}

Considering $M$ as the big-M, the above constraint makes sure $x=1$ if $k>0$. Surely, it is missing all other components.

  • 6
    $\begingroup$ Have you checked some of the questions posted on the site? Such as here or here? $\endgroup$
    – EhsanK
    Jul 1, 2019 at 18:49
  • $\begingroup$ maybe you edit your original question so that it contains this more concise statement. And as @EhsanK says, there may be an answer here already (namely, that strict inequalities require an epsilon to model). $\endgroup$ Jul 1, 2019 at 18:55
  • $\begingroup$ @EhsanK, I have just checked those posts. $\endgroup$
    – tcokyasar
    Jul 1, 2019 at 19:14
  • $\begingroup$ @MarcoLübbecke, do you mean I can introduce $k+\epsilon \leq Mx$ to make sure $x=1$ if $k\geq 0$ ? Then, what is the next constraint to ensure $x=0$ when $k<0$? $\endgroup$
    – tcokyasar
    Jul 1, 2019 at 19:17
  • $\begingroup$ I feel the next constraint is $k\geq -M(1-x)$. Please correct me if I am wrong. $\endgroup$
    – tcokyasar
    Jul 1, 2019 at 19:22