-1

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

  • Have you looked at other questions in the [tag:integer-programming] tag, and the questions in the related list? Have you looked at https://cs.stackexchange.com/questions/51025/cast-to-boolean-for-integer-linear-programming and https://cs.stackexchange.com/q/12102/755 and https://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. – D.W. Feb 11 '20 at 08:54
  • 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. – Tobias Dekker Feb 11 '20 at 11:25
  • You need Boolean algebra http://blog.adamfurmanek.pl/2015/08/22/ilp-part-1/ + multiplication https://blog.adamfurmanek.pl/2015/08/29/ilp-part-2/ + comparisons https://blog.adamfurmanek.pl/2015/09/12/ilp-part-4/ + conditional operator https://blog.adamfurmanek.pl/2015/10/17/ilp-part-9/ and you can do whatever you like. – user1543037 Feb 11 '20 at 15:37
  • 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. – D.W. Feb 11 '20 at 17:29

1 Answers1

0

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