26 #ifndef CASADI_BONMIN_INTERFACE_HPP
27 #define CASADI_BONMIN_INTERFACE_HPP
29 #include <IpIpoptApplication.hpp>
30 #include "BonOsiTMINLPInterface.hpp"
31 #include "BonIpoptSolver.hpp"
33 #include "BonBonminSetup.hpp"
34 #include "BonOACutGenerator2.hpp"
35 #include "BonEcpCuts.hpp"
36 #include "BonOaNlpOptim.hpp"
38 #include <casadi/interfaces/bonmin/casadi_nlpsol_bonmin_export.h>
39 #include "casadi/core/nlpsol_impl.hpp"
40 #include "casadi/core/timing.hpp"
74 struct BonminMemory :
public NlpsolMemory {
76 double *gk, *grad_fk, *jac_gk, *hess_lk, *grad_lk;
79 std::vector<double> inf_pr, inf_du, mu, d_norm, regularization_size,
80 obj, alpha_pr, alpha_du;
81 std::vector<casadi_int> ls_trials;
82 const char* return_status;
83 casadi_int iter_count;
85 Bonmin::TMINLP::SosInfo sos_info;
99 class BonminInterface :
public Nlpsol {
100 friend class BonminUserClass;
103 Sparsity hesslag_sp_;
105 explicit BonminInterface(
const std::string& name,
const Function& nlp);
106 ~BonminInterface()
override;
109 const char* plugin_name()
const override {
return "bonmin";}
112 std::string class_name()
const override {
return "BonminInterface";}
115 static Nlpsol* creator(
const std::string& name,
const Function& nlp) {
116 return new BonminInterface(name, nlp);
121 static const Options options_;
122 const Options& get_options()
const override {
return options_;}
126 void init(
const Dict& opts)
override;
129 void* alloc_mem()
const override {
return new BonminMemory();}
132 int init_mem(
void* mem)
const override;
135 void free_mem(
void *mem)
const override {
delete static_cast<BonminMemory*
>(mem);}
138 Dict get_stats(
void* mem)
const override;
141 void set_work(
void* mem,
const double**& arg,
double**& res,
142 casadi_int*& iw,
double*& w)
const override;
145 int solve(
void* mem)
const override;
154 void finalize_solution(BonminMemory* m, Bonmin::TMINLP::SolverReturn status,
155 const double* x,
double obj_value)
const;
156 bool get_bounds_info(BonminMemory* m,
double* x_l,
double* x_u,
157 double* g_l,
double* g_u)
const;
158 bool get_starting_point(BonminMemory* m,
bool init_x,
double* x,
159 bool init_z,
double* z_L,
double* z_U,
160 bool init_lambda,
double* lambda)
const;
161 void get_nlp_info(BonminMemory* m,
int& nx,
int& ng,
162 int& nnz_jac_g,
int& nnz_h_lag)
const;
163 int get_number_of_nonlinear_variables()
const;
164 bool get_list_of_nonlinear_variables(
int num_nonlin_vars,
int* pos_nonlin_vars)
const;
165 bool intermediate_callback(BonminMemory* m,
const double* x,
const double* z_L,
166 const double* z_U,
const double* g,
167 const double* lambda,
double obj_value,
int iter,
168 double inf_pr,
double inf_du,
double mu,
double d_norm,
169 double regularization_size,
double alpha_du,
double alpha_pr,
170 int ls_trials,
bool full_callback)
const;
171 const Bonmin::TMINLP::SosInfo& sosConstraints(BonminMemory* m)
const;
174 bool integer_support()
const override {
return true;}
177 static const std::string meta_doc;
180 std::vector<double> sos1_weights_;
181 std::vector<int> sos1_indices_;
182 std::vector<int> sos1_priorities_;
183 std::vector<int> sos1_starts_;
184 std::vector<char> sos1_types_;
186 casadi_int sos_num_nz_;
189 bool pass_nonlinear_variables_;
190 bool pass_nonlinear_constraints_;
191 std::vector<bool> nl_ex_;
192 std::vector<bool> nl_g_;
193 Dict var_string_md_, var_integer_md_, var_numeric_md_,
194 con_string_md_, con_integer_md_, con_numeric_md_;
197 void serialize_body(SerializingStream &s)
const override;
200 static ProtoFunction* deserialize(DeserializingStream& s) {
return new BonminInterface(s); }
204 explicit BonminInterface(DeserializingStream& s);
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.