73 struct MadnlpCStats
stats;
101 template<
typename T1>
102 int casadi_madnlp_eval_constr_jac(
const T1* w, T1* res,
void* user_data) {
109 d_oracle->
arg[0] = w;
110 d_oracle->
arg[1] = d_nlp->
p;
111 d_oracle->
res[0] = res;
113 return calc_function(&d->
prob->nlp_jac_g, d_oracle);
117 template<
typename T1>
118 int casadi_madnlp_eval_constr(
const T1* w, T1* res,
void* user_data) {
119 casadi_int i,k,column;
125 d_oracle->
arg[0] = w;
126 d_oracle->
arg[1] = d_nlp->
p;
127 d_oracle->
res[0] = res;
129 return calc_function(&d->
prob->nlp_g, d_oracle);
133 template<
typename T1>
134 int casadi_madnlp_eval_obj_grad(
const T1* w, T1* res,
void* user_data) {
141 T1 objective_scale = 1.0;
143 d_oracle->
arg[0] = w;
144 d_oracle->
arg[1] = d_nlp->
p;
145 d_oracle->
res[0] = res;
146 return calc_function(&d->
prob->nlp_grad_f, d_oracle);
154 template<
typename T1>
155 int casadi_madnlp_eval_obj(
const T1* w, T1* res,
void* user_data) {
161 T1 objective_scale = 1.0;
163 d_oracle->
arg[0] = w;
164 d_oracle->
arg[1] = d_nlp->p;
165 d_oracle->
res[0] = res;
166 return calc_function(&d->
prob->nlp_f, d_oracle);
173 template<
typename T1>
174 int casadi_madnlp_eval_lag_hess(T1 objective_scale,
const T1* w,
const T1* lam,
175 T1* res,
void* user_data){
176 casadi_int k, column, i;
183 d_oracle->
arg[0] = w;
184 d_oracle->
arg[1] = d_nlp->
p;
185 d_oracle->
arg[2] = &objective_scale;
186 d_oracle->
arg[3] = lam;
187 d_oracle->
res[0] = res;
189 return calc_function(&d->
prob->nlp_hess_l, d_oracle);
202 template<
typename T1>
203 void casadi_madnlp_work(
const casadi_madnlp_prob<T1>* p, casadi_int* sz_arg, casadi_int* sz_res, casadi_int* sz_iw, casadi_int* sz_w) {
204 casadi_nlpsol_work(p->
nlp, sz_arg, sz_res, sz_iw, sz_w);
207 *sz_w = casadi_max(*sz_w, 2*(p->
nlp->nx+p->
nlp->ng));
212 template<
typename T1>
226 template<
typename T1>
228 casadi_int k, i, start, stop, nx;
233 struct MadnlpCInterface* c_interface = &d->
c_interface;
235 c_interface->eval_constr_jac = casadi_madnlp_eval_constr_jac<T1>;
236 c_interface->eval_obj_grad = casadi_madnlp_eval_obj_grad<T1>;
237 c_interface->eval_obj = casadi_madnlp_eval_obj<T1>;
238 c_interface->eval_constr = casadi_madnlp_eval_constr<T1>;
239 c_interface->eval_lag_hess = casadi_madnlp_eval_lag_hess<T1>;
240 c_interface->nw = p_nlp->
nx;
241 c_interface->nc = p_nlp->
ng;
242 c_interface->nnzo = p_nlp->
nx;
243 c_interface->nnzj = d->
prob->nnz_jac_g;
244 c_interface->nnzh = d->
prob->nnz_hess_l;
245 c_interface->user_data = d;
247 c_interface->nzj_i = d->
prob->nzj_i;
248 c_interface->nzj_j = d->
prob->nzj_j;
249 c_interface->nzh_i = d->
prob->nzh_i;
250 c_interface->nzh_j = d->
prob->nzh_j;
257 template<
typename T1>
260 casadi_int k, i, column;
268 const struct MadnlpCNumericIn* in = madnlp_c_input(d->
solver);
270 casadi_copy(d_nlp->
z, p_nlp->
nx, in->x0);
271 casadi_copy(d_nlp->
lam + p_nlp->
nx, p_nlp->
ng, in->l0);
272 casadi_copy(d_nlp->
lbx, p_nlp->
nx, in->lbx);
273 casadi_copy(d_nlp->
ubx, p_nlp->
nx, in->ubx);
274 casadi_copy(d_nlp->
lbg, p_nlp->
ng, in->lbg);
275 casadi_copy(d_nlp->
ubg, p_nlp->
ng, in->ubg);
277 madnlp_int ret = madnlp_c_solve(d->
solver);
280 madnlp_c_destroy(d->
solver);
284 const struct MadnlpCNumericOut* out = madnlp_c_output(d->
solver);
288 for (casadi_int i=0; i<p_nlp->
nx; ++i) {
290 d_nlp->
z[i] = out->sol[i];
292 d_nlp->
lam[i] = out->mul_U[i]-out->mul_L[i];
295 for (casadi_int i=0; i<p_nlp->
ng; ++i) {
296 d_nlp->
z[p_nlp->
nx+i] = out->con[i];
297 d_nlp->
lam[p_nlp->
nx+i] = out->mul[i];
300 const struct MadnlpCStats* stats = madnlp_c_get_stats(d->
solver);
302 printf(
"iter %d\n", stats->iter);
304 d->
stats.iter = stats->iter;
305 d->
stats.status = stats->status;
306 d->
stats.dual_feas = stats->dual_feas;
307 d->
stats.primal_feas = stats->primal_feas;
309 if (d->
stats.status==MADNLP_SOLVE_SUCCEEDED ||
310 d->
stats.status==MADNLP_SOLVED_TO_ACCEPTABLE_LEVEL) {
312 }
else if (d->
stats.status==MADNLP_MAXIMUM_ITERATIONS_EXCEEDED ||
313 d->
stats.status==MADNLP_MAXIMUM_WALLTIME_EXCEEDED) {
319 madnlp_c_destroy(d->
solver);
struct MadnlpCSolver * solver
struct MadnlpCInterface c_interface
struct MadnlpCStats stats
casadi_nlpsol_data< T1 > * nlp
int unified_return_status
const casadi_madnlp_prob< T1 > * prob
OracleCallback nlp_hess_l
const casadi_nlpsol_prob< T1 > * nlp
OracleCallback nlp_grad_f
casadi_oracle_data< T1 > * oracle