Bounds on slack variables

Hi,

I have a quick question regarding the bounds on slack constraints. I’m implementing a nlp ocp using python templating, and I have a single nonlinear constraint I’m implementing as a soft constraint on the upper bound. For example:
0.0 <= h(x,p)
h(x,p) - upper_slack_variable <= 10.0

I understand setting my basic ocp.constraints.lh / uh, (e.g. 0 and 10 here), but I am slightly confused on how I should be setting ocp.constraints.lsh / ush, and what they exactly mean. (I was under the impression that the slack variables would all have built in lower bounds of 0 based on the acados problem formulation, and have no upper bound).

Would I set ush = 0.0, and leave out lsh, to indicate that the slack variable is only on the upper bound? (Along with setting idxsh = 0, since only a single constraint).

1 Like

Hi @bjt,

first of all welcome to the Forum! :wave:

Did you read this:
ush - Lower bounds on slacks corresponding to soft upper bounds for nonlinear constraints. Not required - zeros by default
lsh- Lower bounds on slacks corresponding to soft lower bounds for nonlinear constraints. Not required - zeros by default

[from Interfaces Overview — acados documentation]

This is indeed the default.
Note: there are actually no upper bounds on slacks.

Also: If you soften h_i, you actually soften the lower and upper bound of it.
If you want to have a hard lower bound it would probably be the safest to impose a separate hard constraint.

Best,
Jonathan

Hi Jonathan,

Thanks for the response. I did read the definitions in the interfaces, but that was where I was getting confused. Since I assumed that the default of slack variables being >= 0 with no upper bound was the “only” case, I wasn’t sure why I would need to set ush or lsh. (Disclaimer, this is my first time implementing soft constraints in general).

Following through several examples in acados/examples that use soft constraints, I mainly see both ush and lsh set to zero, (which is what I’m also currently doing, understanding it as my slack variables are ideally zero). In what situation would I be setting these ush and lsh bounds to non-zero values? (sorry if that’s a bit open-ended…)

Thanks,
Ben

1 Like

Hi Ben,

no worries.

Indeed, I never set lsh, ush values to anything but zeros myself and I dont have a problem in mind where nonzero values are desirable.

This is also the reason why these fields are not exposed in the Matlab interface.
It should not be mandatory to set them in the Python interface, too.

Best,
Jonathan

1 Like

Thank you @bjt for asking the question and @FreyJo for the answer. Apart from the same doubt, I noticed that slack variables could occasionally go to negative, which does not really make sense in terms of optimality. Meanwhile, I think it will also causing some issues if I have linear penalty for the slack variable since it will make the cost negative (i.e. a reward).

I think

ush - upper bounds on slacks corresponding to soft upper bounds for nonlinear constraints
lsh - lower bounds on slacks corresponding to soft lower bounds for nonlinear

should be
ush - lower bounds on slacks corresponding to soft upper bounds for nonlinear constraints
lsh - lower bounds on slacks corresponding to soft lower bounds for nonlinear constraints
according to the doc.

1 Like

Right, it was fixed in the docs already.
I also updated my post above now :sweat_smile:

1 Like