Thank you again for all your work on acados.
My question is, what should I do to create a new ocp problem (new initial conditions and new parameters) without recompiling the solver with the python interface?

I am trying to solve a multi-robot motion planning problem with an MPC. Each robot has an initial position and a goal to reach. I would like to solve the MPC for different couples (initial position,goal). For this, I set the goal as a parameter. I export the solver once, solve the first ocp, and then to solve a new ocp, I update the parameter (goal) with ocp_solver.acados_ocp.parameter_values = goal, and I use ocp_solver.solve_for_x0(x0) to use the new initial position. However, the results I get are still different than the ones I get if I recompile the solver.

At each time step, I also initialize the solver and the integrator using set():
ocp_solver.set(0, “lbx”, xcurrent)
ocp_solver.set(0, “ubx”, xcurrent)
ocp_solver.set(0,‘x’,xcurrent)
ocp_solver.set(0,‘u’,np.zeros((nu,)))
ocp_solver.set(0,‘p’, goal)

What instructions do you think I should add? Does the ocp_solver keep the previous solution in memory and is it possible to delete it? I tried the function reset(), but then I get errors of status 4. I have also tried to use store_iterate() and load_iterate() but the problem is still here. I probably do not use these functions correctly? I do store_iterate(“json_file.json”) once after exporting/compiling the solver. And then, during the simulation I do load_iterate(“json_file.json”) at each time step, before initializing the solver, before calling .solve_for_x0. Should I create different json files for each different ocp?

I don’t think reset() is the issue because when I solve the problem exporting the solver for the specific initial positions and goals, then it works well. The problem occurs when I want to solve multiple ocp without re-exporting the solver.

Indeed the first debugging you propose actually reveals the problem!

When I apply store_iterate() after exporting the solver, every values are zeros except the x_i values that are equal to the my initial conditions x0. I guess these values correspond to the initial condition constraint.

When I apply store_iterate() after reset() then all the values in the json file are equal to zero, the x_i values too.

If I set my initial condition using ocp_solver.set(i,'x',x0) before store_iterate() and now both json files are the same, but the problem is still not solved.

Initialize the solver, so the initial constraint, initial values of my state, and initial value of the goal parameter:

for i in range(Npred+1):
ocp_solver.set(i,'x',x0)
ocp_solver.set(i,'p', goal)
ocp_solver.set(0, "lbx", x0)
ocp_solver.set(0, "ubx", x0)

I especially needed to do it until Npred+1 and not Npred. Otherwise, my cost was NaN at the end of the horizon, since my goal is directly used in my cost function.

ocp_solver.store_iterate(json_file)

Then, in the closed-loop simulation, at each timestep:

I was actually stuck on this problem for a long time, so thank you so much for your precious help and amazing responsiveness!
Your suggested tricks will definitely be useful for any problem I face in the future.