help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Constraint on a binary variable


From: Heinrich Schuchardt
Subject: Re: Constraint on a binary variable
Date: Wed, 30 Jun 2021 17:40:45 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

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

[Prev in Thread] Current Thread [Next in Thread]