Ownership of data in C-interface

Hi all,

I’m not sure if the ocp_nlp_(...)_set functions let the solver refer to client-defined variables, such that future mutations of the client variables automatically register with the solver. Or do I need to call the ocp_nlp_(\w+)_set function every time I get new values to be set?

For example:

Eigen::VectorXd x0(MODEL_NX); // Defined by client program

ocp_nlp_constraints_model_set(nlp_config, nlp_dims, nlp_in, 0, "lbx", x0.data());
ocp_nlp_constraints_model_set(nlp_config, nlp_dims, nlp_in, 0, "ubx", x0.data());

// Do I only need to change x0 in the future?
// Or do I need to define x0 anew and call ocp_nlp_constraints_model_set again?

For reference, in the past I used ACADO and took the approach from rpg_mpc, i.e. defining non-owning views overs the solver’s working variables.

ACADOvariables vars; // Global variable shared with the solver

Eigen::Map<Eigen::VectorXd> x0(vars->x0, ACADO_NX); // Define the view once
// Future mutation of x0 IS setting the solver's working variable

and it is clear that changing x0 IS actually changing the data of ACADOvariables.x0.

I’m encountering the same question, do you know the answer in the Meantime?

Something like this is not supported officially.
You should call the setters.
Of course it is possible to directly write to the problem data of the solver, but then you are not using the C interface and it can easily lead to undefined behavior.