27 #ifndef CASADI_FEASIBLESQPMETHOD_HPP
28 #define CASADI_FEASIBLESQPMETHOD_HPP
30 #include "casadi/core/nlpsol_impl.hpp"
31 #include <casadi/solvers/casadi_nlpsol_feasiblesqpmethod_export.h>
44 struct FeasiblesqpmethodMemory :
public NlpsolMemory {
55 const char* return_status;
65 class Feasiblesqpmethod :
public Nlpsol {
67 explicit Feasiblesqpmethod(
const std::string& name,
const Function& nlp);
68 ~Feasiblesqpmethod()
override;
71 const char* plugin_name()
const override {
return "feasiblesqpmethod";}
74 std::string class_name()
const override {
return "Feasiblesqpmethod";}
77 static Nlpsol* creator(
const std::string& name,
const Function& nlp) {
78 return new Feasiblesqpmethod(name, nlp);
83 static const Options options_;
84 const Options& get_options()
const override {
return options_;}
88 Dict get_stats(
void* mem)
const override;
91 void init(
const Dict& opts)
override;
94 void* alloc_mem()
const override {
return new FeasiblesqpmethodMemory();}
97 int init_mem(
void* mem)
const override;
100 void free_mem(
void *mem)
const override {
delete static_cast<FeasiblesqpmethodMemory*
>(mem);}
103 void set_work(
void* mem,
const double**& arg,
double**& res,
104 casadi_int*& iw,
double*& w)
const override;
106 double eval_m_k(
void* mem)
const;
108 double eval_tr_ratio(
double val_f,
double val_f_corr,
double val_m_k)
const;
110 void tr_update(
void* mem,
double& tr_rad,
double tr_ratio)
const;
112 int step_update(
void* mem,
double tr_ratio)
const;
115 int feasibility_iterations(
void* mem,
double tr_rad)
const;
117 void anderson_acc_step_update(
void* mem, casadi_int iter_index)
const;
119 void anderson_acc_init_memory(
void* mem,
double* step,
double* iterate)
const;
121 void anderson_acc_update_memory(
void* mem,
double* step,
double* iterate)
const;
124 int solve(
void* mem)
const override;
145 casadi_int block_size_ = 0;
148 casadi_int max_iter_, min_iter_;
151 casadi_int lbfgs_memory_;
154 casadi_int sz_anderson_memory_;
157 double tol_pr_, tol_du_;
171 bool print_header_, print_iteration_, print_status_;
180 ConvexifyData convexify_data_;
188 double optim_tol_, feas_tol_;
191 double tr_eta1_, tr_eta2_;
192 double tr_alpha1_, tr_alpha2_;
195 double tr_acceptance_;
196 double tr_rad_min_, tr_rad_max_;
198 std::vector<double> tr_scale_vector_;
201 double contraction_acceptance_value_;
202 casadi_int watchdog_;
203 casadi_int max_inner_iter_;
207 void codegen_body(CodeGenerator& g)
const override;
210 void codegen_declarations(CodeGenerator& g)
const override;
213 const Function getConic()
const {
return qpsol_;}
216 void print_iteration()
const;
219 void print_iteration(casadi_int iter,
double obj,
double m_k,
220 double tr_ratio,
double pr_inf,
double du_inf,
221 double dx_norm,
double rg,
double tr_rad,
222 std::string info)
const;
225 virtual int solve_QP(FeasiblesqpmethodMemory* m,
const double* H,
const double* g,
226 const double* lbdz,
const double* ubdz,
228 double* x_opt,
double* dlam,
int mode)
const;
231 virtual int solve_LP(FeasiblesqpmethodMemory* m,
const double* g,
232 const double* lbdz,
const double* ubdz,
234 double* x_opt,
double* dlam,
int mode)
const;
237 void codegen_qp_solve(CodeGenerator& cg,
const std::string& H,
const std::string& g,
238 const std::string& lbdz,
const std::string& ubdz,
239 const std::string& A,
const std::string& x_opt,
240 const std::string& dlam,
int mode)
const;
242 void codegen_tr_update(CodeGenerator& cg,
243 const std::string& tr_rad,
const std::string& tr_ratio)
const;
245 void codegen_eval_m_k(CodeGenerator& cg)
const;
247 void codegen_eval_tr_ratio(CodeGenerator& cg,
248 const std::string& val_f,
const std::string& val_f_corr,
const std::string& val_m_k)
const;
250 void codegen_step_update(CodeGenerator& cg,
const std::string& tr_ratio)
const;
252 void codegen_feasibility_iterations(CodeGenerator& cg,
const std::string& tr_rad)
const;
270 static const std::string meta_doc;
274 void serialize_body(SerializingStream &s)
const override;
277 static ProtoFunction* deserialize(DeserializingStream& s) {
return new Feasiblesqpmethod(s); }
281 explicit Feasiblesqpmethod(DeserializingStream& s);
284 void set_feasiblesqpmethod_prob();
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.