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
-
$\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$D.W.– D.W. ♦2020年02月11日 08:54:28 +00:00Commented 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$Tobias Dekker– Tobias Dekker2020年02月11日 11:25:42 +00:00Commented 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$user1543037– user15430372020年02月11日 15:37:57 +00:00Commented 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$D.W.– D.W. ♦2020年02月11日 17:29:26 +00:00Commented Feb 11, 2020 at 17:29
1 Answer 1
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
Explore related questions
See similar questions with these tags.