I want to write the following constraint:

Let $z$ be an integer variable such that $0\le z\le M$, and $t$ be a binary variable where $M$ denotes big-M. The logical constraint is as follows:

  • if $z \leq M$ and $z > 0$ then $t=1$;

  • if $z=0$ then $t=0$.

Is this $z≤Mt$ sufficient? The $t$ and $z$ variables are not in my objective function but variable $t$ is connected to another variable in the objective function?

Thank you very much, I appreciate your help.


The big-M constraint $z \le M t$ does enforce $z > 0 \implies t = 1$, equivalently its contrapositive $t = 0 \implies z = 0$, but not the converse $$z = 0 \implies t = 0. \tag1$$ To enforce $(1)$, consider its contrapositive $$t = 1 \implies z > 0 \tag2,$$ which you can enforce via big-M constraint $$\epsilon - z \le (\epsilon - 0)(1 - t),$$ equivalently, $$z \ge \epsilon t,$$ where $\epsilon > 0$ is a tolerance that represents the smallest value of $z$ that you would consider to be positive.

  • 1
    $\begingroup$ $z$ is asserted to be integer, so $\epsilon=1$. $\endgroup$
    – prubin
    Aug 15 '20 at 20:55
  • $\begingroup$ Yep. Thanks, @prubin! $\endgroup$
    – RobPratt
    Aug 15 '20 at 20:56
  • $\begingroup$ @RobPratt Thank you very much for your answer. You've been a great help. $\endgroup$
    – che
    Aug 15 '20 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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