26 #ifndef CASADI_SNOPT_INTERFACE_HPP
27 #define CASADI_SNOPT_INTERFACE_HPP
29 #include "casadi/core/nlpsol_impl.hpp"
30 #include "casadi/core/im.hpp"
32 #include "casadi/interfaces/snopt/casadi_nlpsol_snopt_export.h"
34 #include "snopt_cwrap.h"
52 struct SnoptMemory :
public NlpsolMemory {
54 const SnoptInterface&
self;
57 double *xk2, *lam_gk, *lam_xk;
60 double *gk, *jac_fk, *jac_gk;
62 std::vector<double> bl, bu, xx;
64 std::vector<int> hs, locJ, indJ;
68 std::vector<double> A_data, valJ, rc, pi;
71 static std::vector<SnoptMemory*> mempool;
77 SnoptMemory(
const SnoptInterface&
self);
87 class SnoptInterface :
public Nlpsol {
94 explicit SnoptInterface(
const std::string& name,
const Function& nlp);
97 ~SnoptInterface()
override;
100 const char* plugin_name()
const override {
return "snopt";}
103 std::string class_name()
const override {
return "SnoptInterface";}
106 static Nlpsol* creator(
const std::string& name,
const Function& nlp) {
107 return new SnoptInterface(name, nlp);
112 static const Options options_;
113 const Options& get_options()
const override {
return options_;}
117 void init(
const Dict& opts)
override;
120 void* alloc_mem()
const override {
return new SnoptMemory(*
this);}
123 int init_mem(
void* mem)
const override;
126 void free_mem(
void *mem)
const override {
delete static_cast<SnoptMemory*
>(mem);}
129 void set_work(
void* mem,
const double**& arg,
double**& res,
130 casadi_int*& iw,
double*& w)
const override;
133 int solve(
void* mem)
const override;
136 Dict get_stats(
void* mem)
const override;
138 static std::map<int, std::string> status_;
139 static std::map<int, std::string> secondary_status_;
141 std::string formatStatus(
int status)
const;
142 std::string formatSecondaryStatus(
int status)
const;
144 void userfun(SnoptMemory* m,
int* mode,
int nnObj,
int nnCon,
int nnJac,
int nnL,
int neJac,
145 const double* x,
double* fObj,
double*gObj,
double* fCon,
double* gCon,
146 int nState,
char* cu,
int lencu,
int* iu,
int leniu,
double* ru,
int lenru)
const;
157 static void userfunPtr(
int * mode,
int* nnObj,
int * nnCon,
int *nJac,
int *nnL,
int * neJac,
158 double *x,
double *fObj,
double *gObj,
double * fCon,
double* gCon,
159 int* nState,
char* cu,
int* lencu,
int* iu,
int* leniu,
160 double* ru,
int *lenru);
168 static const std::string meta_doc;
177 void serialize_body(SerializingStream &s)
const override;
180 static ProtoFunction* deserialize(DeserializingStream& s) {
return new SnoptInterface(s); }
184 explicit SnoptInterface(DeserializingStream& s);
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.