0
$\begingroup$

I want to create constraints such that I can implement the following condition:

Let A be an integer variable>= 0 with an upper bound of 12

I want to introduce the following variable B also an integer:

if A = 1 then B = 0 else B = A

asked Feb 11, 2020 at 8:21
$\endgroup$
4
  • $\begingroup$ Have you looked at other questions in the integer-programming tag, and the questions in the related list? Have you looked at cs.stackexchange.com/questions/51025/… and cs.stackexchange.com/q/12102/755 and cs.stackexchange.com/q/76549/755? I suspect you'll find that the question is answered there. Also please edit your question to indicate whether you know of an upper bound on A or not. $\endgroup$ Commented Feb 11, 2020 at 8:54
  • $\begingroup$ I checked all these topics but could not found a solution for this question. Most of the answers are about boolean variables and not integers, which makes it more complicated. $\endgroup$ Commented Feb 11, 2020 at 11:25
  • $\begingroup$ You need Boolean algebra blog.adamfurmanek.pl/2015/08/22/ilp-part-1 + multiplication blog.adamfurmanek.pl/2015/08/29/ilp-part-2 + comparisons blog.adamfurmanek.pl/2015/09/12/ilp-part-4 + conditional operator blog.adamfurmanek.pl/2015/10/17/ilp-part-9 and you can do whatever you like. $\endgroup$ Commented Feb 11, 2020 at 15:37
  • $\begingroup$ The first question I linked is about integers. The second also discusses about integers; see "cast to boolean". There are also other questions in the tag that are about integers. I suggest spending a little more time to read through that material and learn about the typical techniques used there, and I suspect that will give you some ideas how to handle your particular situation. $\endgroup$ Commented Feb 11, 2020 at 17:29

1 Answer 1

0
$\begingroup$

you can introduce a binary variable z verifying the following constraints :

  • (A-1) <= 12*z

  • z<= 0.5*A

  • -(1-z)*12 <= B-A <= (1-z)*12

  • -12*z <= B <= 12*z

answered Feb 12, 2020 at 15:07
$\endgroup$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.