On 6/30/21 5:24 PM, Philippe Jugla wrote:
Hi everyone,

In my model, I have a variable "p" which has an upper bound pmax := 2.5
and a lower bound pmin := -2.5.
I would simply like to add a binary variable "sign" which takes the values :

1 if variable p is positive
0 if variable p is negative (or vice-versa)

I thought of something like :

s.t c1 : sign >= p[t] / pmax;

So if p[t] is positive : sign >0 and <1, therefore sign will be forced to 1.
However, if p[t] is negative, "sign" is greater than a negative value so
the variable is no longer constrained, and can take values 0 or 1.

How can I work things out ?

Thanks for your help

Best regards,
Philippe

var sign, binary;
var p, >= -2.5, <= 2.5;
s.t. constraint: p <= 2.5 * sign;
#maximize obj: p;
minimize obj: p;
solve;
display p, sign;
end;

Best regards

Heinrich


Reply via email to