help-glpk
[Top][All Lists]
Advanced

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

Constraint on a binary variable


From: Philippe Jugla
Subject: Constraint on a binary variable
Date: Wed, 30 Jun 2021 15:24:18 +0000

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

reply via email to

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