About the use of slack variables

Hi guys :wave:

I am trying to add slack variables to my OCP and I just would ask you some clarification.

My OCP have 2 state and 1 input. I want to add

  • a slack variable on the linear constraint on the first state x1 (construct by using the matrrix ‘Jsbx’).
  • a slack variable on the NONlinear constraint on the control input u (construct by using ‘constr_expr_h’).

Leaving out the Mayer term this is what i set:

s_x = 10; % Weight for x1 slack variable
s_u = 50; % Weight for u slack variable

Z = diag([s_x;s_u]);
z = zeros(2,1);

Jsbx = 1;
Jsh = 1;

What it is not so clear for me is: what is the order to fill the weight matrix Z? The first element of Z, which slack variable corresponds to? There is an order in which slack variables are stacked? (for example firstly eventual slack on linear constraints on state, then on input and finally on nonlinear constraints)

Have a nice day,
Giulio

Hi Giulio,

I think this quote from the docs page should clarify it:

the inequalities are internally organized in the following order:
[ lbu lbx lg lh lphi ubu ubx ug uh uphi;
lsbu lsbx lsg lsh lsphi usbu usbx usg ush usphi]

https://docs.acados.org/python_interface/index.html

So, in your example, z should first contain the slack penalty on the bounds on x, and then the on for the general inequality h.

Best,
Jonathan

Thank you so much !!! :smiley:
Have a nice day ! :slight_smile:

1 Like