1 #include "sleqp_func.hpp"
5 #include "sleqp_interface.hpp"
11 SLEQP_VALUE_REASON reason,
17 SLEQP_CALL(sleqp_vec_to_raw(value, m->
xk));
49 }
catch (std::exception& ex) {
52 <<
"\" evaluating objective value"
55 sleqp_raise(SLEQP_FUNC_EVAL_ERROR,
"%s", ex.what());
78 const int num_vars = sleqp_func_num_vars(func);
80 SLEQP_CALL(sleqp_vec_set_from_raw(obj_grad,
85 }
catch (std::exception& ex) {
88 <<
"\" evaluating objective gradient"
91 sleqp_raise(SLEQP_FUNC_EVAL_ERROR,
"%s", ex.what());
113 const int num_cons = sleqp_func_num_cons(func);
115 SLEQP_CALL(sleqp_vec_set_from_raw(cons_val,
120 }
catch (std::exception& ex) {
123 <<
"\" evaluating constraint value"
126 sleqp_raise(SLEQP_FUNC_EVAL_ERROR,
"%s", ex.what());
149 }
catch (std::exception& ex) {
152 <<
"\" evaluating constraint Jacobian"
155 sleqp_raise(SLEQP_FUNC_EVAL_ERROR,
"%s", ex.what());
162 const casadi_int nnz = colind[ncol];
164 SLEQP_CALL(sleqp_mat_reserve(cons_jac, nnz));
166 double* cons_jac_data = sleqp_mat_data(cons_jac);
167 int* cons_jac_rows = sleqp_mat_rows(cons_jac);
168 int* cons_jac_cols = sleqp_mat_cols(cons_jac);
170 for(
int k = 0; k < nnz; ++k) {
171 cons_jac_data[k] = m->
jac_gk[k];
172 cons_jac_rows[k] = row[k];
175 for(
int k = 0; k <= ncol; ++k) {
176 cons_jac_cols[k] = colind[k];
179 SLEQP_CALL(sleqp_mat_set_nnz(cons_jac, nnz));
185 const SleqpVec* direction,
186 const SleqpVec* cons_duals,
192 SLEQP_CALL(sleqp_vec_to_raw(direction, m->
h_dk));
193 SLEQP_CALL(sleqp_vec_to_raw(cons_duals, m->
h_mk));
215 }
catch (std::exception& ex) {
218 <<
"\" evaluating constraint Hessian product"
221 sleqp_raise(SLEQP_FUNC_EVAL_ERROR,
"%s", ex.what());
224 const int num_vars = sleqp_func_num_vars(func);
226 SLEQP_CALL(sleqp_vec_set_from_raw(
product, m->
h_pk, num_vars, 0.));
242 SleqpFuncCallbacks callbacks{};
254 SLEQP_CALL_EXC(sleqp_func_create(star,
258 static_cast<void*
>(m)));
int calc_function(OracleMemory *m, const std::string &fcn, const double *const *arg=nullptr, int thread_id=0) const
const Sparsity & jac_sparsity() const
casadi_int size2() const
Get the number of columns.
const casadi_int * row() const
Get a reference to row-vector,.
const casadi_int * colind() const
Get a reference to the colindex of all column element (see class description)
T product(const std::vector< T > &values)
product
static SLEQP_RETCODE casadi_func_cons_val(SleqpFunc *func, SleqpVec *cons_val, void *func_data)
void casadi_sleqp_func_create(SleqpFunc **star, int num_vars, int num_cons, SLEQPMemory *m)
static SLEQP_RETCODE casadi_func_free(void *func_data)
static SLEQP_RETCODE casadi_func_nonzeros(SleqpFunc *func, int *obj_grad_nnz, int *cons_val_nnz, int *cons_jac_nnz, int *hess_prod_nnz, void *func_data)
static SLEQP_RETCODE casadi_func_obj_val(SleqpFunc *func, double *obj_val, void *func_data)
static SLEQP_RETCODE casadi_func_hess_prod(SleqpFunc *func, const SleqpVec *direction, const SleqpVec *cons_duals, SleqpVec *product, void *func_data)
static SLEQP_RETCODE casadi_func_obj_grad(SleqpFunc *func, SleqpVec *obj_grad, void *func_data)
static SLEQP_RETCODE casadi_func_cons_jac(SleqpFunc *func, SleqpMat *cons_jac, void *func_data)
static SLEQP_RETCODE casadi_func_set(SleqpFunc *func, SleqpVec *value, SLEQP_VALUE_REASON reason, bool *reject, void *func_data)
casadi_nlpsol_data< double > d_nlp
const SLEQPInterface * interface