Reputation: 933
In AMPL I have a set of variables x[e], for some calculations I need a binary variable w[e] which equals 1 when x[e] > 0 and 0 if x[e] = 0. I tried a lot of stuff to make this constraint, but I failed to come up with something. Is this possible?
Upvotes: 1
Views: 306
Reputation: 141
I have solved your problem the following way:
var u binary;
this is our binary variable that will be 0 or 1. Then we put following constraint:
subject to U_constraint :
x <= 999999 * u;
Now when x = 0 then AMPL will make u = 0 and when x != 0 obviously u = 1.
Upvotes: 1