Constraint on a binary variable

Philippe Jugla <[email protected]> Wed, 30 Jun 2021 15:24:18 +0000
Newsgroups gmane.comp.gnu.glpk
Message-ID <AS8PR09MB4774CA434429D8BE9DEDC71FF0019@AS8PR09MB4774.eurprd09.prod.outlook.com>
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