Running single functions of the auto-generated code via C-interface

Hi there,

I’m currently trying to get more insights into my optimal control problem and why the solution looks like it does. Specifically, I’m wondering how I can see what constraints are active and which are not. Is there a simple way of doing this? Just looking at the output of the solver when increasing the verbosity flag is not the most insightful information, frankly.

Particularly, I’m curious about evaluating the nonlinear constraints and/or transition function at the state/inputs of my solution using the C-interface.

I have found the following functions, which seem relevant, but I could not figure out how to use them:

// ocp_nlp_constraints_bgh.h
void ocp_nlp_constraints_bgh_compute_fun(void *config_, void *dims, void *model_,
                                            void *opts_, void *memory_, void *work_);

// my_solver_name_constr_h_fun.c
CASADI_SYMBOL_EXPORT int my_solver_name_constr_h_fun(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, int mem){
  return casadi_f0(arg, res, iw, w, mem);
}

I’m thankful for any pointers or example code :slight_smile:

Hi,

Specifically, I’m wondering how I can see what constraints are active and which are not. Is there a simple way of doing this?

One way would be to check the multipliers, an inequality multiplier which is (numerically) bigger than zero indicate that the corresponding constraint is active.

If you want to evaluate the nonlinear constraint h externally, this can indeed be done calling

my_solver_name_constr_h_fun

This boils down to calling a CasADi generated function in C.
Unfortunately, I don’t have a good reference for this right now.

One thing that I agree would be very useful is to add a get functionality for the full inequality residual at a given shooting node. Right now, one can only get the max norm of the residual over all inequalities, which gives not much insight on which constraints are violated.

Thanks for the quick reply.

Unfortunately, I don’t have a good reference for this right now.

That’s too bad. I will make an update in case I can get this running.

One thing that I agree would be very useful is to add a get functionality for the full inequality residual at a given shooting node. Right now, one can only get the max norm of the residual over all inequalities, which gives not much insight on which constraints are violated.

Yes, that would be pretty helpful. I have to see whether I maybe find some time in the future to start working on this.

Cheers