Issue with slack variable getters for Matlab

Hi!
Thank you for adding getters for slack variables for Matlab. As in the example, ~/acados/examples/acados_matlab_octave/getting_started/extensive_example_ocp.m the code for getting slack variable values looks like,

% get slack values
for i = 0:N-1
sl = ocp.get(‘sl’, i);
su = ocp.get(‘su’, i);
t = ocp.get(‘t’, i);
end
sl = ocp.get(‘sl’, N);
su = ocp.get(‘su’, N);

I am afraid that this is probably wrong, because the index in Matlab cannot start from 0 in the for loop. When I run the code, I get empty sl and su of dimension 0x1. This is unusual for Matlab. Moreover, if you are running the loop to get slack values for the horizon, then it should be filled in a matrix instead of rewriting over the same variable sl and su. The correct code could look something like this in my opinion If n_executions>0 :

for i=1:n_executions
% get slack values
for i = 1:N-1
sl(:, i, n_executions) = ocp.get(‘sl’, i);
su(:, i, n_executions) = ocp.get(‘su’, i);
t(:, i, n_executions) = ocp.get(‘t’, i);
end
sl(:, N, n_executions) = ocp.get(‘sl’, N);
su(:, N, n_executions) = ocp.get(‘su’, N);

end

One more thing, it is possible to get sl and su values individually. But we set values of only Z, z, Z_e and z_e and not Z_l, Z_u, z_l, z_u .... Should the dimension of Z and Z_e be adjusted according to sl and su or I am over-complicating this?
Does sl_e and su_e correspond to sl(N) and su(N)?

It would be really helpful if you can look into the issue. If there is something I misunderstood, then please guide me :slight_smile:

Best,
Smit

Hi @smit,

They can, just the indexing of variables is 1-based in Matlab.
However, internally in acados, there are N+1 shooting nodes that are identified with 0-based indices.

Which makes sense, since this example has no soft constraints.
Try running the same piece of Code in another example, such as

to get non empty slack values.

That piece of code was just to show how the getters is to be used, you can obviously store the values as you did or in any other way.

Setting Z, will set both Z_l and Z_u to the same values at a stage, same for z with z_l, z_u.

yes.

If size(Z) ~= size(sl_i) with i=0,…,N-1 or
size(Z_e) ~= size(sl_e), probably something is wrong with your problem formulation.

I hope that clarifies a bit.

Best,
Jonathan

Hi Jonathan,

Thank you for the reply. If this is the case then my problem formulation is correct according to the above method of yours. I am still checking for any mistakes.

I see that my slack values go negative sometimes. In some of the previous post(sorry i cant find it) I read that by default in Matlab the lower bound on slacks is set to 0. Is there any way in which I can set the lower and upper bounds on the slack variables for Matlab implementation?

Best,
Smit

There are only lower bounds for the slack variables, these are always 0 and cannot be changed from the Matlab interface as it is.

If you get negative slack values, the solver should terminate with non-zero status. Is that the case?
Or if they are negative but with smaller absolute value than the tolerance that should also be fine.

Best,
Jonathan

Hi,

Thank you for the information regarding the bounds of slack variables.

Yes, I get negative slack values with non-zero status. The negative values are in the range of 10^(-something). Not sure if I can set the tolerance myself in the problem.

Also, my slack values hardly go positive, they just stay in the range of 10^(-something) making me wonder if they ever get activated. Well, I do need to look into my problem formulation regarding this.

Best,
Smit