combining constraints

70 views
Skip to first unread message

Jack

unread,
May 10, 2020, 11:28:57 PM5/10/20
to YALMIP
I have the following constraint

lb <= x <= ub

and I would like to combine it with the additional constraint

L <= x <= U   or   x = 0

i.e., if x is not at least L, U then set x to 0. However, if x is beyond the bounds of L, U, then, it needs to be bounded/overlayed by the above [lb, ub].
I would be able to combine the two constraints using min's of upper bound and max's of lower bound, but, am not sure how to deal with the x = 0. Any advice on doing this would be much appreciated. Thank you

Johan Löfberg

unread,
May 11, 2020, 2:01:08 AM5/11/20
to YALMIP
That's called a semi-continuous variable, semivar, supported by some of the integer solvers

If your solver doesn't support it, introduce a binary variable z, and add constraints [L*z <= x <= U*z]

Jack

unread,
May 12, 2020, 5:20:06 PM5/12/20
to YALMIP
thank you for your reply. i am using mosek and believe that it does support that. do i just need to define the binary variable z and add on this constraint [L*z <= x <= U*z] in conjunction to my other one lb <= x <= ub? Do i need to optimize any function of z in the objective as wel

Jack

unread,
May 12, 2020, 6:02:56 PM5/12/20
to YALMIP
Also, another follow up Q to this --> i need to guarantee that for every factor of the upper (U > 0) and lower bounds (L <= 0), the result would be ceiled:

U < x < 2*U  then x = U; if 2*U < x < 3*U then x = 3*U

2*L < x <  L  then x = L; if 2*L < x < 3*L then x = 3*L

I would appreciate your help on these two. Thank you.

Jack

unread,
May 12, 2020, 6:20:50 PM5/12/20
to YALMIP
apologies, the result is rounded (not ceiled) to the nearest bound so

if x < U/2 then x = 0

thank you

Johan Löfberg

unread,
May 13, 2020, 1:09:11 AM5/13/20
to YALMIP
only cplex and gurobi support sem-continuous natively, i.e. semivar

The constraint [lb <= x <= ub] is redundant when you have [L*z <= x <= U*z]  in the model (assuming lb=L and ub=U, nothing else makes sense). But of course, it doesn't matter if you happen to have redundant stuff in the model

The objective got nothing to do with setting up a semi-continuous structure

Johan Löfberg

unread,
May 13, 2020, 1:13:40 AM5/13/20
to YALMIP
This makes no sense with semi-continuous models. Then would either have L>0 and U>0 or L<0 and U<0. If they have different signs, it is not a semi-continuous model as 0 is included in the range, so it is a standard variable

It is not clear what you are talking about here. It sounds like you simply is saying x is integer or quantized. However since U is an upper bound (?) saying x > U makes no sense

Johan Löfberg

unread,
May 13, 2020, 1:18:32 AM5/13/20
to YALMIP
Now it sounds like you re talking about something like [L*z <= x <= U*z,  x >= U/2*z1, x <=  L/2*z2, z == z1+z2] for binary z,z1,z2 (either 0, or outside L/2 <= x<=U/2 but inside L <= x <= U)

Jack

unread,
May 13, 2020, 10:50:06 PM5/13/20
to YALMIP
thank you for your reply. I had come across the semi-continuous var in sec 9.1.2 here

Apologies for the ambiguity --> x is originally a continuous variable in my optimization (with constraint lb <= x <= ub) and I was looking to add on to this constraint so that x is returned as an integer rounded to L, U (s.t. these are not equal to lb, ub -- do realize this would be redundant and the optimizer would take into account when it sees this) depending on which side x is on since L <= 0, U > 0. So, for the case

1. x nonnegative and if 0 < x < U then the continuous x be rounded to nearest bound. similarly, if U < x < 2U then the continuous x be rounded to nearest bound

2. x nonpositive and if L < x < 0 then the continuous x be rounded to nearest bound. similarly, if 2*L < x < L then the continuous x be rounded to the nearest bound

I could do this post-optimization, but, would have liked to encode these requirements as a constraint itself. Thank you again.

Johan Löfberg

unread,
May 14, 2020, 1:36:15 AM5/14/20
to YALMIP
So with U = 10, you are effectively saying x is 0, 10 or 20, i.e. ismember(x,[0 10 20]), etc when you have the negative values

Jack

unread,
May 14, 2020, 2:00:16 AM5/14/20
to YALMIP
Could I embed this as a constraint on top of the lb, ub? would it tantamount to the one you provided above
[L*z <= x <= U*z,  x >= U/2*z1, x <=  L/2*z2, z == z1+z2] for binary z,z1,z2
and could I also have the bound with lb, ub on "x"?

Im thinking that performing the round post-optimization would not be an optimal soln?

Johan Löfberg

unread,
May 14, 2020, 2:06:53 AM5/14/20
to YALMIP
You can add as much as you want. They are either redundant or relevant, or causes infeasibility

Looks weird though, as those are semicontinuous (x either 0 or larger than U/2 etc) and then you want to add the new quantization on top of that (x either 0 or U or 2U). Taken together that is simply x is either 0, U or 2U so the semicontinuous structure is just redundant

post-procssing is typically sub-optimal. if it wasn't, integer programming would be trivial 

Jack

unread,
May 14, 2020, 1:47:31 PM5/14/20
to YALMIP
Thank you again - would the optimizer accept multiples of L, U as a constraint on x?
Realize that you said "ismember(x,[0 10 20])" earlier but am not sure how to include this in from the traditional "lb <= x <= ub"
Thank you again

Johan Löfberg

unread,
May 14, 2020, 1:50:58 PM5/14/20
to YALMIP
Not sure what you mean. The quantization in ismember is arbitrary, ismember(x,[-5 0 1 2 pi 42]) or what ever
Reply all
Reply to author
Forward
0 new messages