26 #include "implicit_to_nlp.hpp"
27 #include "casadi/core/nlpsol.hpp"
28 #include "casadi/core/nlpsol_impl.hpp"
33 int CASADI_ROOTFINDER_NLPSOL_EXPORT
36 plugin->name =
"nlpsol";
38 plugin->version = CASADI_VERSION;
63 "Options to be passed to solver."}}
72 std::string nlpsol_plugin;
76 for (
auto&& op : opts) {
77 if (op.first==
"nlpsol") {
78 nlpsol_plugin = op.second.to_string();
79 }
else if (op.first==
"nlpsol_options") {
88 std::vector<MX> inputs;
89 for (casadi_int i=0; i<
n_in_; ++i) {
96 MX p = veccat(inputs);
102 std::vector< MX > args_call(
n_in_);
104 for (casadi_int i=0, i2=0; i<
n_in_; ++i)
105 if (i!=
iin_) args_call[i] = inputs[i2++];
109 MXDict nlp = {{
"x", u}, {
"p", p}, {
"f", nlp_f}, {
"g", nlp_g}};
112 casadi_assert(!nlpsol_plugin.empty(),
"'nlpsol' option has not been set");
128 casadi_int*& iw,
double*& w)
const {
141 std::fill_n(m->arg,
static_cast<casadi_int
>(
NLPSOL_NUM_IN),
nullptr);
142 std::fill_n(m->res,
static_cast<casadi_int
>(
NLPSOL_NUM_OUT),
nullptr);
152 std::fill_n(m->lbx,
n_, -std::numeric_limits<double>::infinity());
154 std::fill_n(m->ubx,
n_, std::numeric_limits<double>::infinity());
156 for (casadi_int k=0; k<
u_c_.size(); ++k) {
157 if (
u_c_[k] > 0) m->lbx[k] = 0;
158 if (
u_c_[k] < 0) m->ubx[k] = 0;
164 for (casadi_int i=0; i<
n_in_; ++i) {
176 solver_(m->arg, m->res, m->iw, m->w, 0);
182 bool has_aux =
false;
183 for (casadi_int i=0; i<
n_out_; ++i) {
184 if (i!=
iout_ && m->ires[i]) {
192 std::copy_n(m->iarg,
n_in_, m->arg);
194 std::copy_n(m->ires,
n_out_, m->res);
195 m->res[
iout_] =
nullptr;
196 oracle_(m->arg, m->res, m->iw, m->w, 0);
201 auto *nlpsol_m =
static_cast<NlpsolMemory*
>(nlpsol_mem);
202 m->
success = nlpsol_m->success;
203 m->unified_return_status = nlpsol_m->unified_return_status;
std::vector< Sparsity > sparsity_in_
Input and output sparsity.
size_t n_in_
Number of inputs and outputs.
casadi_int nnz_in() const
Number of input/output nonzeros.
void alloc_w(size_t sz_w, bool persistent=false)
Ensure required length of w field.
void alloc(const Function &f, bool persistent=false, int num_threads=1)
Ensure work vectors long enough to evaluate function.
void * memory(int ind) const
Get memory object.
casadi_int nnz_in() const
Get number of input nonzeros.
Dict stats(int mem=0) const
Get all statistics obtained at the end of the last evaluate call.
static MX sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
ImplicitToNlp(const std::string &name, const Function &f)
Constructor.
Dict get_stats(void *mem) const override
Get all statistics.
static const Options options_
Options.
static const std::string meta_doc
A documentation string.
~ImplicitToNlp() override
Destructor.
int solve(void *mem) const override
Solve the system of equations and calculate derivatives.
Function solver_
NLP solver.
static Rootfinder * creator(const std::string &name, const Function &f)
Create a new Rootfinder.
void init(const Dict &opts) override
Initialize.
Function oracle_
Oracle: Used to generate other functions.
static void registerPlugin(const Plugin &plugin, bool needs_lock=true)
Register an integrator in the factory.
void clear_mem()
Clear all memory (called from destructor)
casadi_int n_
Number of equations.
std::vector< casadi_int > u_c_
Constraints on decision variables.
Dict get_stats(void *mem) const override
Get all statistics.
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
casadi_int iin_
Indices of the input and output that correspond to the actual root-finding.
static const Options options_
Options.
void init(const Dict &opts) override
Initialize.
std::vector< std::string > nlpsol_options(const std::string &name)
Get all options for a plugin.
Function nlpsol(const std::string &name, const std::string &solver, const SXDict &nlp, const Dict &opts)
@ NLPSOL_P
Value of fixed parameters (np x 1)
@ NLPSOL_UBX
Decision variables upper bound (nx x 1), default +inf.
@ NLPSOL_UBG
Constraints upper bound (ng x 1), default +inf.
@ NLPSOL_LBG
Constraints lower bound (ng x 1), default -inf.
@ NLPSOL_LBX
Decision variables lower bound (nx x 1), default -inf.
void CASADI_ROOTFINDER_NLPSOL_EXPORT casadi_load_rootfinder_nlpsol()
std::map< std::string, MX > MXDict
@ NLPSOL_X
Decision variables at the optimal solution (nx x 1)
void casadi_copy(const T1 *x, casadi_int n, T1 *y)
COPY: y <-x.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
int CASADI_ROOTFINDER_NLPSOL_EXPORT casadi_register_rootfinder_nlpsol(Rootfinder::Plugin *plugin)
const double pi
Define pi.
Options metadata for a class.