Binary Variable to check if another variable is 0
回答済みHello together, i would like to add a binary variable to my integer program. My ILP has a integer variable 'storage' that counts how much room is left on each day. Now i want to add a binary variable for each day that checks whether the variable storage is 0. If the storage variable is larger than 0 the binary variable should be 1 and 0 if the storage variable is 0. Does anybody have an idea how i could add this constraint?
-
正式なコメント
Dear Daniel,
Let flag be a binary variable that takes on the value of one if and only if the general integer variable storage is strictly greater than zero (i.e. flag=0 when storage=0). Also, let BigM be an integer parameter that measures the biggest possible value for the variable storage. Then, you can enforce the desired behavior by adding the following auxiliary constraints:
model.addConstr(storage >= flag, name="aux_1")
model.addConstr(storage <= BigM*flag, name="aux_2")Remark1: If storage=0, then flag=0 to avoid violating constraint "aux_1".
Remark2: If storage>=1, then flag=1 to avoid violating constraint "aux_2".
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Juan, thank you so much for your quick response. I implemented this and it worked pretty well.
It led to two questions: 1) How do I implement BigM in Gurobi with Python? Do i have to import something? 2) The binary variable does not only take the value 0 and 1, but also -0. What does -0 mean?
0
投稿コメントは受け付けていません。
コメント
3件のコメント