Reputation: 119
I'm trying to formulate a constraint for a MIP problem that involves binary variable v and continuous variable i, such as:
if i = 0, v = 0, and if i > 0, v = 1
I haven't been able to think of a solution to this and I'm not sure if there is a solution. Any suggestion is greatly appreciated. Thank you!
Upvotes: 0
Views: 1101
Reputation: 2072
You can also model this using the 'traditional' Big-M formulation which is documented in many places on the internet and in many textbooks.
Usually this is done in a pair of constraints like this:
i <= M * v
This forces i to be zero if v is zero, and also if i is non-zero then v must be 1 which covers most of your requirement, but still allows i = 0 and v = 1. In many cases the objective is trying to minimise some expression including v and that may be sufficient to encourage v=0 when i=0. But don't fall into the silly error of using a really big value for M as that will adversely affect your linear relaxations and possibly overal performance.
Then you might also need to add a further constraint to force v to zero if i is zero such as:
v <= i
which would have the effect of directly forcing v to zero if i is zero.
Upvotes: 3
Reputation: 10059
you can rely on logical constraints. In OPL you can write
dvar boolean v;
dvar float+ i;
subject to
{
v==!(i==0);
}
And you can do the same with all CPLEX APIs
Upvotes: 1