How to fix the error of failed since variables [zm] are free

309 views Asked by At

By running the code, it shows the error of:

RuntimeError: Error in Function::Function for 'nlp' [MXFunction] at .../casadi/core/function.cpp:249:
.../casadi/core/function_internal.cpp:145: Error calling MXFunction::init for 'nlp':
.../casadi/core/mx_function.cpp:406: nlp::init: Initialization failed since variables [zm] are free. These symbols occur in the output expressions but you forgot to declare these as inputs. Set option 'allow_free' to allow free variables."

The definition for zm is shown as

zm = ca.MX.sym('zm', (Dim_aux, 1))

The problem may come from the following codes

vars_NLP   = ca.vertcat(u.reshape((Dim_ctrl * N, 1)), x.reshape((Dim_state * (N+1), 1)), z.reshape((Dim_aux * N, 1)))
cons_NLP = cons_dynamics + cons_ineq + cons_init
cons_NLP = ca.vertcat(*cons_NLP)

prob = {"x": vars_NLP, "p":p, "f": J, "g":cons_NLP}

return prob, N, vars_NLP.shape[0], cons_NLP.shape[0], p.shape[0], lb_var, ub_var, lb_cons, ub_cons

But I am not sure how to fix it

0

There are 0 answers