[Matlab] Create multiple OCP models in one script

I was trying to compare performance of several MHEs (with different time horizon, for example), but I’m not sure how to correctly code it - it looks like acados generates code with predefined filenames, so during compilation of the second model matlab crashes:

%% acados ocp
ocp1 = acados_ocp(ocp_model, ocp_opts);
% modify second problem with shorter horizon
ocp_model.set('T',t_step*ocp_Nsmall);
ocp_opts.set('param_scheme_N', ocp_Nsmall);
ocp2 = acados_ocp(ocp_model, ocp_opts);

Is there a way around it?

Hi Anton,

Indeed it is not really supported to have multiple acados ocp solvers in Matlab.
However, to compare different OCP/MHE solvers, you can always delete the old one with clear.

Here is a sketch of for a performance comparison script:

for ii = 1:length(n_formulations)
    clear ocp
    % formulate your problem in ocp_model, ocp_opts.
    ocp = acados_ocp(ocp_model, ocp_opts);
    % call the solver, store data to be compared
end
%% evaluation

Cheers,
Jonathan