Re: Constraint on a binary variable
Michael Hennebry <[email protected]> Thu, 1 Jul 2021 15:56:06 -0500 (CDT)
| Newsgroups | gmane.comp.gnu.glpk |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 30 Jun 2021, Philippe Jugla wrote: > 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) A solution is the convex hull of two line segments in (sign, x)-space: (0, -2.5) (0, 0) and (1, 0) (1, 2.5) This is 2-dimensional and the parallelogram is easily drawn. Two of the sides are 0<=sgn<=1 . The other two are -2.5 <= p - 2.5*sign <= 2.5 . No need to play games with the objective function. -- Michael [email protected] "Sorry but your password must contain an uppercase letter, a number, a haiku, a gang sign, a heiroglyph, and the blood of a virgin." -- someeecards