List of all members | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes
casadi::Feasiblesqpmethod Class Reference

'feasiblesqpmethod' plugin for Nlpsol More...

#include <feasiblesqpmethod.hpp>

Detailed Description

A textbook FeasibleSQPMethod

Extra doc: https://github.com/casadi/casadi/wiki/L_241


List of available options
IdTypeDescription
anderson_memoryOT_INTAnderson memory. If Anderson is used default is 1, else default is 0.
contraction_acceptance_valueOT_DOUBLEIf the empirical contraction rate in the feasibility iterations is above this value in the heuristics the iterations are aborted.
convexify_marginOT_DOUBLEWhen using a convexification strategy, make sure that the smallest eigenvalue4 is at least this (default: 1e-7).
convexify_strategyOT_STRINGNONE|regularize|eigen-reflect|eigen-clip. Strategy to convexify the Lagrange Hessian before passing it to the solver.
fOT_FUNCTIONFunction for calculating the objective function (autogenerated by default)
feas_tolOT_DOUBLEFeasibility tolerance. Below this tolerance an iterate is considered to be feasible.
gOT_FUNCTIONFunction for calculating the constraints (autogenerated by default)
grad_fOT_FUNCTIONFunction for calculating the gradient of the objective (autogenerated by default)
hess_lagOT_FUNCTIONFunction for calculating the Hessian of the Lagrangian (autogenerated by default)
hessian_approximationOT_STRINGlimited-memory|exact
init_feasibleOT_BOOLInitialize the QP subproblems with a feasible initial value (default: false).
jac_gOT_FUNCTIONFunction for calculating the Jacobian of the constraints (autogenerated by default)
lbfgs_memoryOT_INTSize of L-BFGS memory.
max_inner_iterOT_DOUBLEMaximum number of inner iterations.
max_iterOT_INTMaximum number of SQP iterations
max_iter_eigOT_DOUBLEMaximum number of iterations to compute an eigenvalue decomposition (default: 50).
merit_memoryOT_INTSize of memory to store history of merit function values
min_iterOT_INTMinimum number of SQP iterations
optim_tolOT_DOUBLEOptimality tolerance. Below this value an iterate is considered to be optimal.
print_headerOT_BOOLPrint the header with problem statistics
print_iterationOT_BOOLPrint the iterations
print_statusOT_BOOLPrint a status message after solving
qpsolOT_STRINGThe QP solver to be used by the SQP method [qpoases]
qpsol_optionsOT_DICTOptions to be passed to the QP solver
solve_typeOT_STRINGThe solver type: Either SQP or SLP. Defaults to SQP
tol_duOT_DOUBLEStopping criterion for dual infeasability
tol_prOT_DOUBLEStopping criterion for primal infeasibility
tr_acceptanceOT_DOUBLEIs the trust-region ratio above this value, the step is accepted.
tr_alpha1OT_DOUBLELower alpha in trust-region size criterion.
tr_alpha2OT_DOUBLEUpper alpha in trust-region size criterion.
tr_eta1OT_DOUBLELower eta in trust-region acceptance criterion.
tr_eta2OT_DOUBLEUpper eta in trust-region acceptance criterion.
tr_rad0OT_DOUBLEInitial trust-region radius.
tr_rad_maxOT_DOUBLEMaximum trust-region radius.
tr_rad_minOT_DOUBLEMinimum trust-region radius.
tr_scale_vectorOT_DOUBLEVECTORVector that tells where trust-region is applied.
tr_tolOT_DOUBLETrust-region tolerance. Below this value another scalar is equal to the trust region radius.
use_andersonOT_BOOLUse Anderson Acceleration. (default false)
watchdogOT_INTNumber of watchdog iterations in feasibility iterations. After this amount of iterations, it is checked with the contraction acceptance value, if iterations are converging.


List of available options
IdTypeDescriptionUsed in
ad_weightOT_DOUBLEWeighting factor for derivative calculation.When there is an option of either using forward or reverse mode directional derivatives, the condition ad_weight*nf<=(1-ad_weight)*na is used where nf and na are estimates of the number of forward/reverse mode directional derivatives needed. By default, ad_weight is calculated automatically, but this can be overridden by setting this option. In particular, 0 means forcing forward mode and 1 forcing reverse mode. Leave unset for (class specific) heuristics.casadi::FunctionInternal
ad_weight_spOT_DOUBLEWeighting factor for sparsity pattern calculation calculation.Overrides default behavior. Set to 0 and 1 to force forward and reverse mode respectively. Cf. option "ad_weight". When set to -1, sparsity is completely ignored and dense matrices are used.casadi::FunctionInternal
always_inlineOT_BOOLForce inlining.casadi::FunctionInternal
anderson_memoryOT_INTAnderson memory. If Anderson is used default is 1, else default is 0.casadi::Feasiblesqpmethod
bound_consistencyOT_BOOLEnsure that primal-dual solution is consistent with the boundscasadi::Nlpsol
cacheOT_DICTPrepopulate the function cache. Default: emptycasadi::FunctionInternal
calc_fOT_BOOLCalculate 'f' in the Nlpsol base classcasadi::Nlpsol
calc_gOT_BOOLCalculate 'g' in the Nlpsol base classcasadi::Nlpsol
calc_lam_pOT_BOOLCalculate 'lam_p' in the Nlpsol base classcasadi::Nlpsol
calc_lam_xOT_BOOLCalculate 'lam_x' in the Nlpsol base classcasadi::Nlpsol
calc_multipliersOT_BOOLCalculate Lagrange multipliers in the Nlpsol base classcasadi::Nlpsol
common_optionsOT_DICTOptions for auto-generated functionscasadi::OracleFunction
compilerOT_STRINGJust-in-time compiler plugin to be used.casadi::FunctionInternal
contraction_acceptance_valueOT_DOUBLEIf the empirical contraction rate in the feasibility iterations is above this value in the heuristics the iterations are aborted.casadi::Feasiblesqpmethod
convexify_marginOT_DOUBLEWhen using a convexification strategy, make sure that the smallest eigenvalue4 is at least this (default: 1e-7).casadi::Feasiblesqpmethod
convexify_strategyOT_STRINGNONE|regularize|eigen-reflect|eigen-clip. Strategy to convexify the Lagrange Hessian before passing it to the solver.casadi::Feasiblesqpmethod
custom_jacobianOT_FUNCTIONOverride CasADi's AD. Use together with 'jac_penalty': 0. Note: Highly experimental. Syntax may break often.casadi::FunctionInternal
der_optionsOT_DICTDefault options to be used to populate forward_options, reverse_options, and jacobian_options before those options are merged in.casadi::FunctionInternal
derivative_ofOT_FUNCTIONThe function is a derivative of another function. The type of derivative (directional derivative, Jacobian) is inferred from the function name.casadi::FunctionInternal
detect_simple_boundsOT_BOOLAutomatically detect simple bounds (lbx/ubx) (default false). This is hopefully beneficial to speed and robustness but may also have adverse affects: 1) Subtleties in heuristics and stopping criteria may change the solution, 2) IPOPT may lie about multipliers of simple equality bounds unless 'fixed_variable_treatment' is set to 'relax_bounds'.casadi::Nlpsol
detect_simple_bounds_is_simpleOT_BOOLVECTORFor internal use only.casadi::Nlpsol
detect_simple_bounds_partsOT_FUNCTIONFor internal use only.casadi::Nlpsol
detect_simple_bounds_target_xOT_INTVECTORFor internal use only.casadi::Nlpsol
discreteOT_BOOLVECTORIndicates which of the variables are discrete, i.e. integer-valuedcasadi::Nlpsol
dumpOT_BOOLDump function to file upon first evaluation. [false]casadi::FunctionInternal
dump_dirOT_STRINGDirectory to dump inputs/outputs to. Make sure the directory exists [.]casadi::FunctionInternal
dump_formatOT_STRINGChoose file format to dump matrices. See DM.from_file [mtx]casadi::FunctionInternal
dump_inOT_BOOLDump numerical values of inputs to file (readable with DM.from_file) [default: false] A counter is used to generate unique names. The counter may be reset using reset_dump_count.casadi::FunctionInternal
dump_outOT_BOOLDump numerical values of outputs to file (readable with DM.from_file) [default: false] A counter is used to generate unique names. The counter may be reset using reset_dump_count.casadi::FunctionInternal
enable_fdOT_BOOLEnable derivative calculation by finite differencing. [default: false]]casadi::FunctionInternal
enable_forwardOT_BOOLEnable derivative calculation using generated functions for Jacobian-times-vector products - typically using forward mode AD - if available. [default: true]casadi::FunctionInternal
enable_jacobianOT_BOOLEnable derivative calculation using generated functions for Jacobians of all differentiable outputs with respect to all differentiable inputs - if available. [default: true]casadi::FunctionInternal
enable_reverseOT_BOOLEnable derivative calculation using generated functions for transposed Jacobian-times-vector products - typically using reverse mode AD - if available. [default: true]casadi::FunctionInternal
equalityOT_BOOLVECTORIndicate an upfront hint which of the constraints are equalities. Some solvers may be able to exploit this knowledge. When true, the corresponding lower and upper bounds are assumed equal. When false, the corresponding bounds may be equal or different.casadi::Nlpsol
error_on_failOT_BOOLThrow exceptions when function evaluation fails (default true).casadi::ProtoFunction
eval_errors_fatalOT_BOOLWhen errors occur during evaluation of f,g,...,stop the iterationscasadi::Nlpsol
expandOT_BOOLReplace MX with SX expressions in problem formulation [false] This happens before creating derivatives unless indicated by postpone_expandcasadi::OracleFunction
external_transformOT_VECTORVECTORList of external_transform instruction arguments. Default: emptycasadi::FunctionInternal
fOT_FUNCTIONFunction for calculating the objective function (autogenerated by default)casadi::Feasiblesqpmethod
fd_methodOT_STRINGMethod for finite differencing [default 'central']casadi::FunctionInternal
fd_optionsOT_DICTOptions to be passed to the finite difference instancecasadi::FunctionInternal
feas_tolOT_DOUBLEFeasibility tolerance. Below this tolerance an iterate is considered to be feasible.casadi::Feasiblesqpmethod
forward_optionsOT_DICTOptions to be passed to a forward mode constructorcasadi::FunctionInternal
gOT_FUNCTIONFunction for calculating the constraints (autogenerated by default)casadi::Feasiblesqpmethod
gather_statsOT_BOOLDeprecated option (ignored): Statistics are now always collected.casadi::FunctionInternal
grad_fOT_FUNCTIONFunction for calculating the gradient of the objective (autogenerated by default)casadi::Feasiblesqpmethod
hess_lagOT_FUNCTIONFunction for calculating the Hessian of the Lagrangian (autogenerated by default)casadi::Feasiblesqpmethod
hessian_approximationOT_STRINGlimited-memory|exactcasadi::Feasiblesqpmethod
ignore_check_vecOT_BOOLIf set to true, the input shape of F will not be checked.casadi::Nlpsol
init_feasibleOT_BOOLInitialize the QP subproblems with a feasible initial value (default: false).casadi::Feasiblesqpmethod
input_schemeOT_STRINGVECTORDeprecated option (ignored)casadi::FunctionInternal
inputs_checkOT_BOOLThrow exceptions when the numerical values of the inputs don't make sensecasadi::FunctionInternal
is_diff_inOT_BOOLVECTORIndicate for each input if it should be differentiable.casadi::FunctionInternal
is_diff_outOT_BOOLVECTORIndicate for each output if it should be differentiable.casadi::FunctionInternal
iteration_callbackOT_FUNCTIONA function that will be called at each iteration with the solver as input. Check documentation of Callback.casadi::Nlpsol
iteration_callback_ignore_errorsOT_BOOLIf set to true, errors thrown by iteration_callback will be ignored.casadi::Nlpsol
iteration_callback_stepOT_INTOnly call the callback function every few iterations.casadi::Nlpsol
jac_gOT_FUNCTIONFunction for calculating the Jacobian of the constraints (autogenerated by default)casadi::Feasiblesqpmethod
jac_penaltyOT_DOUBLEWhen requested for a number of forward/reverse directions, it may be cheaper to compute first the full jacobian and then multiply with seeds, rather than obtain the requested directions in a straightforward manner. Casadi uses a heuristic to decide which is cheaper. A high value of 'jac_penalty' makes it less likely for the heurstic to chose the full Jacobian strategy. The special value -1 indicates never to use the full Jacobian strategycasadi::FunctionInternal
jacobian_optionsOT_DICTOptions to be passed to a Jacobian constructorcasadi::FunctionInternal
jitOT_BOOLUse just-in-time compiler to speed up the evaluationcasadi::FunctionInternal
jit_cleanupOT_BOOLCleanup up the temporary source file that jit creates. Default: truecasadi::FunctionInternal
jit_nameOT_STRINGThe file name used to write out code. The actual file names used depend on 'jit_temp_suffix' and include extensions. Default: 'jit_tmp'casadi::FunctionInternal
jit_optionsOT_DICTOptions to be passed to the jit compiler.casadi::FunctionInternal
jit_serializeOT_STRINGSpecify behaviour when serializing a jitted function: SOURCE|link|embed.casadi::FunctionInternal
jit_temp_suffixOT_BOOLUse a temporary (seemingly random) filename suffix for generated code and libraries. This is desired for thread-safety. This behaviour may defeat caching compiler wrappers. Default: truecasadi::FunctionInternal
lbfgs_memoryOT_INTSize of L-BFGS memory.casadi::Feasiblesqpmethod
max_inner_iterOT_DOUBLEMaximum number of inner iterations.casadi::Feasiblesqpmethod
max_ioOT_INTAcceptable number of inputs and outputs. Warn if exceeded.casadi::FunctionInternal
max_iterOT_INTMaximum number of SQP iterationscasadi::Feasiblesqpmethod
max_iter_eigOT_DOUBLEMaximum number of iterations to compute an eigenvalue decomposition (default: 50).casadi::Feasiblesqpmethod
max_num_dirOT_INTSpecify the maximum number of directions for derivative functions. Overrules the builtin optimized_num_dir.casadi::FunctionInternal
merit_memoryOT_INTSize of memory to store history of merit function valuescasadi::Feasiblesqpmethod
min_iterOT_INTMinimum number of SQP iterationscasadi::Feasiblesqpmethod
min_lamOT_DOUBLEMinimum allowed multiplier valuecasadi::Nlpsol
monitorOT_STRINGVECTORSet of user problem functions to be monitoredcasadi::OracleFunction
never_inlineOT_BOOLForbid inlining.casadi::FunctionInternal
no_nlp_gradOT_BOOLPrevent the creation of the 'nlp_grad' functioncasadi::Nlpsol
optim_tolOT_DOUBLEOptimality tolerance. Below this value an iterate is considered to be optimal.casadi::Feasiblesqpmethod
oracle_optionsOT_DICTOptions to be passed to the oracle functioncasadi::Nlpsol
output_schemeOT_STRINGVECTORDeprecated option (ignored)casadi::FunctionInternal
post_expandOT_BOOLAfter construction, expand this Function. Default: Falsecasadi::FunctionInternal
post_expand_optionsOT_DICTOptions to be passed to post-construction expansion. Default: emptycasadi::FunctionInternal
postpone_expandOT_BOOLWhen expand is active, postpone it until after creation of derivatives. Default: Falsecasadi::OracleFunction
print_canonicalOT_BOOLWhen printing numerical matrices, use a format that is exact and reproducible in generated C code.casadi::FunctionInternal
print_headerOT_BOOLPrint the header with problem statisticscasadi::Feasiblesqpmethod
print_inOT_BOOLPrint numerical values of inputs [default: false]casadi::FunctionInternal
print_iterationOT_BOOLPrint the iterationscasadi::Feasiblesqpmethod
print_outOT_BOOLPrint numerical values of outputs [default: false]casadi::FunctionInternal
print_statusOT_BOOLPrint a status message after solvingcasadi::Feasiblesqpmethod
print_timeOT_BOOLprint information about execution time. Implies record_time.casadi::ProtoFunction
qpsolOT_STRINGThe QP solver to be used by the SQP method [qpoases]casadi::Feasiblesqpmethod
qpsol_optionsOT_DICTOptions to be passed to the QP solvercasadi::Feasiblesqpmethod
record_timeOT_BOOLrecord information about execution time, for retrieval with stats().casadi::ProtoFunction
regularity_checkOT_BOOLThrow exceptions when NaN or Inf appears during evaluationcasadi::ProtoFunction
reverse_optionsOT_DICTOptions to be passed to a reverse mode constructorcasadi::FunctionInternal
sens_linsolOT_STRINGLinear solver used for parametric sensitivities (default 'qr').casadi::Nlpsol
sens_linsol_optionsOT_DICTLinear solver options used for parametric sensitivities.casadi::Nlpsol
show_eval_warningsOT_BOOLShow warnings generated from function evaluations [true]casadi::OracleFunction
solve_typeOT_STRINGThe solver type: Either SQP or SLP. Defaults to SQPcasadi::Feasiblesqpmethod
specific_optionsOT_DICTOptions for specific auto-generated functions, overwriting the defaults from common_options. Nested dictionary.casadi::OracleFunction
tol_duOT_DOUBLEStopping criterion for dual infeasabilitycasadi::Feasiblesqpmethod
tol_prOT_DOUBLEStopping criterion for primal infeasibilitycasadi::Feasiblesqpmethod
tr_acceptanceOT_DOUBLEIs the trust-region ratio above this value, the step is accepted.casadi::Feasiblesqpmethod
tr_alpha1OT_DOUBLELower alpha in trust-region size criterion.casadi::Feasiblesqpmethod
tr_alpha2OT_DOUBLEUpper alpha in trust-region size criterion.casadi::Feasiblesqpmethod
tr_eta1OT_DOUBLELower eta in trust-region acceptance criterion.casadi::Feasiblesqpmethod
tr_eta2OT_DOUBLEUpper eta in trust-region acceptance criterion.casadi::Feasiblesqpmethod
tr_rad0OT_DOUBLEInitial trust-region radius.casadi::Feasiblesqpmethod
tr_rad_maxOT_DOUBLEMaximum trust-region radius.casadi::Feasiblesqpmethod
tr_rad_minOT_DOUBLEMinimum trust-region radius.casadi::Feasiblesqpmethod
tr_scale_vectorOT_DOUBLEVECTORVector that tells where trust-region is applied.casadi::Feasiblesqpmethod
tr_tolOT_DOUBLETrust-region tolerance. Below this value another scalar is equal to the trust region radius.casadi::Feasiblesqpmethod
use_andersonOT_BOOLUse Anderson Acceleration. (default false)casadi::Feasiblesqpmethod
user_dataOT_VOIDPTRA user-defined field that can be used to identify the function or pass additional informationcasadi::FunctionInternal
verboseOT_BOOLVerbose evaluation – for debuggingcasadi::ProtoFunction
verbose_initOT_BOOLPrint out timing information about the different stages of initializationcasadi::Nlpsol
warn_initial_boundsOT_BOOLWarn if the initial guess does not satisfy LBX and UBXcasadi::Nlpsol
watchdogOT_INTNumber of watchdog iterations in feasibility iterations. After this amount of iterations, it is checked with the contraction acceptance value, if iterations are converging.casadi::Feasiblesqpmethod

Definition at line 65 of file feasiblesqpmethod.hpp.

Inheritance diagram for casadi::Feasiblesqpmethod:
Inheritance graph
[legend]
Collaboration diagram for casadi::Feasiblesqpmethod:
Collaboration graph
[legend]

Public Types

typedef Nlpsol *(* Creator) (const std::string &name, const Function &oracle)
 
using weak_ref_type = WeakRefInternal
 
typedef int(* RegFcn) (Plugin *plugin)
 

Public Member Functions

 Feasiblesqpmethod (const std::string &name, const Function &nlp)
 
 ~Feasiblesqpmethod () override
 
const char * plugin_name () const override
 
std::string class_name () const override
 Get type name. More...
 
Dict get_stats (void *mem) const override
 Get all statistics. More...
 
void init (const Dict &opts) override
 Initialize. More...
 
void * alloc_mem () const override
 Create memory block. More...
 
int init_mem (void *mem) const override
 Initalize memory block. More...
 
void free_mem (void *mem) const override
 Free memory block. More...
 
void set_work (void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
 Set the (persistent) work vectors. More...
 
double eval_m_k (void *mem) const
 
double eval_tr_ratio (double val_f, double val_f_corr, double val_m_k) const
 
void tr_update (void *mem, double &tr_rad, double tr_ratio) const
 
int step_update (void *mem, double tr_ratio) const
 
int feasibility_iterations (void *mem, double tr_rad) const
 
void anderson_acc_step_update (void *mem, casadi_int iter_index) const
 
void anderson_acc_init_memory (void *mem, double *step, double *iterate) const
 
void anderson_acc_update_memory (void *mem, double *step, double *iterate) const
 
int solve (void *mem) const override
 
void codegen_body (CodeGenerator &g) const override
 Generate code for the function body. More...
 
void codegen_declarations (CodeGenerator &g) const override
 Generate code for the declarations of the C function. More...
 
const Function getConic () const
 Access Conic. More...
 
void print_iteration () const
 Print iteration header. More...
 
void print_iteration (casadi_int iter, double obj, double m_k, double tr_ratio, double pr_inf, double du_inf, double dx_norm, double rg, double tr_rad, std::string info) const
 Print iteration. More...
 
virtual int solve_QP (FeasiblesqpmethodMemory *m, const double *H, const double *g, const double *lbdz, const double *ubdz, const double *A, double *x_opt, double *dlam, int mode) const
 
virtual int solve_LP (FeasiblesqpmethodMemory *m, const double *g, const double *lbdz, const double *ubdz, const double *A, double *x_opt, double *dlam, int mode) const
 
void codegen_qp_solve (CodeGenerator &cg, const std::string &H, const std::string &g, const std::string &lbdz, const std::string &ubdz, const std::string &A, const std::string &x_opt, const std::string &dlam, int mode) const
 
void codegen_tr_update (CodeGenerator &cg, const std::string &tr_rad, const std::string &tr_ratio) const
 
void codegen_eval_m_k (CodeGenerator &cg) const
 
void codegen_eval_tr_ratio (CodeGenerator &cg, const std::string &val_f, const std::string &val_f_corr, const std::string &val_m_k) const
 
void codegen_step_update (CodeGenerator &cg, const std::string &tr_ratio) const
 
void codegen_feasibility_iterations (CodeGenerator &cg, const std::string &tr_rad) const
 
void serialize_body (SerializingStream &s) const override
 Serialize an object without type information. More...
 
void serialize_type (SerializingStream &s) const override
 Serialize type information. More...
 
std::string serialize_base_function () const override
 String used to identify the immediate FunctionInternal subclass. More...
 
void disp_more (std::ostream &stream) const override
 Print description. More...
 
virtual void check_inputs (void *mem) const
 Check if the inputs correspond to a well-posed problem. More...
 
double get_default_in (casadi_int ind) const override
 Get default input value. More...
 
virtual bool integer_support () const
 Can discrete variables be treated. More...
 
int eval (const double **arg, double **res, casadi_int *iw, double *w, void *mem) const final
 Evaluate numerically. More...
 
void codegen_body_enter (CodeGenerator &g) const override
 Generate code for the function body. More...
 
void codegen_body_exit (CodeGenerator &g) const override
 Generate code for the function body. More...
 
bool uses_output () const override
 Do the derivative functions need nondifferentiated outputs? More...
 
int callback (NlpsolMemory *m) const
 
Function kkt () const
 
bool is_a (const std::string &type, bool recursive) const override
 Check if the function is of a particular type. More...
 
virtual DM getReducedHessian ()
 
virtual void setOptionsFromFile (const std::string &file)
 Read options from parameter xml. More...
 
void finalize () override
 Finalize initialization. More...
 
void join_results (OracleMemory *m) const
 Combine results from different threads. More...
 
const Functionoracle () const override
 Get oracle. More...
 
void expand ()
 
Function create_function (const Function &oracle, const std::string &fname, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Function::AuxOut &aux=Function::AuxOut(), const Dict &opts=Dict())
 
Function create_function (const std::string &fname, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Function::AuxOut &aux=Function::AuxOut(), const Dict &opts=Dict())
 
Function create_function (const std::string &fname, const std::vector< MX > &e_in, const std::vector< MX > &e_out, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Dict &opts=Dict())
 
Function create_forward (const std::string &fname, casadi_int nfwd)
 
void set_function (const Function &fcn, const std::string &fname, bool jit=false)
 
void set_function (const Function &fcn)
 
int calc_function (OracleMemory *m, const std::string &fcn, const double *const *arg=nullptr, int thread_id=0) const
 
int calc_sp_forward (const std::string &fcn, const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const
 
int calc_sp_reverse (const std::string &fcn, bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const
 
std::vector< std::string > get_function () const override
 Get list of dependency functions. More...
 
const Functionget_function (const std::string &name) const override
 
virtual bool monitored (const std::string &name) const
 
bool has_function (const std::string &fname) const override
 
std::string generate_dependencies (const std::string &fname, const Dict &opts) const override
 Export / Generate C code for the generated functions. More...
 
void jit_dependencies (const std::string &fname) override
 JIT for dependencies. More...
 
int local_init_mem (void *mem) const
 Initalize memory block. More...
 
void set_temp (void *mem, const double **arg, double **res, casadi_int *iw, double *w) const override
 Set the work vectors. More...
 
virtual std::string getAdaptorSolverName () const
 Obtain solver name from Adaptor. More...
 
Dict generate_options (const std::string &target) const override
 Reconstruct options dict. More...
 
void change_option (const std::string &option_name, const GenericType &option_value) override
 Change option after object creation for debugging. More...
 
void reset_dump_count ()
 Reset the counter used to name dump files. More...
 
Function self () const
 Get a public class instance. More...
 
virtual Function factory (const std::string &name, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Function::AuxOut &aux, const Dict &opts) const
 
void add_embedded (std::map< FunctionInternal *, Function > &all_fun, const Function &dep, casadi_int max_depth) const
 
virtual void find (std::map< FunctionInternal *, Function > &all_fun, casadi_int max_depth) const
 
virtual std::vector< bool > which_depends (const std::string &s_in, const std::vector< std::string > &s_out, casadi_int order, bool tr=false) const
 Which variables enter with some order. More...
 
virtual int eval_sx (const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w, void *mem, bool always_inline, bool never_inline) const
 Evaluate with symbolic scalars. More...
 
virtual void eval_mx (const MXVector &arg, MXVector &res, bool always_inline, bool never_inline) const
 Evaluate with symbolic matrices. More...
 
template<typename M >
void call (const std::vector< M > &arg, std::vector< M > &res, bool always_inline, bool never_inline) const
 Call a function, templated. More...
 
template<typename M >
bool matching_arg (const std::vector< M > &arg, casadi_int &npar) const
 Check if input arguments that needs to be replaced. More...
 
template<typename M >
bool matching_res (const std::vector< M > &arg, casadi_int &npar) const
 Check if output arguments that needs to be replaced. More...
 
template<typename M >
std::vector< M > replace_arg (const std::vector< M > &arg, casadi_int npar) const
 Replace 0-by-0 inputs. More...
 
template<typename M >
std::vector< M > project_arg (const std::vector< M > &arg, casadi_int npar) const
 Project sparsities. More...
 
template<typename M >
std::vector< M > project_res (const std::vector< M > &arg, casadi_int npar) const
 Project sparsities. More...
 
template<typename M >
std::vector< M > replace_res (const std::vector< M > &res, casadi_int npar) const
 Replace 0-by-0 outputs. More...
 
template<typename M >
std::vector< std::vector< M > > replace_fseed (const std::vector< std::vector< M >> &fseed, casadi_int npar) const
 Replace 0-by-0 forward seeds. More...
 
template<typename M >
std::vector< std::vector< M > > replace_fseed (const std::vector< std::vector< M > > &fseed, casadi_int npar) const
 
template<typename M >
std::vector< std::vector< M > > replace_aseed (const std::vector< std::vector< M >> &aseed, casadi_int npar) const
 Replace 0-by-0 reverse seeds. More...
 
template<typename M >
std::vector< std::vector< M > > replace_aseed (const std::vector< std::vector< M > > &aseed, casadi_int npar) const
 
std::vector< MXmapsum_mx (const std::vector< MX > &arg, const std::string &parallelization)
 Parallel evaluation. More...
 
std::string diff_prefix (const std::string &prefix) const
 Determine prefix for differentiated functions. More...
 
virtual Function slice (const std::string &name, const std::vector< casadi_int > &order_in, const std::vector< casadi_int > &order_out, const Dict &opts) const
 returns a new function with a selection of inputs/outputs of the original More...
 
bool has_derivative () const
 Can derivatives be calculated in any way? More...
 
virtual double ad_weight () const
 Weighting factor for chosing forward/reverse mode. More...
 
virtual double sp_weight () const
 Weighting factor for chosing forward/reverse mode,. More...
 
virtual std::vector< MXfree_mx () const
 Get free variables (MX) More...
 
virtual std::vector< SXfree_sx () const
 Get free variables (SX) More...
 
virtual bool has_free () const
 Does the function have free variables. More...
 
virtual void generate_lifted (Function &vdef_fcn, Function &vinit_fcn) const
 Extract the functions needed for the Lifted Newton method. More...
 
virtual casadi_int n_instructions () const
 Get the number of atomic operations. More...
 
virtual casadi_int instruction_id (casadi_int k) const
 Get an atomic operation operator index. More...
 
virtual std::vector< casadi_int > instruction_input (casadi_int k) const
 Get the (integer) input arguments of an atomic operation. More...
 
virtual double instruction_constant (casadi_int k) const
 Get the floating point output argument of an atomic operation. More...
 
virtual std::vector< casadi_int > instruction_output (casadi_int k) const
 Get the (integer) output argument of an atomic operation. More...
 
virtual casadi_int n_nodes () const
 Number of nodes in the algorithm. More...
 
virtual MX instruction_MX (casadi_int k) const
 get MX expression associated with instruction More...
 
virtual SX instructions_sx () const
 get SX expression associated with instructions More...
 
Function wrap () const
 Wrap in an Function instance consisting of only one MX call. More...
 
Function wrap_as_needed (const Dict &opts) const
 Wrap in an Function instance consisting of only one MX call. More...
 
Dict cache () const
 Get all functions in the cache. More...
 
bool incache (const std::string &fname, Function &f, const std::string &suffix="") const
 Get function in cache. More...
 
void tocache (const Function &f, const std::string &suffix="") const
 Save function to cache. More...
 
void tocache_if_missing (Function &f, const std::string &suffix="") const
 Save function to cache, only if missing. More...
 
void codegen (CodeGenerator &g, const std::string &fname) const
 Generate code the function. More...
 
void codegen_meta (CodeGenerator &g) const
 Generate meta-information allowing a user to evaluate a generated function. More...
 
void codegen_sparsities (CodeGenerator &g) const
 Codegen sparsities. More...
 
virtual std::string codegen_name (const CodeGenerator &g, bool ns=true) const
 Get name in codegen. More...
 
std::string codegen_mem (CodeGenerator &g, const std::string &index="mem") const
 Get thread-local memory object. More...
 
virtual void codegen_incref (CodeGenerator &g) const
 Codegen incref for dependencies. More...
 
virtual void codegen_decref (CodeGenerator &g) const
 Codegen decref for dependencies. More...
 
virtual void codegen_alloc_mem (CodeGenerator &g) const
 Codegen decref for alloc_mem. More...
 
virtual void codegen_init_mem (CodeGenerator &g) const
 Codegen decref for init_mem. More...
 
virtual void codegen_free_mem (CodeGenerator &g) const
 Codegen for free_mem. More...
 
virtual void codegen_checkout (CodeGenerator &g) const
 Codegen for checkout. More...
 
virtual void codegen_release (CodeGenerator &g) const
 Codegen for release. More...
 
std::string signature (const std::string &fname) const
 Code generate the function. More...
 
std::string signature_unrolled (const std::string &fname) const
 Code generate the function. More...
 
virtual std::string codegen_mem_type () const
 Thread-local memory object type. More...
 
virtual bool has_codegen () const
 Is codegen supported? More...
 
virtual void export_code (const std::string &lang, std::ostream &stream, const Dict &options) const
 Export function in a specific language. More...
 
void disp (std::ostream &stream, bool more) const override
 Display object. More...
 
std::string definition () const
 Get function signature: name:(inputs)->(outputs) More...
 
void print_dimensions (std::ostream &stream) const
 Print dimensions of inputs and outputs. More...
 
virtual std::vector< std::string > get_free () const
 Print free variables. More...
 
void get_partition (casadi_int iind, casadi_int oind, Sparsity &D1, Sparsity &D2, bool compact, bool symmetric, bool allow_forward, bool allow_reverse) const
 Get the unidirectional or bidirectional partition. More...
 
virtual double get_max_in (casadi_int ind) const
 Get largest input value. More...
 
virtual double get_min_in (casadi_int ind) const
 Get smallest input value. More...
 
virtual std::vector< double > get_nominal_in (casadi_int ind) const
 
virtual std::vector< double > get_nominal_out (casadi_int ind) const
 
virtual double get_reltol () const
 Get relative tolerance. More...
 
virtual double get_abstol () const
 Get absolute tolerance. More...
 
virtual bool get_diff_in (casadi_int i)
 Which inputs are differentiable. More...
 
virtual bool get_diff_out (casadi_int i)
 Which outputs are differentiable. More...
 
casadi_int index_in (const std::string &name) const
 Get input scheme index by name. More...
 
casadi_int index_out (const std::string &name) const
 Get output scheme index by name. More...
 
virtual int sp_forward (const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const
 Propagate sparsity forward. More...
 
virtual int sp_forward_block (const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem, casadi_int oind, casadi_int iind) const
 Propagate sparsity forward, specific block. More...
 
virtual int sp_reverse (bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const
 Propagate sparsity backwards. More...
 
void sz_work (size_t &sz_arg, size_t &sz_res, size_t &sz_iw, size_t &sz_w) const
 Get number of temporary variables needed. More...
 
size_t sz_arg () const
 Get required length of arg field. More...
 
size_t sz_res () const
 Get required length of res field. More...
 
size_t sz_iw () const
 Get required length of iw field. More...
 
size_t sz_w () const
 Get required length of w field. More...
 
void alloc_arg (size_t sz_arg, bool persistent=false)
 Ensure required length of arg field. More...
 
void alloc_res (size_t sz_res, bool persistent=false)
 Ensure required length of res field. More...
 
void alloc_iw (size_t sz_iw, bool persistent=false)
 Ensure required length of iw field. More...
 
void alloc_w (size_t sz_w, bool persistent=false)
 Ensure required length of w field. More...
 
void alloc (const Function &f, bool persistent=false, int num_threads=1)
 Ensure work vectors long enough to evaluate function. More...
 
void setup (void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
 Set the (persistent and temporary) work vectors. More...
 
virtual Dict info () const
 
Function map (casadi_int n, const std::string &parallelization) const
 Generate/retrieve cached serial map. More...
 
void generate_in (const std::string &fname, const double **arg) const
 Export an input file that can be passed to generate C code with a main. More...
 
void generate_out (const std::string &fname, double **res) const
 
virtual void merge (const std::vector< MX > &arg, std::vector< MX > &subs_from, std::vector< MX > &subs_to) const
 List merge opportunitities. More...
 
template<typename MatType >
std::vector< std::vector< MatType > > fwd_seed (casadi_int nfwd) const
 Symbolic expressions for the forward seeds. More...
 
template<typename MatType >
std::vector< std::vector< MatType > > symbolicAdjSeed (casadi_int nadj, const std::vector< MatType > &v) const
 Symbolic expressions for the adjoint seeds. More...
 
void print_in (std::ostream &stream, const double **arg, bool truncate) const
 Print inputs. More...
 
void print_out (std::ostream &stream, double **res, bool truncate) const
 Print outputs. More...
 
void construct (const Dict &opts)
 Construct. More...
 
void print_options (std::ostream &stream) const
 Print list of options. More...
 
void print_option (const std::string &name, std::ostream &stream) const
 Print all information there is to know about a certain option. More...
 
bool has_option (const std::string &option_name) const
 Does a particular option exist. More...
 
int checkout () const
 Checkout a memory object. More...
 
void release (int mem) const
 Release a memory object. More...
 
void * memory (int ind) const
 Memory objects. More...
 
bool has_memory (int ind) const
 Check for existance of memory object. More...
 
virtual void check_mem_count (casadi_int n) const
 Check for validatity of memory object count. More...
 
void clear_mem ()
 Clear all memory (called from destructor) More...
 
void print (const char *fmt,...) const
 C-style formatted printing during evaluation. More...
 
void sprint (char *buf, size_t buf_sz, const char *fmt,...) const
 C-style formatted printing to string. More...
 
void format_time (char *buffer, double time) const
 Format time in a fixed width 8 format. More...
 
void print_time (const std::map< std::string, FStats > &fstats) const
 Print timing statistics. More...
 
void serialize (SerializingStream &s) const
 Serialize an object. More...
 
casadi_int getCount () const
 Get the reference count. More...
 
std::string debug_repr (const SharedObjectInternal *) const
 
GenericWeakRef< SharedObject, SharedObjectInternal > * weak ()
 Get a weak reference to the object. More...
 
size_t get_n_in () override
 Number of function inputs and outputs. More...
 
size_t get_n_out () override
 Number of function inputs and outputs. More...
 
Sparsity get_sparsity_in (casadi_int i) override
 Sparsities of function inputs and outputs. More...
 
Sparsity get_sparsity_out (casadi_int i) override
 Sparsities of function inputs and outputs. More...
 
std::string get_name_in (casadi_int i) override
 Names of function input and outputs. More...
 
std::string get_name_out (casadi_int i) override
 Names of function input and outputs. More...
 
bool has_forward (casadi_int nfwd) const override
 Generate a function that calculates forward mode derivatives. More...
 
Function get_forward (casadi_int nfwd, const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const override
 Generate a function that calculates forward mode derivatives. More...
 
bool has_reverse (casadi_int nadj) const override
 Generate a function that calculates reverse mode derivatives. More...
 
Function get_reverse (casadi_int nadj, const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const override
 Generate a function that calculates reverse mode derivatives. More...
 
virtual bool has_spfwd () const
 Is the class able to propagate seeds through the algorithm? More...
 
virtual bool has_sprev () const
 Is the class able to propagate seeds through the algorithm? More...
 
int eval_gen (const double **arg, double **res, casadi_int *iw, double *w, void *mem, bool always_inline, bool never_inline) const
 Evaluate numerically. More...
 
int eval_gen (const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w, void *mem, bool always_inline, bool never_inline) const
 Evaluate a function, overloaded. More...
 
int eval_gen (const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem, bool always_inline, bool never_inline) const
 Evaluate a function, overloaded. More...
 
virtual std::vector< DMeval_dm (const std::vector< DM > &arg) const
 Evaluate with DM matrices. More...
 
virtual bool has_eval_dm () const
 Evaluate with DM matrices. More...
 
void call_gen (const MXVector &arg, MXVector &res, casadi_int npar, bool always_inline, bool never_inline) const
 Call a function, overloaded. More...
 
template<typename D >
void call_gen (const std::vector< Matrix< D > > &arg, std::vector< Matrix< D > > &res, casadi_int npar, bool always_inline, bool never_inline) const
 Call a function, overloaded. More...
 
template<typename M >
void check_arg (const std::vector< M > &arg, casadi_int &npar) const
 Check if input arguments have correct length and dimensions. More...
 
template<typename M >
void check_res (const std::vector< M > &res, casadi_int &npar) const
 Check if output arguments have correct length and dimensions. More...
 
template<typename M >
std::map< std::string, M > convert_arg (const std::vector< M > &arg) const
 Convert from/to input/output lists/map. More...
 
template<typename M >
std::vector< M > convert_arg (const std::map< std::string, M > &arg) const
 Convert from/to input/output lists/map. More...
 
template<typename M >
std::map< std::string, M > convert_res (const std::vector< M > &res) const
 Convert from/to input/output lists/map. More...
 
template<typename M >
std::vector< M > convert_res (const std::map< std::string, M > &res) const
 Convert from/to input/output lists/map. More...
 
std::vector< double > nz_in (const std::vector< DM > &arg) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< DMnz_in (const std::vector< double > &arg) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< double > nz_out (const std::vector< DM > &res) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< DMnz_out (const std::vector< double > &res) const
 Convert from/to flat vector of input/output nonzeros. More...
 
virtual void call_forward (const std::vector< MX > &arg, const std::vector< MX > &res, const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens, bool always_inline, bool never_inline) const
 Forward mode AD, virtual functions overloaded in derived classes. More...
 
virtual void call_forward (const std::vector< SX > &arg, const std::vector< SX > &res, const std::vector< std::vector< SX > > &fseed, std::vector< std::vector< SX > > &fsens, bool always_inline, bool never_inline) const
 Forward mode AD, virtual functions overloaded in derived classes. More...
 
virtual void call_reverse (const std::vector< MX > &arg, const std::vector< MX > &res, const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens, bool always_inline, bool never_inline) const
 Reverse mode, virtual functions overloaded in derived classes. More...
 
virtual void call_reverse (const std::vector< SX > &arg, const std::vector< SX > &res, const std::vector< std::vector< SX > > &aseed, std::vector< std::vector< SX > > &asens, bool always_inline, bool never_inline) const
 Reverse mode, virtual functions overloaded in derived classes. More...
 
Function jacobian () const
 Return Jacobian of all input elements with respect to all output elements. More...
 
virtual bool has_jacobian () const
 Return Jacobian of all input elements with respect to all output elements. More...
 
virtual Function get_jacobian (const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const
 Return Jacobian of all input elements with respect to all output elements. More...
 
Sparsityjac_sparsity (casadi_int oind, casadi_int iind, bool compact, bool symmetric) const
 Get Jacobian sparsity. More...
 
virtual bool has_jac_sparsity (casadi_int oind, casadi_int iind) const
 Get Jacobian sparsity. More...
 
virtual Sparsity get_jac_sparsity (casadi_int oind, casadi_int iind, bool symmetric) const
 Get Jacobian sparsity. More...
 
Function forward (casadi_int nfwd) const
 Return function that calculates forward derivatives. More...
 
Function reverse (casadi_int nadj) const
 Return function that calculates adjoint derivatives. More...
 
virtual const SX sx_in (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< SXsx_in () const
 Get function input(s) and output(s) More...
 
virtual const SX sx_out (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< SXsx_out () const
 Get function input(s) and output(s) More...
 
virtual const MX mx_in (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< MXmx_in () const
 Get function input(s) and output(s) More...
 
virtual const MX mx_out (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< MXmx_out () const
 Get function input(s) and output(s) More...
 
const DM dm_in (casadi_int ind) const
 Get function input(s) and output(s) More...
 
const std::vector< DMdm_in () const
 Get function input(s) and output(s) More...
 
const DM dm_out (casadi_int ind) const
 Get function input(s) and output(s) More...
 
const std::vector< DMdm_out () const
 Get function input(s) and output(s) More...
 
casadi_int nnz_in () const
 Number of input/output nonzeros. More...
 
casadi_int nnz_in (casadi_int ind) const
 Number of input/output nonzeros. More...
 
casadi_int nnz_out () const
 Number of input/output nonzeros. More...
 
casadi_int nnz_out (casadi_int ind) const
 Number of input/output nonzeros. More...
 
casadi_int numel_in () const
 Number of input/output elements. More...
 
casadi_int numel_in (casadi_int ind) const
 Number of input/output elements. More...
 
casadi_int numel_out (casadi_int ind) const
 Number of input/output elements. More...
 
casadi_int numel_out () const
 Number of input/output elements. More...
 
casadi_int size1_in (casadi_int ind) const
 Input/output dimensions. More...
 
casadi_int size2_in (casadi_int ind) const
 Input/output dimensions. More...
 
casadi_int size1_out (casadi_int ind) const
 Input/output dimensions. More...
 
casadi_int size2_out (casadi_int ind) const
 Input/output dimensions. More...
 
std::pair< casadi_int, casadi_int > size_in (casadi_int ind) const
 Input/output dimensions. More...
 
std::pair< casadi_int, casadi_int > size_out (casadi_int ind) const
 Input/output dimensions. More...
 
const Sparsitysparsity_in (casadi_int ind) const
 Input/output sparsity. More...
 
const Sparsitysparsity_out (casadi_int ind) const
 Input/output sparsity. More...
 
bool all_scalar () const
 Are all inputs and outputs scalar. More...
 
virtual bool jac_is_symm (casadi_int oind, casadi_int iind) const
 Is a Jacobian block known to be symmetric a priori? More...
 
Sparsity to_compact (casadi_int oind, casadi_int iind, const Sparsity &sp) const
 Convert to compact Jacobian sparsity pattern. More...
 
Sparsity from_compact (casadi_int oind, casadi_int iind, const Sparsity &sp) const
 Convert from compact Jacobian sparsity pattern. More...
 
template<bool fwd>
Sparsity get_jac_sparsity_gen (casadi_int oind, casadi_int iind) const
 Get the sparsity pattern via sparsity seed propagation. More...
 
Sparsity get_jac_sparsity_hierarchical (casadi_int oind, casadi_int iind) const
 A flavor of get_jac_sparsity_gen that does hierarchical block structure recognition. More...
 
Sparsity get_jac_sparsity_hierarchical_symm (casadi_int oind, casadi_int iind) const
 
virtual std::vector< MXsymbolic_output (const std::vector< MX > &arg) const
 Get a vector of symbolic variables corresponding to the outputs. More...
 
virtual size_t codegen_sz_arg (const CodeGenerator &g) const
 Get required lengths, for codegen. More...
 
virtual size_t codegen_sz_res (const CodeGenerator &g) const
 Get required lengths, for codegen. More...
 
virtual size_t codegen_sz_iw (const CodeGenerator &g) const
 Get required lengths, for codegen. More...
 
virtual size_t codegen_sz_w (const CodeGenerator &g) const
 Get required lengths, for codegen. More...
 
virtual bool fwdViaJac (casadi_int nfwd) const
 Calculate derivatives by multiplying the full Jacobian and multiplying. More...
 
virtual bool adjViaJac (casadi_int nadj) const
 Calculate derivatives by multiplying the full Jacobian and multiplying. More...
 

Static Public Member Functions

static Nlpsolcreator (const std::string &name, const Function &nlp)
 Create a new NLP Solver. More...
 
static ProtoFunctiondeserialize (DeserializingStream &s)
 Deserialize into MX. More...
 
static void bound_consistency (casadi_int n, double *z, double *lam, const double *lbz, const double *ubz)
 
static std::string shortname ()
 Short name. More...
 
template<typename Type >
static void append_to_vec (GenericType &t, Type el)
 WORKAROUND: Add an element to an std::vector stored in a GenericType: More...
 
template<typename XType >
static Function create_oracle (const std::map< std::string, XType > &d, const Dict &opts)
 Convert dictionary to Problem. More...
 
static std::string forward_name (const std::string &fcn, casadi_int nfwd)
 Helper function: Get name of forward derivative function. More...
 
static std::string reverse_name (const std::string &fcn, casadi_int nadj)
 Helper function: Get name of adjoint derivative function. More...
 
template<typename MatType >
static MatType ensure_stacked (const MatType &v, const Sparsity &sp, casadi_int n)
 Ensure that a matrix's sparsity is a horizontal multiple of another, or empty. More...
 
template<typename MatType >
static bool purgable (const std::vector< MatType > &seed)
 Can a derivative direction be skipped. More...
 
static std::string string_from_UnifiedReturnStatus (UnifiedReturnStatus status)
 
static void print_canonical (std::ostream &stream, const Sparsity &sp, const double *nz)
 Print canonical representation of a numeric matrix. More...
 
static void print_canonical (std::ostream &stream, casadi_int sz, const double *nz)
 Print canonical representation of a numeric vector. More...
 
static void print_canonical (std::ostream &stream, double a)
 Print canonical representation of a number. More...
 
static bool has_plugin (const std::string &pname, bool verbose=false)
 Check if a plugin is available or can be loaded. More...
 
static const Optionsplugin_options (const std::string &pname)
 Get the plugin options. More...
 
static Deserialize plugin_deserialize (const std::string &pname)
 Get the plugin deserialize_map. More...
 
static Plugin pluginFromRegFcn (RegFcn regfcn)
 Instantiate a Plugin struct from a factory function. More...
 
static Plugin load_plugin (const std::string &pname, bool register_plugin=true, bool needs_lock=true)
 Load a plugin dynamically. More...
 
static handle_t load_library (const std::string &libname, std::string &resultpath, bool global)
 Load a library dynamically. More...
 
static void registerPlugin (const Plugin &plugin, bool needs_lock=true)
 Register an integrator in the factory. More...
 
static void registerPlugin (RegFcn regfcn, bool needs_lock=true)
 Register an integrator in the factory. More...
 
static Plugin & getPlugin (const std::string &pname)
 Load and get the creator function. More...
 
static Nlpsolinstantiate (const std::string &fname, const std::string &pname, Problem problem)
 
static bool check_mat (const Sparsity &arg, const Sparsity &inp, casadi_int &npar)
 

Public Attributes

casadi_feasiblesqpmethod_prob< double > p_
 
Function qpsol_
 QP solver for the subproblems. More...
 
Function qpsol_ela_
 QP solver for elastic mode subproblems. More...
 
bool exact_hessian_
 Exact Hessian? More...
 
bool use_sqp_
 Exact Hessian? More...
 
bool use_anderson_
 Use Anderson Acceleration. More...
 
casadi_int block_size_ = 0
 Maximum block size of Hessian. More...
 
casadi_int max_iter_
 Maximum, minimum number of SQP iterations. More...
 
casadi_int min_iter_
 
casadi_int lbfgs_memory_
 Memory size of L-BFGS method. More...
 
casadi_int sz_anderson_memory_
 
double tol_pr_
 Tolerance of primal and dual infeasibility. More...
 
double tol_du_
 
bool init_feasible_
 Initialize feasible qp's. More...
 
bool print_header_
 
bool print_iteration_
 
bool print_status_
 
Sparsity Hsp_
 
Sparsity Asp_
 
ConvexifyData convexify_data_
 Data for convexification. More...
 
bool convexify_
 convexify? More...
 
double optim_tol_
 
double feas_tol_
 
double tr_eta1_
 
double tr_eta2_
 
double tr_alpha1_
 
double tr_alpha2_
 
double tr_tol_
 
double tr_rad0_
 
double tr_acceptance_
 
double tr_rad_min_
 
double tr_rad_max_
 
std::vector< double > tr_scale_vector_
 
double contraction_acceptance_value_
 
casadi_int watchdog_
 
casadi_int max_inner_iter_
 
casadi_nlpsol_prob< double > p_nlp_
 
casadi_int nx_
 Number of variables. More...
 
casadi_int ng_
 Number of constraints. More...
 
casadi_int np_
 Number of parameters. More...
 
Function fcallback_
 callback function, executed at each iteration More...
 
casadi_int callback_step_
 Execute the callback function only after this amount of iterations. More...
 
std::string sens_linsol_
 Linear solver and options. More...
 
Dict sens_linsol_options_
 
std::vector< char > detect_simple_bounds_is_simple_
 
Function detect_simple_bounds_parts_
 
std::vector< casadi_int > detect_simple_bounds_target_x_
 
std::vector< casadi_int > detect_simple_bounds_target_g_
 
bool mi_
 
WeakRef kkt_
 Cache for KKT function. More...
 
bool always_inline_
 
bool never_inline_
 
size_t n_in_
 Number of inputs and outputs. More...
 
size_t n_out_
 
std::vector< bool > is_diff_in_
 Are inputs and outputs differentiable? More...
 
std::vector< bool > is_diff_out_
 
std::vector< Sparsitysparsity_in_
 Input and output sparsity. More...
 
std::vector< Sparsitysparsity_out_
 
std::vector< std::string > name_in_
 Input and output scheme. More...
 
std::vector< std::string > name_out_
 
bool jit_
 Use just-in-time compiler. More...
 
bool jit_cleanup_
 Cleanup jit source file. More...
 
std::string jit_serialize_
 Serialize behaviour. More...
 
std::string jit_name_
 Name if jit source file. More...
 
std::string jit_base_name_
 
bool jit_temp_suffix_
 Use a temporary name. More...
 
eval_t eval_
 Numerical evaluation redirected to a C function. More...
 
casadi_checkout_t checkout_
 Checkout redirected to a C function. More...
 
casadi_release_t release_
 Release redirected to a C function. More...
 
Dict stats_
 Dict of statistics (resulting from evaluate) More...
 
bool has_refcount_
 Reference counting in codegen? More...
 
Dict cache_init_
 Values to prepopulate the function cache with. More...
 
WeakCache< std::string, Functioncache_
 Function cache. More...
 
std::vector< Sparsityjac_sparsity_ [2]
 Cache for sparsities of the Jacobian blocks. More...
 
Function derivative_of_
 If the function is the derivative of another function. More...
 
void * user_data_
 User-set field. More...
 
std::string compiler_plugin_
 Just-in-time compiler. More...
 
Importer compiler_
 
Dict jit_options_
 
double jac_penalty_
 Penalty factor for using a complete Jacobian to calculate directional derivatives. More...
 
bool enable_forward_
 
bool enable_reverse_
 
bool enable_jacobian_
 
bool enable_fd_
 
bool enable_forward_op_
 
bool enable_reverse_op_
 
bool enable_jacobian_op_
 
bool enable_fd_op_
 
double ad_weight_
 Weighting factor for derivative calculation and sparsity pattern calculation. More...
 
double ad_weight_sp_
 
casadi_int max_num_dir_
 Maximum number of sensitivity directions. More...
 
bool inputs_check_
 Errors are thrown if numerical values of inputs look bad. More...
 
Dict fd_options_
 
double fd_step_
 
std::string fd_method_
 
bool print_in_
 
bool print_out_
 
bool print_canonical_
 
casadi_int max_io_
 
bool dump_in_
 
bool dump_out_
 
bool dump_
 
std::string dump_dir_
 
std::string dump_format_
 
Dict forward_options_
 
Dict reverse_options_
 
Dict jacobian_options_
 
Dict der_options_
 
Function custom_jacobian_
 
casadi_int dump_count_
 
std::string name_
 Name. More...
 
bool verbose_
 Verbose printout. More...
 
bool print_time_
 
bool record_time_
 
bool regularity_check_
 Errors are thrown when NaN is produced. More...
 
bool error_on_fail_
 Throw an exception on failure? More...
 
bool eval_errors_fatal_
 Options. More...
 
bool warn_initial_bounds_
 Options. More...
 
bool iteration_callback_ignore_errors_
 Options. More...
 
bool calc_multipliers_
 Options. More...
 
bool calc_lam_x_
 Options. More...
 
bool calc_lam_p_
 Options. More...
 
bool calc_f_
 Options. More...
 
bool calc_g_
 Options. More...
 
bool bound_consistency_
 Options. More...
 
double min_lam_
 Options. More...
 
bool no_nlp_grad_
 Options. More...
 
std::vector< bool > discrete_
 Options. More...
 
std::vector< bool > equality_
 Options. More...
 

Static Public Attributes

static const std::string meta_doc
 A documentation string. More...
 
static std::map< std::string, Plugin > solvers_
 Collection of solvers. More...
 
static const std::string infix_ = "nlpsol"
 Infix. More...
 
static std::map< std::string, ProtoFunction *(*)(DeserializingStream &)> deserialize_map
 

Protected Member Functions

 Feasiblesqpmethod (DeserializingStream &s)
 Deserializing constructor. More...
 
void set_jac_sparsity (casadi_int oind, casadi_int iind, const Sparsity &sp)
 Populate jac_sparsity_ and jac_sparsity_compact_ during initialization. More...
 
void initSingleton ()
 
void destroySingleton ()
 
shared_from_this ()
 Get a shared object from the current internal object. More...
 
const B shared_from_this () const
 Get a shared object from the current internal object. More...
 

Protected Attributes

Function oracle_
 Oracle: Used to generate other functions. More...
 
Dict common_options_
 Options for creating functions. More...
 
Dict specific_options_
 
bool show_eval_warnings_
 Show evaluation warnings. More...
 
int max_num_threads_
 
std::map< std::string, RegFunall_functions_
 
std::vector< std::string > monitor_
 
size_t stride_arg_
 
size_t stride_res_
 
size_t stride_iw_
 
size_t stride_w_
 
bool post_expand_
 
static const Options options_
 Options. More...
 
const Optionsget_options () const override
 Options. More...
 

Member Typedef Documentation

◆ Creator

typedef Nlpsol*(* casadi::Nlpsol::Creator) (const std::string &name, const Function &oracle)
inherited

Definition at line 277 of file nlpsol_impl.hpp.

◆ RegFcn

typedef int(* casadi::PluginInterface< Nlpsol >::RegFcn) (Plugin *plugin)
inherited

Definition at line 73 of file plugin_interface.hpp.

◆ weak_ref_type

Definition at line 152 of file shared_object.hpp.

Constructor & Destructor Documentation

◆ Feasiblesqpmethod() [1/2]

casadi::Feasiblesqpmethod::Feasiblesqpmethod ( const std::string &  name,
const Function nlp 
)
explicit

Definition at line 61 of file feasiblesqpmethod.cpp.

62  : Nlpsol(name, nlp) {
63  }
Nlpsol(const std::string &name, const Function &oracle)
Constructor.
Definition: nlpsol.cpp:267

◆ ~Feasiblesqpmethod()

casadi::Feasiblesqpmethod::~Feasiblesqpmethod ( )
override

Definition at line 65 of file feasiblesqpmethod.cpp.

65  {
66  clear_mem();
67  }
void clear_mem()
Clear all memory (called from destructor)

References casadi::ProtoFunction::clear_mem().

◆ Feasiblesqpmethod() [2/2]

casadi::Feasiblesqpmethod::Feasiblesqpmethod ( DeserializingStream s)
explicitprotected

Definition at line 2340 of file feasiblesqpmethod.cpp.

2340  : Nlpsol(s) {
2341  int version = s.version("Feasiblesqpmethod", 1, 3);
2342  s.unpack("Feasiblesqpmethod::qpsol", qpsol_);
2343  if (version>=3) {
2344  s.unpack("Feasiblesqpmethod::qpsol_ela", qpsol_ela_);
2345  }
2346  s.unpack("Feasiblesqpmethod::exact_hessian", exact_hessian_);
2347  s.unpack("Feasiblesqpmethod::max_iter", max_iter_);
2348  s.unpack("Feasiblesqpmethod::min_iter", min_iter_);
2349  s.unpack("Feasiblesqpmethod::lbfgs_memory", lbfgs_memory_);
2350  s.unpack("Feasiblesqpmethod::tol_pr_", tol_pr_);
2351  s.unpack("Feasiblesqpmethod::tol_du_", tol_du_);
2352  s.unpack("Feasiblesqpmethod::print_header", print_header_);
2353  s.unpack("Feasiblesqpmethod::print_iteration", print_iteration_);
2354  s.unpack("Feasiblesqpmethod::print_status", print_status_);
2355 
2356  // if (version>=3) {
2357  // s.unpack("Feasiblesqpmethod::elastic_mode", elastic_mode_);
2358  // s.unpack("Feasiblesqpmethod::gamma_0", gamma_0_);
2359  // s.unpack("Feasiblesqpmethod::gamma_max", gamma_max_);
2360  // s.unpack("Feasiblesqpmethod::gamma_1_min", gamma_1_min_);
2361  // s.unpack("Feasiblesqpmethod::init_feasible", init_feasible_);
2362  // s.unpack("Feasiblesqpmethod::so_corr", so_corr_);
2363  // } else {
2364  // // elastic_mode_ = false;
2365  // // gamma_0_ = 0;
2366  // // gamma_max_ = 0;
2367  // // gamma_1_min_ = 0;
2368  // init_feasible_ = false;
2369  // // so_corr_ = false;
2370  // }
2371 
2372  s.unpack("Feasiblesqpmethod::Hsp", Hsp_);
2373  if (version==1) {
2374  Sparsity Hrsp;
2375  s.unpack("Feasiblesqpmethod::Hrsp", Hrsp);
2376  }
2377  s.unpack("Feasiblesqpmethod::Asp", Asp_);
2378  if (version==1) {
2379  double convexify_margin;
2380  s.unpack("Feasiblesqpmethod::convexify_margin", convexify_margin);
2381  char convexify_strategy;
2382  s.unpack("Feasiblesqpmethod::convexify_strategy", convexify_strategy);
2383  casadi_assert(convexify_strategy==0, "deserializtion failed.");
2384  bool Hsp_project;
2385  s.unpack("Feasiblesqpmethod::Hsp_project", Hsp_project);
2386  bool scc_transform;
2387  s.unpack("Feasiblesqpmethod::scc_transform", scc_transform);
2388  std::vector<casadi_int> scc_offset;
2389  s.unpack("Feasiblesqpmethod::scc_offset", scc_offset);
2390  std::vector<casadi_int> scc_mapping;
2391  s.unpack("Feasiblesqpmethod::scc_mapping", scc_mapping);
2392  casadi_int max_iter_eig;
2393  s.unpack("Feasiblesqpmethod::max_iter_eig", max_iter_eig);
2394  casadi_int block_size;
2395  s.unpack("Feasiblesqpmethod::block_size", block_size);
2396  Sparsity scc_sp;
2397  s.unpack("Feasiblesqpmethod::scc_sp", scc_sp);
2398  convexify_ = false;
2399  }
2400  if (version>=2) {
2401  s.unpack("Feasiblesqpmethod::convexify", convexify_);
2402  if (convexify_) Convexify::deserialize(s, "Feasiblesqpmethod::", convexify_data_);
2403  }
2404  set_feasiblesqpmethod_prob();
2405  }
static MXNode * deserialize(DeserializingStream &s)
Deserialize without type information.
Definition: convexify.hpp:104
casadi_int lbfgs_memory_
Memory size of L-BFGS method.
ConvexifyData convexify_data_
Data for convexification.
casadi_int max_iter_
Maximum, minimum number of SQP iterations.
Function qpsol_ela_
QP solver for elastic mode subproblems.
Function qpsol_
QP solver for the subproblems.
bool exact_hessian_
Exact Hessian?
double tol_pr_
Tolerance of primal and dual infeasibility.

References Asp_, convexify_, convexify_data_, casadi::Convexify::deserialize(), exact_hessian_, Hsp_, lbfgs_memory_, max_iter_, min_iter_, print_header_, print_iteration_, print_status_, qpsol_, qpsol_ela_, tol_du_, tol_pr_, casadi::DeserializingStream::unpack(), and casadi::DeserializingStream::version().

Member Function Documentation

◆ ad_weight()

double casadi::FunctionInternal::ad_weight ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l5

Definition at line 3274 of file function_internal.cpp.

3274  {
3275  // If reverse mode derivatives unavailable, use forward
3276  if (!enable_reverse_) return 0;
3277 
3278  // If forward mode derivatives unavailable, use reverse
3279  if (!enable_forward_ && !enable_fd_) return 1;
3280 
3281  // Use the (potentially user set) option
3282  return ad_weight_;
3283  }
double ad_weight_
Weighting factor for derivative calculation and sparsity pattern calculation.

References casadi::FunctionInternal::ad_weight_, casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, and casadi::FunctionInternal::enable_reverse_.

Referenced by casadi::FunctionInternal::adjViaJac(), casadi::Function::expand(), casadi::FunctionInternal::fwdViaJac(), casadi::FunctionInternal::get_partition(), casadi::FunctionInternal::wrap(), and casadi::FunctionInternal::wrap_as_needed().

◆ add_embedded()

void casadi::FunctionInternal::add_embedded ( std::map< FunctionInternal *, Function > &  all_fun,
const Function dep,
casadi_int  max_depth 
) const
inherited

Definition at line 3717 of file function_internal.cpp.

3718  {
3719  // Add, if not already in graph and not null
3720  if (!dep.is_null() && all_fun.find(dep.get()) == all_fun.end()) {
3721  // Add to map
3722  all_fun[dep.get()] = dep;
3723  // Also add its dependencies
3724  if (max_depth > 0) dep->find(all_fun, max_depth - 1);
3725  }
3726  }

References casadi::FunctionInternal::find(), casadi::Function::get(), and casadi::GenericShared< Shared, Internal >::is_null().

Referenced by casadi::MXFunction::find(), casadi::Switch::find(), casadi::SXFunction::find(), and casadi::BSplineInterpolant::find().

◆ adjViaJac()

bool casadi::FunctionInternal::adjViaJac ( casadi_int  nadj) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nc

Definition at line 3009 of file function_internal.cpp.

3009  {
3010  if (!enable_reverse_) return true;
3011  if (jac_penalty_==-1) return false;
3012 
3013  // Heuristic 1: Jac calculated via reverse mode likely cheaper
3014  if (jac_penalty_*static_cast<double>(nnz_out())<nadj) return true;
3015 
3016  // Heuristic 2: Jac calculated via forward mode likely cheaper
3017  double w = ad_weight();
3018  if ((enable_forward_ || enable_fd_) &&
3019  jac_penalty_*w*static_cast<double>(nnz_in())<(1-w)*static_cast<double>(nadj))
3020  return true; // NOLINT
3021 
3022  return false;
3023  }
double jac_penalty_
Penalty factor for using a complete Jacobian to calculate directional derivatives.
virtual double ad_weight() const
Weighting factor for chosing forward/reverse mode.
casadi_int nnz_in() const
Number of input/output nonzeros.
casadi_int nnz_out() const
Number of input/output nonzeros.

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::enable_reverse_, casadi::FunctionInternal::jac_penalty_, casadi::FunctionInternal::nnz_in(), and casadi::FunctionInternal::nnz_out().

Referenced by casadi::FunctionInternal::call_reverse().

◆ all_scalar()

bool casadi::FunctionInternal::all_scalar ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mi

Definition at line 3748 of file function_internal.cpp.

3748  {
3749  // Check inputs
3750  for (casadi_int i=0; i<n_in_; ++i) {
3751  if (!sparsity_in_[i].is_scalar()) return false;
3752  }
3753  // Check outputs
3754  for (casadi_int i=0; i<n_out_; ++i) {
3755  if (!sparsity_out_[i].is_scalar()) return false;
3756  }
3757  // All are scalar
3758  return true;
3759  }
std::vector< Sparsity > sparsity_in_
Input and output sparsity.
size_t n_in_
Number of inputs and outputs.
std::vector< Sparsity > sparsity_out_

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::sparsity_in_, and casadi::FunctionInternal::sparsity_out_.

Referenced by casadi::FunctionInternal::call().

◆ alloc()

void casadi::FunctionInternal::alloc ( const Function f,
bool  persistent = false,
int  num_threads = 1 
)
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_n8

Definition at line 2958 of file function_internal.cpp.

2958  {
2959  if (f.is_null()) return;
2960  size_t sz_arg, sz_res, sz_iw, sz_w;
2961  f.sz_work(sz_arg, sz_res, sz_iw, sz_w);
2962  alloc_arg(sz_arg*num_threads, persistent);
2963  alloc_res(sz_res*num_threads, persistent);
2964  alloc_iw(sz_iw*num_threads, persistent);
2965  alloc_w(sz_w*num_threads, persistent);
2966  }
void alloc_iw(size_t sz_iw, bool persistent=false)
Ensure required length of iw field.
void alloc_res(size_t sz_res, bool persistent=false)
Ensure required length of res field.
void alloc_arg(size_t sz_arg, bool persistent=false)
Ensure required length of arg field.
size_t sz_res() const
Get required length of res field.
size_t sz_w() const
Get required length of w field.
void alloc_w(size_t sz_w, bool persistent=false)
Ensure required length of w field.
size_t sz_arg() const
Get required length of arg field.
size_t sz_iw() const
Get required length of iw field.

References casadi::FunctionInternal::alloc_arg(), casadi::FunctionInternal::alloc_iw(), casadi::FunctionInternal::alloc_res(), casadi::FunctionInternal::alloc_w(), casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), and casadi::Function::sz_work().

Referenced by casadi::OracleFunction::finalize(), casadi::KinsolInterface::get_jtimes(), casadi::FiniteDiff::init(), casadi::Nlpsol::init(), casadi::Rootfinder::init(), casadi::Switch::init(), init(), casadi::ImplicitToNlp::init(), casadi::QpToNlp::init(), casadi::Qrsqp::init(), casadi::Scpgen::init(), and casadi::Sqpmethod::init().

◆ alloc_arg()

void casadi::FunctionInternal::alloc_arg ( size_t  sz_arg,
bool  persistent = false 
)
inherited

◆ alloc_iw()

void casadi::FunctionInternal::alloc_iw ( size_t  sz_iw,
bool  persistent = false 
)
inherited

◆ alloc_mem()

void* casadi::Feasiblesqpmethod::alloc_mem ( ) const
inlineoverridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 94 of file feasiblesqpmethod.hpp.

94 { return new FeasiblesqpmethodMemory();}

◆ alloc_res()

void casadi::FunctionInternal::alloc_res ( size_t  sz_res,
bool  persistent = false 
)
inherited

◆ alloc_w()

void casadi::FunctionInternal::alloc_w ( size_t  sz_w,
bool  persistent = false 
)
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_n7

Definition at line 2950 of file function_internal.cpp.

2950  {
2951  if (persistent) {
2952  sz_w_per_ += sz_w;
2953  } else {
2954  sz_w_tmp_ = std::max(sz_w_tmp_, sz_w);
2955  }
2956  }

References casadi::FunctionInternal::sz_w().

Referenced by casadi::FunctionInternal::alloc(), casadi::BlazingSplineFunction::init(), casadi::External::init(), casadi::FiniteDiff::init(), casadi::FmuFunction::init(), casadi::Integrator::init(), casadi::FixedStepIntegrator::init(), casadi::Interpolant::init(), casadi::JitFunction::init(), casadi::Map::init(), casadi::OmpMap::init(), casadi::ThreadMap::init(), casadi::MapSum::init(), casadi::MXFunction::init(), casadi::Nlpsol::init(), casadi::Rootfinder::init(), casadi::Switch::init(), casadi::SXFunction::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::CbcInterface::init(), casadi::ClarabelInterface::init(), casadi::ClpInterface::init(), casadi::CplexInterface::init(), casadi::DaqpInterface::init(), casadi::FatropConicInterface::init(), casadi::FatropInterface::init(), casadi::GurobiInterface::init(), casadi::HighsInterface::init(), casadi::HpipmInterface::init(), casadi::IpoptInterface::init(), casadi::KnitroInterface::init(), casadi::MadnlpInterface::init(), casadi::OoqpInterface::init(), casadi::OsqpInterface::init(), casadi::ProxqpInterface::init(), casadi::QpoasesInterface::init(), casadi::SLEQPInterface::init(), casadi::SlicotDple::init(), casadi::SlicotExpm::init(), casadi::SnoptInterface::init(), casadi::CvodesInterface::init(), casadi::IdasInterface::init(), casadi::KinsolInterface::init(), casadi::SundialsInterface::init(), casadi::SuperscsInterface::init(), casadi::WorhpInterface::init(), casadi::BSplineInterpolant::init(), casadi::FastNewton::init(), init(), casadi::ImplicitToNlp::init(), casadi::Ipqp::init(), casadi::LinearInterpolant::init(), casadi::LinearInterpolantJac::init(), casadi::Newton::init(), casadi::QpToNlp::init(), casadi::Qrqp::init(), casadi::Qrsqp::init(), casadi::Scpgen::init(), and casadi::Sqpmethod::init().

◆ anderson_acc_init_memory()

void casadi::Feasiblesqpmethod::anderson_acc_init_memory ( void *  mem,
double *  step,
double *  iterate 
) const

Definition at line 612 of file feasiblesqpmethod.cpp.

612  {
613  auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
614  auto d = &m->d;
615 
616  casadi_clear(d->anderson_memory_step, sz_anderson_memory_*nx_);
617  casadi_clear(d->anderson_memory_iterate, sz_anderson_memory_*nx_);
618 
619  // if (sz_anderson_memory_ == 1) {
620  // casadi_copy(step, nx_, d->anderson_memory_step);
621  // casadi_copy(x, nx_, d->anderson_memory_iterate);
622  // } else {
623  // print("This is not implemented yet!!!");
624  // }
625 
626  casadi_copy(step, nx_, d->anderson_memory_step);
627  casadi_copy(iterate, nx_, d->anderson_memory_iterate);
628 
629 }
casadi_int nx_
Number of variables.
Definition: nlpsol_impl.hpp:66
void casadi_copy(const T1 *x, casadi_int n, T1 *y)
COPY: y <-x.
void casadi_clear(T1 *x, casadi_int n)
CLEAR: x <- 0.

References casadi::casadi_clear(), casadi::casadi_copy(), casadi::FeasiblesqpmethodMemory::d, casadi::Nlpsol::nx_, and sz_anderson_memory_.

Referenced by feasibility_iterations().

◆ anderson_acc_step_update()

void casadi::Feasiblesqpmethod::anderson_acc_step_update ( void *  mem,
casadi_int  iter_index 
) const

Definition at line 553 of file feasiblesqpmethod.cpp.

553  {
554  auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
555  auto d = &m->d;
556 
557  if (sz_anderson_memory_ == 1) {
558  // Calculte gamma
559  casadi_copy(d->dx_feas, nx_, d->z_tmp);
560  casadi_axpy(nx_, -1.0, d->anderson_memory_step, d->z_tmp);
561  *d->gamma = casadi_dot(nx_, d->dx_feas, d->z_tmp) / casadi_dot(nx_, d->z_tmp, d->z_tmp);
562  // DM(gamma).to_file("gamma.mtx");
563 
564 
565  // Prepare the step update
566  casadi_copy(d->z_feas, nx_, d->z_tmp);
567  casadi_axpy(nx_, -1.0, d->anderson_memory_iterate, d->z_tmp);
568  casadi_axpy(nx_, 1.0, d->dx_feas, d->z_tmp);
569  casadi_axpy(nx_, -1.0, d->anderson_memory_step, d->z_tmp);
570 
571  // Update the Anderson memory
572  anderson_acc_update_memory(mem, d->dx_feas, d->z_feas);
573  // casadi_copy(d->dx_feas, nx_, d->anderson_memory_step);
574  // casadi_copy(d->z_feas, nx_, d->anderson_memory_iterate);
575 
576  // Do the step update
577  double beta = 1.0;
578  casadi_axpy(nx_, beta, d->dx_feas, d->z_feas);
579  casadi_axpy(nx_, -*d->gamma, d->z_tmp, d->z_feas);
580  // DM(std::vector<double>(d->z_feas,d->z_feas+nx_)).to_file("dx_anderson2.mtx");
581 
582  } else {
583  print("This is not implemented yet!!!");
584  casadi_int curr_stage = fmin(iter_index+1, sz_anderson_memory_);
585  // Create matrix F_k
586  casadi_copy(d->dx_feas, nx_, d->z_tmp);
587  casadi_copy(d->anderson_memory_step, (curr_stage-1)*nx_, d->z_tmp+nx_);
588  casadi_axpy(curr_stage*nx_, -1.0, d->anderson_memory_step+nx_, d->z_tmp);
589 
590  // Solve the least-squares problem
591  casadi_dense_lsqr_solve(d->z_tmp, d->dx_feas, 1, 1, curr_stage, nx_, d->gamma);
592 
593  // Update the Anderson memory
594  anderson_acc_update_memory(mem, d->dx_feas, d->z_feas);
595 
597  double beta = 1.0;
598  // Calculate E_k + beta*F_k
599  casadi_axpy(nx_, 1.0, d->z_feas, d->z_tmp);
600  casadi_axpy((curr_stage-1)*nx_, 1.0, d->anderson_memory_iterate, d->z_tmp+nx_);
601  casadi_axpy(curr_stage*nx_, -1.0, d->anderson_memory_iterate, d->z_tmp);
602  // Do the final update
603  casadi_axpy(nx_, beta, d->dx_feas, d->z_feas);
604  casadi_axpy(nx_, -*d->gamma, d->z_tmp, d->z_feas);
605 
606  }
607 }
void anderson_acc_update_memory(void *mem, double *step, double *iterate) const
void print(const char *fmt,...) const
C-style formatted printing during evaluation.
T1 casadi_dot(casadi_int n, const T1 *x, const T1 *y)
Inner product.
void casadi_axpy(casadi_int n, T1 alpha, const T1 *x, T1 *y)
AXPY: y <- a*x + y.

References anderson_acc_update_memory(), casadi::casadi_axpy(), casadi::casadi_copy(), casadi::casadi_dot(), casadi::FeasiblesqpmethodMemory::d, casadi::Nlpsol::nx_, casadi::ProtoFunction::print(), and sz_anderson_memory_.

Referenced by feasibility_iterations().

◆ anderson_acc_update_memory()

void casadi::Feasiblesqpmethod::anderson_acc_update_memory ( void *  mem,
double *  step,
double *  iterate 
) const

Definition at line 634 of file feasiblesqpmethod.cpp.

634  {
635  auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
636  auto d = &m->d;
637 
638  if (sz_anderson_memory_ == 1) {
639  casadi_copy(step, nx_, d->anderson_memory_step);
640  casadi_copy(iterate, nx_, d->anderson_memory_iterate);
641  } else {
642  // Shift old values further
643  casadi_copy(d->anderson_memory_step,
644  (sz_anderson_memory_-1)*nx_, d->anderson_memory_step + nx_);
645  casadi_copy(d->anderson_memory_iterate,
646  (sz_anderson_memory_-1)*nx_, d->anderson_memory_iterate + nx_);
647  // Insert new values
648  casadi_copy(step, nx_, d->anderson_memory_step);
649  casadi_copy(iterate, nx_, d->anderson_memory_iterate);
650  }
651 }

References casadi::casadi_copy(), casadi::FeasiblesqpmethodMemory::d, casadi::Nlpsol::nx_, and sz_anderson_memory_.

Referenced by anderson_acc_step_update().

◆ append_to_vec()

template<typename Type >
static void casadi::Nlpsol::append_to_vec ( GenericType t,
Type  el 
)
inlinestaticinherited

Definition at line 312 of file nlpsol_impl.hpp.

312  {
313  std::vector<Type> v = t;
314  v.push_back(el);
315  t = v;
316  }

◆ bound_consistency()

void casadi::Nlpsol::bound_consistency ( casadi_int  n,
double *  z,
double *  lam,
const double *  lbz,
const double *  ubz 
)
staticinherited

Definition at line 678 of file nlpsol.cpp.

679  {
680  casadi_assert_dev(z!=nullptr);
681  casadi_assert_dev(lam!=nullptr);
682  casadi_assert_dev(lbz!=nullptr);
683  casadi_assert_dev(ubz!=nullptr);
684  // Local variables
685  casadi_int i;
686  // Loop over variables
687  for (i=0; i<n; ++i) {
688  // Make sure bounds are respected
689  z[i] = std::fmin(std::fmax(z[i], lbz[i]), ubz[i]);
690  // Adjust multipliers
691  if (std::isinf(lbz[i]) && std::isinf(ubz[i])) {
692  // Both multipliers are infinite
693  lam[i] = 0.;
694  } else if (std::isinf(lbz[i]) || z[i] - lbz[i] > ubz[i] - z[i]) {
695  // Infinite lower bound or closer to upper bound than lower bound
696  lam[i] = std::fmax(0., lam[i]);
697  } else if (std::isinf(ubz[i]) || z[i] - lbz[i] < ubz[i] - z[i]) {
698  // Infinite upper bound or closer to lower bound than upper bound
699  lam[i] = std::fmin(0., lam[i]);
700  }
701  }
702  }

Referenced by casadi::Nlpsol::eval().

◆ cache()

Dict casadi::FunctionInternal::cache ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_26g

Definition at line 1054 of file function_internal.cpp.

1054  {
1055  // Return value
1056  Dict ret;
1057 
1058  // Retrieve all Function instances that haven't been deleted
1059  std::vector<std::string> keys;
1060  std::vector<Function> entries;
1061  cache_.cache(keys, entries);
1062 
1063  for (size_t i=0; i<keys.size(); ++i) {
1064  // Get the name of the key
1065  std::string s = keys[i];
1066  casadi_assert_dev(s.size() > 0);
1067  // Replace ':' with '_'
1068  std::replace(s.begin(), s.end(), ':', '_');
1069  // Remove trailing underscore, if any
1070  if (s.back() == '_') s.resize(s.size() - 1);
1071  // Add entry to function return
1072  ret[s] = entries[i];
1073  }
1074 
1075  return ret;
1076  }
WeakCache< std::string, Function > cache_
Function cache.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.

References casadi::FunctionInternal::cache_.

◆ calc_function()

int casadi::OracleFunction::calc_function ( OracleMemory m,
const std::string &  fcn,
const double *const *  arg = nullptr,
int  thread_id = 0 
) const
inherited

Definition at line 302 of file oracle_function.cpp.

304  {
305  auto ml = m->thread_local_mem.at(thread_id);
306  // Is the function monitored?
307  bool monitored = this->monitored(fcn);
308 
309  // Print progress
310  if (monitored) casadi_message("Calling \"" + fcn + "\"");
311 
312  // Respond to a possible Crl+C signals
313  // Python interrupt checker needs the GIL.
314  // We may not have access to it in a multi-threaded context
315  // See issue #2955
317 
318  // Get function
319  const Function& f = get_function(fcn);
320 
321  // Get statistics structure
322  FStats& fstats = ml->fstats.at(fcn);
323 
324  // Number of inputs and outputs
325  casadi_int n_in = f.n_in(), n_out = f.n_out();
326 
327  // Prepare stats, start timer
328  ScopedTiming tic(fstats);
329 
330  // Input buffers
331  if (arg) {
332  std::fill_n(ml->arg, n_in, nullptr);
333  for (casadi_int i=0; i<n_in; ++i) ml->arg[i] = *arg++;
334  }
335 
336  // Print inputs nonzeros
337  if (monitored) {
338  std::stringstream s;
339  s << fcn << " input nonzeros:\n";
340  for (casadi_int i=0; i<n_in; ++i) {
341  s << " " << i << " (" << f.name_in(i) << "): ";
342  if (ml->arg[i]) {
343  // Print nonzeros
344  s << "[";
345  for (casadi_int k=0; k<f.nnz_in(i); ++k) {
346  if (k!=0) s << ", ";
347  DM::print_scalar(s, ml->arg[i][k]);
348  }
349  s << "]\n";
350  } else {
351  // All zero input
352  s << "0\n";
353  }
354  }
355  casadi_message(s.str());
356  }
357 
358  // Evaluate memory-less
359  try {
360  if (f(ml->arg, ml->res, ml->iw, ml->w)) {
361  // Recoverable error
362  if (monitored) casadi_message(name_ + ":" + fcn + " failed");
363  return 1;
364  }
365  } catch(std::exception& ex) {
366  // Fatal error: Generate stack trace
367  casadi_error("Error in " + name_ + ":" + fcn + ":" + std::string(ex.what()));
368  }
369 
370  // Print output nonzeros
371  if (monitored) {
372  std::stringstream s;
373  s << fcn << " output nonzeros:\n";
374  for (casadi_int i=0; i<n_out; ++i) {
375  s << " " << i << " (" << f.name_out(i) << "): ";
376  if (ml->res[i]) {
377  // Print nonzeros
378  s << "[";
379  for (casadi_int k=0; k<f.nnz_out(i); ++k) {
380  if (k!=0) s << ", ";
381  DM::print_scalar(s, ml->res[i][k]);
382  }
383  s << "]\n";
384  } else {
385  // Ignored output
386  s << " N/A\n";
387  }
388  }
389  casadi_message(s.str());
390  }
391 
392  // Make sure not NaN or Inf
393  for (casadi_int i=0; i<n_out; ++i) {
394  if (!ml->res[i]) continue;
395  if (!std::all_of(ml->res[i], ml->res[i]+f.nnz_out(i), [](double v) { return isfinite(v);})) {
396  std::stringstream ss;
397 
398  auto it = std::find_if(ml->res[i], ml->res[i] + f.nnz_out(i),
399  [](double v) { return !isfinite(v);});
400  casadi_int k = std::distance(ml->res[i], it);
401  bool is_nan = isnan(ml->res[i][k]);
402  ss << name_ << ":" << fcn << " failed: " << (is_nan? "NaN" : "Inf") <<
403  " detected for output " << f.name_out(i) << ", at " << f.sparsity_out(i).repr_el(k) << ".";
404 
405  if (regularity_check_) {
406  casadi_error(ss.str());
407  } else {
408  if (show_eval_warnings_) casadi_warning(ss.str());
409  }
410  return -1;
411  }
412  }
413 
414  // Success
415  return 0;
416 }
static void check()
Raises an error if an interrupt was captured.
void print_scalar(std::ostream &stream) const
Print scalar.
std::vector< std::string > get_function() const override
Get list of dependency functions.
virtual bool monitored(const std::string &name) const
bool show_eval_warnings_
Show evaluation warnings.
bool regularity_check_
Errors are thrown when NaN is produced.

References casadi::InterruptHandler::check(), casadi::OracleFunction::get_function(), casadi::OracleFunction::max_num_threads_, casadi::OracleFunction::monitored(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::ProtoFunction::name_, casadi::Function::name_in(), casadi::Function::name_out(), casadi::Function::nnz_in(), casadi::Function::nnz_out(), casadi::Matrix< double >::print_scalar(), casadi::ProtoFunction::regularity_check_, casadi::Sparsity::repr_el(), casadi::OracleFunction::show_eval_warnings_, casadi::Function::sparsity_out(), and casadi::OracleMemory::thread_local_mem.

Referenced by casadi::KinsolInterface::bjac(), casadi::SundialsInterface::calc_daeB(), casadi::SundialsInterface::calc_daeF(), casadi::Integrator::calc_edot(), casadi::calc_function(), casadi::SundialsInterface::calc_jacF(), casadi::SundialsInterface::calc_jtimesF(), casadi::SundialsInterface::calc_quadB(), casadi::SundialsInterface::calc_quadF(), casadi::casadi_func_cons_jac(), casadi::casadi_func_cons_val(), casadi::casadi_func_hess_prod(), casadi::casadi_func_obj_grad(), casadi::casadi_func_obj_val(), casadi::KinsolInterface::djac(), casadi::Nlpsol::eval(), casadi::AlpaqaProblem::eval_f(), casadi::BonminUserClass::eval_f(), casadi::IpoptUserClass::eval_f(), casadi::AlpaqaProblem::eval_f_grad_f(), casadi::AlpaqaProblem::eval_g(), casadi::BonminUserClass::eval_g(), casadi::IpoptUserClass::eval_g(), casadi::BonminUserClass::eval_grad_f(), casadi::IpoptUserClass::eval_grad_f(), casadi::AlpaqaProblem::eval_grad_L(), casadi::BonminUserClass::eval_h(), casadi::IpoptUserClass::eval_h(), casadi::AlpaqaProblem::eval_hess_L(), casadi::AlpaqaProblem::eval_hess_L_prod(), casadi::AlpaqaProblem::eval_hess_ψ(), casadi::AlpaqaProblem::eval_hess_ψ_prod(), casadi::AlpaqaProblem::eval_jac_g(), casadi::BonminUserClass::eval_jac_g(), casadi::IpoptUserClass::eval_jac_g(), casadi::AlpaqaProblem::eval_ψ(), casadi::AlpaqaProblem::eval_ψ_grad_ψ(), casadi::Blocksqp::evaluate(), feasibility_iterations(), casadi::KinsolInterface::psetup(), casadi::KnitroInterface::solve(), casadi::SnoptInterface::solve(), casadi::WorhpInterface::solve(), solve(), casadi::Newton::solve(), casadi::Qrsqp::solve(), casadi::Sqpmethod::solve(), casadi::FixedStepIntegrator::stepB(), casadi::FixedStepIntegrator::stepF(), casadi::Integrator::trigger_event(), and casadi::SnoptInterface::userfun().

◆ calc_sp_forward()

int casadi::OracleFunction::calc_sp_forward ( const std::string &  fcn,
const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w 
) const
inherited

◆ calc_sp_reverse()

int casadi::OracleFunction::calc_sp_reverse ( const std::string &  fcn,
bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w 
) const
inherited

◆ call()

template<typename M >
void casadi::FunctionInternal::call ( const std::vector< M > &  arg,
std::vector< M > &  res,
bool  always_inline,
bool  never_inline 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kh

Definition at line 1559 of file function_internal.hpp.

1560  {
1561  // If all inputs are scalar ...
1562  if (all_scalar()) {
1563  // ... and some arguments are matrix-valued with matching dimensions ...
1564  bool matrix_call = false;
1565  std::pair<casadi_int, casadi_int> sz;
1566  for (auto&& a : arg) {
1567  if (!a.is_scalar() && !a.is_empty()) {
1568  if (!matrix_call) {
1569  // Matrix call
1570  matrix_call = true;
1571  sz = a.size();
1572  } else if (a.size()!=sz) {
1573  // Not same dimensions
1574  matrix_call = false;
1575  break;
1576  }
1577  }
1578  }
1579 
1580  // ... then, call multiple times
1581  if (matrix_call) {
1582  // Start with zeros
1583  res.resize(n_out_);
1584  M z = M::zeros(sz);
1585  for (auto&& a : res) a = z;
1586  // Call multiple times
1587  std::vector<M> arg1 = arg, res1;
1588  for (casadi_int c=0; c<sz.second; ++c) {
1589  for (casadi_int r=0; r<sz.first; ++r) {
1590  // Get scalar arguments
1591  for (casadi_int i=0; i<arg.size(); ++i) {
1592  if (arg[i].size()==sz) arg1[i] = arg[i](r, c);
1593  }
1594  // Call recursively with scalar arguments
1595  call(arg1, res1, always_inline, never_inline);
1596  // Get results
1597  casadi_assert_dev(res.size() == res1.size());
1598  for (casadi_int i=0; i<res.size(); ++i) res[i](r, c) = res1[i];
1599  }
1600  }
1601  // All elements assigned
1602  return;
1603  }
1604  }
1605 
1606  // Check if inputs need to be replaced
1607  casadi_int npar = 1;
1608  if (!matching_arg(arg, npar)) {
1609  return call(replace_arg(arg, npar), res, always_inline, never_inline);
1610  }
1611 
1612  // Call the type-specific method
1613  call_gen(arg, res, npar, always_inline, never_inline);
1614  }
void call_gen(const MXVector &arg, MXVector &res, casadi_int npar, bool always_inline, bool never_inline) const
Call a function, overloaded.
std::vector< M > replace_arg(const std::vector< M > &arg, casadi_int npar) const
Replace 0-by-0 inputs.
bool matching_arg(const std::vector< M > &arg, casadi_int &npar) const
Check if input arguments that needs to be replaced.
void call(const std::vector< M > &arg, std::vector< M > &res, bool always_inline, bool never_inline) const
Call a function, templated.
bool all_scalar() const
Are all inputs and outputs scalar.

References casadi::FunctionInternal::all_scalar(), casadi::FunctionInternal::call_gen(), casadi::FunctionInternal::matching_arg(), casadi::FunctionInternal::n_out_, and casadi::FunctionInternal::replace_arg().

◆ call_forward() [1/2]

void casadi::FunctionInternal::call_forward ( const std::vector< MX > &  arg,
const std::vector< MX > &  res,
const std::vector< std::vector< MX > > &  fseed,
std::vector< std::vector< MX > > &  fsens,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ku

Definition at line 3029 of file function_internal.cpp.

3033  {
3034  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3035  casadi_assert(!always_inline, "Class " + class_name() +
3036  " cannot be inlined in an MX expression");
3037 
3038  // Derivative information must be available
3039  casadi_assert(has_derivative(),
3040  "Derivatives cannot be calculated for " + name_);
3041 
3042  // Number of directional derivatives
3043  casadi_int nfwd = fseed.size();
3044  fsens.resize(nfwd);
3045 
3046  // Quick return if no seeds
3047  if (nfwd==0) return;
3048 
3049  // Check if seeds need to have dimensions corrected
3050  casadi_int npar = 1;
3051  for (auto&& r : fseed) {
3052  if (!matching_arg(r, npar)) {
3053  return FunctionInternal::call_forward(arg, res, replace_fseed(fseed, npar),
3054  fsens, always_inline, never_inline);
3055  }
3056  }
3057 
3058  // Calculating full Jacobian and then multiplying
3059  if (fwdViaJac(nfwd)) {
3060  // Multiply the Jacobian from the right
3061  std::vector<MX> darg = arg;
3062  darg.insert(darg.end(), res.begin(), res.end());
3063  std::vector<MX> J = jacobian()(darg);
3064  // Join forward seeds
3065  std::vector<MX> v(nfwd), all_fseed(n_in_);
3066  for (size_t i = 0; i < n_in_; ++i) {
3067  for (size_t d = 0; d < nfwd; ++d) v[d] = vec(fseed.at(d).at(i));
3068  all_fseed[i] = horzcat(v);
3069  }
3070  // Calculate forward sensitivities
3071  std::vector<MX> all_fsens(n_out_);
3072  std::vector<MX>::const_iterator J_it = J.begin();
3073  for (size_t oind = 0; oind < n_out_; ++oind) {
3074  for (size_t iind = 0; iind < n_in_; ++iind) {
3075  // Add contribution
3076  MX a = mtimes(*J_it++, all_fseed[iind]);
3077  all_fsens[oind] = all_fsens[oind].is_empty(true) ? a : all_fsens[oind] + a;
3078  }
3079  }
3080  // Split forward sensitivities
3081  for (size_t d = 0; d < nfwd; ++d) fsens[d].resize(n_out_);
3082  for (size_t i = 0; i < n_out_; ++i) {
3083  v = horzsplit(all_fsens[i]);
3084  casadi_assert_dev(v.size() == nfwd);
3085  for (size_t d = 0; d < nfwd; ++d) fsens[d][i] = reshape(v[d], size_out(i));
3086  }
3087  } else {
3088  // Evaluate in batches
3089  casadi_assert_dev(enable_forward_ || enable_fd_);
3090  casadi_int max_nfwd = max_num_dir_;
3091  if (!enable_fd_) {
3092  while (!has_forward(max_nfwd)) max_nfwd/=2;
3093  }
3094  casadi_int offset = 0;
3095  while (offset<nfwd) {
3096  // Number of derivatives, in this batch
3097  casadi_int nfwd_batch = std::min(nfwd-offset, max_nfwd);
3098 
3099  // All inputs and seeds
3100  std::vector<MX> darg;
3101  darg.reserve(n_in_ + n_out_ + n_in_);
3102  darg.insert(darg.end(), arg.begin(), arg.end());
3103  darg.insert(darg.end(), res.begin(), res.end());
3104  std::vector<MX> v(nfwd_batch);
3105  for (casadi_int i=0; i<n_in_; ++i) {
3106  for (casadi_int d=0; d<nfwd_batch; ++d) v[d] = fseed[offset+d][i];
3107  darg.push_back(horzcat(v));
3108  }
3109 
3110  // Create the evaluation node
3111  Function dfcn = self().forward(nfwd_batch);
3112  std::vector<MX> x = dfcn(darg);
3113 
3114  casadi_assert_dev(x.size()==n_out_);
3115 
3116  // Retrieve sensitivities
3117  for (casadi_int d=0; d<nfwd_batch; ++d) fsens[offset+d].resize(n_out_);
3118  for (casadi_int i=0; i<n_out_; ++i) {
3119  if (size2_out(i)>0) {
3120  v = horzsplit(x[i], size2_out(i));
3121  casadi_assert_dev(v.size()==nfwd_batch);
3122  } else {
3123  v = std::vector<MX>(nfwd_batch, MX(size_out(i)));
3124  }
3125  for (casadi_int d=0; d<nfwd_batch; ++d) fsens[offset+d][i] = v[d];
3126  }
3127 
3128  // Update offset
3129  offset += nfwd_batch;
3130  }
3131  }
3132  }
virtual void call_forward(const std::vector< MX > &arg, const std::vector< MX > &res, const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens, bool always_inline, bool never_inline) const
Forward mode AD, virtual functions overloaded in derived classes.
Function forward(casadi_int nfwd) const
Return function that calculates forward derivatives.
virtual bool has_forward(casadi_int nfwd) const
Return function that calculates forward derivatives.
std::vector< std::vector< M > > replace_fseed(const std::vector< std::vector< M >> &fseed, casadi_int npar) const
Replace 0-by-0 forward seeds.
bool has_derivative() const
Can derivatives be calculated in any way?
casadi_int size2_out(casadi_int ind) const
Input/output dimensions.
std::pair< casadi_int, casadi_int > size_out(casadi_int ind) const
Input/output dimensions.
casadi_int max_num_dir_
Maximum number of sensitivity directions.
virtual bool fwdViaJac(casadi_int nfwd) const
Calculate derivatives by multiplying the full Jacobian and multiplying.
Function jacobian() const
Return Jacobian of all input elements with respect to all output elements.
virtual std::string class_name() const =0
Readable name of the internal class.

References casadi::SharedObjectInternal::class_name(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::forward(), casadi::FunctionInternal::fwdViaJac(), casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::has_forward(), casadi::FunctionInternal::jacobian(), casadi::FunctionInternal::matching_arg(), casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::replace_fseed(), casadi::FunctionInternal::size2_out(), and casadi::FunctionInternal::size_out().

Referenced by casadi::Rootfinder::ad_forward(), casadi::Call::ad_forward(), casadi::MXFunction::ad_forward(), casadi::XFunction< DerivedType, MatType, NodeType >::call_forward(), casadi::MX::forward(), casadi::Integrator::get_forward_dae(), and casadi::Scpgen::init().

◆ call_forward() [2/2]

void casadi::FunctionInternal::call_forward ( const std::vector< SX > &  arg,
const std::vector< SX > &  res,
const std::vector< std::vector< SX > > &  fseed,
std::vector< std::vector< SX > > &  fsens,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ku

Definition at line 3248 of file function_internal.cpp.

3252  {
3253  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3254  if (fseed.empty()) { // Quick return if no seeds
3255  fsens.clear();
3256  return;
3257  }
3258  casadi_error("'forward' (SX) not defined for " + class_name());
3259  }

References casadi::SharedObjectInternal::class_name().

◆ call_gen() [1/2]

void casadi::FunctionInternal::call_gen ( const MXVector arg,
MXVector res,
casadi_int  npar,
bool  always_inline,
bool  never_inline 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kg

Definition at line 3922 of file function_internal.cpp.

3924  {
3925  if (npar==1) {
3926  eval_mx(arg, res, always_inline, never_inline);
3927  } else {
3928  // Split it up arguments
3929  std::vector<std::vector<MX>> v(npar, arg);
3930  std::vector<MX> t;
3931  for (int i=0; i<n_in_; ++i) {
3932  if (arg[i].size2()!=size2_in(i)) {
3933  t = horzsplit(arg[i], size2_in(i));
3934  casadi_assert_dev(t.size()==npar);
3935  for (int p=0; p<npar; ++p) v[p][i] = t[p];
3936  }
3937  }
3938  // Unroll the loop
3939  for (int p=0; p<npar; ++p) {
3940  eval_mx(v[p], t, always_inline, never_inline);
3941  v[p] = t;
3942  }
3943  // Concatenate results
3944  t.resize(npar);
3945  res.resize(n_out_);
3946  for (int i=0; i<n_out_; ++i) {
3947  for (int p=0; p<npar; ++p) t[p] = v[p][i];
3948  res[i] = horzcat(t);
3949  }
3950  }
3951  }
virtual void eval_mx(const MXVector &arg, MXVector &res, bool always_inline, bool never_inline) const
Evaluate with symbolic matrices.
casadi_int size2_in(casadi_int ind) const
Input/output dimensions.

References casadi::FunctionInternal::eval_mx(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, and casadi::FunctionInternal::size2_in().

Referenced by casadi::FunctionInternal::call().

◆ call_gen() [2/2]

template<typename D >
void casadi::FunctionInternal::call_gen ( const std::vector< Matrix< D > > &  arg,
std::vector< Matrix< D > > &  res,
casadi_int  npar,
bool  always_inline,
bool  never_inline 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kg

Definition at line 1663 of file function_internal.hpp.

1665  {
1666  std::vector< Matrix<D> > arg2 = project_arg(arg, npar);
1667 
1668  // Which arguments require mapped evaluation
1669  std::vector<bool> mapped(n_in_);
1670  for (casadi_int i=0; i<n_in_; ++i) {
1671  mapped[i] = arg[i].size2()!=size2_in(i);
1672  }
1673 
1674  // Allocate results
1675  res.resize(n_out_);
1676  for (casadi_int i=0; i<n_out_; ++i) {
1677  if (!res[i].sparsity().is_stacked(sparsity_out(i), npar)) {
1678  res[i] = Matrix<D>::zeros(repmat(sparsity_out(i), 1, npar));
1679  }
1680  }
1681 
1682  // Allocate temporary memory if needed
1683  std::vector<casadi_int> iw_tmp(sz_iw());
1684  std::vector<D> w_tmp(sz_w());
1685 
1686  // Get pointers to input arguments
1687  std::vector<const D*> argp(sz_arg());
1688  for (casadi_int i=0; i<n_in_; ++i) argp[i]=get_ptr(arg2[i]);
1689 
1690  // Get pointers to output arguments
1691  std::vector<D*> resp(sz_res());
1692  for (casadi_int i=0; i<n_out_; ++i) resp[i]=get_ptr(res[i]);
1693 
1694  // For all parallel calls
1695  for (casadi_int p=0; p<npar; ++p) {
1696  // Call memory-less
1697  if (eval_gen(get_ptr(argp), get_ptr(resp),
1698  get_ptr(iw_tmp), get_ptr(w_tmp), memory(0),
1699  always_inline, never_inline)) {
1700  if (error_on_fail_) casadi_error("Evaluation failed");
1701  }
1702  // Update offsets
1703  if (p==npar-1) break;
1704  for (casadi_int i=0; i<n_in_; ++i) if (mapped[i]) argp[i] += nnz_in(i);
1705  for (casadi_int i=0; i<n_out_; ++i) resp[i] += nnz_out(i);
1706  }
1707  }
std::vector< M > project_arg(const std::vector< M > &arg, casadi_int npar) const
Project sparsities.
const Sparsity & sparsity_out(casadi_int ind) const
Input/output sparsity.
int eval_gen(const double **arg, double **res, casadi_int *iw, double *w, void *mem, bool always_inline, bool never_inline) const
Evaluate numerically.
static Matrix< Scalar > zeros(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries zero.
bool error_on_fail_
Throw an exception on failure?
void * memory(int ind) const
Memory objects.
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.

References casadi::ProtoFunction::error_on_fail_, casadi::FunctionInternal::eval_gen(), casadi::get_ptr(), casadi::ProtoFunction::memory(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::project_arg(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::sparsity_out(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), and casadi::GenericMatrix< Matrix< Scalar > >::zeros().

◆ call_reverse() [1/2]

void casadi::FunctionInternal::call_reverse ( const std::vector< MX > &  arg,
const std::vector< MX > &  res,
const std::vector< std::vector< MX > > &  aseed,
std::vector< std::vector< MX > > &  asens,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kv

Definition at line 3134 of file function_internal.cpp.

3138  {
3139  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3140  casadi_assert(!always_inline, "Class " + class_name() +
3141  " cannot be inlined in an MX expression");
3142 
3143  // Derivative information must be available
3144  casadi_assert(has_derivative(),
3145  "Derivatives cannot be calculated for " + name_);
3146 
3147  // Number of directional derivatives
3148  casadi_int nadj = aseed.size();
3149  asens.resize(nadj);
3150 
3151  // Quick return if no seeds
3152  if (nadj==0) return;
3153 
3154  // Check if seeds need to have dimensions corrected
3155  casadi_int npar = 1;
3156  for (auto&& r : aseed) {
3157  if (!matching_res(r, npar)) {
3158  return FunctionInternal::call_reverse(arg, res, replace_aseed(aseed, npar),
3159  asens, always_inline, never_inline);
3160  }
3161  }
3162 
3163  // Calculating full Jacobian and then multiplying likely cheaper
3164  if (adjViaJac(nadj)) {
3165  // Multiply the transposed Jacobian from the right
3166  std::vector<MX> darg = arg;
3167  darg.insert(darg.end(), res.begin(), res.end());
3168  std::vector<MX> J = jacobian()(darg);
3169  // Join adjoint seeds
3170  std::vector<MX> v(nadj), all_aseed(n_out_);
3171  for (size_t i = 0; i < n_out_; ++i) {
3172  for (size_t d = 0; d < nadj; ++d) v[d] = vec(aseed.at(d).at(i));
3173  all_aseed[i] = horzcat(v);
3174  }
3175  // Calculate adjoint sensitivities
3176  std::vector<MX> all_asens(n_in_);
3177  std::vector<MX>::const_iterator J_it = J.begin();
3178  for (size_t oind = 0; oind < n_out_; ++oind) {
3179  for (size_t iind = 0; iind < n_in_; ++iind) {
3180  // Add contribution
3181  MX a = mtimes((*J_it++).T(), all_aseed[oind]);
3182  all_asens[iind] = all_asens[iind].is_empty(true) ? a : all_asens[iind] + a;
3183  }
3184  }
3185  // Split adjoint sensitivities
3186  for (size_t d = 0; d < nadj; ++d) asens[d].resize(n_in_);
3187  for (size_t i = 0; i < n_in_; ++i) {
3188  v = horzsplit(all_asens[i]);
3189  casadi_assert_dev(v.size() == nadj);
3190  for (size_t d = 0; d < nadj; ++d) {
3191  if (asens[d][i].is_empty(true)) {
3192  asens[d][i] = reshape(v[d], size_in(i));
3193  } else {
3194  asens[d][i] += reshape(v[d], size_in(i));
3195  }
3196  }
3197  }
3198  } else {
3199  // Evaluate in batches
3200  casadi_assert_dev(enable_reverse_);
3201  casadi_int max_nadj = max_num_dir_;
3202 
3203  while (!has_reverse(max_nadj)) max_nadj/=2;
3204  casadi_int offset = 0;
3205  while (offset<nadj) {
3206  // Number of derivatives, in this batch
3207  casadi_int nadj_batch = std::min(nadj-offset, max_nadj);
3208 
3209  // All inputs and seeds
3210  std::vector<MX> darg;
3211  darg.reserve(n_in_ + n_out_ + n_out_);
3212  darg.insert(darg.end(), arg.begin(), arg.end());
3213  darg.insert(darg.end(), res.begin(), res.end());
3214  std::vector<MX> v(nadj_batch);
3215  for (casadi_int i=0; i<n_out_; ++i) {
3216  for (casadi_int d=0; d<nadj_batch; ++d) v[d] = aseed[offset+d][i];
3217  darg.push_back(horzcat(v));
3218  }
3219 
3220  // Create the evaluation node
3221  Function dfcn = self().reverse(nadj_batch);
3222  std::vector<MX> x = dfcn(darg);
3223  casadi_assert_dev(x.size()==n_in_);
3224 
3225  // Retrieve sensitivities
3226  for (casadi_int d=0; d<nadj_batch; ++d) asens[offset+d].resize(n_in_);
3227  for (casadi_int i=0; i<n_in_; ++i) {
3228  if (size2_in(i)>0) {
3229  v = horzsplit(x[i], size2_in(i));
3230  casadi_assert_dev(v.size()==nadj_batch);
3231  } else {
3232  v = std::vector<MX>(nadj_batch, MX(size_in(i)));
3233  }
3234  for (casadi_int d=0; d<nadj_batch; ++d) {
3235  if (asens[offset+d][i].is_empty(true)) {
3236  asens[offset+d][i] = v[d];
3237  } else {
3238  asens[offset+d][i] += v[d];
3239  }
3240  }
3241  }
3242  // Update offset
3243  offset += nadj_batch;
3244  }
3245  }
3246  }
virtual bool adjViaJac(casadi_int nadj) const
Calculate derivatives by multiplying the full Jacobian and multiplying.
std::pair< casadi_int, casadi_int > size_in(casadi_int ind) const
Input/output dimensions.
virtual void call_reverse(const std::vector< MX > &arg, const std::vector< MX > &res, const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens, bool always_inline, bool never_inline) const
Reverse mode, virtual functions overloaded in derived classes.
Function reverse(casadi_int nadj) const
Return function that calculates adjoint derivatives.
bool matching_res(const std::vector< M > &arg, casadi_int &npar) const
Check if output arguments that needs to be replaced.
virtual bool has_reverse(casadi_int nadj) const
Return function that calculates adjoint derivatives.
std::vector< std::vector< M > > replace_aseed(const std::vector< std::vector< M >> &aseed, casadi_int npar) const
Replace 0-by-0 reverse seeds.

References casadi::FunctionInternal::adjViaJac(), casadi::SharedObjectInternal::class_name(), casadi::FunctionInternal::enable_reverse_, casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::has_reverse(), casadi::FunctionInternal::jacobian(), casadi::FunctionInternal::matching_res(), casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::replace_aseed(), casadi::FunctionInternal::reverse(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::size_in(), and casadi::T.

Referenced by casadi::Rootfinder::ad_reverse(), casadi::MXFunction::ad_reverse(), casadi::Call::ad_reverse(), casadi::XFunction< DerivedType, MatType, NodeType >::call_reverse(), casadi::Scpgen::init(), and casadi::MX::reverse().

◆ call_reverse() [2/2]

void casadi::FunctionInternal::call_reverse ( const std::vector< SX > &  arg,
const std::vector< SX > &  res,
const std::vector< std::vector< SX > > &  aseed,
std::vector< std::vector< SX > > &  asens,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kv

Definition at line 3261 of file function_internal.cpp.

3265  {
3266  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3267  if (aseed.empty()) { // Quick return if no seeds
3268  asens.clear();
3269  return;
3270  }
3271  casadi_error("'reverse' (SX) not defined for " + class_name());
3272  }

References casadi::SharedObjectInternal::class_name().

◆ callback()

int casadi::Nlpsol::callback ( NlpsolMemory m) const
inherited

Definition at line 1121 of file nlpsol.cpp.

1121  {
1122  // Quick return if no callback function
1123  if (fcallback_.is_null()) return 0;
1124  // Callback inputs
1125  std::fill_n(m->arg, fcallback_.n_in(), nullptr);
1126 
1127  auto d_nlp = &m->d_nlp;
1128 
1129  m->arg[NLPSOL_X] = d_nlp->z;
1130  m->arg[NLPSOL_F] = &d_nlp->objective;
1131  m->arg[NLPSOL_G] = d_nlp->z + nx_;
1132  m->arg[NLPSOL_LAM_G] = d_nlp->lam + nx_;
1133  m->arg[NLPSOL_LAM_X] = d_nlp->lam;
1134 
1135  // Callback outputs
1136  std::fill_n(m->res, fcallback_.n_out(), nullptr);
1137  double ret = 0;
1138  m->res[0] = &ret;
1139 
1140  // Start timer
1141  m->fstats.at("callback_fun").tic();
1142  try {
1143  // Evaluate
1144  fcallback_(m->arg, m->res, m->iw, m->w, 0);
1145  } catch(KeyboardInterruptException& ex) {
1146  (void)ex; // unused
1147  throw;
1148  } catch(std::exception& ex) {
1149  print("WARNING: intermediate_callback error: %s\n", ex.what());
1151  }
1152 
1153  // User user interruption?
1154  if (static_cast<casadi_int>(ret)) return 1;
1155 
1156  // Stop timer
1157  m->fstats.at("callback_fun").toc();
1158 
1159  return 0;
1160  }
casadi_int n_out() const
Get the number of function outputs.
Definition: function.cpp:823
casadi_int n_in() const
Get the number of function inputs.
Definition: function.cpp:819
bool is_null() const
Is a null pointer?
bool iteration_callback_ignore_errors_
Options.
Definition: nlpsol_impl.hpp:95
Function fcallback_
callback function, executed at each iteration
Definition: nlpsol_impl.hpp:75
@ NLPSOL_G
Constraints function at the optimal solution (ng x 1)
Definition: nlpsol.hpp:221
@ NLPSOL_X
Decision variables at the optimal solution (nx x 1)
Definition: nlpsol.hpp:217
@ NLPSOL_F
Cost function value at the optimal solution (1 x 1)
Definition: nlpsol.hpp:219
@ NLPSOL_LAM_G
Lagrange multipliers for bounds on G at the solution (ng x 1)
Definition: nlpsol.hpp:225
@ NLPSOL_LAM_X
Lagrange multipliers for bounds on X at the solution (nx x 1)
Definition: nlpsol.hpp:223

References casadi::OracleMemory::arg, casadi::NlpsolMemory::d_nlp, casadi::Nlpsol::fcallback_, casadi::ProtoFunctionMemory::fstats, casadi::GenericShared< Shared, Internal >::is_null(), casadi::Nlpsol::iteration_callback_ignore_errors_, casadi::OracleMemory::iw, casadi::Function::n_in(), casadi::Function::n_out(), casadi::NLPSOL_F, casadi::NLPSOL_G, casadi::NLPSOL_LAM_G, casadi::NLPSOL_LAM_X, casadi::NLPSOL_X, casadi::Nlpsol::nx_, casadi::ProtoFunction::print(), casadi::OracleMemory::res, casadi::OracleMemory::w, and casadi::CasadiException::what().

Referenced by solve(), casadi::Qrsqp::solve(), and casadi::Sqpmethod::solve().

◆ change_option()

void casadi::FunctionInternal::change_option ( const std::string &  option_name,
const GenericType option_value 
)
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_k5

Reimplemented from casadi::ProtoFunction.

Reimplemented in casadi::MXFunction.

Definition at line 433 of file function_internal.cpp.

434  {
435  if (option_name == "print_in") {
436  print_in_ = option_value;
437  } else if (option_name == "print_out") {
438  print_out_ = option_value;
439  } else if (option_name == "print_canonical") {
440  print_canonical_ = option_value;
441  } else if (option_name=="ad_weight") {
442  ad_weight_ = option_value;
443  } else if (option_name=="ad_weight_sp") {
444  ad_weight_sp_ = option_value;
445  } else if (option_name=="dump") {
446  dump_ = option_value;
447  } else if (option_name=="dump_in") {
448  dump_in_ = option_value;
449  } else if (option_name=="dump_out") {
450  dump_out_ = option_value;
451  } else if (option_name=="dump_dir") {
452  dump_dir_ = option_value.to_string();
453  } else if (option_name=="dump_format") {
454  dump_format_ = option_value.to_string();
455  } else {
456  // Option not found - continue to base classes
457  ProtoFunction::change_option(option_name, option_value);
458  }
459  }
virtual void change_option(const std::string &option_name, const GenericType &option_value)
Change option after object creation for debugging.

References casadi::FunctionInternal::ad_weight_, casadi::FunctionInternal::ad_weight_sp_, casadi::ProtoFunction::change_option(), casadi::FunctionInternal::dump_, casadi::FunctionInternal::dump_dir_, casadi::FunctionInternal::dump_format_, casadi::FunctionInternal::dump_in_, casadi::FunctionInternal::dump_out_, casadi::FunctionInternal::print_canonical_, casadi::FunctionInternal::print_in_, casadi::FunctionInternal::print_out_, and casadi::GenericType::to_string().

Referenced by casadi::FmuFunction::change_option(), and casadi::MXFunction::change_option().

◆ check_arg()

template<typename M >
void casadi::FunctionInternal::check_arg ( const std::vector< M > &  arg,
casadi_int &  npar 
) const
inherited

Raises errors.

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
[out]nparmax number of horizontal repetitions across all arguments (or -1)

Extra doc: https://github.com/casadi/casadi/wiki/L_ki

Definition at line 1710 of file function_internal.hpp.

1710  {
1711  casadi_assert(arg.size()==n_in_, "Incorrect number of inputs: Expected "
1712  + str(n_in_) + ", got " + str(arg.size()));
1713  for (casadi_int i=0; i<n_in_; ++i) {
1714  if (!check_mat(arg[i].sparsity(), sparsity_in(i), npar)) {
1715  // Dimensions
1716  std::string d_arg = str(arg[i].size1()) + "-by-" + str(arg[i].size2());
1717  std::string d_in = str(size1_in(i)) + "-by-" + str(size2_in(i));
1718  std::string e = "Input " + str(i) + " (" + name_in_[i] + ") has mismatching shape. "
1719  "Got " + d_arg + ". Allowed dimensions, in general, are:\n"
1720  " - The input dimension N-by-M (here " + d_in + ")\n"
1721  " - A scalar, i.e. 1-by-1\n"
1722  " - M-by-N if N=1 or M=1 (i.e. a transposed vector)\n"
1723  " - N-by-M1 if K*M1=M for some K (argument repeated horizontally)\n";
1724  if (npar!=-1) {
1725  e += " - N-by-P*M, indicating evaluation with multiple arguments (P must be a "
1726  "multiple of " + str(npar) + " for consistency with previous inputs)";
1727  }
1728  casadi_error(e);
1729  }
1730  }
1731  }
casadi_int size1_in(casadi_int ind) const
Input/output dimensions.
const Sparsity & sparsity_in(casadi_int ind) const
Input/output sparsity.
static bool check_mat(const Sparsity &arg, const Sparsity &inp, casadi_int &npar)
std::vector< std::string > name_in_
Input and output scheme.
std::string str(const T &v)
String representation, any type.

References casadi::FunctionInternal::check_mat(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::size1_in(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::sparsity_in(), and casadi::str().

Referenced by casadi::FunctionInternal::mapsum_mx(), and casadi::FunctionInternal::matching_arg().

◆ check_inputs()

void casadi::Nlpsol::check_inputs ( void *  mem) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1nx

Definition at line 613 of file nlpsol.cpp.

613  {
614  auto m = static_cast<NlpsolMemory*>(mem);
615  auto d_nlp = &m->d_nlp;
616 
617  // Skip check?
618  if (!inputs_check_) return;
619 
620  const double inf = std::numeric_limits<double>::infinity();
621 
622  // Number of equality constraints
623  casadi_int n_eq = 0;
624 
625  // Detect ill-posed problems (simple bounds)
626  for (casadi_int i=0; i<nx_; ++i) {
627  double lb = d_nlp->lbx ? d_nlp->lbx[i] : get_default_in(NLPSOL_LBX);
628  double ub = d_nlp->ubx ? d_nlp->ubx[i] : get_default_in(NLPSOL_UBX);
629  double x0 = d_nlp->x0 ? d_nlp->x0[i] : get_default_in(NLPSOL_X0);
630  casadi_assert(lb <= ub && lb!=inf && ub!=-inf,
631  "Ill-posed problem detected: "
632  "LBX[" + str(i) + "] <= UBX[" + str(i) + "] was violated. "
633  "Got LBX[" + str(i) + "]=" + str(lb) + " and UBX[" + str(i) + "] = " + str(ub) + ".");
634  if (warn_initial_bounds_ && (x0>ub || x0<lb)) {
635  casadi_warning("Nlpsol: The initial guess does not satisfy LBX and UBX. "
636  "Option 'warn_initial_bounds' controls this warning.");
637  break;
638  }
639  if (lb==ub) n_eq++;
640  }
641 
642  // Detect ill-posed problems (nonlinear bounds)
643  for (casadi_int i=0; i<nnz_out(NLPSOL_G); ++i) {
644  double lb = d_nlp->lbg ? d_nlp->lbg[i] : get_default_in(NLPSOL_LBG);
645  double ub = d_nlp->ubg ? d_nlp->ubg[i] : get_default_in(NLPSOL_UBG);
646  casadi_assert(lb <= ub && lb!=inf && ub!=-inf,
647  "Ill-posed problem detected: "
648  "LBG[" + str(i) + "] <= UBG[" + str(i) + "] was violated. "
649  "Got LBG[" + str(i) + "] = " + str(lb) + " and UBG[" + str(i) + "] = " + str(ub) + ".");
650  if (lb==ub) n_eq++;
651  }
652 
653  // Make sure enough degrees of freedom
654  using casadi::str; // Workaround, MingGW bug, cf. CasADi issue #890
655  if (n_eq> nx_) {
656  casadi_warning("NLP is overconstrained: There are " + str(n_eq) +
657  " equality constraints but only " + str(nx_) + " variables.");
658  }
659  }
bool inputs_check_
Errors are thrown if numerical values of inputs look bad.
bool warn_initial_bounds_
Options.
Definition: nlpsol_impl.hpp:94
double get_default_in(casadi_int ind) const override
Get default input value.
@ NLPSOL_UBX
Decision variables upper bound (nx x 1), default +inf.
Definition: nlpsol.hpp:202
@ NLPSOL_X0
Decision variables, initial guess (nx x 1)
Definition: nlpsol.hpp:196
@ NLPSOL_UBG
Constraints upper bound (ng x 1), default +inf.
Definition: nlpsol.hpp:206
@ NLPSOL_LBG
Constraints lower bound (ng x 1), default -inf.
Definition: nlpsol.hpp:204
@ NLPSOL_LBX
Decision variables lower bound (nx x 1), default -inf.
Definition: nlpsol.hpp:200
const double inf
infinity
Definition: calculus.hpp:50

References casadi::NlpsolMemory::d_nlp, casadi::Nlpsol::get_default_in(), casadi::inf, casadi::FunctionInternal::inputs_check_, casadi::NLPSOL_G, casadi::NLPSOL_LBG, casadi::NLPSOL_LBX, casadi::NLPSOL_UBG, casadi::NLPSOL_UBX, casadi::NLPSOL_X0, casadi::FunctionInternal::nnz_out(), casadi::Nlpsol::nx_, casadi::str(), and casadi::Nlpsol::warn_initial_bounds_.

Referenced by casadi::Nlpsol::eval(), casadi::AlpaqaInterface::set_work(), and casadi::SLEQPInterface::set_work().

◆ check_mat()

bool casadi::FunctionInternal::check_mat ( const Sparsity arg,
const Sparsity inp,
casadi_int &  npar 
)
staticinherited

Helper function

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
npar[out]required number of parallel calls (or -1)

Definition at line 3460 of file function_internal.cpp.

3460  {
3461  // Matching dimensions
3462  if (arg.size()==inp.size()) return true;
3463  // Calling with empty matrix - set all to zero
3464  if (arg.is_empty()) return true;
3465  // Calling with a scalar - set all
3466  if (arg.is_scalar()) return true;
3467  // Vectors that are transposes of each other
3468  if (arg.is_vector() && inp.size()==std::make_pair(arg.size2(), arg.size1())) return true;
3469  // Horizontal repmat
3470  if (arg.size1()==inp.size1() && arg.size2()>0 && inp.size2()>0
3471  && inp.size2()%arg.size2()==0) return true;
3472  if (npar==-1) return false;
3473  // Evaluate with multiple arguments
3474  if (arg.size1()==inp.size1() && arg.size2()>0 && inp.size2()>0
3475  && arg.size2()%(npar*inp.size2())==0) {
3476  npar *= arg.size2()/(npar*inp.size2());
3477  return true;
3478  }
3479  // No match
3480  return false;
3481  }

References casadi::Sparsity::is_empty(), casadi::Sparsity::is_scalar(), casadi::Sparsity::is_vector(), casadi::Sparsity::size(), casadi::Sparsity::size1(), and casadi::Sparsity::size2().

Referenced by casadi::FunctionInternal::check_arg(), casadi::FunctionInternal::check_res(), and casadi::FunctionInternal::mapsum_mx().

◆ check_mem_count()

virtual void casadi::ProtoFunction::check_mem_count ( casadi_int  n) const
inlinevirtualinherited

Purpose if to allow more helpful error messages

Extra doc: https://github.com/casadi/casadi/wiki/L_2b7

Reimplemented in casadi::FmuFunction.

Definition at line 179 of file function_internal.hpp.

179 { }

Referenced by casadi::ProtoFunction::checkout().

◆ check_res()

template<typename M >
void casadi::FunctionInternal::check_res ( const std::vector< M > &  res,
casadi_int &  npar 
) const
inherited

Raises errors.

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
[out]nparmax number of horizontal repetitions across all arguments (or -1)

Extra doc: https://github.com/casadi/casadi/wiki/L_kj

Definition at line 1734 of file function_internal.hpp.

1734  {
1735  casadi_assert(res.size()==n_out_, "Incorrect number of outputs: Expected "
1736  + str(n_out_) + ", got " + str(res.size()));
1737  for (casadi_int i=0; i<n_out_; ++i) {
1738  casadi_assert(check_mat(res[i].sparsity(), sparsity_out(i), npar),
1739  "Output " + str(i) + " (" + name_out_[i] + ") has mismatching shape. "
1740  "Expected " + str(size_out(i)) + ", got " + str(res[i].size()));
1741  }
1742  }
std::vector< std::string > name_out_

References casadi::FunctionInternal::check_mat(), casadi::FunctionInternal::n_out_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::size_out(), casadi::FunctionInternal::sparsity_out(), and casadi::str().

Referenced by casadi::FunctionInternal::matching_res().

◆ checkout()

int casadi::ProtoFunction::checkout ( ) const
inherited

Definition at line 3669 of file function_internal.cpp.

3669  {
3670 #ifdef CASADI_WITH_THREAD
3671  std::lock_guard<std::mutex> lock(mtx_);
3672 #endif //CASADI_WITH_THREAD
3673  if (unused_.empty()) {
3674  check_mem_count(mem_.size()+1);
3675  // Allocate a new memory object
3676  void* m = alloc_mem();
3677  mem_.push_back(m);
3678  if (init_mem(m)) {
3679  casadi_error("Failed to create or initialize memory object");
3680  }
3681  return static_cast<int>(mem_.size()) - 1;
3682  } else {
3683  // Use an unused memory object
3684  int m = unused_.top();
3685  unused_.pop();
3686  return m;
3687  }
3688  }
virtual int init_mem(void *mem) const
Initalize memory block.
virtual void * alloc_mem() const
Create memory block.
virtual void check_mem_count(casadi_int n) const
Check for validatity of memory object count.

References casadi::ProtoFunction::alloc_mem(), casadi::ProtoFunction::check_mem_count(), and casadi::ProtoFunction::init_mem().

Referenced by casadi::ProtoFunction::finalize(), casadi::FunctionBuffer::FunctionBuffer(), and casadi::Sqpmethod::init_mem().

◆ class_name()

std::string casadi::Feasiblesqpmethod::class_name ( ) const
inlineoverridevirtual

Extra doc: https://github.com/casadi/casadi/wiki/L_1o4

Reimplemented from casadi::Nlpsol.

Definition at line 74 of file feasiblesqpmethod.hpp.

74 { return "Feasiblesqpmethod";}

◆ clear_mem()

void casadi::ProtoFunction::clear_mem ( )
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_jq

Definition at line 3557 of file function_internal.cpp.

3557  {
3558  for (auto&& i : mem_) {
3559  if (i!=nullptr) free_mem(i);
3560  }
3561  mem_.clear();
3562  }
virtual void free_mem(void *mem) const
Free memory block.

References casadi::ProtoFunction::free_mem().

Referenced by casadi::AlpaqaInterface::~AlpaqaInterface(), casadi::AmplInterface::~AmplInterface(), casadi::BlazingSplineFunction::~BlazingSplineFunction(), casadi::Blocksqp::~Blocksqp(), casadi::BonminInterface::~BonminInterface(), casadi::BSplineInterpolant::~BSplineInterpolant(), casadi::CallbackInternal::~CallbackInternal(), casadi::CbcInterface::~CbcInterface(), casadi::ClarabelInterface::~ClarabelInterface(), casadi::ClpInterface::~ClpInterface(), casadi::CplexInterface::~CplexInterface(), casadi::CsparseInterface::~CsparseInterface(), casadi::CvodesInterface::~CvodesInterface(), casadi::DaqpInterface::~DaqpInterface(), casadi::External::~External(), casadi::FastNewton::~FastNewton(), casadi::FatropConicInterface::~FatropConicInterface(), casadi::FatropInterface::~FatropInterface(), ~Feasiblesqpmethod(), casadi::FiniteDiff::~FiniteDiff(), casadi::FixedStepIntegrator::~FixedStepIntegrator(), casadi::FmuFunction::~FmuFunction(), casadi::GurobiInterface::~GurobiInterface(), casadi::HighsInterface::~HighsInterface(), casadi::HpipmInterface::~HpipmInterface(), casadi::HpmpcInterface::~HpmpcInterface(), casadi::IdasInterface::~IdasInterface(), casadi::ImplicitToNlp::~ImplicitToNlp(), casadi::IpoptInterface::~IpoptInterface(), casadi::Ipqp::~Ipqp(), casadi::JitFunction::~JitFunction(), casadi::KinsolInterface::~KinsolInterface(), casadi::KnitroInterface::~KnitroInterface(), casadi::LapackLu::~LapackLu(), casadi::LapackQr::~LapackQr(), casadi::LinearInterpolant::~LinearInterpolant(), casadi::LinearInterpolantJac::~LinearInterpolantJac(), casadi::LinsolLdl::~LinsolLdl(), casadi::LinsolQr::~LinsolQr(), casadi::LinsolTridiag::~LinsolTridiag(), casadi::Lsqr::~Lsqr(), casadi::Ma27Interface::~Ma27Interface(), casadi::MadnlpInterface::~MadnlpInterface(), casadi::Map::~Map(), casadi::MapSum::~MapSum(), casadi::MumpsInterface::~MumpsInterface(), casadi::MXFunction::~MXFunction(), casadi::Newton::~Newton(), casadi::Nlpsol::~Nlpsol(), casadi::OmpMap::~OmpMap(), casadi::OoqpInterface::~OoqpInterface(), casadi::OsqpInterface::~OsqpInterface(), casadi::ProxqpInterface::~ProxqpInterface(), casadi::QpoasesInterface::~QpoasesInterface(), casadi::QpToNlp::~QpToNlp(), casadi::Qrqp::~Qrqp(), casadi::Qrsqp::~Qrsqp(), casadi::Scpgen::~Scpgen(), casadi::SLEQPInterface::~SLEQPInterface(), casadi::SlicotDple::~SlicotDple(), casadi::SlicotExpm::~SlicotExpm(), casadi::SnoptInterface::~SnoptInterface(), casadi::Sqpmethod::~Sqpmethod(), casadi::SuperscsInterface::~SuperscsInterface(), casadi::Switch::~Switch(), casadi::SXFunction::~SXFunction(), casadi::SymbolicQr::~SymbolicQr(), casadi::ThreadMap::~ThreadMap(), and casadi::WorhpInterface::~WorhpInterface().

◆ codegen()

void casadi::FunctionInternal::codegen ( CodeGenerator g,
const std::string &  fname 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lm

Definition at line 2390 of file function_internal.cpp.

2390  {
2391  // Define function
2392  g << "/* " << definition() << " */\n";
2393  g << "static " << signature(fname) << " {\n";
2394 
2395  // Reset local variables, flush buffer
2396  g.flush(g.body);
2397 
2398  g.scope_enter();
2399 
2400  // Generate function body (to buffer)
2401  codegen_body(g);
2402 
2403  g.scope_exit();
2404 
2405  // Finalize the function
2406  g << "return 0;\n";
2407  g << "}\n\n";
2408 
2409  // Flush to function body
2410  g.flush(g.body);
2411  }
std::string definition() const
Get function signature: name:(inputs)->(outputs)
virtual void codegen_body(CodeGenerator &g) const
Generate code for the function body.
std::string signature(const std::string &fname) const
Code generate the function.

References casadi::CodeGenerator::body, casadi::FunctionInternal::codegen_body(), casadi::FunctionInternal::definition(), casadi::CodeGenerator::flush(), casadi::CodeGenerator::scope_enter(), casadi::CodeGenerator::scope_exit(), and casadi::FunctionInternal::signature().

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_alloc_mem()

void casadi::FunctionInternal::codegen_alloc_mem ( CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lt

Reimplemented in casadi::External.

Definition at line 2438 of file function_internal.cpp.

2438  {
2439  bool needs_mem = !codegen_mem_type().empty();
2440  if (needs_mem) {
2441  std::string name = codegen_name(g, false);
2442  std::string mem_counter = g.shorthand(name + "_mem_counter");
2443  g << "return " + mem_counter + "++;\n";
2444  }
2445  }
virtual std::string codegen_mem_type() const
Thread-local memory object type.
virtual std::string codegen_name(const CodeGenerator &g, bool ns=true) const
Get name in codegen.

References casadi::FunctionInternal::codegen_mem_type(), casadi::FunctionInternal::codegen_name(), and casadi::CodeGenerator::shorthand().

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_body()

void casadi::Feasiblesqpmethod::codegen_body ( CodeGenerator g) const
overridevirtual

Reimplemented from casadi::FunctionInternal.

Definition at line 1427 of file feasiblesqpmethod.cpp.

1427  {
1428  g.add_auxiliary(CodeGenerator::AUX_FEASIBLESQPMETHOD);
1429  codegen_body_enter(g);
1430  // From nlpsol
1431  g.local("m_p", "const casadi_real", "*");
1432  g.init_local("m_p", g.arg(NLPSOL_P));
1433  g.local("m_f", "casadi_real");
1434  g.local("m_f_feas", "casadi_real");
1435  g.copy_default(g.arg(NLPSOL_X0), nx_, "d_nlp.z", "0", false);
1436  g.copy_default(g.arg(NLPSOL_LAM_X0), nx_, "d_nlp.lam", "0", false);
1437  g.copy_default(g.arg(NLPSOL_LAM_G0), ng_, "d_nlp.lam+"+str(nx_), "0", false);
1438  g.copy_default(g.arg(NLPSOL_LBX), nx_, "d_nlp.lbz", "-casadi_inf", false);
1439  g.copy_default(g.arg(NLPSOL_UBX), nx_, "d_nlp.ubz", "casadi_inf", false);
1440  g.copy_default(g.arg(NLPSOL_LBG), ng_, "d_nlp.lbz+"+str(nx_),
1441  "-casadi_inf", false);
1442  g.copy_default("d_nlp.ubg", ng_, "d_nlp.ubz+"+str(nx_),
1443  "casadi_inf", false);
1444  casadi_assert(exact_hessian_, "Codegen implemented for exact Hessian only.", false);
1445 
1446  // auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
1447  // auto d_nlp = &m->d_nlp;
1448  // auto d = &m->d;
1449  // Define the problem struct and problem data struct here
1450  g.local("d", "struct casadi_feasiblesqpmethod_data");
1451  g.local("p", "struct casadi_feasiblesqpmethod_prob");
1452 
1453  g << "d.prob = &p;\n";
1454  g << "p.sp_h = " << g.sparsity(Hsp_) << ";\n";
1455  g << "p.sp_a = " << g.sparsity(Asp_) << ";\n";
1456  g << "p.nlp = &p_nlp;\n";
1457  g << "casadi_feasiblesqpmethod_init(&d, &iw, &w, " << sz_anderson_memory_ << ");\n";
1458 
1459  g.local("m_w", "casadi_real", "*");
1460  g << "m_w = w;\n";
1461  g.local("m_iw", "casadi_int", "*");
1462  g << "m_iw = iw;\n";
1463  g.local("m_arg", "const casadi_real", "**");
1464  g.init_local("m_arg", "arg+" + str(NLPSOL_NUM_IN));
1465  g.local("m_res", "casadi_real", "**");
1466  g.init_local("m_res", "res+" + str(NLPSOL_NUM_OUT));
1467 
1468  // g.local("ret", "int");
1469  g.local("ret", "casadi_int");
1470 
1471  // Number of SQP iterations
1472  // m->iter_count = 0;
1473  g.local("iter_count", "casadi_int");
1474  g.init_local("iter_count", "0");
1475 
1476  // Reset
1477  // int step_accepted = 0;
1478  g.local("step_accepted", "casadi_int");
1479  g.init_local("step_accepted", "0");
1480 
1481  // Default quadratic model value of objective
1482  // double m_k = -1.0;
1483  g.local("m_k", "casadi_real");
1484  g.init_local("m_k", "-1.0");
1485 
1486  // double tr_ratio = 0.0;
1487  g.local("tr_ratio", "casadi_real");
1488  g.init_local("tr_ratio", "0.0");
1489 
1490  // double tr_rad = tr_rad0_;
1491  // double tr_rad_prev = tr_rad0_;
1492  g.local("tr_rad", "casadi_real");
1493  g << "tr_rad = " << tr_rad0_ << ";\n";
1494  g.local("tr_rad_prev", "casadi_real");
1495  g << "tr_rad_prev = " << tr_rad0_ << ";\n";
1496 
1497  // transfer the scale vector to the problem
1498  // casadi_copy(get_ptr(tr_scale_vector_), nx_, d->tr_scale_vector);
1499  //transfer the scale vector to the problem
1500  g << g.copy(g.constant(tr_scale_vector_), nx_, "d.tr_scale_vector") << "\n";
1501  // g << g.copy("casadi_tr_scale_vector_", nx_, "d.tr_scale_vector") << "\n";
1502 
1503  // for (casadi_int i=0;i<nx_;++i) {
1504  // d->tr_mask[i] = d->tr_scale_vector[i]!=0;
1505  // }
1506  g << "for (casadi_int i = 0; i < " << nx_ << "; ++i) {\n";
1507  g << "d.tr_mask[i] = d.tr_scale_vector != 0;\n";
1508  g << "}\n";
1509 
1510 
1511  // HERE STARTS THE MAIN OPTIMIZATION LOOP ---------------------------------
1512  // For seeds ---- This is so far needed!!! ------------------
1513  // const double one = 1.;
1514  g.local("one", "const casadi_real");
1515  g.init_local("one", "1");
1516 
1517  // Info for printing
1518  // string info = "";
1519 
1520  // casadi_clear(d->dx, nx_);
1521  g << g.clear("d.dx", nx_) << "\n";
1522 
1523  // ------------------------------------------------------------------------
1524  // MAIN OPTIMIZATION LOOP
1525  // ------------------------------------------------------------------------
1526  // while (true) {
1527  g.comment("MAIN OPTIMIZATION LOOP");
1528  g << "while (1) {\n";
1529  // if(m->iter_count == 0) {
1530  g << "if (iter_count == 0) {;\n";
1531  // Evaluate the sensitivities -------------------------------------------
1532  // Evaluate f
1533  // m->arg[0] = d_nlp->z;
1534  // m->arg[1] = d_nlp->p;
1535  // m->res[0] = &d_nlp->f;
1536  // if (calc_function(m, "nlp_f")) {
1537  // uout() << "What does it mean that calc_function fails here??" << std::endl;
1538  // }
1539  g.comment("Evaluate f");
1540  g << "m_arg[0] = d_nlp.z;\n";
1541  g << "m_arg[1] = m_p;\n";
1542  g << "m_res[0] = &m_f;\n";
1543  std::string nlp_f = g(get_function("nlp_f"), "m_arg", "m_res", "m_iw", "m_w");
1544  // g << "if (" + nlp_f + ") return 1;\n";
1545  g << "if (" + nlp_f + ") return 10;\n";
1546 
1547  // Evaluate g
1548  // m->arg[0] = d_nlp->z;
1549  // m->arg[1] = d_nlp->p;
1550  // m->res[0] = d_nlp->z + nx_;
1551  // if (calc_function(m, "nlp_g")) {
1552  // uout() << "What does it mean that calc_function fails here??" << std::endl;
1553  // }
1554  g.comment("Evaluate g");
1555  g << "m_arg[0] = d_nlp.z;\n";
1556  g << "m_arg[1] = m_p;\n";
1557  g << "m_res[0] = d_nlp.z+" + str(nx_) + ";\n";
1558  std::string nlp_g = g(get_function("nlp_g"), "m_arg", "m_res", "m_iw", "m_w");
1559  // g << "if (" + nlp_g + ") return 1;\n";
1560  g << "if (" + nlp_g + ") return 20;\n";
1561 
1562  // Evaluate grad_f
1563  // m->arg[0] = d_nlp->z;
1564  // m->arg[1] = d_nlp->p;
1565  // m->res[0] = d->gf;
1566  // if (calc_function(m, "nlp_grad_f")) {
1567  // uout() << "What does it mean that calc_function fails here??" << std::endl;
1568  // }
1569  g.comment("Evaluate grad f");
1570  g << "m_arg[0] = d_nlp.z;\n";
1571  g << "m_arg[1] = m_p;\n";
1572  g << "m_res[0] = d.gf;\n";
1573  std::string nlp_grad_f = g(get_function("nlp_grad_f"), "m_arg", "m_res", "m_iw", "m_w");
1574  // g << "if (" + nlp_grad_f + ") return 1;\n";
1575  g << "if (" + nlp_grad_f + ") return 30;\n";
1576 
1577  // Evaluate jac_g
1578  // m->arg[0] = d_nlp->z;
1579  // m->arg[1] = d_nlp->p;
1580  // m->res[0] = d->Jk;
1581  // switch (calc_function(m, "nlp_jac_g")) {
1582  // case -1:
1583  // m->return_status = "Non_Regular_Sensitivities";
1584  // m->unified_return_status = SOLVER_RET_NAN;
1585  // if (print_status_)
1586  // print("MESSAGE(feasiblesqpmethod): "
1587  // "No regularity of sensitivities at current point.\n");
1588  // return 1;
1589  // case 0:
1590  // break;
1591  // default:
1592  // return 1;
1593 
1594  // }
1595  g.comment("Evaluate jac g");
1596  g << "m_arg[0] = d_nlp.z;\n";
1597  g << "m_arg[1] = m_p;\n";
1598  g << "m_res[0] = d.Jk;\n";
1599  std::string nlp_jac_g = g(get_function("nlp_jac_g"), "m_arg", "m_res", "m_iw", "m_w");
1600  // g << "if (" + nlp_jac_g + ") return 1;\n";
1601  g << "if (" + nlp_jac_g + ") return 40;\n";
1602 
1603  // if (use_sqp_) {
1604  // if (exact_hessian_) {
1605  // // Update/reset exact Hessian
1606  // m->arg[0] = d_nlp->z;
1607  // m->arg[1] = d_nlp->p;
1608  // m->arg[2] = &one;
1609  // m->arg[3] = d_nlp->lam + nx_;
1610  // m->res[0] = d->Bk;
1611  // if (calc_function(m, "nlp_hess_l")) return 1;
1612  // if (convexify_) {
1613  // ScopedTiming tic(m->fstats.at("convexify"));
1614  // if (convexify_eval(&convexify_data_.config, d->Bk, d->Bk, m->iw, m->w)) return 1;
1615  // }
1616  // } else if (m->iter_count==0) {
1617  // ScopedTiming tic(m->fstats.at("BFGS"));
1618  // // Initialize BFGS
1619  // casadi_fill(d->Bk, Hsp_.nnz(), 1.);
1620  // casadi_bfgs_reset(Hsp_, d->Bk);
1621  // } else {
1622  // ScopedTiming tic(m->fstats.at("BFGS"));
1623  // // Update BFGS
1624  // if (m->iter_count % lbfgs_memory_ == 0) casadi_bfgs_reset(Hsp_, d->Bk);
1625  // // Update the Hessian approximation
1626  // casadi_bfgs(Hsp_, d->Bk, d->dx, d->gLag, d->gLag_old, m->w);
1627  // }
1628  g.comment("Just exact Hessian implemented, GN would be possible!");
1629  g << "m_arg[0] = d_nlp.z;\n";
1630  g << "m_arg[1] = m_p;\n";
1631  g << "m_arg[2] = &one;\n";
1632  g << "m_arg[3] = d_nlp.lam+" + str(nx_) + ";\n";
1633  g << "m_res[0] = d.Bk;\n";
1634  std::string nlp_hess_l = g(get_function("nlp_hess_l"), "m_arg", "m_res", "m_iw", "m_w");
1635  // g << "if (" + nlp_hess_l + ") return 1;\n";
1636  g << "if (" + nlp_hess_l + ") return 70;\n";
1637 
1638  // }
1639  // test if initialization is feasible
1640  // if (casadi_max_viol(nx_ + ng_, d_nlp->z, d_nlp->lbz, d_nlp->ubz) > feas_tol_) {
1641  // if (print_status_) print("MESSAGE(feasiblesqpmethod): "
1642  // "No feasible initialization given! "
1643  // "Find feasible initialization.\n");
1644  // m->return_status = "No_Feasible_Initialization";
1645  // break;
1646  // }
1647  std::string viol = g.max_viol(nx_+ ng_, "d_nlp.z", "d_nlp.lbz", "d_nlp.ubz");
1648  g << "if (" << viol << "> " << feas_tol_ << ") {\n";
1649  g << "printf(\"MESSAGE(feasiblesqpmethod): "
1650  "No feasible initialization given! Find feasible initialization.\\n\");\n";
1651  g << "break;\n";
1652  g << "}\n";
1653 
1654  // } else if (step_accepted == 0) {
1655  g << "} else if (step_accepted == 0) {\n";
1656  // Evaluate grad_f
1657  // m->arg[0] = d_nlp->z;
1658  // m->arg[1] = d_nlp->p;
1659  // m->res[0] = d->gf;
1660  // if (calc_function(m, "nlp_grad_f")) {
1661  // uout() << "What does it mean that calc_function fails here??" << std::endl;
1662  // }
1663  g.comment("Evaluate grad f");
1664  g << "m_arg[0] = d_nlp.z;\n";
1665  g << "m_arg[1] = m_p;\n";
1666  g << "m_res[0] = d.gf;\n";
1667  nlp_grad_f = g(get_function("nlp_grad_f"), "m_arg", "m_res", "m_iw", "m_w");
1668  // g << "if (" + nlp_grad_f + ") return 1;\n";
1669  g << "if (" + nlp_grad_f + ") return 50;\n";
1670 
1671  // Evaluate jac_g
1672  // m->arg[0] = d_nlp->z;
1673  // m->arg[1] = d_nlp->p;
1674  // m->res[0] = d->Jk;
1675  // switch (calc_function(m, "nlp_jac_g")) {
1676  // case -1:
1677  // m->return_status = "Non_Regular_Sensitivities";
1678  // m->unified_return_status = SOLVER_RET_NAN;
1679  // if (print_status_)
1680  // print("MESSAGE(feasiblesqpmethod): "
1681  // "No regularity of sensitivities at current point.\n");
1682  // return 1;
1683  // case 0:
1684  // break;
1685  // default:
1686  // return 1;
1687  // }
1688  g.comment("Evaluate jac g");
1689  g << "m_arg[0] = d_nlp.z;\n";
1690  g << "m_arg[1] = m_p;\n";
1691  g << "m_res[0] = d.Jk;\n";
1692  nlp_jac_g = g(get_function("nlp_jac_g"), "m_arg", "m_res", "m_iw", "m_w");
1693  // g << "if (" + nlp_jac_g + ") return 1;\n";
1694  g << "if (" + nlp_jac_g + ") return 60;\n";
1695 
1696  // if (use_sqp_) {
1697  // if (exact_hessian_) {
1698  // // Update/reset exact Hessian
1699  // m->arg[0] = d_nlp->z;
1700  // m->arg[1] = d_nlp->p;
1701  // m->arg[2] = &one;
1702  // m->arg[3] = d_nlp->lam + nx_;
1703  // m->res[0] = d->Bk;
1704  // if (calc_function(m, "nlp_hess_l")) return 1;
1705  // if (convexify_) {
1706  // ScopedTiming tic(m->fstats.at("convexify"));
1707  // if (convexify_eval(&convexify_data_.config, d->Bk, d->Bk, m->iw, m->w)) return 1;
1708  // }
1709  // } else if (m->iter_count==0) {
1710  // ScopedTiming tic(m->fstats.at("BFGS"));
1711  // // Initialize BFGS
1712  // casadi_fill(d->Bk, Hsp_.nnz(), 1.);
1713  // casadi_bfgs_reset(Hsp_, d->Bk);
1714  // } else {
1715  // ScopedTiming tic(m->fstats.at("BFGS"));
1716  // // Update BFGS
1717  // if (m->iter_count % lbfgs_memory_ == 0) casadi_bfgs_reset(Hsp_, d->Bk);
1718  // // Update the Hessian approximation
1719  // casadi_bfgs(Hsp_, d->Bk, d->dx, d->gLag, d->gLag_old, m->w);
1720  // }
1721  // }
1722  g.comment("Just exact Hessian implemented, GN would be possible!");
1723  g << "m_arg[0] = d_nlp.z;\n";
1724  g << "m_arg[1] = m_p;\n";
1725  g << "m_arg[2] = &one;\n";
1726  g << "m_arg[3] = d_nlp.lam+" + str(nx_) + ";\n";
1727  g << "m_res[0] = d.Bk;\n";
1728  nlp_hess_l = g(get_function("nlp_hess_l"), "m_arg", "m_res", "m_iw", "m_w");
1729  // g << "if (" + nlp_hess_l + ") return 1;\n";
1730  g << "if (" + nlp_hess_l + ") return 70;\n";
1731 
1732  // }
1733  g << "}\n";
1734 
1735  // // Evaluate the gradient of the Lagrangian
1736  // casadi_copy(d->gf, nx_, d->gLag);
1737  // casadi_mv(d->Jk, Asp_, d_nlp->lam+nx_, d->gLag, true);
1738  // casadi_axpy(nx_, 1., d_nlp->lam, d->gLag);
1739  g.comment("Evaluate the gradient of the Lagrangian");
1740  g << g.copy("d.gf", nx_, "d.gLag") << "\n";
1741  g << g.mv("d.Jk", Asp_, "d_nlp.lam+"+str(nx_), "d.gLag", true) << "\n";
1742  g << g.axpy(nx_, "1.0", "d_nlp.lam", "d.gLag") << "\n";
1743 
1744  // Primal infeasability
1745  // double pr_inf = casadi_max_viol(nx_+ng_, d_nlp->z, d_nlp->lbz, d_nlp->ubz);
1746  g.comment("Primal infeasability");
1747  g.local("pr_inf", "casadi_real");
1748  g << "pr_inf = " << g.max_viol(nx_+ng_, "d_nlp.z", "d_nlp.lbz", "d_nlp.ubz") << ";\n";
1749 
1750  // inf-norm of Lagrange gradient
1751  // double du_inf = casadi_norm_inf(nx_, d->gLag);
1752  g.comment("inf-norm of lagrange gradient");
1753  g.local("du_inf", "casadi_real");
1754  g << "du_inf = " << g.norm_inf(nx_, "d.gLag") << ";\n";
1755 
1756  // inf-norm of step, d->dx is a nullptr???
1757  // double dx_norminf = casadi_norm_inf(nx_, d->dx);
1758  g.comment("inf-norm of step");
1759  g.local("dx_norminf", "casadi_real");
1760  g << "dx_norminf = " << g.norm_inf(nx_, "d.dx") << ";\n";
1761 
1762  // Printing information about the actual iterate
1763  // if (print_iteration_) {
1764  // // if (m->iter_count % 10 == 0) print_iteration();
1765  // print_iteration();
1766  // print_iteration(m->iter_count, d_nlp->f, m_k, tr_ratio,
1767  // pr_inf, du_inf, dx_norminf, m->reg, tr_rad_prev, info);
1768  // info = "";
1769  // }
1770  g << "if (" << print_iteration_ << ") {\n";
1771  g << "printf(\"%4s %9s %14s %9s %9s %9s %9s %5s\\n\", "
1772  "\"iter\", \"m_k\", \"objective\", \"tr_ratio\", "
1773  "\"inf_pr\",\"inf_du\", \"||d||\", \"tr_rad\");\n";
1774  g << "printf(\"%4lld %9.2e %14.6e %9.2e %9.2e %9.2e %9.2e %5.2e\\n\", "
1775  "iter_count, m_k, m_f, tr_ratio, pr_inf, du_inf, dx_norminf, tr_rad_prev);";
1776  g << "}\n";
1777 
1778  // tr_rad_prev = tr_rad;
1779  g << "tr_rad_prev = tr_rad;\n";
1780 
1781  // // Callback function NOT IMPLEMENTED IN CODEGEN
1782  // if (callback(m)) {
1783  // if (print_status_) print("WARNING(feasiblesqpmethod): Aborted by callback...\n");
1784  // m->return_status = "User_Requested_Stop";
1785  // break;
1786  // }
1787 
1788  // Checking convergence criteria
1789  // Where is the complementarity condition??
1790  // if (m->iter_count >= min_iter_ && pr_inf < tol_pr_ && du_inf < tol_du_) {
1791  // if (print_status_)
1792  // print("MESSAGE(feasiblesqpmethod): "
1793  // "Convergence achieved after %d iterations\n", m->iter_count);
1794  // m->return_status = "Solve_Succeeded";
1795  // m->success = true;
1796  // break;
1797  // }
1798 
1799 
1800  g << "if (iter_count >= " << max_iter_ << ") {\n";
1801  g << "if (" << print_status_ << ") {\n";
1802  g << g.printf("MESSAGE(feasiblesqpmethod): "
1803  "Maximum number of iterations reached.\\n") << "\n";
1804  g << "break;\n";
1805  g << "}\n";
1806  g << "}\n";
1807 
1808  // Formulate the QP
1809  // Define lower bounds
1810  // casadi_copy(d_nlp->lbz, nx_+ng_, d->lbdz);
1811  // casadi_axpy(nx_+ng_, -1., d_nlp->z, d->lbdz);
1812  // casadi_clip_min(d->lbdz, nx_, -tr_rad, d->tr_mask);
1813  g.comment("Formulate the QP");
1814  g.comment("Define the lower bounds");
1815  g << g.copy("d_nlp.lbz", nx_+ng_, "d.lbdz") << "\n";
1816  g << g.axpy(nx_+ng_, "-1.0", "d_nlp.z", "d.lbdz") << "\n";
1817  g << g.clip_min("d.lbdz", nx_, "-tr_rad", "d.tr_mask") << "\n";
1818 
1819 
1820  // Define upper bounds
1821  // casadi_copy(d_nlp->ubz, nx_+ng_, d->ubdz);
1822  // casadi_axpy(nx_+ng_, -1., d_nlp->z, d->ubdz);
1823  // casadi_clip_max(d->ubdz, nx_, tr_rad, d->tr_mask);
1824  g.comment("Define the upper bounds");
1825  g << g.copy("d_nlp.ubz", nx_+ng_, "d.ubdz") << "\n";
1826  g << g.axpy(nx_+ng_, "-1.0", "d_nlp.z", "d.ubdz") << "\n";
1827  g << g.clip_max("d.ubdz", nx_, "tr_rad", "d.tr_mask") << "\n";
1828 
1829  // // Initial guess
1830  // casadi_copy(d_nlp->lam, nx_+ng_, d->dlam);
1831  g.comment("Initial guess");
1832  g << g.copy("d_nlp.lam", nx_+ng_, "d.dlam") << "\n";
1833 
1834  // Increase counter
1835  // m->iter_count++;
1836  g.comment("Increase counter");
1837  g << "++iter_count;\n";
1838 
1839  // int ret = 0;
1840  // g << "ret = 0;\n";
1841 
1842  // Solve the QP
1843  // if (use_sqp_) {
1844  // ret = solve_QP(m, d->Bk, d->gf, d->lbdz, d->ubdz, d->Jk,
1845  // d->dx, d->dlam, 0);
1846  // } else {
1847  // ret = solve_LP(m, d->gf, d->lbdz, d->ubdz, d->Jk,
1848  // d->dx, d->dlam, 0);
1849  // }
1850  g.comment("Solve the QP");
1851  codegen_qp_solve(g, "d.Bk", "d.gf", "d.lbdz", "d.ubdz", "d.Jk", "d.dx", "d.dlam", 0);
1852 
1853  // // Eval quadratic model and check for convergence
1854  // m_k = eval_m_k(mem);
1855 
1856  g.comment("Eval quadratic model and check for convergence");
1857  codegen_eval_m_k(g);
1858 
1859  g.comment("Checking convergence criteria");
1860  g << "if (fabs(m_k) < " << optim_tol_ << ") {\n";
1861  g << "printf(\"MESSAGE(feasiblesqpmethod): Optimal Point Found? "
1862  "Quadratic model is zero. After %lld iterations.\\n\", iter_count-1);\n";
1863  g << "break;\n";
1864  g << "}\n";
1865 
1866  // uout() << "QP step: " << std::vector<double>(d->dx, d->dx+nx_) << std::endl;
1867  // Detecting indefiniteness
1868  // if (use_sqp_) {
1869  // double gain = casadi_bilin(d->Bk, Hsp_, d->dx, d->dx);
1870  // if (gain < 0) {
1871  // if (print_status_) print("WARNING(feasiblesqpmethod): Indefinite Hessian detected\n");
1872  // }
1873  // }
1874  g.comment("Detecting indefiniteness");
1875  g.comment("TBD");
1876 
1877  // Do the feasibility iterations here
1878  // ret = feasibility_iterations(mem, tr_rad);
1879  g.comment("Do the feasibility iterations here");
1880  codegen_feasibility_iterations(g, "tr_rad");
1881 
1882  g << "if (ret < 0) {\n";
1883  g << "printf(\"Rejected inner iterates\\n\");\n";
1884  g << "tr_rad = 0.5*" << g.masked_norm_inf(nx_, "d.dx", "d.tr_mask") << ";\n";
1885  g << "} else {\n";
1886  g.comment("Evaluate f");
1887  g << "m_arg[0] = d.z_feas;\n";
1888  g << "m_arg[1] = m_p;\n";
1889  g << "m_res[0] = &m_f_feas;\n";
1890  nlp_f = g(get_function("nlp_f"), "m_arg", "m_res", "m_iw", "m_w");
1891  g << "if (" + nlp_f + ") return 1;\n";
1892 
1893  codegen_eval_tr_ratio(g, "m_f", "m_f_feas", "m_k");
1894  codegen_tr_update(g, "tr_rad", "tr_ratio");
1895 
1896  g << "if (tr_rad < "<< feas_tol_ << ") {\n";
1897  g << "if (" << print_status_ << ") {\n";
1898  g << "printf(\"MESSAGE: Trust-Region radius smaller than feasibilty!!\\n\");\n";
1899  g << "}\n";
1900  g << "break;";
1901  g << "}\n";
1902 
1903  codegen_step_update(g, "tr_ratio");
1904  g.comment("Close the step acceptance loop");
1905  g << "}\n";
1906 
1907  // if (!exact_hessian_) {
1908  // // Evaluate the gradient of the Lagrangian with the old x but new lam (for BFGS)
1909  // casadi_copy(d->gf, nx_, d->gLag_old);
1910  // casadi_mv(d->Jk, Asp_, d_nlp->lam+nx_, d->gLag_old, true);
1911  // casadi_axpy(nx_, 1., d_nlp->lam, d->gLag_old);
1912  // }
1913  // }
1914  // g << "}\n";
1915  // g << "if (!" << exact_hessian_ << ") {\n";
1916  // g << g.copy("d.gf", nx_, "d.gLag_old") << "\n";
1917  // g << g.mv("d.Jk", Asp_, "d_nlp.lam+" + str(nx_), "d.gLag_old", true) << ";\n";
1918  // g << g.axpy(nx_, "1.", "d_nlp.lam", "d.gLag_old") << "\n";
1919  // g << "}\n";
1920 
1921  // return 0;
1922  // }
1923  //Close next loop
1924  // g << "}\n";
1925 
1926  // g << "return 0;\n"; // Do we need this??
1927  // Close the loop optimization problem
1928  g.comment("Close the loop optimization problem");
1929  g << "}\n";
1930 
1931  if (bound_consistency_) {
1932  g << g.bound_consistency(nx_+ng_, "d_nlp.z", "d_nlp.lam", "d_nlp.lbz", "d_nlp.ubz") << ";\n";
1933  }
1934  g.copy_check("d_nlp.z", nx_, g.res(NLPSOL_X), false, true);
1935  g.copy_check("d_nlp.z+" + str(nx_), ng_, g.res(NLPSOL_G), false, true);
1936  g.copy_check("d_nlp.lam", nx_, g.res(NLPSOL_LAM_X), false, true);
1937  g.copy_check("d_nlp.lam+"+str(nx_), ng_, g.res(NLPSOL_LAM_G), false, true);
1938  g.copy_check("d_nlp.lam_p", np_, g.res(NLPSOL_LAM_P), false, true);
1939  g.copy_check("&m_f", 1, g.res(NLPSOL_F), false, true);
1940  }
void codegen_eval_tr_ratio(CodeGenerator &cg, const std::string &val_f, const std::string &val_f_corr, const std::string &val_m_k) const
void codegen_eval_m_k(CodeGenerator &cg) const
void codegen_step_update(CodeGenerator &cg, const std::string &tr_ratio) const
void codegen_feasibility_iterations(CodeGenerator &cg, const std::string &tr_rad) const
std::vector< double > tr_scale_vector_
void codegen_qp_solve(CodeGenerator &cg, const std::string &H, const std::string &g, const std::string &lbdz, const std::string &ubdz, const std::string &A, const std::string &x_opt, const std::string &dlam, int mode) const
void codegen_tr_update(CodeGenerator &cg, const std::string &tr_rad, const std::string &tr_ratio) const
void codegen_body_enter(CodeGenerator &g) const override
Generate code for the function body.
Definition: nlpsol.cpp:1179
casadi_int ng_
Number of constraints.
Definition: nlpsol_impl.hpp:69
casadi_int np_
Number of parameters.
Definition: nlpsol_impl.hpp:72
bool bound_consistency_
Options.
Definition: nlpsol_impl.hpp:98
@ NLPSOL_P
Value of fixed parameters (np x 1)
Definition: nlpsol.hpp:198
@ NLPSOL_LAM_G0
Lagrange multipliers for bounds on G, initial guess (ng x 1)
Definition: nlpsol.hpp:210
@ NLPSOL_LAM_X0
Lagrange multipliers for bounds on X, initial guess (nx x 1)
Definition: nlpsol.hpp:208
@ NLPSOL_NUM_IN
Definition: nlpsol.hpp:211
@ NLPSOL_NUM_OUT
Definition: nlpsol.hpp:228
@ NLPSOL_LAM_P
Lagrange multipliers for bounds on P at the solution (np x 1)
Definition: nlpsol.hpp:227

References casadi::CodeGenerator::add_auxiliary(), casadi::CodeGenerator::arg(), Asp_, casadi::CodeGenerator::AUX_FEASIBLESQPMETHOD, casadi::CodeGenerator::axpy(), casadi::CodeGenerator::bound_consistency(), casadi::Nlpsol::bound_consistency_, casadi::CodeGenerator::clear(), casadi::CodeGenerator::clip_max(), casadi::CodeGenerator::clip_min(), casadi::Nlpsol::codegen_body_enter(), codegen_eval_m_k(), codegen_eval_tr_ratio(), codegen_feasibility_iterations(), codegen_qp_solve(), codegen_step_update(), codegen_tr_update(), casadi::CodeGenerator::comment(), casadi::CodeGenerator::constant(), casadi::CodeGenerator::copy(), casadi::CodeGenerator::copy_check(), casadi::CodeGenerator::copy_default(), exact_hessian_, feas_tol_, casadi::OracleFunction::get_function(), Hsp_, casadi::CodeGenerator::init_local(), casadi::CodeGenerator::local(), casadi::CodeGenerator::masked_norm_inf(), max_iter_, casadi::CodeGenerator::max_viol(), casadi::CodeGenerator::mv(), casadi::Nlpsol::ng_, casadi::NLPSOL_F, casadi::NLPSOL_G, casadi::NLPSOL_LAM_G, casadi::NLPSOL_LAM_G0, casadi::NLPSOL_LAM_P, casadi::NLPSOL_LAM_X, casadi::NLPSOL_LAM_X0, casadi::NLPSOL_LBG, casadi::NLPSOL_LBX, casadi::NLPSOL_NUM_IN, casadi::NLPSOL_NUM_OUT, casadi::NLPSOL_P, casadi::NLPSOL_UBX, casadi::NLPSOL_X, casadi::NLPSOL_X0, casadi::CodeGenerator::norm_inf(), casadi::Nlpsol::np_, casadi::Nlpsol::nx_, optim_tol_, print_iteration_, print_status_, casadi::CodeGenerator::printf(), casadi::CodeGenerator::res(), casadi::CodeGenerator::sparsity(), casadi::str(), sz_anderson_memory_, tr_rad0_, and tr_scale_vector_.

◆ codegen_body_enter()

void casadi::Nlpsol::codegen_body_enter ( CodeGenerator g) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1o0

Reimplemented from casadi::OracleFunction.

Definition at line 1179 of file nlpsol.cpp.

1179  {
1181  g.local("d_nlp", "struct casadi_nlpsol_data");
1182  g.local("p_nlp", "struct casadi_nlpsol_prob");
1183 
1184  g << "d_nlp.oracle = &d_oracle;\n";
1185 
1186  g << "d_nlp.p = arg[" << NLPSOL_P << "];\n";
1187  g << "d_nlp.lbx = arg[" << NLPSOL_LBX << "];\n";
1188  g << "d_nlp.ubx = arg[" << NLPSOL_UBX << "];\n";
1189  g << "d_nlp.lbg = arg[" << NLPSOL_LBG << "];\n";
1190  g << "d_nlp.ubg = arg[" << NLPSOL_UBG << "];\n";
1191  g << "d_nlp.x0 = arg[" << NLPSOL_X0 << "];\n";
1192  g << "d_nlp.lam_x0 = arg[" << NLPSOL_LAM_X0 << "];\n";
1193  g << "d_nlp.lam_g0 = arg[" << NLPSOL_LAM_G0 << "];\n";
1194 
1195  g << "d_nlp.x = res[" << NLPSOL_X << "];\n";
1196  g << "d_nlp.f = res[" << NLPSOL_F << "];\n";
1197  g << "d_nlp.g = res[" << NLPSOL_G << "];\n";
1198  g << "d_nlp.lam_x = res[" << NLPSOL_LAM_X << "];\n";
1199  g << "d_nlp.lam_g = res[" << NLPSOL_LAM_G << "];\n";
1200  g << "d_nlp.lam_p = res[" << NLPSOL_LAM_P << "];\n";
1201 
1202  g << "d_nlp.prob = &p_nlp;\n";
1203  g << "p_nlp.nx = " << nx_ << ";\n";
1204  g << "p_nlp.ng = " << ng_ << ";\n";
1205  g << "p_nlp.np = " << np_ << ";\n";
1206  g << "p_nlp.detect_bounds.ng = " << detect_simple_bounds_is_simple_.size() << ";\n";
1207  if (detect_simple_bounds_is_simple_.size()) {
1208 
1209 
1210  g << "p_nlp.detect_bounds.sz_arg = " << detect_simple_bounds_parts_.sz_arg() << ";\n";
1211  g << "p_nlp.detect_bounds.sz_res = " << detect_simple_bounds_parts_.sz_res() << ";\n";
1212  g << "p_nlp.detect_bounds.sz_iw = " << detect_simple_bounds_parts_.sz_iw() << ";\n";
1213  g << "p_nlp.detect_bounds.sz_w = " << detect_simple_bounds_parts_.sz_w() << ";\n";
1214 
1215  g << "p_nlp.detect_bounds.nb = " << detect_simple_bounds_target_x_.size() << ";\n";
1216  g << "p_nlp.detect_bounds.target_x = "
1217  << g.constant(detect_simple_bounds_target_x_) << ";\n";
1218  g << "p_nlp.detect_bounds.target_g = "
1219  << g.constant(detect_simple_bounds_target_g_) << ";\n";
1220  g << "p_nlp.detect_bounds.is_simple = "
1221  << g.constant(detect_simple_bounds_is_simple_) << ";\n";
1222  std::string w =
1223  g.shorthand(g.wrapper(detect_simple_bounds_parts_, "detect_simple_bounds_wrapper"));
1224  g << "p_nlp.detect_bounds.callback = " << w << ";\n";
1225  g << "p_nlp.detect_bounds.callback_data = 0;\n";
1226  }
1227  g << "casadi_nlpsol_init(&d_nlp, &arg, &res, &iw, &w);\n";
1228 
1229  // Set initial guess
1230  g.copy_default("d_nlp.x0", nx_, "d_nlp.z", "0", false);
1231 
1232  // Read simple bounds and multiplier guesses
1233  g.copy_default("d_nlp.lbx", nx_, "d_nlp.lbz", "-casadi_inf", false);
1234  g.copy_default("d_nlp.ubx", nx_, "d_nlp.ubz", "casadi_inf", false);
1235  g.copy_default("d_nlp.lam_x0", nx_, "d_nlp.lam", "0", false);
1236 
1237  if (detect_simple_bounds_is_simple_.empty()) {
1238  // Read constraint bounds and multiplier guesses
1239  g.copy_default("d_nlp.lbg", ng_, "d_nlp.lbz+"+str(nx_),
1240  "-casadi_inf", false);
1241  g.copy_default("d_nlp.ubg", ng_, "d_nlp.ubz+"+str(nx_),
1242  "casadi_inf", false);
1243  g.copy_default("d_nlp.lam_g0", ng_, "d_nlp.lam+"+str(nx_), "0", false);
1244  } else {
1245  g << "if (casadi_detect_bounds_before(&d_nlp)) return 1;\n";
1246  }
1247 
1248  }
size_t sz_res() const
Get required length of res field.
Definition: function.cpp:1085
size_t sz_iw() const
Get required length of iw field.
Definition: function.cpp:1087
size_t sz_w() const
Get required length of w field.
Definition: function.cpp:1089
size_t sz_arg() const
Get required length of arg field.
Definition: function.cpp:1083
Function detect_simple_bounds_parts_
Definition: nlpsol_impl.hpp:85
std::vector< char > detect_simple_bounds_is_simple_
Definition: nlpsol_impl.hpp:84
std::vector< casadi_int > detect_simple_bounds_target_g_
Definition: nlpsol_impl.hpp:87
std::vector< casadi_int > detect_simple_bounds_target_x_
Definition: nlpsol_impl.hpp:86
virtual void codegen_body_enter(CodeGenerator &g) const
Generate code for the function body.

References casadi::OracleFunction::codegen_body_enter(), casadi::CodeGenerator::constant(), casadi::CodeGenerator::copy_default(), casadi::Nlpsol::detect_simple_bounds_is_simple_, casadi::Nlpsol::detect_simple_bounds_parts_, casadi::Nlpsol::detect_simple_bounds_target_g_, casadi::Nlpsol::detect_simple_bounds_target_x_, casadi::CodeGenerator::local(), casadi::Nlpsol::ng_, casadi::NLPSOL_F, casadi::NLPSOL_G, casadi::NLPSOL_LAM_G, casadi::NLPSOL_LAM_G0, casadi::NLPSOL_LAM_P, casadi::NLPSOL_LAM_X, casadi::NLPSOL_LAM_X0, casadi::NLPSOL_LBG, casadi::NLPSOL_LBX, casadi::NLPSOL_P, casadi::NLPSOL_UBG, casadi::NLPSOL_UBX, casadi::NLPSOL_X, casadi::NLPSOL_X0, casadi::Nlpsol::np_, casadi::Nlpsol::nx_, casadi::CodeGenerator::shorthand(), casadi::str(), casadi::Function::sz_arg(), casadi::Function::sz_iw(), casadi::Function::sz_res(), casadi::Function::sz_w(), and casadi::CodeGenerator::wrapper().

Referenced by casadi::FatropInterface::codegen_body(), casadi::IpoptInterface::codegen_body(), casadi::MadnlpInterface::codegen_body(), codegen_body(), and casadi::Sqpmethod::codegen_body().

◆ codegen_body_exit()

void casadi::Nlpsol::codegen_body_exit ( CodeGenerator g) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_27k

Reimplemented from casadi::OracleFunction.

Definition at line 1269 of file nlpsol.cpp.

1269  {
1270  if (calc_f_ || calc_g_ || calc_lam_x_ || calc_lam_p_) {
1271  g.local("one", "const casadi_real");
1272  g.init_local("one", "1");
1273  g << "d->arg[0] = d_nlp.z;\n";
1274  g << "d->arg[1] = d_nlp.p;\n";
1275  g << "d->arg[2] = &one;\n";
1276  g << "d->arg[3] = d_nlp.lam+" + str(nx_) + ";\n";
1277  g << "d->res[0] = " << (calc_f_ ? "&d_nlp.objective" : "0") << ";\n";
1278  g << "d->res[1] = " << (calc_g_ ? "d_nlp.z+" + str(nx_) : "0") << ";\n";
1279  g << "d->res[2] = " << (calc_lam_x_ ? "d_nlp.lam+" + str(nx_) : "0") << ";\n";
1280  g << "d->res[3] = " << (calc_lam_p_ ? "d_nlp.lam_p" : "0") << ";\n";
1281  std::string nlp_grad = g(get_function("nlp_grad"), "d->arg", "d->res", "d->iw", "d->w");
1282  g << "if (" + nlp_grad + ") return 1;\n";
1283  if (calc_lam_x_) g << g.scal(nx_, "-1.0", "d_nlp.lam") << "\n";
1284  if (calc_lam_p_) g << g.scal(np_, "-1.0", "d_nlp.lam_p") << "\n";
1285  }
1286  if (bound_consistency_) {
1287  g << g.bound_consistency(nx_+ng_, "d_nlp.z", "d_nlp.lam", "d_nlp.lbz", "d_nlp.ubz") << ";\n";
1288  }
1289 
1290  g << g.copy("d_nlp.z", nx_, "d_nlp.x") << "\n";
1291 
1292  if (detect_simple_bounds_is_simple_.empty()) {
1293  g << g.copy("d_nlp.z + " + str(nx_), ng_, "d_nlp.g") << "\n";
1294  g << g.copy("d_nlp.lam", nx_, "d_nlp.lam_x") << "\n";
1295  g << g.copy("d_nlp.lam + " + str(nx_), ng_, "d_nlp.lam_g") << "\n";
1296  } else {
1297  g << "if (casadi_detect_bounds_after(&d_nlp)) return 1;\n";
1298  }
1299 
1300  g.copy_check("&d_nlp.objective", 1, "d_nlp.f", false, true);
1301  g.copy_check("d_nlp.lam_p", np_, "d_nlp.lam_p", false, true);
1302 
1304  }
bool calc_lam_p_
Options.
Definition: nlpsol_impl.hpp:97
bool calc_f_
Options.
Definition: nlpsol_impl.hpp:97
bool calc_g_
Options.
Definition: nlpsol_impl.hpp:97
bool calc_lam_x_
Options.
Definition: nlpsol_impl.hpp:97
virtual void codegen_body_exit(CodeGenerator &g) const
Generate code for the function body.

References casadi::CodeGenerator::bound_consistency(), casadi::Nlpsol::bound_consistency_, casadi::Nlpsol::calc_f_, casadi::Nlpsol::calc_g_, casadi::Nlpsol::calc_lam_p_, casadi::Nlpsol::calc_lam_x_, casadi::OracleFunction::codegen_body_exit(), casadi::CodeGenerator::copy(), casadi::CodeGenerator::copy_check(), casadi::Nlpsol::detect_simple_bounds_is_simple_, casadi::OracleFunction::get_function(), casadi::CodeGenerator::init_local(), casadi::CodeGenerator::local(), casadi::Nlpsol::ng_, casadi::Nlpsol::np_, casadi::Nlpsol::nx_, casadi::CodeGenerator::scal(), and casadi::str().

Referenced by casadi::FatropInterface::codegen_body(), casadi::IpoptInterface::codegen_body(), casadi::MadnlpInterface::codegen_body(), and casadi::Sqpmethod::codegen_body().

◆ codegen_checkout()

void casadi::FunctionInternal::codegen_checkout ( CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lw

Reimplemented in casadi::External.

Definition at line 2447 of file function_internal.cpp.

2447  {
2448  std::string name = codegen_name(g, false);
2449  std::string stack_counter = g.shorthand(name + "_unused_stack_counter");
2450  std::string stack = g.shorthand(name + "_unused_stack");
2451  std::string mem_counter = g.shorthand(name + "_mem_counter");
2452  std::string mem_array = g.shorthand(name + "_mem");
2453  std::string alloc_mem = g.shorthand(name + "_alloc_mem");
2454  std::string init_mem = g.shorthand(name + "_init_mem");
2455 
2456  g.auxiliaries << "static int " << mem_counter << " = 0;\n";
2457  g.auxiliaries << "static int " << stack_counter << " = -1;\n";
2458  g.auxiliaries << "static int " << stack << "[CASADI_MAX_NUM_THREADS];\n";
2459  g.auxiliaries << "static " << codegen_mem_type() <<
2460  " " << mem_array << "[CASADI_MAX_NUM_THREADS];\n\n";
2461  g << "int mid;\n";
2462  g << "if (" << stack_counter << ">=0) {\n";
2463  g << "return " << stack << "[" << stack_counter << "--];\n";
2464  g << "} else {\n";
2465  g << "if (" << mem_counter << "==CASADI_MAX_NUM_THREADS) return -1;\n";
2466  g << "mid = " << alloc_mem << "();\n";
2467  g << "if (mid<0) return -1;\n";
2468  g << "if(" << init_mem << "(mid)) return -1;\n";
2469  g << "return mid;\n";
2470  g << "}\n";
2471  }
void * alloc_mem() const override
Create memory block.

References casadi::FunctionInternal::alloc_mem(), casadi::CodeGenerator::auxiliaries, casadi::FunctionInternal::codegen_mem_type(), casadi::FunctionInternal::codegen_name(), casadi::ProtoFunction::init_mem(), and casadi::CodeGenerator::shorthand().

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_declarations()

void casadi::Feasiblesqpmethod::codegen_declarations ( CodeGenerator g) const
overridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 1417 of file feasiblesqpmethod.cpp.

1417  {
1419  g.add_dependency(get_function("nlp_grad_f"));
1420  g.add_dependency(get_function("nlp_jac_g"));
1421  g.add_dependency(get_function("nlp_g"));
1422  g.add_dependency(get_function("nlp_f"));
1423  if (exact_hessian_) g.add_dependency(get_function("nlp_hess_l"));
1424  g.add_dependency(qpsol_);
1425  }
void codegen_declarations(CodeGenerator &g) const override
Generate code for the declarations of the C function.
Definition: nlpsol.cpp:1250

References casadi::CodeGenerator::add_dependency(), casadi::Nlpsol::codegen_declarations(), exact_hessian_, casadi::OracleFunction::get_function(), and qpsol_.

◆ codegen_decref()

virtual void casadi::FunctionInternal::codegen_decref ( CodeGenerator g) const
inlinevirtualinherited

◆ codegen_eval_m_k()

void casadi::Feasiblesqpmethod::codegen_eval_m_k ( CodeGenerator cg) const

Definition at line 1979 of file feasiblesqpmethod.cpp.

1979  {
1980  // auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
1981  // auto d = &m->d;
1982  // if (use_sqp_) {
1983  // return 0.5*casadi_bilin(d->Bk, Hsp_, d->dx, d->dx) + casadi_dot(nx_, d->gf, d->dx);
1984  // } else {
1985  // return casadi_dot(nx_, d->gf, d->dx);
1986  // }
1987  cg << "m_k = 0.5*" << cg.bilin("d.Bk", Hsp_, "d.dx", "d.dx")
1988  << "+" << cg.dot(nx_, "d.gf", "d.dx") << ";\n";
1989 }

References casadi::CodeGenerator::bilin(), casadi::CodeGenerator::dot(), Hsp_, and casadi::Nlpsol::nx_.

Referenced by codegen_body().

◆ codegen_eval_tr_ratio()

void casadi::Feasiblesqpmethod::codegen_eval_tr_ratio ( CodeGenerator cg,
const std::string &  val_f,
const std::string &  val_f_corr,
const std::string &  val_m_k 
) const

Definition at line 1991 of file feasiblesqpmethod.cpp.

1992  {
1993  // return (val_f - val_f_corr) / (-val_m_k);
1994  cg << "tr_ratio = (" + val_f + "-" + val_f_corr + ") / (-" + val_m_k + ");\n";
1995  }

Referenced by codegen_body().

◆ codegen_feasibility_iterations()

void casadi::Feasiblesqpmethod::codegen_feasibility_iterations ( CodeGenerator cg,
const std::string &  tr_rad 
) const

Definition at line 2027 of file feasiblesqpmethod.cpp.

2028  {
2029  // cg.local("ret", "casadi_int");
2030  cg.init_local("ret", "0");
2031 
2032  // casadi_copy(d->dx, nx_, d->dx_feas);
2033  cg << cg.copy("d.dx", nx_, "d.dx_feas") << "\n";
2034 
2035  // casadi_copy(d->dlam, nx_ + ng_, d->dlam_feas);
2036  cg << cg.copy("d.dlam", nx_, "d.dlam_feas") << "\n";
2037 
2038  // Why do we do this at the moment??
2039  // casadi_copy(d->dlam, nx_+ng_, d->z_tmp);
2040  // casadi_axpy(nx_+ng_, -1.0, d_nlp->lam, d->z_tmp);
2041  cg << cg.copy("d.dlam", nx_+ng_, "d.z_tmp") << "\n";
2042  cg << cg.axpy(nx_+ng_, "-1.0", "d_nlp.lam", "d.z_tmp") << "\n";
2043 
2044  // this is in solve in fslp.py
2045  // double step_inf_norm = casadi_masked_norm_inf(nx_, d->dx, d->tr_mask);
2046  // double prev_step_inf_norm = step_inf_norm;
2047  cg.local("step_inf_norm", "casadi_real");
2048  cg << "step_inf_norm = " << cg.masked_norm_inf(nx_, "d.dx", "d.tr_mask") << ";\n";
2049  cg.local("prev_step_inf_norm", "casadi_real");
2050  cg << "prev_step_inf_norm = step_inf_norm;\n";
2051  // cg.init_local("prev_step_inf_norm", "step_inf_norm");
2052 
2053  // self.x_tmp = self.x_k + p_tmp
2054  // casadi_copy(d_nlp->z, nx_+ng_, d->z_feas);
2055  // casadi_axpy(nx_, 1., d->dx_feas, d->z_feas);
2056  cg << cg.copy("d_nlp.z", nx_+ng_, "d.z_feas") << "\n";
2057  cg << cg.axpy(nx_, "1.0", "d.dx_feas", "d.z_feas") << "\n";
2058 
2059 
2060  // if (use_anderson_) {
2061  // // anderson_acc_init_memory(mem, d->dx_feas, d->z_feas);
2062  // anderson_acc_init_memory(mem, d->dx_feas, d_nlp->z);
2063  // }
2064  // cg << "if (" << use_anderson_ << ") {\n";
2065  // cg << cg.codegen_anderson_acc_init_memory(cg, "d.dx_feas", "d_nlp.z");
2066  // cg << "}\n";
2067 
2068  // Evaluate g
2069  // self.g_tmp = self.__eval_g(self.x_tmp)
2070  // m->arg[0] = d->z_feas;
2071  // m->arg[1] = d_nlp->p;
2072  // m->res[0] = d->z_feas + nx_;
2073  // if (calc_function(m, "nlp_g")) {
2074  // uout() << "What does it mean that calc_function fails here??" << std::endl;
2075  // }
2076  cg.comment("Evaluate g");
2077  cg << "m_arg[0] = d.z_feas;\n";
2078  cg << "m_arg[1] = m_p;\n";
2079  cg << "m_res[0] = d.z_feas+" + str(nx_) + ";\n";
2080  std::string nlp_g = cg(get_function("nlp_g"), "m_arg", "m_res", "m_iw", "m_w");
2081  // cg << "if (" + nlp_g + ") return 1;\n";
2082  cg << "if (" + nlp_g + ") return 100;\n";
2083 
2084 
2085  // int inner_iter = 0;
2086  cg.local("inner_iter", "casadi_int");
2087  cg.init_local("inner_iter", "0");
2088 
2089  // double prev_infeas = casadi_max_viol(nx_+ng_, d->z_feas, d_nlp->lbz, d_nlp->ubz);
2090  // double curr_infeas = prev_infeas;
2091  cg.local("prev_infeas", "casadi_real");
2092  cg << "prev_infeas =" << cg.max_viol(nx_+ng_, "d.z_feas", "d_nlp.lbz", "d_nlp.ubz") << ";\n";
2093  cg.local("curr_infeas", "casadi_real");
2094  cg << "curr_infeas = prev_infeas;\n";
2095 
2096 
2097  // Calculate asymptotic exactness of current step
2098  // casadi_copy(d->dx, nx_, d->z_tmp);
2099  // casadi_axpy(nx_, -1., d->z_feas, d->z_tmp);
2100  // casadi_axpy(nx_, 1., d_nlp->z, d->z_tmp);
2101  // double as_exac = casadi_norm_2(nx_, d->z_tmp) / casadi_norm_2(nx_, d->dx);
2102  cg << cg.copy("d.dx", nx_, "d.z_tmp") << "\n";
2103  cg << cg.axpy(nx_, "-1.0", "d.z_feas", "d.z_tmp") << "\n";
2104  cg << cg.axpy(nx_, "1.0", "d_nlp.z", "d.z_tmp") << "\n";
2105  cg.local("as_exac", "casadi_real");
2106  cg << "as_exac =" << cg.norm_2(nx_, "d.z_tmp") << "/" << cg.norm_2(nx_, "d.dx") << ";\n";
2107 
2108  // double kappa_watchdog = 0.0;
2109  // double kappa = 0.0;
2110  // double acc_as_exac = 0.0;
2111  cg.local("kappa_watchdog", "casadi_real");
2112  cg.init_local("kappa_watchdog", "0.0");
2113  cg.local("kappa", "casadi_real");
2114  cg.init_local("kappa", "0.0");
2115  cg.local("acc_as_exac", "casadi_real");
2116  cg << "acc_as_exac = 0.0;\n";
2117 
2118  // double watchdog_prev_inf_norm = prev_step_inf_norm; // until here everything is correct!
2119  cg.local("watchdog_prev_inf_norm", "casadi_real");
2120  // cg.init_local("watchdog_prev_inf_norm", "prev_step_inf_norm");
2121  cg << "watchdog_prev_inf_norm = prev_step_inf_norm;\n";
2122 
2123  // for (int j=0; j<max_inner_iter_; ++j) {
2124  // if (curr_infeas < feas_tol_) {
2125  // inner_iter = j;
2126  // // kappa_acceptance = true;
2127  // if (as_exac < 0.5) {
2128  // return 0;
2129  // } else {
2130  // return -1;
2131  // }
2132  // } else if (j>0 && (curr_infeas > 1.0 || as_exac > 1.0)) {
2133  // // kappa_acceptance = false;
2134  // return -1;
2135  // }
2136  cg << "for (int j=0;j<" << max_inner_iter_ << "; ++j) {\n";
2137  cg << "if (curr_infeas < " << feas_tol_ << ") {\n";
2138  cg << "inner_iter = j;\n";
2139  cg << "if (as_exac < 0.5) {\n";
2140  cg << "ret = 0; \n";
2141  cg << "break; \n";
2142  cg << "} else {\n";
2143  cg << "ret = -1;\n";
2144  cg << "break; \n";
2145  cg << "}\n";
2146  cg << "} else if (j>0 && (curr_infeas > 1.0 || as_exac > 1.0)) {\n";
2147  cg << "ret = -1;\n";
2148  cg << "break; \n";
2149  cg << "}\n";
2150 
2151 
2152  // inner_iter = j+1;
2153  cg << "inner_iter =j+1;\n";
2154 
2155  // create corrected gradient here -----------------------------
2156  // casadi_copy(d->z_feas, nx_, d->z_tmp);
2157  // casadi_axpy(nx_, -1., d_nlp->z, d->z_tmp);
2158  // casadi_copy(d->gf, nx_, d->gf_feas);
2159  cg << cg.copy("d.z_feas", nx_, "d.z_tmp") << "\n";
2160  cg << cg.axpy(nx_, "-1.0", "d_nlp.z", "d.z_tmp") << "\n";
2161  cg << cg.copy("d.gf", nx_, "d.gf_feas") << "\n";
2162  // In case of SQP we need to multiply with
2163  // if (use_sqp_) {
2164  // casadi_mv(d->Bk, Hsp_, d->z_tmp, d->gf_feas, true);
2165  // }
2166  cg.comment("Just SQP implemented so far!");
2167  // cg << "if (" << use_sqp_ << ") {\n";
2168  cg << cg.mv("d.Bk", Hsp_, "d.z_tmp", "d.gf_feas", true) << "\n";
2169  // cg << "}\n";
2170 
2171  // create bounds of correction QP -----------------------------
2172  // upper bounds of constraints
2173  // casadi_copy(d_nlp->ubz + nx_, ng_, d->ubdz_feas + nx_);
2174  // casadi_axpy(ng_, -1., d->z_feas + nx_, d->ubdz_feas + nx_);
2175  cg << cg.copy("d_nlp.ubz+"+str(nx_), ng_, "d.ubdz_feas+"+str(nx_)) << "\n";
2176  cg << cg.axpy(ng_, "-1.0", "d.z_feas+"+str(nx_), "d.ubdz_feas+"+str(nx_)) << "\n";
2177 
2178  // lower bounds of constraints
2179  // casadi_copy(d_nlp->lbz + nx_, ng_, d->lbdz_feas + nx_);
2180  // casadi_axpy(ng_, -1., d->z_feas + nx_, d->lbdz_feas + nx_);
2181  cg << cg.copy("d_nlp.lbz+"+str(nx_), ng_, "d.lbdz_feas+"+str(nx_)) << "\n";
2182  cg << cg.axpy(ng_, "-1.0", "d.z_feas+"+str(nx_), "d.lbdz_feas+"+str(nx_)) << "\n";
2183 
2184 
2185  // casadi_copy(d_nlp->lbz, nx_, d->lbdz_feas);
2186  // casadi_clip_min(d->lbdz_feas, nx_, -tr_rad, d->tr_mask);
2187  cg << cg.copy("d_nlp.lbz", nx_, "d.lbdz_feas") << "\n";
2188  cg << cg.clip_min("d.lbdz_feas", nx_, "-tr_rad", "d.tr_mask") << "\n";
2189 
2190 
2191  // casadi_axpy(nx_, -1., d->z_feas, d->lbdz_feas);
2192  // casadi_axpy(nx_, 1., d_nlp->z, d->lbdz_feas);
2193  cg << cg.axpy(nx_, "-1.0", "d.z_feas", "d.lbdz_feas") << "\n";
2194  cg << cg.axpy(nx_, "1.0", "d_nlp.z", "d.lbdz_feas") << "\n";
2195 
2196 
2197  // casadi_copy(d_nlp->lbz, nx_, d->z_tmp);
2198  // casadi_axpy(nx_, -1., d->z_feas, d->z_tmp);
2199  cg << cg.copy("d_nlp.lbz", nx_, "d.z_tmp") << "\n";
2200  cg << cg.axpy(nx_, "-1.0", "d.z_feas", "d.z_tmp") << "\n";
2201 
2202  // comparison of both vectors
2203  // casadi_vector_fmax(nx_, d->z_tmp, d->lbdz_feas, d->lbdz_feas);
2204  cg << cg.vector_fmax(nx_, "d.z_tmp", "d.lbdz_feas", "d.lbdz_feas");
2205 
2206  // casadi_copy(d_nlp->ubz, nx_, d->ubdz_feas);
2207  // casadi_clip_max(d->ubdz_feas, nx_, tr_rad, d->tr_mask);
2208  cg << cg.copy("d_nlp.ubz", nx_, "d.ubdz_feas") << "\n";
2209  cg << cg.clip_max("d.ubdz_feas", nx_, "tr_rad", "d.tr_mask") << ";\n";
2210 
2211  // casadi_axpy(nx_, -1., d->z_feas, d->ubdz_feas);
2212  // casadi_axpy(nx_, 1., d_nlp->z, d->ubdz_feas);
2213  cg << cg.axpy(nx_, "-1.0", "d.z_feas", "d.ubdz_feas") << "\n";
2214  cg << cg.axpy(nx_, "1.0", "d_nlp.z", "d.ubdz_feas") << "\n";
2215 
2216 
2217  // casadi_copy(d_nlp->ubz, nx_, d->z_tmp);
2218  // casadi_axpy(nx_, -1., d->z_feas, d->z_tmp);
2219  // casadi_vector_fmin(nx_, d->z_tmp, d->ubdz_feas, d->ubdz_feas);
2220  cg << cg.copy("d_nlp.ubz", nx_, "d.z_tmp") << "\n";
2221  cg << cg.axpy(nx_, "-1.0", "d.z_feas", "d.z_tmp") << "\n";
2222  cg << cg.vector_fmin(nx_, "d.z_tmp", "d.ubdz_feas", "d.ubdz_feas");
2223 
2224  // if (use_sqp_) {
2225  // int ret = solve_QP(m, d->Bk, d->gf_feas, d->lbdz_feas, d->ubdz_feas,
2226  // d->Jk, d->dx_feas, d->dlam_feas, 0);
2227  // } else {
2228  // int ret = solve_LP(m, d->gf_feas, d->lbdz_feas, d->ubdz_feas,
2229  // d->Jk, d->dx_feas, d->dlam_feas, 0);
2230  // }
2231  cg.comment("Just SQP implemented. Solve the feasible QP");
2232  codegen_qp_solve(cg, "d.Bk", "d.gf_feas", "d.lbdz_feas", "d.ubdz_feas",
2233  "d.Jk", "d.dx_feas", "d.dlam_feas", 0);
2234 
2235 
2236  // step_inf_norm = casadi_masked_norm_inf(nx_, d->dx_feas, d->tr_mask);
2237  cg << "step_inf_norm = " << cg.masked_norm_inf(nx_, "d.dx_feas", "d.tr_mask") << ";\n";
2238 
2239  // if (use_anderson_) {
2240  // anderson_acc_step_update(mem, j);
2241  // } else {
2242  // casadi_axpy(nx_, 1., d->dx_feas, d->z_feas);
2243  // }
2244  cg.comment("No Anderson Acceleration implemented yet.");
2245  cg << cg.axpy(nx_, "1.0", "d.dx_feas", "d.z_feas") << "\n";
2246 
2247  // Evaluate g
2248  // m->arg[0] = d->z_feas;
2249  // m->arg[1] = d_nlp->p;
2250  // m->res[0] = d->z_feas + nx_;
2251  // if (calc_function(m, "nlp_g")) {
2252  // uout() << "What does it mean that calc_function fails here??" << std::endl;
2253  // }
2254  cg.comment("Evaluate g");
2255  cg << "m_arg[0] = d.z_feas;\n";
2256  cg << "m_arg[1] = m_p;\n";
2257  cg << "m_res[0] = d.z_feas+" + str(nx_) + ";\n";
2258  nlp_g = cg(get_function("nlp_g"), "m_arg", "m_res", "m_iw", "m_w");
2259  // cg << "if (" + nlp_g + ") return 1;\n";
2260  cg << "if (" + nlp_g + ") return 100;\n";
2261 
2262  // prev_infeas = casadi_max_viol(nx_+ng_, d->z_feas, d_nlp->lbz, d_nlp->ubz);
2263  // curr_infeas = prev_infeas;
2264  // kappa = step_inf_norm/prev_step_inf_norm;
2265  cg << "prev_infeas =" << cg.max_viol(nx_+ng_, "d.z_feas", "d_nlp.lbz", "d_nlp.ubz") << ";\n";
2266  cg << "curr_infeas = prev_infeas;\n";
2267  cg << "kappa = step_inf_norm/prev_step_inf_norm;";
2268 
2269  // casadi_copy(d->dx, nx_, d->z_tmp);
2270  // casadi_axpy(nx_, -1., d->z_feas, d->z_tmp);
2271  // casadi_axpy(nx_, 1., d_nlp->z, d->z_tmp);
2272  // as_exac = casadi_norm_2(nx_, d->z_tmp) / casadi_norm_2(nx_, d->dx);
2273  cg << cg.copy("d.dx", nx_, "d.z_tmp") << "\n";
2274  cg << cg.axpy(nx_, "-1.0", "d.z_feas", "d.z_tmp") << "\n";
2275  cg << cg.axpy(nx_, "1.0", "d_nlp.z", "d.z_tmp") << "\n";
2276  cg.local("as_exac", "casadi_real");
2277  cg << "as_exac =" << cg.norm_2(nx_, "d.z_tmp") << "/" << cg.norm_2(nx_, "d.dx") << ";\n";
2278 
2279  cg << "printf(\"Kappa: %9.10f, Infeasibility: %9.10f, "
2280  "AsymptoticExctness: %9.10f\\n\", kappa, curr_infeas, as_exac);\n";
2281 
2282  // acc_as_exac += as_exac;
2283  cg << "acc_as_exac += as_exac;\n";
2284 
2285  // if (inner_iter % watchdog_ == 0) {
2286  // kappa_watchdog = step_inf_norm / watchdog_prev_inf_norm;
2287  // watchdog_prev_inf_norm = step_inf_norm;
2288  // print("Kappa watchdog: %9.10f\n", kappa_watchdog);
2289  // if (curr_infeas < feas_tol_ && as_exac < 0.5) {
2290  // // kappa_acceptance = true;
2291  // return 0;
2292  // }
2293 
2294  // if (kappa_watchdog > contraction_acceptance_value_ || acc_as_exac/watchdog_ > 0.5) {
2295  // // kappa_acceptance = false;
2296  // return -1;
2297  // }
2298  // // accumulated_as_ex = 0
2299  // acc_as_exac = 0.0;
2300  // }
2301  cg << "if (inner_iter % " << watchdog_ << "== 0) {\n";
2302  cg << "kappa_watchdog = step_inf_norm / watchdog_prev_inf_norm;\n";
2303  cg << "watchdog_prev_inf_norm = step_inf_norm;\n";
2304  cg << "printf(\"Kappa watchdog: %9.10f\\n\", kappa_watchdog);\n";
2305  cg << "if (curr_infeas < "<< feas_tol_ << "&& as_exac < 0.5) {\n";
2306  cg << "ret = 0;\n";
2307  cg << "break; \n";
2308  cg << "}\n";
2309  cg << "if (kappa_watchdog > " << contraction_acceptance_value_ << " || "
2310  << "acc_as_exac/" << watchdog_ << "> 0.5) {\n";
2311  cg << "ret = -1;\n";
2312  cg << "break;\n";
2313  cg << "}\n";
2314 
2315  cg << "acc_as_exac = 0.0;\n";
2316  cg << "}\n"; //Added
2317 
2318  // prev_step_inf_norm = step_inf_norm;
2319  cg << "prev_step_inf_norm = step_inf_norm;\n";
2320  // }
2321  cg << "}\n";
2322  //maximum iterations reached
2323  // kappa_acceptance = false;
2324 // return -1;
2325 // }
2326  cg << "if (inner_iter >=" << max_inner_iter_ << ") {\n";
2327  cg << "ret = -1;\n";
2328  cg << "}\n";
2329 
2330  }

References casadi::CodeGenerator::axpy(), casadi::CodeGenerator::clip_max(), casadi::CodeGenerator::clip_min(), codegen_qp_solve(), casadi::CodeGenerator::comment(), contraction_acceptance_value_, casadi::CodeGenerator::copy(), feas_tol_, casadi::OracleFunction::get_function(), Hsp_, casadi::CodeGenerator::init_local(), casadi::CodeGenerator::local(), casadi::CodeGenerator::masked_norm_inf(), max_inner_iter_, casadi::CodeGenerator::max_viol(), casadi::CodeGenerator::mv(), casadi::Nlpsol::ng_, casadi::CodeGenerator::norm_2(), casadi::Nlpsol::nx_, casadi::str(), casadi::CodeGenerator::vector_fmax(), casadi::CodeGenerator::vector_fmin(), and watchdog_.

Referenced by codegen_body().

◆ codegen_free_mem()

virtual void casadi::FunctionInternal::codegen_free_mem ( CodeGenerator g) const
inlinevirtualinherited

◆ codegen_incref()

virtual void casadi::FunctionInternal::codegen_incref ( CodeGenerator g) const
inlinevirtualinherited

◆ codegen_init_mem()

void casadi::FunctionInternal::codegen_init_mem ( CodeGenerator g) const
virtualinherited

◆ codegen_mem()

std::string casadi::FunctionInternal::codegen_mem ( CodeGenerator g,
const std::string &  index = "mem" 
) const
inherited

◆ codegen_mem_type()

virtual std::string casadi::FunctionInternal::codegen_mem_type ( ) const
inlinevirtualinherited

◆ codegen_meta()

void casadi::FunctionInternal::codegen_meta ( CodeGenerator g) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ln

Definition at line 2484 of file function_internal.cpp.

2484  {
2485  bool needs_mem = !codegen_mem_type().empty();
2486 
2487  g << g.declare("int " + name_ + "_alloc_mem(void)") << " {\n";
2488  if (needs_mem) {
2489  g << "return " << codegen_name(g) << "_alloc_mem();\n";
2490  } else {
2491  g << "return 0;\n";
2492  }
2493  g << "}\n\n";
2494 
2495  g << g.declare("int " + name_ + "_init_mem(int mem)") << " {\n";
2496  if (needs_mem) {
2497  g << "return " << codegen_name(g) << "_init_mem(mem);\n";
2498  } else {
2499  g << "return 0;\n";
2500  }
2501  g << "}\n\n";
2502 
2503  g << g.declare("void " + name_ + "_free_mem(int mem)") << " {\n";
2504  if (needs_mem) {
2505  g << codegen_name(g) << "_free_mem(mem);\n";
2506  }
2507  g << "}\n\n";
2508 
2509  // Checkout/release routines
2510  g << g.declare("int " + name_ + "_checkout(void)") << " {\n";
2511  if (needs_mem) {
2512  g << "return " << codegen_name(g) << "_checkout();\n";
2513  } else {
2514  g << "return 0;\n";
2515  }
2516  g << "}\n\n";
2517 
2518  if (needs_mem) {
2519  g << g.declare("void " + name_ + "_release(int mem)") << " {\n";
2520  g << codegen_name(g) << "_release(mem);\n";
2521  } else {
2522  g << g.declare("void " + name_ + "_release(int mem)") << " {\n";
2523  }
2524  g << "}\n\n";
2525 
2526  // Reference counter routines
2527  g << g.declare("void " + name_ + "_incref(void)") << " {\n";
2528  codegen_incref(g);
2529  g << "}\n\n"
2530  << g.declare("void " + name_ + "_decref(void)") << " {\n";
2531  codegen_decref(g);
2532  g << "}\n\n";
2533 
2534  // Number of inputs and outptus
2535  g << g.declare("casadi_int " + name_ + "_n_in(void)")
2536  << " { return " << n_in_ << ";}\n\n"
2537  << g.declare("casadi_int " + name_ + "_n_out(void)")
2538  << " { return " << n_out_ << ";}\n\n";
2539 
2540  // Default inputs
2541  g << g.declare("casadi_real " + name_ + "_default_in(casadi_int i)") << " {\n"
2542  << "switch (i) {\n";
2543  for (casadi_int i=0; i<n_in_; ++i) {
2544  double def = get_default_in(i);
2545  if (def!=0) g << "case " << i << ": return " << g.constant(def) << ";\n";
2546  }
2547  g << "default: return 0;\n}\n"
2548  << "}\n\n";
2549 
2550  // Input names
2551  g << g.declare("const char* " + name_ + "_name_in(casadi_int i)") << " {\n"
2552  << "switch (i) {\n";
2553  for (casadi_int i=0; i<n_in_; ++i) {
2554  g << "case " << i << ": return \"" << name_in_[i] << "\";\n";
2555  }
2556  g << "default: return 0;\n}\n"
2557  << "}\n\n";
2558 
2559  // Output names
2560  g << g.declare("const char* " + name_ + "_name_out(casadi_int i)") << " {\n"
2561  << "switch (i) {\n";
2562  for (casadi_int i=0; i<n_out_; ++i) {
2563  g << "case " << i << ": return \"" << name_out_[i] << "\";\n";
2564  }
2565  g << "default: return 0;\n}\n"
2566  << "}\n\n";
2567 
2568  // Codegen sparsities
2569  codegen_sparsities(g);
2570 
2571  // Function that returns work vector lengths
2572  g << g.declare(
2573  "int " + name_ + "_work(casadi_int *sz_arg, casadi_int* sz_res, "
2574  "casadi_int *sz_iw, casadi_int *sz_w)")
2575  << " {\n"
2576  << "if (sz_arg) *sz_arg = " << codegen_sz_arg(g) << ";\n"
2577  << "if (sz_res) *sz_res = " << codegen_sz_res(g) << ";\n"
2578  << "if (sz_iw) *sz_iw = " << codegen_sz_iw(g) << ";\n"
2579  << "if (sz_w) *sz_w = " << codegen_sz_w(g) << ";\n"
2580  << "return 0;\n"
2581  << "}\n\n";
2582 
2583  // Function that returns work vector lengths in bytes
2584  g << g.declare(
2585  "int " + name_ + "_work_bytes(casadi_int *sz_arg, casadi_int* sz_res, "
2586  "casadi_int *sz_iw, casadi_int *sz_w)")
2587  << " {\n"
2588  << "if (sz_arg) *sz_arg = " << codegen_sz_arg(g) << "*sizeof(const casadi_real*);\n"
2589  << "if (sz_res) *sz_res = " << codegen_sz_res(g) << "*sizeof(casadi_real*);\n"
2590  << "if (sz_iw) *sz_iw = " << codegen_sz_iw(g) << "*sizeof(casadi_int);\n"
2591  << "if (sz_w) *sz_w = " << codegen_sz_w(g) << "*sizeof(casadi_real);\n"
2592  << "return 0;\n"
2593  << "}\n\n";
2594 
2595  // Also add to header file to allow getting
2596  if (g.with_header) {
2597  g.header
2598  << "#define " << name_ << "_SZ_ARG " << codegen_sz_arg(g) << "\n"
2599  << "#define " << name_ << "_SZ_RES " << codegen_sz_res(g) << "\n"
2600  << "#define " << name_ << "_SZ_IW " << codegen_sz_iw(g) << "\n"
2601  << "#define " << name_ << "_SZ_W " << codegen_sz_w(g) << "\n";
2602  }
2603 
2604  // Which inputs are differentiable
2605  if (!all(is_diff_in_)) {
2606  g << g.declare("int " + name_ + "_diff_in(casadi_int i)") << " {\n"
2607  << "switch (i) {\n";
2608  for (casadi_int i=0; i<n_in_; ++i) {
2609  g << "case " << i << ": return " << is_diff_in_[i] << ";\n";
2610  }
2611  g << "default: return -1;\n}\n"
2612  << "}\n\n";
2613  }
2614 
2615  // Which outputs are differentiable
2616  if (!all(is_diff_out_)) {
2617  g << g.declare("int " + name_ + "_diff_out(casadi_int i)") << " {\n"
2618  << "switch (i) {\n";
2619  for (casadi_int i=0; i<n_out_; ++i) {
2620  g << "case " << i << ": return " << is_diff_out_[i] << ";\n";
2621  }
2622  g << "default: return -1;\n}\n"
2623  << "}\n\n";
2624  }
2625 
2626  // Generate mex gateway for the function
2627  if (g.mex) {
2628  // Begin conditional compilation
2629  g << "#ifdef MATLAB_MEX_FILE\n";
2630 
2631  // Declare wrapper
2632  g << "void mex_" << name_
2633  << "(int resc, mxArray *resv[], int argc, const mxArray *argv[]) {\n"
2634  << "casadi_int i;\n";
2635  g << "int mem;\n";
2636  // Work vectors, including input and output buffers
2637  casadi_int i_nnz = nnz_in(), o_nnz = nnz_out();
2638  size_t sz_w = this->sz_w();
2639  for (casadi_int i=0; i<n_in_; ++i) {
2640  const Sparsity& s = sparsity_in_[i];
2641  sz_w = std::max(sz_w, static_cast<size_t>(s.size1())); // To be able to copy a column
2642  sz_w = std::max(sz_w, static_cast<size_t>(s.size2())); // To be able to copy a row
2643  }
2644  sz_w += i_nnz + o_nnz;
2645  g << CodeGenerator::array("casadi_real", "w", sz_w);
2646  g << CodeGenerator::array("casadi_int", "iw", sz_iw());
2647  std::string fw = "w+" + str(i_nnz + o_nnz);
2648 
2649  // Copy inputs to buffers
2650  casadi_int offset=0;
2651  g << CodeGenerator::array("const casadi_real*", "arg", sz_arg(), "{0}");
2652 
2653  // Allocate output buffers
2654  g << "casadi_real* res[" << sz_res() << "] = {0};\n";
2655 
2656  // Check arguments
2657  g << "if (argc>" << n_in_ << ") mexErrMsgIdAndTxt(\"Casadi:RuntimeError\","
2658  << "\"Evaluation of \\\"" << name_ << "\\\" failed. Too many input arguments "
2659  << "(%d, max " << n_in_ << ")\", argc);\n";
2660 
2661  g << "if (resc>" << n_out_ << ") mexErrMsgIdAndTxt(\"Casadi:RuntimeError\","
2662  << "\"Evaluation of \\\"" << name_ << "\\\" failed. "
2663  << "Too many output arguments (%d, max " << n_out_ << ")\", resc);\n";
2664 
2665  for (casadi_int i=0; i<n_in_; ++i) {
2666  std::string p = "argv[" + str(i) + "]";
2667  g << "if (--argc>=0) arg[" << i << "] = "
2668  << g.from_mex(p, "w", offset, sparsity_in_[i], fw) << "\n";
2669  offset += nnz_in(i);
2670  }
2671 
2672  for (casadi_int i=0; i<n_out_; ++i) {
2673  if (i==0) {
2674  // if i==0, always store output (possibly ans output)
2675  g << "--resc;\n";
2676  } else {
2677  // Store output, if it exists
2678  g << "if (--resc>=0) ";
2679  }
2680  // Create and get pointer
2681  g << g.res(i) << " = w+" << str(offset) << ";\n";
2682  offset += nnz_out(i);
2683  }
2684  g << name_ << "_incref();\n";
2685  g << "mem = " << name_ << "_checkout();\n";
2686 
2687  // Call the function
2688  g << "i = " << name_ << "(arg, res, iw, " << fw << ", mem);\n"
2689  << "if (i) mexErrMsgIdAndTxt(\"Casadi:RuntimeError\",\"Evaluation of \\\"" << name_
2690  << "\\\" failed.\");\n";
2691  g << name_ << "_release(mem);\n";
2692  g << name_ << "_decref();\n";
2693 
2694  // Save results
2695  for (casadi_int i=0; i<n_out_; ++i) {
2696  g << "if (" << g.res(i) << ") resv[" << i << "] = "
2697  << g.to_mex(sparsity_out_[i], g.res(i)) << "\n";
2698  }
2699 
2700  // End conditional compilation and function
2701  g << "}\n"
2702  << "#endif\n\n";
2703  }
2704 
2705  if (g.main) {
2706  // Declare wrapper
2707  g << "casadi_int main_" << name_ << "(casadi_int argc, char* argv[]) {\n";
2708 
2709  g << "casadi_int j;\n";
2710  g << "casadi_real* a;\n";
2711  g << "const casadi_real* r;\n";
2712  g << "casadi_int flag;\n";
2713  if (needs_mem) g << "int mem;\n";
2714 
2715 
2716 
2717  // Work vectors and input and output buffers
2718  size_t nr = sz_w() + nnz_in() + nnz_out();
2719  g << CodeGenerator::array("casadi_int", "iw", sz_iw())
2720  << CodeGenerator::array("casadi_real", "w", nr);
2721 
2722  // Input buffers
2723  g << "const casadi_real* arg[" << sz_arg() << "];\n";
2724 
2725  // Output buffers
2726  g << "casadi_real* res[" << sz_res() << "];\n";
2727 
2728  casadi_int off=0;
2729  for (casadi_int i=0; i<n_in_; ++i) {
2730  g << "arg[" << i << "] = w+" << off << ";\n";
2731  off += nnz_in(i);
2732  }
2733  for (casadi_int i=0; i<n_out_; ++i) {
2734  g << "res[" << i << "] = w+" << off << ";\n";
2735  off += nnz_out(i);
2736  }
2737 
2738  // TODO(@jaeandersson): Read inputs from file. For now; read from stdin
2739  g << "a = w;\n"
2740  << "for (j=0; j<" << nnz_in() << "; ++j) "
2741  << "if (scanf(\"%lg\", a++)<=0) return 2;\n";
2742 
2743  if (needs_mem) {
2744  g << "mem = " << name_ << "_checkout();\n";
2745  }
2746 
2747  // Call the function
2748  g << "flag = " << name_ << "(arg, res, iw, w+" << off << ", ";
2749  if (needs_mem) {
2750  g << "mem";
2751  } else {
2752  g << "0";
2753  }
2754  g << ");\n";
2755  if (needs_mem) {
2756  g << name_ << "_release(mem);\n";
2757  }
2758  g << "if (flag) return flag;\n";
2759 
2760  // TODO(@jaeandersson): Write outputs to file. For now: print to stdout
2761  g << "r = w+" << nnz_in() << ";\n"
2762  << "for (j=0; j<" << nnz_out() << "; ++j) "
2763  << g.printf("%g ", "*r++") << "\n";
2764 
2765  // End with newline
2766  g << g.printf("\\n") << "\n";
2767 
2768  // Finalize function
2769  g << "return 0;\n"
2770  << "}\n\n";
2771  }
2772 
2773  if (g.with_mem) {
2774  // Allocate memory
2775  g << g.declare("casadi_functions* " + name_ + "_functions(void)") << " {\n"
2776  << "static casadi_functions fun = {\n"
2777  << name_ << "_incref,\n"
2778  << name_ << "_decref,\n"
2779  << name_ << "_checkout,\n"
2780  << name_ << "_release,\n"
2781  << name_ << "_default_in,\n"
2782  //<< name_ << "_alloc_mem,\n"
2783  //<< name_ << "_init_mem,\n"
2784  //<< name_ << "_free_mem,\n"
2785  << name_ << "_n_in,\n"
2786  << name_ << "_n_out,\n"
2787  << name_ << "_name_in,\n"
2788  << name_ << "_name_out,\n"
2789  << name_ << "_sparsity_in,\n"
2790  << name_ << "_sparsity_out,\n"
2791  << name_ << "_work,\n"
2792  << name_ << "\n"
2793  << "};\n"
2794  << "return &fun;\n"
2795  << "}\n";
2796  }
2797  // Flush
2798  g.flush(g.body);
2799  }
static std::string array(const std::string &type, const std::string &name, casadi_int len, const std::string &def=std::string())
virtual size_t codegen_sz_res(const CodeGenerator &g) const
Get required lengths, for codegen.
virtual size_t codegen_sz_arg(const CodeGenerator &g) const
Get required lengths, for codegen.
std::vector< bool > is_diff_out_
virtual size_t codegen_sz_iw(const CodeGenerator &g) const
Get required lengths, for codegen.
virtual void codegen_incref(CodeGenerator &g) const
Codegen incref for dependencies.
virtual size_t codegen_sz_w(const CodeGenerator &g) const
Get required lengths, for codegen.
std::vector< bool > is_diff_in_
Are inputs and outputs differentiable?
virtual void codegen_decref(CodeGenerator &g) const
Codegen decref for dependencies.
void codegen_sparsities(CodeGenerator &g) const
Codegen sparsities.
virtual double get_default_in(casadi_int ind) const
Get default input value.
bool all(const std::vector< bool > &v)
Check if all arguments are true.
Definition: casadi_misc.cpp:77

References casadi::all(), casadi::CodeGenerator::array(), casadi::CodeGenerator::body, casadi::FunctionInternal::codegen_decref(), casadi::FunctionInternal::codegen_incref(), casadi::FunctionInternal::codegen_mem_type(), casadi::FunctionInternal::codegen_name(), casadi::FunctionInternal::codegen_sparsities(), casadi::FunctionInternal::codegen_sz_arg(), casadi::FunctionInternal::codegen_sz_iw(), casadi::FunctionInternal::codegen_sz_res(), casadi::FunctionInternal::codegen_sz_w(), casadi::CodeGenerator::constant(), casadi::CodeGenerator::declare(), casadi::CodeGenerator::flush(), casadi::CodeGenerator::from_mex(), casadi::FunctionInternal::get_default_in(), casadi::CodeGenerator::header, casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::CodeGenerator::main, casadi::CodeGenerator::mex, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::CodeGenerator::printf(), casadi::CodeGenerator::res(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::FunctionInternal::sparsity_in_, casadi::FunctionInternal::sparsity_out_, casadi::str(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), casadi::CodeGenerator::to_mex(), casadi::CodeGenerator::with_header, and casadi::CodeGenerator::with_mem.

Referenced by casadi::CodeGenerator::add().

◆ codegen_name()

std::string casadi::FunctionInternal::codegen_name ( const CodeGenerator g,
bool  ns = true 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lp

Definition at line 2801 of file function_internal.cpp.

2801  {
2802  if (ns) {
2803  // Get the index of the function
2804  for (auto&& e : g.added_functions_) {
2805  if (e.f.get()==this) return e.codegen_name;
2806  }
2807  } else {
2808  for (casadi_int i=0;i<g.added_functions_.size();++i) {
2809  const auto & e = g.added_functions_[i];
2810  if (e.f.get()==this) return "f" + str(i);
2811  }
2812  }
2813  casadi_error("Function '" + name_ + "' not found");
2814  }

References casadi::CodeGenerator::added_functions_, casadi::ProtoFunction::name_, and casadi::str().

Referenced by casadi::FunctionInternal::codegen_alloc_mem(), casadi::FunctionInternal::codegen_checkout(), casadi::Call::codegen_decref(), casadi::Call::codegen_incref(), casadi::FunctionInternal::codegen_mem(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::codegen_release(), and casadi::CodeGenerator::mem().

◆ codegen_qp_solve()

void casadi::Feasiblesqpmethod::codegen_qp_solve ( CodeGenerator cg,
const std::string &  H,
const std::string &  g,
const std::string &  lbdz,
const std::string &  ubdz,
const std::string &  A,
const std::string &  x_opt,
const std::string &  dlam,
int  mode 
) const

Definition at line 1943 of file feasiblesqpmethod.cpp.

1947  {
1948  for (casadi_int i=0;i<qpsol_.n_in();++i) cg << "m_arg[" << i << "] = 0;\n";
1949  cg << "m_arg[" << CONIC_H << "] = " << H << ";\n";
1950  cg << "m_arg[" << CONIC_G << "] = " << g << ";\n";
1951  cg << "m_arg[" << CONIC_X0 << "] = " << x_opt << ";\n";
1952  cg << "m_arg[" << CONIC_LAM_X0 << "] = " << dlam << ";\n";
1953  cg << "m_arg[" << CONIC_LAM_A0 << "] = " << dlam << "+" << nx_ << ";\n";
1954  cg << "m_arg[" << CONIC_LBX << "] = " << lbdz << ";\n";
1955  cg << "m_arg[" << CONIC_UBX << "] = " << ubdz << ";\n";
1956  cg << "m_arg[" << CONIC_A << "] = " << A << ";\n";
1957  cg << "m_arg[" << CONIC_LBA << "] = " << lbdz << "+" << nx_ << ";\n";
1958  cg << "m_arg[" << CONIC_UBA << "] = " << ubdz << "+" << nx_ << ";\n";
1959  for (casadi_int i=0;i<qpsol_.n_out();++i) cg << "m_res[" << i << "] = 0;\n";
1960  cg << "m_res[" << CONIC_X << "] = " << x_opt << ";\n";
1961  cg << "m_res[" << CONIC_LAM_X << "] = " << dlam << ";\n";
1962  cg << "m_res[" << CONIC_LAM_A << "] = " << dlam << "+" << nx_ << ";\n";
1963  std::string flag = cg(qpsol_, "m_arg", "m_res", "m_iw", "m_w");
1964  cg << "ret = " << flag << ";\n";
1965  cg << "if (ret == -1000) return -1000;\n"; // equivalent to raise Exception
1966  }
@ CONIC_UBA
dense, (nc x 1)
Definition: conic.hpp:181
@ CONIC_X0
dense, (n x 1)
Definition: conic.hpp:187
@ CONIC_A
The matrix A: sparse, (nc x n) - product with x must be dense.
Definition: conic.hpp:177
@ CONIC_G
The vector g: dense, (n x 1)
Definition: conic.hpp:175
@ CONIC_LBA
dense, (nc x 1)
Definition: conic.hpp:179
@ CONIC_UBX
dense, (n x 1)
Definition: conic.hpp:185
@ CONIC_H
Definition: conic.hpp:173
@ CONIC_LAM_A0
dense
Definition: conic.hpp:191
@ CONIC_LBX
dense, (n x 1)
Definition: conic.hpp:183
@ CONIC_LAM_X0
dense
Definition: conic.hpp:189
@ CONIC_X
The primal solution.
Definition: conic.hpp:201
@ CONIC_LAM_A
The dual solution corresponding to linear bounds.
Definition: conic.hpp:205
@ CONIC_LAM_X
The dual solution corresponding to simple bounds.
Definition: conic.hpp:207

References casadi::CONIC_A, casadi::CONIC_G, casadi::CONIC_H, casadi::CONIC_LAM_A, casadi::CONIC_LAM_A0, casadi::CONIC_LAM_X, casadi::CONIC_LAM_X0, casadi::CONIC_LBA, casadi::CONIC_LBX, casadi::CONIC_UBA, casadi::CONIC_UBX, casadi::CONIC_X, casadi::CONIC_X0, casadi::Function::n_in(), casadi::Function::n_out(), casadi::Nlpsol::nx_, and qpsol_.

Referenced by codegen_body(), and codegen_feasibility_iterations().

◆ codegen_release()

void casadi::FunctionInternal::codegen_release ( CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lx

Reimplemented in casadi::External.

Definition at line 2473 of file function_internal.cpp.

2473  {
2474  std::string name = codegen_name(g, false);
2475  std::string stack_counter = g.shorthand(name + "_unused_stack_counter");
2476  std::string stack = g.shorthand(name + "_unused_stack");
2477  g << stack << "[++" << stack_counter << "] = mem;\n";
2478  }

References casadi::FunctionInternal::codegen_name(), and casadi::CodeGenerator::shorthand().

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_sparsities()

void casadi::FunctionInternal::codegen_sparsities ( CodeGenerator g) const
inherited

◆ codegen_step_update()

void casadi::Feasiblesqpmethod::codegen_step_update ( CodeGenerator cg,
const std::string &  tr_ratio 
) const

Definition at line 1997 of file feasiblesqpmethod.cpp.

1998  {
1999  // auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
2000  // auto d_nlp = &m->d_nlp;
2001  // auto d = &m->d;
2002 
2003  // if (tr_ratio > tr_acceptance_) {
2004  // // This is not properly implemented yet: d_nlp->z_old = d_mlp->z;
2005  // casadi_copy(d->z_feas, nx_ + ng_, d_nlp->z);
2006  // d_nlp->f = d->f_feas;
2007  // casadi_copy(d->dlam_feas, nx_ + ng_, d_nlp->lam);
2008 
2009  // uout() << "ACCEPTED" << std::endl;
2010  // return 0;
2011  // } else {
2012  // uout() << "REJECTED" << std::endl;
2013  // return -1;
2014  // }
2015  cg << "if(" + tr_ratio + ">" << tr_acceptance_ << ") {\n";
2016  cg << cg.copy("d.z_feas", nx_ + ng_, "d_nlp.z") << "\n";
2017  cg << "m_f = m_f_feas;\n";
2018  cg << cg.copy("d.dlam_feas", nx_ + ng_, "d_nlp.lam") << "\n";
2019  cg << "printf(\"ACCEPTED\\n\");\n";
2020  cg << "ret = 0;\n";
2021  cg << "} else {\n";
2022  cg << "printf(\"REJECTED\\n\");\n";
2023  cg << "ret = -1;\n";
2024  cg << "}\n";
2025 }

References casadi::CodeGenerator::copy(), casadi::Nlpsol::ng_, casadi::Nlpsol::nx_, and tr_acceptance_.

Referenced by codegen_body().

◆ codegen_sz_arg()

size_t casadi::FunctionInternal::codegen_sz_arg ( const CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29g

Definition at line 2913 of file function_internal.cpp.

2913  {
2914  return sz_arg();
2915  }

References casadi::FunctionInternal::sz_arg().

Referenced by casadi::FunctionInternal::codegen_meta().

◆ codegen_sz_iw()

size_t casadi::FunctionInternal::codegen_sz_iw ( const CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29g

Definition at line 2919 of file function_internal.cpp.

2919  {
2920  return sz_iw();
2921  }

References casadi::FunctionInternal::sz_iw().

Referenced by casadi::FunctionInternal::codegen_meta().

◆ codegen_sz_res()

size_t casadi::FunctionInternal::codegen_sz_res ( const CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29g

Definition at line 2916 of file function_internal.cpp.

2916  {
2917  return sz_res();
2918  }

References casadi::FunctionInternal::sz_res().

Referenced by casadi::FunctionInternal::codegen_meta().

◆ codegen_sz_w()

size_t casadi::FunctionInternal::codegen_sz_w ( const CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29g

Reimplemented in casadi::SXFunction.

Definition at line 2922 of file function_internal.cpp.

2922  {
2923  return sz_w();
2924  }

References casadi::FunctionInternal::sz_w().

Referenced by casadi::FunctionInternal::codegen_meta().

◆ codegen_tr_update()

void casadi::Feasiblesqpmethod::codegen_tr_update ( CodeGenerator cg,
const std::string &  tr_rad,
const std::string &  tr_ratio 
) const

Definition at line 1968 of file feasiblesqpmethod.cpp.

1969  {
1970  cg << "if (tr_ratio < " << tr_eta1_ << ") {\n";
1971  cg << "tr_rad = " << tr_alpha1_ <<"*" << cg.masked_norm_inf(nx_, "d.dx", "d.tr_mask") << ";\n";
1972  std::string tol = "fabs(" + cg.masked_norm_inf(nx_, "d.dx", "d.tr_mask") + " - tr_rad)";
1973  cg << "} else if (tr_ratio > " << tr_eta2_ << " && " << tol << " < " << optim_tol_ << " ) {\n";
1974  cg << "tr_rad = " << cg.fmin(str(tr_alpha2_)+"*tr_rad", str(tr_rad_max_)) << ";\n";
1975  cg << "}\n";
1976  cg.comment("else: keep trust-region as it is....");
1977  }

References casadi::CodeGenerator::comment(), casadi::CodeGenerator::fmin(), casadi::CodeGenerator::masked_norm_inf(), casadi::Nlpsol::nx_, optim_tol_, casadi::str(), tr_alpha1_, tr_alpha2_, tr_eta1_, tr_eta2_, and tr_rad_max_.

Referenced by codegen_body().

◆ construct()

void casadi::ProtoFunction::construct ( const Dict opts)
inherited

Prepares the function for evaluation

Extra doc: https://github.com/casadi/casadi/wiki/L_jf

Definition at line 138 of file function_internal.cpp.

138  {
139  // Sanitize dictionary is needed
140  if (!Options::is_sane(opts)) {
141  // Call recursively
142  return construct(Options::sanitize(opts));
143  }
144 
145  // Make sure all options exist
146  get_options().check(opts);
147 
148  // Initialize the class hierarchy
149  try {
150  init(opts);
151  } catch(std::exception& e) {
152  casadi_error("Error calling " + class_name() + "::init for '" + name_ + "':\n"
153  + std::string(e.what()));
154  }
155 
156  // Revisit class hierarchy in reverse order
157  try {
158  finalize();
159  } catch(std::exception& e) {
160  casadi_error("Error calling " + class_name() + "::finalize for '" + name_ + "':\n"
161  + std::string(e.what()));
162  }
163  }
void construct(const Dict &opts)
Construct.
virtual const Options & get_options() const
Options.
virtual void init(const Dict &opts)
Initialize.
virtual void finalize()
Finalize the object creation.
static bool is_sane(const Dict &opts)
Is the dictionary sane.
Definition: options.cpp:169
static Dict sanitize(const Dict &opts, bool top_level=true)
Sanitize a options dictionary.
Definition: options.cpp:173
void check(const Dict &opts) const
Check if options exist.
Definition: options.cpp:240

References casadi::Options::check(), casadi::SharedObjectInternal::class_name(), casadi::ProtoFunction::finalize(), casadi::ProtoFunction::get_options(), casadi::ProtoFunction::init(), casadi::Options::is_sane(), casadi::ProtoFunction::name_, and casadi::Options::sanitize().

Referenced by casadi::Function::create(), casadi::FmuFunction::factory(), casadi::FmuFunction::get_forward(), casadi::FmuFunction::get_jacobian(), casadi::LinearInterpolant::get_jacobian(), and casadi::FmuFunction::get_reverse().

◆ convert_arg() [1/2]

template<typename M >
std::vector< M > casadi::FunctionInternal::convert_arg ( const std::map< std::string, M > &  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ks

Definition at line 1834 of file function_internal.hpp.

1835  {
1836  // Get default inputs
1837  std::vector<M> arg_v(n_in_);
1838  for (casadi_int i=0; i<arg_v.size(); ++i) {
1839  arg_v[i] = get_default_in(i);
1840  }
1841 
1842  // Assign provided inputs
1843  for (auto&& e : arg) {
1844  arg_v.at(index_in(e.first)) = e.second;
1845  }
1846 
1847  return arg_v;
1848  }
casadi_int index_in(const std::string &name) const
Get input scheme index by name.

References casadi::FunctionInternal::get_default_in(), casadi::FunctionInternal::index_in(), and casadi::FunctionInternal::n_in_.

◆ convert_arg() [2/2]

template<typename M >
std::map< std::string, M > casadi::FunctionInternal::convert_arg ( const std::vector< M > &  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ks

Definition at line 1822 of file function_internal.hpp.

1823  {
1824  casadi_assert(arg.size()==n_in_, "Incorrect number of inputs: Expected "
1825  + str(n_in_) + ", got " + str(arg.size()));
1826  std::map<std::string, M> ret;
1827  for (casadi_int i=0;i<n_in_;++i) {
1828  ret[name_in_[i]] = arg[i];
1829  }
1830  return ret;
1831  }

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::name_in_, and casadi::str().

◆ convert_res() [1/2]

template<typename M >
std::vector< M > casadi::FunctionInternal::convert_res ( const std::map< std::string, M > &  res) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ks

Definition at line 1863 of file function_internal.hpp.

1864  {
1865  // Get default inputs
1866  std::vector<M> res_v(n_out_);
1867  for (casadi_int i=0; i<res_v.size(); ++i) {
1868  res_v[i] = std::numeric_limits<double>::quiet_NaN();
1869  }
1870 
1871  // Assign provided inputs
1872  for (auto&& e : res) {
1873  M a = e.second;
1874  res_v.at(index_out(e.first)) = a;
1875  }
1876  return res_v;
1877  }
casadi_int index_out(const std::string &name) const
Get output scheme index by name.

References casadi::FunctionInternal::index_out(), and casadi::FunctionInternal::n_out_.

◆ convert_res() [2/2]

template<typename M >
std::map< std::string, M > casadi::FunctionInternal::convert_res ( const std::vector< M > &  res) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ks

Definition at line 1851 of file function_internal.hpp.

1852  {
1853  casadi_assert(res.size()==n_out_, "Incorrect number of outputs: Expected "
1854  + str(n_out_) + ", got " + str(res.size()));
1855  std::map<std::string, M> ret;
1856  for (casadi_int i=0;i<n_out_;++i) {
1857  ret[name_out_[i]] = res[i];
1858  }
1859  return ret;
1860  }

References casadi::FunctionInternal::n_out_, casadi::FunctionInternal::name_out_, and casadi::str().

◆ create_forward()

Function casadi::OracleFunction::create_forward ( const std::string &  fname,
casadi_int  nfwd 
)
inherited

Create an oracle function as a forward derivative of a different function

Definition at line 278 of file oracle_function.cpp.

278  {
279  // Create derivative
280  Function ret = get_function(fname).forward(nfwd);
281  std::string fwd_name = forward_name(fname, nfwd); // may be different from ret.name()
282  if (!has_function(fwd_name)) set_function(ret, fwd_name, true);
283  return ret;
284 }
static std::string forward_name(const std::string &fcn, casadi_int nfwd)
Helper function: Get name of forward derivative function.
void set_function(const Function &fcn, const std::string &fname, bool jit=false)
bool has_function(const std::string &fname) const override

References casadi::FunctionInternal::forward_name(), casadi::OracleFunction::get_function(), casadi::OracleFunction::has_function(), and casadi::OracleFunction::set_function().

Referenced by casadi::Integrator::init(), casadi::ImplicitFixedStepIntegrator::init(), casadi::SLEQPInterface::init(), casadi::SundialsInterface::init(), and casadi::RungeKutta::setup_step().

◆ create_function() [1/3]

Function casadi::OracleFunction::create_function ( const Function oracle,
const std::string &  fname,
const std::vector< std::string > &  s_in,
const std::vector< std::string > &  s_out,
const Function::AuxOut aux = Function::AuxOut(),
const Dict opts = Dict() 
)
inherited

Create an oracle function, using a different oracle function Temporary addition to allow transition from one oracle formulation to another.

Definition at line 235 of file oracle_function.cpp.

239  {
240  // Print progress
241  if (verbose_) {
242  casadi_message(name_ + "::create_function " + fname + ":" + str(s_in) + "->" + str(s_out));
243  }
244 
245  // Check if function is already in cache
246  Function ret;
247  if (incache(fname, ret)) {
248  // Consistency checks
249  casadi_assert(ret.n_in() == s_in.size(), fname + " has wrong number of inputs");
250  casadi_assert(ret.n_out() == s_out.size(), fname + " has wrong number of outputs");
251  } else {
252  // Retrieve specific set of options if available
253  Dict specific_options;
254  auto it = specific_options_.find(fname);
255  if (it!=specific_options_.end()) specific_options = it->second;
256 
257  // Combine specific and common options
258  Dict opt = combine(specific_options, common_options_);
259  opt = combine(opts, opt);
260 
261  // Generate the function
262  ret = oracle.factory(fname, s_in, s_out, aux, opt);
263 
264  // Make sure that it's sound
265  if (ret.has_free()) {
266  casadi_error("Cannot create '" + fname + "' since " + str(ret.get_free()) + " are free.");
267  }
268 
269  // Add to cache
270  tocache_if_missing(ret);
271  }
272 
273  // Save and return
274  set_function(ret, fname, true);
275  return ret;
276 }
void tocache_if_missing(Function &f, const std::string &suffix="") const
Save function to cache, only if missing.
bool incache(const std::string &fname, Function &f, const std::string &suffix="") const
Get function in cache.
Function factory(const std::string &name, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const AuxOut &aux=AuxOut(), const Dict &opts=Dict()) const
Definition: function.cpp:1820
Dict common_options_
Options for creating functions.
const Function & oracle() const override
Get oracle.
bool verbose_
Verbose printout.
Dict combine(const Dict &first, const Dict &second, bool recurse)
Combine two dicts. First has priority.

References casadi::combine(), casadi::OracleFunction::common_options_, casadi::Function::factory(), casadi::Function::get_free(), casadi::Function::has_free(), casadi::FunctionInternal::incache(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::ProtoFunction::name_, casadi::OracleFunction::oracle(), casadi::OracleFunction::set_function(), casadi::OracleFunction::specific_options_, casadi::str(), casadi::FunctionInternal::tocache_if_missing(), and casadi::ProtoFunction::verbose_.

Referenced by casadi::OracleFunction::create_function(), casadi::Integrator::init(), casadi::Nlpsol::init(), casadi::AlpaqaInterface::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::FatropInterface::init(), casadi::IpoptInterface::init(), casadi::KnitroInterface::init(), casadi::MadnlpInterface::init(), casadi::SLEQPInterface::init(), casadi::SnoptInterface::init(), casadi::SundialsInterface::init(), casadi::WorhpInterface::init(), init(), casadi::Qrsqp::init(), and casadi::Sqpmethod::init().

◆ create_function() [2/3]

Function casadi::OracleFunction::create_function ( const std::string &  fname,
const std::vector< MX > &  e_in,
const std::vector< MX > &  e_out,
const std::vector< std::string > &  s_in,
const std::vector< std::string > &  s_out,
const Dict opts = Dict() 
)
inherited

Create an oracle function from MX

Definition at line 187 of file oracle_function.cpp.

192  {
193 
194  // Print progress
195  if (verbose_) {
196  casadi_message(name_ + "::create_function " + fname + ":" + str(s_in) + "->" + str(s_out));
197  }
198 
199  // Check if function is already in cache
200  Function ret;
201  if (incache(fname, ret)) {
202  // Consistency checks
203  casadi_assert(ret.n_in() == s_in.size(), fname + " has wrong number of inputs");
204  casadi_assert(ret.n_out() == s_out.size(), fname + " has wrong number of outputs");
205  } else {
206  // Retrieve specific set of options if available
207  Dict specific_options;
208  auto it = specific_options_.find(fname);
209  if (it!=specific_options_.end()) specific_options = it->second;
210 
211  // Combine specific and common options
212  Dict opt = combine(specific_options, common_options_);
213  opt = combine(opts, opt);
214 
215  // Generate the function
216  ret = Function(fname, e_in, e_out, s_in, s_out, opt);
217 
218  // Make sure that it's sound
219  if (ret.has_free()) {
220  casadi_error("Cannot create '" + fname + "' since " + str(ret.get_free()) + " are free.");
221  }
222 
223  // TODO(jgillis) Conditionally convert to SX
224 
225  // Add to cache
226  tocache_if_missing(ret);
227  }
228 
229  // Save and return
230  set_function(ret, fname, true);
231  return ret;
232 
233 }

References casadi::combine(), casadi::OracleFunction::common_options_, casadi::FunctionInternal::Function, casadi::Function::get_free(), casadi::Function::has_free(), casadi::FunctionInternal::incache(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::ProtoFunction::name_, casadi::OracleFunction::set_function(), casadi::OracleFunction::specific_options_, casadi::str(), casadi::FunctionInternal::tocache_if_missing(), and casadi::ProtoFunction::verbose_.

◆ create_function() [3/3]

Function casadi::OracleFunction::create_function ( const std::string &  fname,
const std::vector< std::string > &  s_in,
const std::vector< std::string > &  s_out,
const Function::AuxOut aux = Function::AuxOut(),
const Dict opts = Dict() 
)
inherited

Create an oracle function

Definition at line 179 of file oracle_function.cpp.

183  {
184  return create_function(oracle_, fname, s_in, s_out, aux, opts);
185 }
Function oracle_
Oracle: Used to generate other functions.
Function create_function(const Function &oracle, const std::string &fname, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Function::AuxOut &aux=Function::AuxOut(), const Dict &opts=Dict())

References casadi::OracleFunction::create_function(), and casadi::OracleFunction::oracle_.

◆ create_oracle()

template<typename XType >
Function casadi::Nlpsol::create_oracle ( const std::map< std::string, XType > &  d,
const Dict opts 
)
staticinherited

Definition at line 129 of file nlpsol.cpp.

130  {
131  std::vector<XType> nl_in(NL_NUM_IN), nl_out(NL_NUM_OUT);
132  for (auto&& i : d) {
133  if (i.first=="x") {
134  nl_in[NL_X]=i.second;
135  } else if (i.first=="p") {
136  nl_in[NL_P]=i.second;
137  } else if (i.first=="f") {
138  nl_out[NL_F]=i.second;
139  } else if (i.first=="g") {
140  nl_out[NL_G]=i.second;
141  } else {
142  casadi_error("No such field: " + i.first);
143  }
144  }
145  if (nl_out[NL_F].is_empty()) nl_out[NL_F] = 0;
146  if (nl_out[NL_G].is_empty()) nl_out[NL_G] = XType(0, 1);
147 
148  // Options for the oracle
149  Dict oracle_options;
150  Dict::const_iterator it = opts.find("oracle_options");
151  if (it != opts.end()) {
152  // "oracle_options" has been set
153  oracle_options = it->second;
154  } else {
155  // Propagate selected options from Nlpsol to oracle by default
156  for (const char* op : {"verbose", "regularity_check"})
157  if ((it = opts.find(op)) != opts.end()) {
158  oracle_options[op] = it->second;
159  }
160  }
161 
162  // Create oracle
163  return Function("nlp", nl_in, nl_out, NL_INPUTS, NL_OUTPUTS, oracle_options);
164  }
@ NL_X
Decision variable.
Definition: nlpsol.hpp:170
@ NL_P
Fixed parameter.
Definition: nlpsol.hpp:172
@ NL_NUM_IN
Number of NLP inputs.
Definition: nlpsol.hpp:174
@ NL_F
Objective function.
Definition: nlpsol.hpp:183
@ NL_G
Constraint function.
Definition: nlpsol.hpp:185
@ NL_NUM_OUT
Number of NLP outputs.
Definition: nlpsol.hpp:187
const std::vector< std::string > NL_INPUTS
Shortname for onput arguments of an NLP function.
Definition: nlpsol.hpp:178
const std::vector< std::string > NL_OUTPUTS
Shortname for output arguments of an NLP function.
Definition: nlpsol.hpp:191

References casadi::FunctionInternal::Function, casadi::NL_F, casadi::NL_G, casadi::NL_INPUTS, casadi::NL_NUM_IN, casadi::NL_NUM_OUT, casadi::NL_OUTPUTS, casadi::NL_P, and casadi::NL_X.

Referenced by casadi::construct_nlpsol().

◆ creator()

static Nlpsol* casadi::Feasiblesqpmethod::creator ( const std::string &  name,
const Function nlp 
)
inlinestatic

Definition at line 77 of file feasiblesqpmethod.hpp.

77  {
78  return new Feasiblesqpmethod(name, nlp);
79  }
Feasiblesqpmethod(const std::string &name, const Function &nlp)

Referenced by casadi::casadi_register_nlpsol_feasiblesqpmethod().

◆ debug_repr()

std::string casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::debug_repr ( const Internal *  i) const
inherited

Definition at line 62 of file generic_shared_internal.hpp.

162  {
163  // Note: i != this because of something something multiple inheritance
164  return str( (casadi_int)(i)) + "/" + static_cast<const Internal*>(this)->class_name();
165  }

◆ definition()

std::string casadi::FunctionInternal::definition ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ma

Definition at line 1025 of file function_internal.cpp.

1025  {
1026  std::stringstream s;
1027 
1028  // Print name
1029  s << name_ << ":(";
1030  // Print input arguments
1031  for (casadi_int i=0; i<n_in_; ++i) {
1032  if (!is_diff_in_.empty() && !is_diff_in_[i]) s << "#";
1033  s << name_in_[i] << sparsity_in_[i].postfix_dim() << (i==n_in_-1 ? "" : ",");
1034  }
1035  s << ")->(";
1036  // Print output arguments
1037  for (casadi_int i=0; i<n_out_; ++i) {
1038  if (!is_diff_out_.empty() && !is_diff_out_[i]) s << "#";
1039  s << name_out_[i] << sparsity_out_[i].postfix_dim() << (i==n_out_-1 ? "" : ",");
1040  }
1041  s << ")";
1042 
1043  return s.str();
1044  }

References casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::sparsity_in_, and casadi::FunctionInternal::sparsity_out_.

Referenced by casadi::FunctionInternal::codegen(), casadi::FunctionInternal::disp(), casadi::MXFunction::should_inline(), and casadi::SXFunction::should_inline().

◆ deserialize()

static ProtoFunction* casadi::Feasiblesqpmethod::deserialize ( DeserializingStream s)
inlinestatic

Definition at line 277 of file feasiblesqpmethod.hpp.

277 { return new Feasiblesqpmethod(s); }

Referenced by casadi::casadi_register_nlpsol_feasiblesqpmethod().

◆ destroySingleton()

void casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::destroySingleton ( )
inlineprotectedinherited

Called in the destructor of singletons

Definition at line 77 of file generic_shared_internal.hpp.

77  {
78  static_cast<Internal*>(this)->count--;
79  }

◆ diff_prefix()

std::string casadi::FunctionInternal::diff_prefix ( const std::string &  prefix) const
inherited

Definition at line 2127 of file function_internal.cpp.

2127  {
2128  // Highest index found in current inputs and outputs
2129  casadi_int highest_index = 0;
2130  // Loop over both input names and output names
2131  for (const std::vector<std::string>& name_io : {name_in_, name_out_}) {
2132  for (const std::string& n : name_io) {
2133  // Find end of prefix, skip if no prefix
2134  size_t end = n.find('_');
2135  if (end >= n.size()) continue;
2136  // Skip if too short
2137  if (end < prefix.size()) continue;
2138  // Skip if wrong prefix
2139  if (n.compare(0, prefix.size(), prefix) != 0) continue;
2140  // Beginning of index
2141  size_t begin = prefix.size();
2142  // Check if any index
2143  casadi_int this_index;
2144  if (begin == end) {
2145  // No prefix, implicitly 1
2146  this_index = 1;
2147  } else {
2148  // Read index from string
2149  this_index = std::stoi(n.substr(begin, end - begin));
2150  }
2151  // Find the highest index
2152  if (this_index > highest_index) highest_index = this_index;
2153  }
2154  }
2155  // Return one higher index
2156  if (highest_index == 0) {
2157  return prefix + "_";
2158  } else {
2159  return prefix + std::to_string(highest_index + 1) + "_";
2160  }
2161  }

References casadi::FunctionInternal::name_in_, and casadi::FunctionInternal::name_out_.

Referenced by casadi::FunctionInternal::forward(), and casadi::FunctionInternal::reverse().

◆ disp()

void casadi::FunctionInternal::disp ( std::ostream &  stream,
bool  more 
) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_m8

Implements casadi::SharedObjectInternal.

Definition at line 1046 of file function_internal.cpp.

1046  {
1047  stream << definition() << " " << class_name();
1048  if (more) {
1049  stream << std::endl;
1050  disp_more(stream);
1051  }
1052  }
virtual void disp_more(std::ostream &stream) const
Print more.

References casadi::SharedObjectInternal::class_name(), casadi::FunctionInternal::definition(), and casadi::FunctionInternal::disp_more().

Referenced by casadi::MXFunction::eval(), and casadi::SXFunction::eval().

◆ disp_more()

void casadi::Nlpsol::disp_more ( std::ostream &  stream) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1nt

Reimplemented from casadi::FunctionInternal.

Definition at line 842 of file nlpsol.cpp.

842  {
843  stream << "minimize f(x;p) subject to lbx<=x<=ubx, lbg<=g(x;p)<=ubg defined by:\n";
844  oracle_.disp(stream, true);
845  }
void disp(std::ostream &stream, bool more=false) const
Print a description of the object.

References casadi::SharedObject::disp(), and casadi::OracleFunction::oracle_.

◆ dm_in() [1/2]

const std::vector< DM > casadi::FunctionInternal::dm_in ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l7

Definition at line 3328 of file function_internal.cpp.

3328  {
3329  std::vector<DM> ret(n_in_);
3330  for (casadi_int i=0; i<ret.size(); ++i) {
3331  ret[i] = dm_in(i);
3332  }
3333  return ret;
3334  }
const std::vector< DM > dm_in() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_in_.

Referenced by casadi::FunctionInternal::nz_in().

◆ dm_in() [2/2]

const DM casadi::FunctionInternal::dm_in ( casadi_int  ind) const
inherited

◆ dm_out() [1/2]

const std::vector< DM > casadi::FunctionInternal::dm_out ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l7

Definition at line 3336 of file function_internal.cpp.

3336  {
3337  std::vector<DM> ret(n_out_);
3338  for (casadi_int i=0; i<ret.size(); ++i) {
3339  ret[i] = dm_out(i);
3340  }
3341  return ret;
3342  }
const std::vector< DM > dm_out() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_out_.

Referenced by casadi::FunctionInternal::nz_out().

◆ dm_out() [2/2]

const DM casadi::FunctionInternal::dm_out ( casadi_int  ind) const
inherited

◆ ensure_stacked()

template<typename MatType >
MatType casadi::FunctionInternal::ensure_stacked ( const MatType &  v,
const Sparsity sp,
casadi_int  n 
)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_26j

Definition at line 1880 of file function_internal.hpp.

1880  {
1881  // Check dimensions
1882  if (v.size1() == sp.size1() && v.size2() == n * sp.size2()) {
1883  // Ensure that sparsity is a horizontal multiple of original input, or has no entries
1884  if (v.nnz() != 0 && !v.sparsity().is_stacked(sp, n)) {
1885  return project(v, repmat(sp, 1, n));
1886  }
1887  } else {
1888  // Correct empty sparsity
1889  casadi_assert_dev(v.is_empty());
1890  return MatType(sp.size1(), sp.size2() * n);
1891  }
1892  // No correction needed
1893  return v;
1894  }

References casadi::Sparsity::size1(), and casadi::Sparsity::size2().

◆ eval()

int casadi::Nlpsol::eval ( const double **  arg,
double **  res,
casadi_int *  iw,
double *  w,
void *  mem 
) const
finalvirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kb

Reimplemented from casadi::FunctionInternal.

Definition at line 704 of file nlpsol.cpp.

704  {
705  auto m = static_cast<NlpsolMemory*>(mem);
706 
707  auto d_nlp = &m->d_nlp;
708 
709  // Reset the solver, prepare for solution
710  setup(m, arg, res, iw, w);
711  auto p_nlp = d_nlp->prob;
712 
713  // Set initial guess
714  casadi_copy(d_nlp->x0, nx_, d_nlp->z);
715 
716  // Read simple bounds and multiplier guesses
717  casadi_copy(d_nlp->lbx, nx_, d_nlp->lbz);
718  casadi_copy(d_nlp->ubx, nx_, d_nlp->ubz);
719  casadi_copy(d_nlp->lam_x0, nx_, d_nlp->lam);
720 
721  if (p_nlp->detect_bounds.ng==0) {
722  // Read constraint bounds and multiplier guesses
723  casadi_copy(d_nlp->lbg, ng_, d_nlp->lbz+nx_);
724  casadi_copy(d_nlp->ubg, ng_, d_nlp->ubz+nx_);
725  casadi_copy(d_nlp->lam_g0, ng_, d_nlp->lam+nx_);
726  } else {
727  if (casadi_detect_bounds_before(d_nlp)) return 1;
728  }
729 
730  // Set multipliers to nan
731  casadi_fill(d_nlp->lam_p, np_, nan);
732 
733  // Reset f, g
734  d_nlp->objective = nan;
735  casadi_fill(d_nlp->z + nx_, ng_, nan);
736 
737  // Check the provided inputs
738  check_inputs(m);
739 
740  // Solve the NLP
741  int flag = solve(m);
742 
743  // Join statistics (introduced for parallel oracle facilities)
744  join_results(m);
745 
746  // Calculate multiplers
747  if ((calc_f_ || calc_g_ || calc_lam_x_ || calc_lam_p_) && !flag) {
748  const double lam_f = 1.;
749  m->arg[0] = d_nlp->z;
750  m->arg[1] = d_nlp->p;
751  m->arg[2] = &lam_f;
752  m->arg[3] = d_nlp->lam + nx_;
753  m->res[0] = calc_f_ ? &d_nlp->objective : nullptr;
754  m->res[1] = calc_g_ ? d_nlp->z + nx_ : nullptr;
755  m->res[2] = calc_lam_x_ ? d_nlp->lam : nullptr;
756  m->res[3] = calc_lam_p_ ? d_nlp->lam_p : nullptr;
757  if (calc_function(m, "nlp_grad")) {
758  casadi_warning("Failed to calculate multipliers");
759  }
760  if (calc_lam_x_) casadi_scal(nx_, -1., d_nlp->lam);
761  if (calc_lam_p_) casadi_scal(np_, -1., d_nlp->lam_p);
762  }
763 
764  // Make sure that an optimal solution is consistant with bounds
765  if (bound_consistency_ && !flag) {
766  bound_consistency(nx_+ng_, d_nlp->z, d_nlp->lam, d_nlp->lbz, d_nlp->ubz);
767  }
768 
769  // Get optimal solution
770  casadi_copy(d_nlp->z, nx_, d_nlp->x);
771 
772  if (p_nlp->detect_bounds.ng==0) {
773  casadi_copy(d_nlp->z + nx_, ng_, d_nlp->g);
774  casadi_copy(d_nlp->lam, nx_, d_nlp->lam_x);
775  casadi_copy(d_nlp->lam + nx_, ng_, d_nlp->lam_g);
776  } else {
777  if (casadi_detect_bounds_after(d_nlp)) return 1;
778  }
779 
780  casadi_copy(d_nlp->lam_p, np_, d_nlp->lam_p);
781  casadi_copy(&d_nlp->objective, 1, d_nlp->f);
782 
783  if (m->success) m->unified_return_status = SOLVER_RET_SUCCESS;
784 
785  if (error_on_fail_ && !m->success)
786  casadi_error("nlpsol process failed. "
787  "Set 'error_on_fail' option to false to ignore this error.");
788 
789  if (m->unified_return_status==SOLVER_RET_EXCEPTION) {
790  casadi_error("An exception was raised in the solver.");
791  }
792  return flag;
793  }
void setup(void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
Set the (persistent and temporary) work vectors.
virtual void check_inputs(void *mem) const
Check if the inputs correspond to a well-posed problem.
Definition: nlpsol.cpp:613
static void bound_consistency(casadi_int n, double *z, double *lam, const double *lbz, const double *ubz)
Definition: nlpsol.cpp:678
virtual int solve(void *mem) const =0
void join_results(OracleMemory *m) const
Combine results from different threads.
int calc_function(OracleMemory *m, const std::string &fcn, const double *const *arg=nullptr, int thread_id=0) const
void casadi_fill(T1 *x, casadi_int n, T1 alpha)
FILL: x <- alpha.
const double nan
Not a number.
Definition: calculus.hpp:53
void casadi_scal(casadi_int n, T1 alpha, T1 *x)
SCAL: x <- alpha*x.
@ SOLVER_RET_SUCCESS
@ SOLVER_RET_EXCEPTION

References casadi::Nlpsol::bound_consistency(), casadi::Nlpsol::bound_consistency_, casadi::Nlpsol::calc_f_, casadi::OracleFunction::calc_function(), casadi::Nlpsol::calc_g_, casadi::Nlpsol::calc_lam_p_, casadi::Nlpsol::calc_lam_x_, casadi::casadi_copy(), casadi::casadi_fill(), casadi::casadi_scal(), casadi::Nlpsol::check_inputs(), casadi::NlpsolMemory::d_nlp, casadi::ProtoFunction::error_on_fail_, casadi::OracleFunction::join_results(), casadi::nan, casadi::Nlpsol::ng_, casadi::Nlpsol::np_, casadi::Nlpsol::nx_, casadi::FunctionInternal::setup(), casadi::Nlpsol::solve(), casadi::SOLVER_RET_EXCEPTION, and casadi::SOLVER_RET_SUCCESS.

◆ eval_dm()

std::vector< DM > casadi::FunctionInternal::eval_dm ( const std::vector< DM > &  arg) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ke

Reimplemented in casadi::CallbackInternal.

Definition at line 2110 of file function_internal.cpp.

2110  {
2111  casadi_error("'eval_dm' not defined for " + class_name());
2112  }

References casadi::SharedObjectInternal::class_name().

Referenced by casadi::FunctionInternal::eval().

◆ eval_gen() [1/3]

int casadi::FunctionInternal::eval_gen ( const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w,
void *  mem,
bool  always_inline,
bool  never_inline 
) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kf

Definition at line 435 of file function_internal.hpp.

436  {
437  return sp_forward(arg, res, iw, w, mem);
438  }
virtual int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const
Propagate sparsity forward.

◆ eval_gen() [2/3]

int casadi::FunctionInternal::eval_gen ( const double **  arg,
double **  res,
casadi_int *  iw,
double *  w,
void *  mem,
bool  always_inline,
bool  never_inline 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kb

Definition at line 914 of file function_internal.cpp.

916  {
917  casadi_int dump_id = (dump_in_ || dump_out_ || dump_) ? get_dump_id() : 0;
918  if (dump_in_) dump_in(dump_id, arg);
919  if (dump_ && dump_id==0) dump();
920  if (print_in_) print_in(uout(), arg, false);
921  auto m = static_cast<ProtoFunctionMemory*>(mem);
922 
923  // Avoid memory corruption
924  for (casadi_int i=0;i<n_in_;++i) {
925  casadi_assert(arg[i]==0 || arg[i]+nnz_in(i)<=w || arg[i]>=w+sz_w(),
926  "Memory corruption detected for input " + name_in_[i] + ".\n"+
927  "arg[" + str(i) + "] " + str(arg[i]) + "-" + str(arg[i]+nnz_in(i)) +
928  " intersects with w " + str(w)+"-"+str(w+sz_w())+".");
929  }
930  for (casadi_int i=0;i<n_out_;++i) {
931  casadi_assert(res[i]==0 || res[i]+nnz_out(i)<=w || res[i]>=w+sz_w(),
932  "Memory corruption detected for output " + name_out_[i]);
933  }
934  // Reset statistics
935  for (auto&& s : m->fstats) s.second.reset();
936  if (m->t_total) m->t_total->tic();
937  int ret;
938  if (eval_) {
939  auto m = static_cast<FunctionMemory*>(mem);
940  m->stats_available = true;
941  int mem_ = 0;
942  if (checkout_) {
943 #ifdef CASADI_WITH_THREAD
944  std::lock_guard<std::mutex> lock(mtx_);
945 #endif //CASADI_WITH_THREAD
946  mem_ = checkout_();
947  }
948  ret = eval_(arg, res, iw, w, mem_);
949  if (release_) {
950 #ifdef CASADI_WITH_THREAD
951  std::lock_guard<std::mutex> lock(mtx_);
952 #endif //CASADI_WITH_THREAD
953  release_(mem_);
954  }
955  } else {
956  ret = eval(arg, res, iw, w, mem);
957  }
958  if (m->t_total) m->t_total->toc();
959  // Show statistics
960  print_time(m->fstats);
961 
962  if (dump_out_) dump_out(dump_id, res);
963  if (print_out_) print_out(uout(), res, false);
964  // Check all outputs for NaNs
965  if (regularity_check_) {
966  for (casadi_int i = 0; i < n_out_; ++i) {
967  // Skip of not calculated
968  if (!res[i]) continue;
969  // Loop over nonzeros
970  casadi_int nnz = this->nnz_out(i);
971  for (casadi_int nz = 0; nz < nnz; ++nz) {
972  if (isnan(res[i][nz]) || isinf(res[i][nz])) {
973  // Throw readable error message
974  casadi_error(str(res[i][nz]) + " detected for output " + name_out_[i] + " at "
975  + sparsity_out(i).repr_el(nz));
976  }
977  }
978  }
979  }
980  return ret;
981  }
void print_in(std::ostream &stream, const double **arg, bool truncate) const
Print inputs.
casadi_release_t release_
Release redirected to a C function.
virtual int eval(const double **arg, double **res, casadi_int *iw, double *w, void *mem) const
Evaluate numerically.
eval_t eval_
Numerical evaluation redirected to a C function.
casadi_checkout_t checkout_
Checkout redirected to a C function.
void print_out(std::ostream &stream, double **res, bool truncate) const
Print outputs.
void print_time(const std::map< std::string, FStats > &fstats) const
Print timing statistics.
std::ostream & uout()

References casadi::FunctionInternal::checkout_, casadi::FunctionInternal::dump_, casadi::FunctionInternal::dump_in_, casadi::FunctionInternal::dump_out_, casadi::FunctionInternal::eval(), casadi::FunctionInternal::eval_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::print_in(), casadi::FunctionInternal::print_in_, casadi::FunctionInternal::print_out(), casadi::FunctionInternal::print_out_, casadi::ProtoFunction::print_time(), casadi::ProtoFunction::regularity_check_, casadi::FunctionInternal::release_, casadi::FunctionInternal::sparsity_out(), casadi::FunctionMemory::stats_available, casadi::str(), casadi::FunctionInternal::sz_w(), and casadi::uout().

Referenced by casadi::FunctionInternal::call_gen().

◆ eval_gen() [3/3]

int casadi::FunctionInternal::eval_gen ( const SXElem **  arg,
SXElem **  res,
casadi_int *  iw,
SXElem w,
void *  mem,
bool  always_inline,
bool  never_inline 
) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kf

Definition at line 431 of file function_internal.hpp.

432  {
433  return eval_sx(arg, res, iw, w, mem, always_inline, never_inline);
434  }
virtual int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w, void *mem, bool always_inline, bool never_inline) const
Evaluate with symbolic scalars.

◆ eval_m_k()

double casadi::Feasiblesqpmethod::eval_m_k ( void *  mem) const

Definition at line 503 of file feasiblesqpmethod.cpp.

503  {
504  auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
505  auto d = &m->d;
506  if (use_sqp_) {
507  return 0.5*casadi_bilin(d->Bk, Hsp_, d->dx, d->dx) + casadi_dot(nx_, d->gf, d->dx);
508  } else {
509  return casadi_dot(nx_, d->gf, d->dx);
510  }
511 }
T1 casadi_bilin(const T1 *A, const casadi_int *sp_A, const T1 *x, const T1 *y)

References casadi::casadi_bilin(), casadi::casadi_dot(), casadi::FeasiblesqpmethodMemory::d, Hsp_, casadi::Nlpsol::nx_, and use_sqp_.

Referenced by solve().

◆ eval_mx()

void casadi::FunctionInternal::eval_mx ( const MXVector arg,
MXVector res,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kd

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 2325 of file function_internal.cpp.

2326  {
2327 
2328  always_inline = always_inline || always_inline_;
2329  never_inline = never_inline || never_inline_;
2330 
2331  // The code below creates a call node, to inline, wrap in an MXFunction
2332  if (always_inline) {
2333  casadi_assert(!never_inline, "Inconsistent options for " + str(name_));
2334  return wrap().call(arg, res, true);
2335  }
2336 
2337  // Create a call-node
2338  res = Call::create(self(), arg);
2339  }
static std::vector< MX > create(const Function &fcn, const std::vector< MX > &arg)
Create function call node.
Function wrap() const
Wrap in an Function instance consisting of only one MX call.
void call(const std::vector< DM > &arg, std::vector< DM > &res, bool always_inline=false, bool never_inline=false) const
Evaluate the function symbolically or numerically.
Definition: function.cpp:357

References casadi::FunctionInternal::always_inline_, casadi::Function::call(), casadi::Call::create(), casadi::ProtoFunction::name_, casadi::FunctionInternal::never_inline_, casadi::str(), and casadi::FunctionInternal::wrap().

Referenced by casadi::FunctionInternal::call_gen(), casadi::MXFunction::eval_mx(), and casadi::SXFunction::eval_mx().

◆ eval_sx()

int casadi::FunctionInternal::eval_sx ( const SXElem **  arg,
SXElem **  res,
casadi_int *  iw,
SXElem w,
void *  mem,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kc

Reimplemented in casadi::SXFunction, casadi::Switch, casadi::MXFunction, casadi::MapSum, and casadi::Map.

Definition at line 2114 of file function_internal.cpp.

2116  {
2117 
2118  always_inline = always_inline || always_inline_;
2119  never_inline = never_inline || never_inline_;
2120 
2121  casadi_assert(!always_inline, "'eval_sx' not defined for " + class_name() +
2122  " in combination with always_inline true");
2123 
2124  return CallSX::eval_sx(self(), arg, res);
2125  }
static int eval_sx(const Function &f, const SXElem **arg, SXElem **res)
Definition: call_sx.hpp:63

References casadi::FunctionInternal::always_inline_, casadi::SharedObjectInternal::class_name(), casadi::CallSX::eval_sx(), and casadi::FunctionInternal::never_inline_.

Referenced by casadi::MXFunction::eval_sx(), and casadi::SXFunction::eval_sx().

◆ eval_tr_ratio()

double casadi::Feasiblesqpmethod::eval_tr_ratio ( double  val_f,
double  val_f_corr,
double  val_m_k 
) const

Definition at line 513 of file feasiblesqpmethod.cpp.

513  {
514  return (val_f - val_f_corr) / (-val_m_k);
515 }

Referenced by solve().

◆ expand()

void casadi::OracleFunction::expand ( )
inherited

Definition at line 455 of file oracle_function.cpp.

455  {
456  oracle_ = oracle_.expand();
457 }
Function expand() const
Expand a function to SX.
Definition: function.cpp:308

References casadi::Function::expand(), and casadi::OracleFunction::oracle_.

Referenced by casadi::OracleFunction::init().

◆ export_code()

void casadi::FunctionInternal::export_code ( const std::string &  lang,
std::ostream &  stream,
const Dict options 
) const
virtualinherited

◆ factory()

Function casadi::FunctionInternal::factory ( const std::string &  name,
const std::vector< std::string > &  s_in,
const std::vector< std::string > &  s_out,
const Function::AuxOut aux,
const Dict opts 
) const
virtualinherited

◆ feasibility_iterations()

int casadi::Feasiblesqpmethod::feasibility_iterations ( void *  mem,
double  tr_rad 
) const

Definition at line 659 of file feasiblesqpmethod.cpp.

659  {
660  auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
661  auto d_nlp = &m->d_nlp;
662  auto d = &m->d;
663 
664  // p_tmp = p
665  casadi_copy(d->dx, nx_, d->dx_feas);
666 
667 // lam_p_g_tmp = self.lam_p_g_k
668 // lam_p_x_tmp = self.lam_p_x_k
669  casadi_copy(d->dlam, nx_ + ng_, d->dlam_feas);
670 
671  // Why do we do this at the moment??
672  casadi_copy(d->dlam, nx_+ng_, d->z_tmp);
673  casadi_axpy(nx_+ng_, -1.0, d_nlp->lam, d->z_tmp);
674 
675  // this is in solve in fslp.py
676  double step_inf_norm = casadi_masked_norm_inf(nx_, d->dx, d->tr_mask);
677  double prev_step_inf_norm = step_inf_norm;
678 
679  // bool kappa_acceptance = false;
680 
681  // self.x_tmp = self.x_k + p_tmp
682  casadi_copy(d_nlp->z, nx_+ng_, d->z_feas);
683  casadi_axpy(nx_, 1., d->dx_feas, d->z_feas);
684 
685  if (use_anderson_) {
686  // anderson_acc_init_memory(mem, d->dx_feas, d->z_feas);
687  anderson_acc_init_memory(mem, d->dx_feas, d_nlp->z);
688  }
689 
690  // DM(std::vector<double>(d->z_feas,d->z_feas+nx_)).to_file("dx_anderson1.mtx");
691  // Evaluate g
692  // self.g_tmp = self.__eval_g(self.x_tmp)
693  m->arg[0] = d->z_feas;
694  m->arg[1] = d_nlp->p;
695  m->res[0] = d->z_feas + nx_;
696  if (calc_function(m, "nlp_g")) {
697  uout() << "What does it mean that calc_function fails here??" << std::endl;
698  }
699  int inner_iter = 0;
700 
701 // asymptotic_exactness = []
702  // double asymptotic_exactness = 0.0;
703 // self.prev_infeas = self.feasibility_measure(self.x_tmp, self.g_tmp)
704 // self.curr_infeas = self.feasibility_measure(self.x_tmp, self.g_tmp)
705 
706  double prev_infeas = casadi_max_viol(nx_+ng_, d->z_feas, d_nlp->lbz, d_nlp->ubz);
707  double curr_infeas = prev_infeas;
708 // feasibilities = [self.prev_infeas]
709 // step_norms = []
710 // kappas = []
711 
712 // watchdog_prev_inf_norm = self.prev_step_inf_norm
713 // accumulated_as_ex = 0
714 
715  // Calculate asymptotic exactness of current step
716  casadi_copy(d->dx, nx_, d->z_tmp);
717  casadi_axpy(nx_, -1., d->z_feas, d->z_tmp);
718  casadi_axpy(nx_, 1., d_nlp->z, d->z_tmp);
719  double as_exac = casadi_norm_2(nx_, d->z_tmp) / casadi_norm_2(nx_, d->dx);
720 
721  double kappa_watchdog = 0.0;
722  double kappa = 0.0;
723  double acc_as_exac = 0.0;
724 
725 
726  double watchdog_prev_inf_norm = prev_step_inf_norm; // until here everything is correct!
727 
728  for (int j=0; j<max_inner_iter_; ++j) {
729  if (curr_infeas < feas_tol_) {
730  inner_iter = j;
731  // kappa_acceptance = true;
732  if (as_exac < 0.5) {
733  return 0;
734  } else {
735  return -1;
736  }
737  } else if (j>0 && (curr_infeas > 1.0 || as_exac > 1.0)) {
738  // kappa_acceptance = false;
739  return -1;
740  }
741  inner_iter = j+1;
742 
743  // self.lam_tmp_g = self.lam_p_g_k
744  // self.lam_tmp_x = self.lam_p_x_k
745 
746  // create corrected gradient here -----------------------------
747  casadi_copy(d->z_feas, nx_, d->z_tmp);
748  casadi_axpy(nx_, -1., d_nlp->z, d->z_tmp);
749  casadi_copy(d->gf, nx_, d->gf_feas);
750  // In case of SQP we need to multiply with
751  if (use_sqp_) {
752  casadi_mv(d->Bk, Hsp_, d->z_tmp, d->gf_feas, true);
753  }
754 
755  // create bounds of correction QP -----------------------------
756  // upper bounds of constraints
757  casadi_copy(d_nlp->ubz + nx_, ng_, d->ubdz_feas + nx_);
758  casadi_axpy(ng_, -1., d->z_feas + nx_, d->ubdz_feas + nx_);
759 
760  // lower bounds of constraints
761  casadi_copy(d_nlp->lbz + nx_, ng_, d->lbdz_feas + nx_);
762  casadi_axpy(ng_, -1., d->z_feas + nx_, d->lbdz_feas + nx_);
763 
764  // lower bounds of variables
765  // lbp = cs.fmax(-self.tr_rad_k*self.tr_scale_mat_inv_k @
766  // cs.DM.ones(self.nx, 1) - (self.x_tmp-self.x_k),
767  // self.lbx - self.x_tmp)
768 
769  casadi_copy(d_nlp->lbz, nx_, d->lbdz_feas);
770  casadi_clip_min(d->lbdz_feas, nx_, -tr_rad, d->tr_mask);
771  // DM(std::vector<double>(d->lbdz_feas,d->lbdz_feas+nx_)).to_file("lbx_feas_part1_part1.mtx");
772  // casadi_fill(d->lbdz_feas, nx_, -tr_rad);
773  casadi_axpy(nx_, -1., d->z_feas, d->lbdz_feas);
774  casadi_axpy(nx_, 1., d_nlp->z, d->lbdz_feas);
775  // DM(std::vector<double>(d->lbdz_feas,d->lbdz_feas+nx_)).to_file("lbx_feas_part1.mtx");
776 
777 
778  casadi_copy(d_nlp->lbz, nx_, d->z_tmp);
779  casadi_axpy(nx_, -1., d->z_feas, d->z_tmp);
780  // DM(std::vector<double>(d->z_tmp,d->z_tmp+nx_)).to_file("lbx_feas_part2.mtx");
781 
782  // comparison of both vectors
783  casadi_vector_fmax(nx_, d->z_tmp, d->lbdz_feas, d->lbdz_feas);
784  // DM(std::vector<double>(d->lbdz_feas,d->lbdz_feas+nx_)).to_file("lbx_feas_end.mtx");
785 
786 
787  // upper bounds of variables
788  // ubp = cs.fmin(self.tr_rad_k*self.tr_scale_mat_inv_k @
789  // cs.DM.ones(self.nx, 1) - (self.x_tmp-self.x_k),
790  // self.ubx - self.x_tmp)
791 
792 
793  casadi_copy(d_nlp->ubz, nx_, d->ubdz_feas);
794  casadi_clip_max(d->ubdz_feas, nx_, tr_rad, d->tr_mask);
795  // DM(std::vector<double>(d->ubdz_feas,d->ubdz_feas+nx_)).to_file("ubx_feas_part1_part1.mtx");
796  // casadi_fill(d->ubdz_feas, nx_, tr_rad);
797  casadi_axpy(nx_, -1., d->z_feas, d->ubdz_feas);
798  // DM(std::vector<double>(d->z_feas,d->z_feas+nx_)).to_file("ubx_feas_part1_zfeas.mtx");
799  casadi_axpy(nx_, 1., d_nlp->z, d->ubdz_feas);
800 
801  // DM(std::vector<double>(d->ubdz_feas,d->ubdz_feas+nx_)).to_file("ubx_feas_part1.mtx");
802 
803  casadi_copy(d_nlp->ubz, nx_, d->z_tmp);
804  casadi_axpy(nx_, -1., d->z_feas, d->z_tmp);
805  // DM(std::vector<double>(d->z_tmp,d->z_tmp+nx_)).to_file("ubx_feas_part2.mtx");
806  // comparison of both vectors
807  casadi_vector_fmin(nx_, d->z_tmp, d->ubdz_feas, d->ubdz_feas);
808  // DM(std::vector<double>(d->ubdz_feas,d->ubdz_feas+nx_)).to_file("ubx_feas_end.mtx");
809 
810 
811  // std::string suffix = str(j);
812  // DM(std::vector<double>(d_nlp->lbz,d_nlp->lbz+nx_+ng_)).to_file("nlp_lbz"+suffix+".mtx");
813  // DM(std::vector<double>(d_nlp->ubz,d_nlp->ubz+nx_+ng_)).to_file("nlp_ubz"+suffix+".mtx");
814  // DM(std::vector<double>(d->lbdz_feas,d->lbdz_feas+nx_+ng_)).to_file("lbz"+suffix+".mtx");
815  // DM(std::vector<double>(d->ubdz_feas,d->ubdz_feas+nx_+ng_)).to_file("ubz"+suffix+".mtx");
816  // DM(std::vector<double>(d->z_feas,d->z_feas+nx_+ng_)).to_file("z_feas"+suffix+".mtx");
817  // DM(std::vector<double>(d->dx_feas,d->dx_feas+nx_)).to_file("dx_feas"+suffix+".mtx");
818  // copy back d->dx back to d->dx_feas
819  // casadi_copy(d->dx, nx_, d->x_tmp);
820 
821  //prepare step_inf_norm
822  // DM(std::vector<double>(d->dx_feas,d->dx_feas+nx_)).to_file("dx_input.mtx");
823  // DM(std::vector<double>(d->gf_feas,d->gf_feas+nx_)).to_file("gf_feas.mtx");
824  // DM(std::vector<double>(d->lbdz_feas, d->lbdz_feas+nx_)).to_file("lb_var_correction.mtx");
825  // DM(std::vector<double>(d->ubdz_feas, d->ubdz_feas+nx_)).to_file("ub_var_correction.mtx");
826  // DM(std::vector<double>(d->lbdz_feas+nx_,
827  // d->lbdz_feas+nx_+ng_)).to_file("lba_correction.mtx");
828  // DM(std::vector<double>(d->ubdz_feas+nx_,
829  // d->ubdz_feas+nx_+ng_)).to_file("uba_correction.mtx");
830  // DM(std::vector<double>(d->dlam_feas, d->dlam_feas+nx_)).to_file("lam_x.mtx");
831  // DM(std::vector<double>(d->dlam_feas+nx_, d->dlam_feas+nx_+ng_)).to_file("lam_g.mtx");
832 
833  if (use_sqp_) {
834  solve_QP(m, d->Bk, d->gf_feas, d->lbdz_feas, d->ubdz_feas,
835  d->Jk, d->dx_feas, d->dlam_feas, 0);
836  } else {
837  solve_LP(m, d->gf_feas, d->lbdz_feas, d->ubdz_feas,
838  d->Jk, d->dx_feas, d->dlam_feas, 0);
839  }
840 
841  // put definition of ret out of loop
842 
843  // DM(std::vector<double>(d->dx_feas,d->dx_feas+nx_)).to_file("dx_feas.mtx");
844  // uout() << "Feas QP step: " << std::vector<double>(d->dx_feas, d->dx_feas+nx_) << std::endl;
845  //MISSING: Depending on the result terminate program
846 
847  //MISSING: Calculate the step_inf_norm
848  // self.step_inf_norm = cs.fmax(
849  // cs.norm_inf(self.p_k),
850  // cs.fmax(
851  // cs.norm_inf(self.lam_tmp_g-self.lam_p_g_k),
852  // cs.norm_inf(self.lam_tmp_x-self.lam_p_x_k)
853  // )
854  // )
855 
856  // TODO(david) the python code has a bug and does not consider the step in lambda
857  // here!!
858  // casadi_copy(d->dlam_feas, nx_+ng_, d->z_tmp);
859  // casadi_axpy(nx_+ng_, -1.0, d->dlam, d->z_tmp);
860  step_inf_norm = casadi_masked_norm_inf(nx_, d->dx_feas, d->tr_mask);
861 
862  // self.x_tmp = self.x_tmp + p_tmp
863  // self.g_tmp = self.__eval_g(self.x_tmp) # x_tmp = x_{tmp-1} + p_tmp
864 
865  if (use_anderson_) {
866  anderson_acc_step_update(mem, j);
867  } else {
868  casadi_axpy(nx_, 1., d->dx_feas, d->z_feas);
869  }
870 
871  // Evaluate g
872  m->arg[0] = d->z_feas;
873  m->arg[1] = d_nlp->p;
874  m->res[0] = d->z_feas + nx_;
875  if (calc_function(m, "nlp_g")) {
876  uout() << "What does it mean that calc_function fails here??" << std::endl;
877  }
878 
879  // self.curr_infeas = self.feasibility_measure(self.x_tmp, self.g_tmp)
880  // self.prev_infeas = self.curr_infeas
881  prev_infeas = casadi_max_viol(nx_+ng_, d->z_feas, d_nlp->lbz, d_nlp->ubz);
882  curr_infeas = prev_infeas;
883  // kappa = self.step_inf_norm/self.prev_step_inf_norm
884  // kappas.append(kappa)
885  kappa = step_inf_norm/prev_step_inf_norm;
886  //MISSING: as_exac:
887 
888  // DM(std::vector<double>(d_nlp->z, d_nlp->z+nx_)).to_file("x_k.mtx");
889  // DM(std::vector<double>(d->z_feas,d->z_feas+nx_)).to_file("x_tmp.mtx");
890  // DM(std::vector<double>(d->dx_feas,d->dx_feas+nx_)).to_file("dx_feas"+suffix+".mtx");
891  // DM(std::vector<double>(d->dx,d->dx+nx_)).to_file("p_k.mtx");
892 
893 
894  casadi_copy(d->dx, nx_, d->z_tmp);
895  casadi_axpy(nx_, -1., d->z_feas, d->z_tmp);
896  casadi_axpy(nx_, 1., d_nlp->z, d->z_tmp);
897  as_exac = casadi_norm_2(nx_, d->z_tmp) / casadi_norm_2(nx_, d->dx);
898 
899 
900  // as_exac = cs.norm_2(
901  // self.p_k - (self.x_tmp - self.x_k)) / cs.norm_2(self.p_k)
902 
903  // if self.verbose:
904  // print("Kappa: ", kappa,
905  // "Infeasibility", self.feasibility_measure(
906  // self.x_tmp, self.g_tmp),
907  // "Asymptotic Exactness: ", as_exac)
908  print("%6s %9.10f %14s %9.10f %20s %9.10f\n", "Kappa:", kappa,
909  "Infeasibility:", curr_infeas, "AsymptoticExactness:", as_exac);
910 
911  // accumulated_as_ex += as_exac
912  acc_as_exac += as_exac;
913  // if inner_iter % self.watchdog == 0:
914  // kappa_watch = self.step_inf_norm/watchdog_prev_inf_norm
915  // watchdog_prev_inf_norm = self.step_inf_norm
916  // if self.verbose:
917  // print("kappa watchdog: ", kappa_watch)
918  // if self.curr_infeas < self.feas_tol and as_exac < 0.5:
919  // self.kappa_acceptance = True
920  // break
921  if (inner_iter % watchdog_ == 0) {
922  kappa_watchdog = step_inf_norm / watchdog_prev_inf_norm;
923  watchdog_prev_inf_norm = step_inf_norm;
924  print("Kappa watchdog: %9.10f\n", kappa_watchdog);
925  if (curr_infeas < feas_tol_ && as_exac < 0.5) {
926  // kappa_acceptance = true;
927  return 0;
928  }
929  // if kappa_watch > self.contraction_acceptance or
930  // accumulated_as_ex/self.watchdog > 0.5:
931  // self.kappa_acceptance = False
932  // break
933  if (kappa_watchdog > contraction_acceptance_value_ || acc_as_exac/watchdog_ > 0.5) {
934  // kappa_acceptance = false;
935  return -1;
936  }
937  // accumulated_as_ex = 0
938  acc_as_exac = 0.0;
939  }
940 
941  // Do some saving here??
942  // feasibilities.append(
943  // self.feasibility_measure(self.x_tmp, self.g_tmp))
944  // asymptotic_exactness.append(as_exac)
945  // step_norms.append(cs.norm_inf(p_tmp))
946 
947  // self.prev_step_inf_norm = self.step_inf_norm
948  // self.lam_tmp_g = self.lam_p_g_k
949  // self.lam_tmp_x = self.lam_p_x_k
950  prev_step_inf_norm = step_inf_norm;
951  }
952  //maximum iterations reached
953  // kappa_acceptance = false;
954  return -1;
955 }
bool use_anderson_
Use Anderson Acceleration.
virtual int solve_QP(FeasiblesqpmethodMemory *m, const double *H, const double *g, const double *lbdz, const double *ubdz, const double *A, double *x_opt, double *dlam, int mode) const
virtual int solve_LP(FeasiblesqpmethodMemory *m, const double *g, const double *lbdz, const double *ubdz, const double *A, double *x_opt, double *dlam, int mode) const
void anderson_acc_step_update(void *mem, casadi_int iter_index) const
void anderson_acc_init_memory(void *mem, double *step, double *iterate) const
T1 casadi_max_viol(casadi_int n, const T1 *x, const T1 *lb, const T1 *ub)
Largest bound violation.
T1 casadi_norm_2(casadi_int n, const T1 *x)
NORM_2: ||x||_2 -> return.
void casadi_mv(const T1 *x, const casadi_int *sp_x, const T1 *y, T1 *z, casadi_int tr)
Sparse matrix-vector multiplication: z <- z + x*y.

References anderson_acc_init_memory(), anderson_acc_step_update(), casadi::OracleFunction::calc_function(), casadi::casadi_axpy(), casadi::casadi_copy(), casadi::casadi_max_viol(), casadi::casadi_mv(), casadi::casadi_norm_2(), contraction_acceptance_value_, casadi::NlpsolMemory::d_nlp, feas_tol_, Hsp_, max_inner_iter_, casadi::Nlpsol::ng_, casadi::Nlpsol::nx_, casadi::ProtoFunction::print(), solve_LP(), solve_QP(), casadi::uout(), use_anderson_, use_sqp_, and watchdog_.

Referenced by solve().

◆ finalize()

void casadi::OracleFunction::finalize ( )
overridevirtualinherited

Reimplemented from casadi::FunctionInternal.

Definition at line 122 of file oracle_function.cpp.

122  {
123  if (post_expand_) {
124  for (auto&& e : all_functions_) {
125  Function& fcn = e.second.f;
126  fcn = fcn.expand();
127  }
128  }
129 
130  // Allocate space for (parallel) evaluations
131  // Lifted from set_function as max_num_threads_ is not known yet in that method
132  for (auto&& e : all_functions_) {
133  Function& fcn = e.second.f;
134  // Compute strides for multi threading
135  size_t sz_arg, sz_res, sz_iw, sz_w;
136  fcn.sz_work(sz_arg, sz_res, sz_iw, sz_w);
137  stride_arg_ = std::max(stride_arg_, sz_arg);
138  stride_res_ = std::max(stride_res_, sz_res);
139  stride_iw_ = std::max(stride_iw_, sz_iw);
140  stride_w_ = std::max(stride_w_, sz_w);
141  bool persistent = false;
142  alloc(fcn, persistent, max_num_threads_);
143  }
144 
145  // Set corresponding monitors
146  for (const std::string& fname : monitor_) {
147  auto it = all_functions_.find(fname);
148  if (it==all_functions_.end()) {
149  casadi_warning("Ignoring monitor '" + fname + "'."
150  " Available functions: " + join(get_function()) + ".");
151  } else {
152  if (it->second.monitored) casadi_warning("Duplicate monitor " + fname);
153  it->second.monitored = true;
154  }
155  }
156 
157  // Check specific options
158  for (auto&& i : specific_options_) {
159  if (all_functions_.find(i.first)==all_functions_.end())
160  casadi_warning("Ignoring specific_options entry '" + i.first+"'."
161  " Available functions: " + join(get_function()) + ".");
162  }
163 
164  // Recursive call
166 }
void finalize() override
Finalize the object creation.
void alloc(const Function &f, bool persistent=false, int num_threads=1)
Ensure work vectors long enough to evaluate function.
std::map< std::string, RegFun > all_functions_
std::vector< std::string > monitor_
std::string join(const std::vector< std::string > &l, const std::string &delim)

References casadi::OracleFunction::all_functions_, casadi::FunctionInternal::alloc(), casadi::Function::expand(), casadi::FunctionInternal::finalize(), casadi::OracleFunction::get_function(), casadi::join(), casadi::OracleFunction::max_num_threads_, casadi::OracleFunction::monitor_, casadi::OracleFunction::post_expand_, casadi::OracleFunction::specific_options_, casadi::OracleFunction::stride_arg_, casadi::OracleFunction::stride_iw_, casadi::OracleFunction::stride_res_, casadi::OracleFunction::stride_w_, casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), and casadi::Function::sz_work().

◆ find()

virtual void casadi::FunctionInternal::find ( std::map< FunctionInternal *, Function > &  all_fun,
casadi_int  max_depth 
) const
inlinevirtualinherited

◆ format_time()

void casadi::ProtoFunction::format_time ( char *  buffer,
double  time 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_jt

Definition at line 3856 of file function_internal.cpp.

3856  {
3857  // Always of width 8
3858  casadi_assert_dev(time>=0);
3859  double log_time = log10(time);
3860  int magn = static_cast<int>(floor(log_time));
3861  int iprefix = static_cast<int>(floor(log_time/3));
3862  if (iprefix<-4) {
3863  sprint(buffer, 10, " 0");
3864  return;
3865  }
3866  if (iprefix>=5) {
3867  sprint(buffer, 10, " inf");
3868  return;
3869  }
3870  char prefixes[] = "TGMk munp";
3871  char prefix = prefixes[4-iprefix];
3872 
3873  int rem = magn-3*iprefix;
3874  double time_normalized = time/pow(10, 3*iprefix);
3875 
3876  if (rem==0) {
3877  sprint(buffer, 10, " %1.2f%cs", time_normalized, prefix);
3878  } else if (rem==1) {
3879  sprint(buffer, 10, " %2.2f%cs", time_normalized, prefix);
3880  } else {
3881  sprint(buffer, 10, "%3.2f%cs", time_normalized, prefix);
3882  }
3883  }
void sprint(char *buf, size_t buf_sz, const char *fmt,...) const
C-style formatted printing to string.

References casadi::ProtoFunction::sprint().

Referenced by casadi::ProtoFunction::print_time().

◆ forward()

Function casadi::FunctionInternal::forward ( casadi_int  nfwd) const
inherited

forward(nfwd) returns a cached instance if available, and calls Function get_forward(casadi_int nfwd) if no cached version is available.

Extra doc: https://github.com/casadi/casadi/wiki/L_l0

Definition at line 2163 of file function_internal.cpp.

2163  {
2164  casadi_assert_dev(nfwd>=0);
2165  // Used wrapped function if forward not available
2166  if (!enable_forward_ && !enable_fd_) {
2167  // Derivative information must be available
2168  casadi_assert(has_derivative(), "Derivatives cannot be calculated for " + name_);
2169  return wrap().forward(nfwd);
2170  }
2171  // Retrieve/generate cached
2172  Function f;
2173  std::string fname = forward_name(name_, nfwd);
2174  if (!incache(fname, f)) {
2175  casadi_int i;
2176  // Prefix to be used for forward seeds, sensitivities
2177  std::string pref = diff_prefix("fwd");
2178  // Names of inputs
2179  std::vector<std::string> inames;
2180  for (i=0; i<n_in_; ++i) inames.push_back(name_in_[i]);
2181  for (i=0; i<n_out_; ++i) inames.push_back("out_" + name_out_[i]);
2182  for (i=0; i<n_in_; ++i) inames.push_back(pref + name_in_[i]);
2183  // Names of outputs
2184  std::vector<std::string> onames;
2185  for (i=0; i<n_out_; ++i) onames.push_back(pref + name_out_[i]);
2186  // Options
2188  opts = combine(opts, generate_options("forward"));
2189  if (!enable_forward_) opts = fd_options_;
2190  opts["derivative_of"] = self();
2191  // Generate derivative function
2192  casadi_assert_dev(enable_forward_ || enable_fd_);
2193  if (enable_forward_) {
2194  f = get_forward(nfwd, fname, inames, onames, opts);
2195  } else {
2196  // Get FD method
2197  if (fd_method_.empty() || fd_method_=="central") {
2198  f = Function::create(new CentralDiff(fname, nfwd), opts);
2199  } else if (fd_method_=="forward") {
2200  f = Function::create(new ForwardDiff(fname, nfwd), opts);
2201  } else if (fd_method_=="backward") {
2202  f = Function::create(new BackwardDiff(fname, nfwd), opts);
2203  } else if (fd_method_=="smoothing") {
2204  f = Function::create(new Smoothing(fname, nfwd), opts);
2205  } else {
2206  casadi_error("Unknown 'fd_method': " + fd_method_);
2207  }
2208  }
2209  // Consistency check for inputs
2210  casadi_assert_dev(f.n_in()==n_in_ + n_out_ + n_in_);
2211  casadi_int ind=0;
2212  for (i=0; i<n_in_; ++i) f.assert_size_in(ind++, size1_in(i), size2_in(i));
2213  for (i=0; i<n_out_; ++i) f.assert_size_in(ind++, size1_out(i), size2_out(i));
2214  for (i=0; i<n_in_; ++i) f.assert_size_in(ind++, size1_in(i), nfwd*size2_in(i));
2215  // Consistency check for outputs
2216  casadi_assert_dev(f.n_out()==n_out_);
2217  for (i=0; i<n_out_; ++i) f.assert_sparsity_out(i, sparsity_out(i), nfwd);
2218  // Save to cache
2219  tocache_if_missing(f);
2220  }
2221  return f;
2222  }
std::string diff_prefix(const std::string &prefix) const
Determine prefix for differentiated functions.
casadi_int size1_out(casadi_int ind) const
Input/output dimensions.
Dict generate_options(const std::string &target) const override
Reconstruct options dict.
virtual Function get_forward(casadi_int nfwd, const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const
Return function that calculates forward derivatives.
Function forward(casadi_int nfwd) const
Get a function that calculates nfwd forward derivatives.
Definition: function.cpp:1135
static Function create(FunctionInternal *node)
Create from node.
Definition: function.cpp:336

References casadi::Function::assert_size_in(), casadi::Function::assert_sparsity_out(), casadi::combine(), casadi::Function::create(), casadi::FunctionInternal::der_options_, casadi::FunctionInternal::diff_prefix(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::fd_method_, casadi::FunctionInternal::fd_options_, casadi::Function::forward(), casadi::FunctionInternal::forward_name(), casadi::FunctionInternal::forward_options_, casadi::FunctionInternal::generate_options(), casadi::FunctionInternal::get_forward(), casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::incache(), casadi::Function::n_in(), casadi::FunctionInternal::n_in_, casadi::Function::n_out(), casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::size1_in(), casadi::FunctionInternal::size1_out(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::size2_out(), casadi::FunctionInternal::sparsity_out(), casadi::FunctionInternal::tocache_if_missing(), and casadi::FunctionInternal::wrap().

Referenced by casadi::FunctionInternal::call_forward(), and casadi::Function::forward().

◆ forward_name()

static std::string casadi::FunctionInternal::forward_name ( const std::string &  fcn,
casadi_int  nfwd 
)
inlinestaticinherited

◆ free_mem()

void casadi::Feasiblesqpmethod::free_mem ( void *  mem) const
inlineoverridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 100 of file feasiblesqpmethod.hpp.

100 { delete static_cast<FeasiblesqpmethodMemory*>(mem);}

◆ free_mx()

std::vector< MX > casadi::FunctionInternal::free_mx ( ) const
virtualinherited

Reimplemented in casadi::MXFunction.

Definition at line 3377 of file function_internal.cpp.

3377  {
3378  casadi_error("'free_mx' only defined for 'MXFunction'");
3379  }

◆ free_sx()

std::vector< SX > casadi::FunctionInternal::free_sx ( ) const
virtualinherited

Reimplemented in casadi::SXFunction.

Definition at line 3381 of file function_internal.cpp.

3381  {
3382  casadi_error("'free_sx' only defined for 'SXFunction'");
3383  }

◆ from_compact()

Sparsity casadi::FunctionInternal::from_compact ( casadi_int  oind,
casadi_int  iind,
const Sparsity sp 
) const
inherited

Definition at line 1928 of file function_internal.cpp.

1929  {
1930  // Return value
1931  Sparsity r = sp;
1932  // Insert rows if sparse output
1933  if (numel_out(oind) != r.size1()) {
1934  casadi_assert_dev(r.size1() == nnz_out(oind));
1935  r.enlargeRows(numel_out(oind), sparsity_out(oind).find());
1936  }
1937  // Insert columns if sparse input
1938  if (numel_in(iind) != r.size2()) {
1939  casadi_assert_dev(r.size2() == nnz_in(iind));
1940  r.enlargeColumns(numel_in(iind), sparsity_in(iind).find());
1941  }
1942  // Return non-compact pattern
1943  return r;
1944  }
casadi_int numel_out() const
Number of input/output elements.
virtual void find(std::map< FunctionInternal *, Function > &all_fun, casadi_int max_depth) const
casadi_int numel_in() const
Number of input/output elements.

References casadi::Sparsity::enlargeColumns(), casadi::Sparsity::enlargeRows(), casadi::FunctionInternal::find(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::numel_in(), casadi::FunctionInternal::numel_out(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::FunctionInternal::sparsity_in(), and casadi::FunctionInternal::sparsity_out().

Referenced by casadi::FunctionInternal::jac_sparsity().

◆ fwd_seed()

template<typename MatType >
std::vector< std::vector< MatType > > casadi::FunctionInternal::fwd_seed ( casadi_int  nfwd) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nr

Definition at line 1519 of file function_internal.hpp.

1520  {
1521  std::vector<std::vector<MatType>> fseed(nfwd);
1522  for (casadi_int dir=0; dir<nfwd; ++dir) {
1523  fseed[dir].resize(n_in_);
1524  for (casadi_int iind=0; iind<n_in_; ++iind) {
1525  std::string n = "f" + str(dir) + "_" + name_in_[iind];
1526  Sparsity sp = is_diff_in_[iind] ? sparsity_in(iind) : Sparsity(size_in(iind));
1527  fseed[dir][iind] = MatType::sym(n, sp);
1528  }
1529  }
1530  return fseed;
1531  }

References casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::size_in(), casadi::FunctionInternal::sparsity_in(), and casadi::str().

◆ fwdViaJac()

bool casadi::FunctionInternal::fwdViaJac ( casadi_int  nfwd) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nc

Definition at line 2993 of file function_internal.cpp.

2993  {
2994  if (!enable_forward_ && !enable_fd_) return true;
2995  if (jac_penalty_==-1) return false;
2996 
2997  // Heuristic 1: Jac calculated via forward mode likely cheaper
2998  if (jac_penalty_*static_cast<double>(nnz_in())<nfwd) return true;
2999 
3000  // Heuristic 2: Jac calculated via reverse mode likely cheaper
3001  double w = ad_weight();
3002  if (enable_reverse_ &&
3003  jac_penalty_*(1-w)*static_cast<double>(nnz_out())<w*static_cast<double>(nfwd))
3004  return true; // NOLINT
3005 
3006  return false;
3007  }

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::enable_reverse_, casadi::FunctionInternal::jac_penalty_, casadi::FunctionInternal::nnz_in(), and casadi::FunctionInternal::nnz_out().

Referenced by casadi::FunctionInternal::call_forward().

◆ generate_dependencies()

std::string casadi::OracleFunction::generate_dependencies ( const std::string &  fname,
const Dict opts 
) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_j

Reimplemented from casadi::FunctionInternal.

Definition at line 428 of file oracle_function.cpp.

429  {
430  CodeGenerator gen(fname, opts);
431  gen.add(oracle_);
432  for (auto&& e : all_functions_) {
433  if (e.second.jit) gen.add(e.second.f);
434  }
435  return gen.generate();
436 }

References casadi::CodeGenerator::add(), casadi::OracleFunction::all_functions_, casadi::CodeGenerator::generate(), and casadi::OracleFunction::oracle_.

Referenced by casadi::OracleFunction::jit_dependencies().

◆ generate_in()

void casadi::FunctionInternal::generate_in ( const std::string &  fname,
const double **  arg 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ne

Definition at line 749 of file function_internal.cpp.

749  {
750  // Set up output stream
751  auto of_ptr = Filesystem::ofstream_ptr(fname);
752  std::ostream& of = *of_ptr;
753  normalized_setup(of);
754 
755  // Encode each input
756  for (casadi_int i=0; i<n_in_; ++i) {
757  const double* v = arg[i];
758  for (casadi_int k=0;k<nnz_in(i);++k) {
759  normalized_out(of, v ? v[k] : 0);
760  of << std::endl;
761  }
762  }
763  }
static std::unique_ptr< std::ostream > ofstream_ptr(const std::string &path, std::ios_base::openmode mode=std::ios_base::out)
Definition: filesystem.cpp:115
void normalized_setup(std::istream &stream)
void normalized_out(std::ostream &stream, double val)

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::nnz_in(), casadi::normalized_out(), casadi::normalized_setup(), and casadi::Filesystem::ofstream_ptr().

◆ generate_lifted()

void casadi::FunctionInternal::generate_lifted ( Function vdef_fcn,
Function vinit_fcn 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l9

Reimplemented in casadi::MXFunction.

Definition at line 3385 of file function_internal.cpp.

3386  {
3387  casadi_error("'generate_lifted' only defined for 'MXFunction'");
3388  }

◆ generate_options()

Dict casadi::FunctionInternal::generate_options ( const std::string &  target) const
overridevirtualinherited

Reimplemented from casadi::ProtoFunction.

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 391 of file function_internal.cpp.

391  {
392  Dict opts = ProtoFunction::generate_options(target);
393  opts["jac_penalty"] = jac_penalty_;
394  opts["user_data"] = user_data_;
395  opts["inputs_check"] = inputs_check_;
396  if (target!="tmp") opts["jit"] = jit_;
397  opts["jit_cleanup"] = jit_cleanup_;
398  opts["jit_serialize"] = jit_serialize_;
399  opts["compiler"] = compiler_plugin_;
400  opts["jit_options"] = jit_options_;
401  opts["jit_name"] = jit_base_name_;
402  opts["jit_temp_suffix"] = jit_temp_suffix_;
403  opts["ad_weight"] = ad_weight_;
404  opts["ad_weight_sp"] = ad_weight_sp_;
405  opts["always_inline"] = always_inline_;
406  opts["never_inline"] = never_inline_;
407  opts["max_num_dir"] = max_num_dir_;
408  if (target=="clone" || target=="tmp") {
409  opts["enable_forward"] = enable_forward_op_;
410  opts["enable_reverse"] = enable_reverse_op_;
411  opts["enable_jacobian"] = enable_jacobian_op_;
412  opts["enable_fd"] = enable_fd_op_;
413  opts["reverse_options"] = reverse_options_;
414  opts["forward_options"] = forward_options_;
415  opts["jacobian_options"] = jacobian_options_;
416  opts["der_options"] = der_options_;
417  opts["derivative_of"] = derivative_of_;
418  }
419  opts["fd_options"] = fd_options_;
420  opts["fd_method"] = fd_method_;
421  opts["print_in"] = print_in_;
422  opts["print_out"] = print_out_;
423  opts["print_canonical"] = print_canonical_;
424  opts["max_io"] = max_io_;
425  opts["dump_in"] = dump_in_;
426  opts["dump_out"] = dump_out_;
427  opts["dump_dir"] = dump_dir_;
428  opts["dump_format"] = dump_format_;
429  opts["dump"] = dump_;
430  return opts;
431  }
std::string jit_serialize_
Serialize behaviour.
std::string compiler_plugin_
Just-in-time compiler.
void * user_data_
User-set field.
bool jit_
Use just-in-time compiler.
bool jit_temp_suffix_
Use a temporary name.
bool jit_cleanup_
Cleanup jit source file.
Function derivative_of_
If the function is the derivative of another function.
virtual Dict generate_options(const std::string &target) const
Reconstruct options dict.

References casadi::FunctionInternal::ad_weight_, casadi::FunctionInternal::ad_weight_sp_, casadi::FunctionInternal::always_inline_, casadi::FunctionInternal::compiler_plugin_, casadi::FunctionInternal::der_options_, casadi::FunctionInternal::derivative_of_, casadi::FunctionInternal::dump_, casadi::FunctionInternal::dump_dir_, casadi::FunctionInternal::dump_format_, casadi::FunctionInternal::dump_in_, casadi::FunctionInternal::dump_out_, casadi::FunctionInternal::enable_fd_op_, casadi::FunctionInternal::enable_forward_op_, casadi::FunctionInternal::enable_jacobian_op_, casadi::FunctionInternal::enable_reverse_op_, casadi::FunctionInternal::fd_method_, casadi::FunctionInternal::fd_options_, casadi::FunctionInternal::forward_options_, casadi::ProtoFunction::generate_options(), casadi::FunctionInternal::inputs_check_, casadi::FunctionInternal::jac_penalty_, casadi::FunctionInternal::jacobian_options_, casadi::FunctionInternal::jit_, casadi::FunctionInternal::jit_base_name_, casadi::FunctionInternal::jit_cleanup_, casadi::FunctionInternal::jit_options_, casadi::FunctionInternal::jit_serialize_, casadi::FunctionInternal::jit_temp_suffix_, casadi::FunctionInternal::max_io_, casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::never_inline_, casadi::FunctionInternal::print_canonical_, casadi::FunctionInternal::print_in_, casadi::FunctionInternal::print_out_, casadi::FunctionInternal::reverse_options_, and casadi::FunctionInternal::user_data_.

Referenced by casadi::FunctionInternal::forward(), casadi::MXFunction::generate_options(), casadi::SXFunction::generate_options(), casadi::BlazingSplineFunction::get_jacobian(), and casadi::FunctionInternal::reverse().

◆ generate_out()

void casadi::FunctionInternal::generate_out ( const std::string &  fname,
double **  res 
) const
inherited

Definition at line 765 of file function_internal.cpp.

765  {
766  // Set up output stream
767  auto of_ptr = Filesystem::ofstream_ptr(fname);
768  std::ostream& of = *of_ptr;
769  normalized_setup(of);
770 
771  // Encode each input
772  for (casadi_int i=0; i<n_out_; ++i) {
773  const double* v = res[i];
774  for (casadi_int k=0;k<nnz_out(i);++k) {
775  normalized_out(of, v ? v[k] : std::numeric_limits<double>::quiet_NaN());
776  of << std::endl;
777  }
778  }
779  }

References casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_out(), casadi::normalized_out(), casadi::normalized_setup(), and casadi::Filesystem::ofstream_ptr().

◆ get_abstol()

virtual double casadi::FunctionInternal::get_abstol ( ) const
inlinevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mp

Reimplemented in casadi::SundialsInterface, casadi::Smoothing, casadi::CentralDiff, and casadi::ForwardDiff.

Definition at line 1099 of file function_internal.hpp.

1099  {
1100  return eps;
1101  }
const double eps
Machine epsilon.
Definition: calculus.hpp:56

References casadi::eps.

Referenced by casadi::FiniteDiff::init().

◆ get_default_in()

double casadi::Nlpsol::get_default_in ( casadi_int  ind) const
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1ny

Reimplemented from casadi::FunctionInternal.

Definition at line 204 of file nlpsol_impl.hpp.

204 { return nlpsol_default_in(ind);}
double nlpsol_default_in(casadi_int ind)
Default input for an NLP solver.
Definition: nlpsol.cpp:212

References casadi::nlpsol_default_in().

Referenced by casadi::Nlpsol::check_inputs().

◆ get_diff_in()

virtual bool casadi::FunctionInternal::get_diff_in ( casadi_int  i)
inlinevirtualinherited

◆ get_diff_out()

virtual bool casadi::FunctionInternal::get_diff_out ( casadi_int  i)
inlinevirtualinherited

◆ get_forward()

Function casadi::Nlpsol::get_forward ( casadi_int  nfwd,
const std::string &  name,
const std::vector< std::string > &  inames,
const std::vector< std::string > &  onames,
const Dict opts 
) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1o2

Reimplemented from casadi::FunctionInternal.

Definition at line 868 of file nlpsol.cpp.

872  {
873  casadi_assert(detect_simple_bounds_is_simple_.empty(),
874  "Simple bound detection not compatible with get_forward");
875 
876  // Symbolic expression for the input
877  std::vector<MX> arg = mx_in(), res = mx_out();
878 
879  // Initial guesses not used for derivative calculations
881  std::string name = arg[i].is_symbolic() ? arg[i].name() : "tmp_get_forward";
882  arg[i] = MX::sym(name, Sparsity(arg[i].size()));
883  }
884 
885  // Optimal solution
886  MX x = res[NLPSOL_X];
887  MX lam_g = res[NLPSOL_LAM_G];
888  MX lam_x = res[NLPSOL_LAM_X];
889  MX lam_p = res[NLPSOL_LAM_P];
890  MX f = res[NLPSOL_F];
891  MX g = res[NLPSOL_G];
892 
893  // Inputs used
894  MX lbx = arg[NLPSOL_LBX];
895  MX ubx = arg[NLPSOL_UBX];
896  MX lbg = arg[NLPSOL_LBG];
897  MX ubg = arg[NLPSOL_UBG];
898  MX p = arg[NLPSOL_P];
899 
900  // Get KKT function
901  Function kkt = this->kkt();
902 
903  // Hessian of the Lagrangian, Jacobian of the constraints
904  std::vector<MX> HJ_res = kkt({x, p, 1, lam_g});
905  MX JG = HJ_res.at(0);
906  MX HL = HJ_res.at(1);
907 
908  // Active set (assumed known and given by the multiplier signs)
909  MX ubIx = lam_x > min_lam_;
910  MX lbIx = lam_x < -min_lam_;
911  MX bIx = ubIx + lbIx;
912  MX iIx = 1-bIx;
913  MX ubIg = lam_g > min_lam_;
914  MX lbIg = lam_g < -min_lam_;
915  MX bIg = ubIg + lbIg;
916  MX iIg = 1-bIg;
917 
918  // KKT matrix
919  MX H_11 = mtimes(diag(iIx), HL) + diag(bIx);
920  MX H_12 = mtimes(diag(iIx), JG.T());
921  MX H_21 = mtimes(diag(bIg), JG);
922  MX H_22 = diag(-iIg);
923  MX H = MX::blockcat({{H_11, H_12}, {H_21, H_22}});
924 
925  // Sensitivity inputs
926  std::vector<MX> fseed(NLPSOL_NUM_IN);
927  MX fwd_lbx = fseed[NLPSOL_LBX] = MX::sym("fwd_lbx", repmat(x.sparsity(), 1, nfwd));
928  MX fwd_ubx = fseed[NLPSOL_UBX] = MX::sym("fwd_ubx", repmat(x.sparsity(), 1, nfwd));
929  MX fwd_lbg = fseed[NLPSOL_LBG] = MX::sym("fwd_lbg", repmat(g.sparsity(), 1, nfwd));
930  MX fwd_ubg = fseed[NLPSOL_UBG] = MX::sym("fwd_ubg", repmat(g.sparsity(), 1, nfwd));
931  MX fwd_p = fseed[NLPSOL_P] = MX::sym("fwd_p", repmat(p.sparsity(), 1, nfwd));
932 
933  // Guesses are unused
935  fseed[i] = MX(repmat(Sparsity(arg[i].size()), 1, nfwd));
936  }
937 
938  // nlp_grad has the signature
939  // (x, p, lam_f, lam_g) -> (f, g, grad_x, grad_p)
940  // with lam_f=1 and lam_g=lam_g, grad_x = -lam_x, grad_p=-lam_p
941  Function nlp_grad = get_function("nlp_grad");
942 
943  // fwd_nlp_grad has the signature
944  // (x, p, lam_f, lam_g, f, g, grad_x, grad_p,
945  // fwd_x, fwd_p, fwd_lam_f, fwd_lam_g)
946  // -> (fwd_f, fwd_g, fwd_grad_x, fwd_grad_p)
947  Function fwd_nlp_grad = nlp_grad.forward(nfwd);
948 
949  // Calculate sensitivities from fwd_p
950  std::vector<MX> vv = {x, p, 1, lam_g, f, g, -lam_x, -lam_p, 0., fwd_p, 0., 0.};
951  vv = fwd_nlp_grad(vv);
952  MX fwd_g_p = vv.at(1);
953  MX fwd_gL_p = vv.at(2);
954 
955  // Propagate forward seeds
956  MX fwd_alpha_x = (if_else(lbIx, fwd_lbx, 0) + if_else(ubIx, fwd_ubx, 0))
957  - if_else(iIx, fwd_gL_p, 0);
958  MX fwd_alpha_g = (if_else(ubIg, fwd_ubg, 0) + if_else(lbIg, fwd_lbg, 0))
959  - if_else(bIg, fwd_g_p, 0);
960  MX v = MX::vertcat({fwd_alpha_x, fwd_alpha_g});
961 
962  // Solve
964 
965  // Extract sensitivities in x, lam_x and lam_g
966  std::vector<MX> v_split = vertsplit(v, {0, nx_, nx_+ng_});
967  MX fwd_x = v_split.at(0);
968  MX fwd_lam_g = v_split.at(1);
969 
970  // Calculate sensitivities in lam_x, lam_g
971  vv = {x, p, 1, lam_g, f, g, -lam_x, -lam_p,
972  fwd_x, fwd_p, 0, fwd_lam_g};
973  vv = fwd_nlp_grad(vv);
974  MX fwd_f = vv.at(0);
975  MX fwd_g = vv.at(1);
976  MX fwd_lam_x = -vv.at(2);
977  MX fwd_lam_p = -vv.at(3);
978 
979  // Forward sensitivities
980  std::vector<MX> fsens(NLPSOL_NUM_OUT);
981  fsens[NLPSOL_X] = fwd_x;
982  fsens[NLPSOL_F] = fwd_f;
983  fsens[NLPSOL_G] = fwd_g;
984  fsens[NLPSOL_LAM_X] = fwd_lam_x;
985  fsens[NLPSOL_LAM_G] = fwd_lam_g;
986  fsens[NLPSOL_LAM_P] = fwd_lam_p;
987 
988  // Gather return values
989  arg.insert(arg.end(), res.begin(), res.end());
990  arg.insert(arg.end(), fseed.begin(), fseed.end());
991  res = fsens;
992 
993  Dict options = opts;
994  options["allow_duplicate_io_names"] = true;
995 
996  return Function(name, arg, res, inames, onames, options);
997  }
virtual const std::vector< MX > mx_in() const
Get function input(s) and output(s)
virtual const std::vector< MX > mx_out() const
Get function input(s) and output(s)
static MX sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.
static MX blockcat(const std::vector< std::vector< MX > > &v)
Definition: mx.cpp:1197
static MX solve(const MX &a, const MX &b)
Definition: mx.cpp:2007
static MX vertcat(const std::vector< MX > &x)
Definition: mx.cpp:1099
Function kkt() const
Definition: nlpsol.cpp:847
Dict sens_linsol_options_
Definition: nlpsol_impl.hpp:82
double min_lam_
Options.
Definition: nlpsol_impl.hpp:99
std::string sens_linsol_
Linear solver and options.
Definition: nlpsol_impl.hpp:81
NlpsolInput
Input arguments of an NLP Solver.
Definition: nlpsol.hpp:194
double if_else(double x, double y, double z)
Definition: calculus.hpp:290

References casadi::MX::blockcat(), casadi::Nlpsol::detect_simple_bounds_is_simple_, casadi::Function::forward(), casadi::FunctionInternal::Function, casadi::OracleFunction::get_function(), casadi::if_else(), casadi::Nlpsol::kkt(), casadi::Nlpsol::min_lam_, casadi::FunctionInternal::mx_in(), casadi::FunctionInternal::mx_out(), casadi::Nlpsol::ng_, casadi::NLPSOL_F, casadi::NLPSOL_G, casadi::NLPSOL_LAM_G, casadi::NLPSOL_LAM_G0, casadi::NLPSOL_LAM_P, casadi::NLPSOL_LAM_X, casadi::NLPSOL_LAM_X0, casadi::NLPSOL_LBG, casadi::NLPSOL_LBX, casadi::NLPSOL_NUM_IN, casadi::NLPSOL_NUM_OUT, casadi::NLPSOL_P, casadi::NLPSOL_UBG, casadi::NLPSOL_UBX, casadi::NLPSOL_X, casadi::NLPSOL_X0, casadi::Nlpsol::nx_, casadi::Nlpsol::sens_linsol_, casadi::Nlpsol::sens_linsol_options_, casadi::MX::solve(), casadi::MX::sparsity(), casadi::GenericMatrix< MX >::sym(), and casadi::MX::vertcat().

◆ get_free()

std::vector< std::string > casadi::FunctionInternal::get_free ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mc

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 1020 of file function_internal.cpp.

1020  {
1021  casadi_assert_dev(!has_free());
1022  return std::vector<std::string>();
1023  }
virtual bool has_free() const
Does the function have free variables.

References casadi::FunctionInternal::has_free().

◆ get_function() [1/2]

std::vector< std::string > casadi::OracleFunction::get_function ( ) const
overridevirtualinherited

-1 Indicates irregularity

Extra doc: https://github.com/casadi/casadi/wiki/L_i

Reimplemented from casadi::FunctionInternal.

Definition at line 531 of file oracle_function.cpp.

531  {
532  std::vector<std::string> ret;
533  ret.reserve(all_functions_.size());
534  for (auto&& e : all_functions_) {
535  ret.push_back(e.first);
536  }
537  return ret;
538 }

References casadi::OracleFunction::all_functions_.

Referenced by casadi::Rootfinder::ad_forward(), casadi::Rootfinder::ad_reverse(), casadi::OracleFunction::calc_function(), casadi::OracleFunction::calc_sp_forward(), casadi::OracleFunction::calc_sp_reverse(), casadi::FastNewton::codegen_body(), codegen_body(), casadi::Sqpmethod::codegen_body(), casadi::Nlpsol::codegen_body_exit(), casadi::Nlpsol::codegen_declarations(), casadi::FatropInterface::codegen_declarations(), casadi::IpoptInterface::codegen_declarations(), casadi::MadnlpInterface::codegen_declarations(), casadi::FastNewton::codegen_declarations(), codegen_declarations(), casadi::Sqpmethod::codegen_declarations(), codegen_feasibility_iterations(), casadi::FixedStepIntegrator::create_advanced(), casadi::OracleFunction::create_forward(), casadi::AlpaqaProblem::eval_hess_L(), casadi::AlpaqaProblem::eval_hess_ψ(), casadi::OracleFunction::finalize(), casadi::Nlpsol::get_forward(), casadi::OracleFunction::get_function(), casadi::AlpaqaProblem::get_hess_L_num_nonzeros(), casadi::AlpaqaProblem::get_hess_ψ_num_nonzeros(), casadi::Nlpsol::get_reverse(), casadi::FixedStepIntegrator::init(), casadi::ImplicitFixedStepIntegrator::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::FatropInterface::init(), casadi::IpoptInterface::init(), casadi::MadnlpInterface::init(), casadi::SLEQPInterface::init(), casadi::SundialsInterface::init(), casadi::FastNewton::init(), init(), casadi::Sqpmethod::init(), casadi::OracleFunction::monitored(), casadi::FatropInterface::set_fatrop_prob(), casadi::IpoptInterface::set_ipopt_prob(), casadi::MadnlpInterface::set_madnlp_prob(), casadi::SundialsInterface::set_work(), casadi::Collocation::setup_step(), casadi::RungeKutta::setup_step(), casadi::Integrator::sp_jac_dae(), and casadi::Integrator::sp_jac_rdae().

◆ get_function() [2/2]

const Function & casadi::OracleFunction::get_function ( const std::string &  name) const
overridevirtualinherited

Reimplemented from casadi::FunctionInternal.

Definition at line 540 of file oracle_function.cpp.

540  {
541  auto it = all_functions_.find(name);
542  casadi_assert(it!=all_functions_.end(),
543  "No function \"" + name + "\" in " + name_ + ". " +
544  "Available functions: " + join(get_function()) + ".");
545  return it->second.f;
546 }

References casadi::OracleFunction::all_functions_, casadi::OracleFunction::get_function(), casadi::join(), and casadi::ProtoFunction::name_.

◆ get_jac_sparsity()

Sparsity casadi::FunctionInternal::get_jac_sparsity ( casadi_int  oind,
casadi_int  iind,
bool  symmetric 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kz Get, if necessary generate, the sparsity of a Jacobian block

Reimplemented in casadi::FmuFunction, casadi::GenericExternal, casadi::Expm, and casadi::CallbackInternal.

Definition at line 1871 of file function_internal.cpp.

1872  {
1873  if (symmetric) {
1874  casadi_assert(sparsity_out_[oind].is_dense(),
1875  "Symmetry exploitation in Jacobian assumes dense expression. "
1876  "A potential workaround is to apply densify().");
1877  }
1878  // Check if we are able to propagate dependencies through the function
1879  if (has_spfwd() || has_sprev()) {
1880  // Get weighting factor
1881  double w = sp_weight();
1882 
1883  // Skip generation, assume dense
1884  if (w == -1) return Sparsity();
1885 
1886  Sparsity sp;
1887  if (nnz_in(iind) > 3*bvec_size && nnz_out(oind) > 3*bvec_size &&
1889  if (symmetric) {
1890  sp = get_jac_sparsity_hierarchical_symm(oind, iind);
1891  } else {
1892  sp = get_jac_sparsity_hierarchical(oind, iind);
1893  }
1894  } else {
1895  // Number of nonzero inputs and outputs
1896  casadi_int nz_in = nnz_in(iind);
1897  casadi_int nz_out = nnz_out(oind);
1898 
1899  // Number of forward sweeps we must make
1900  casadi_int nsweep_fwd = nz_in/bvec_size;
1901  if (nz_in%bvec_size) nsweep_fwd++;
1902 
1903  // Number of adjoint sweeps we must make
1904  casadi_int nsweep_adj = nz_out/bvec_size;
1905  if (nz_out%bvec_size) nsweep_adj++;
1906 
1907  // Use forward mode?
1908  if (w*static_cast<double>(nsweep_fwd) <= (1-w)*static_cast<double>(nsweep_adj)) {
1909  sp = get_jac_sparsity_gen<true>(oind, iind);
1910  } else {
1911  sp = get_jac_sparsity_gen<false>(oind, iind);
1912  }
1913  }
1914  return sp;
1915  } else {
1916  // Not calculated
1917  return Sparsity();
1918  }
1919  }
virtual bool has_sprev() const
Is the class able to propagate seeds through the algorithm?
Sparsity get_jac_sparsity_hierarchical_symm(casadi_int oind, casadi_int iind) const
virtual double sp_weight() const
Weighting factor for chosing forward/reverse mode,.
Sparsity get_jac_sparsity_hierarchical(casadi_int oind, casadi_int iind) const
A flavor of get_jac_sparsity_gen that does hierarchical block structure recognition.
std::vector< double > nz_in(const std::vector< DM > &arg) const
Convert from/to flat vector of input/output nonzeros.
std::vector< double > nz_out(const std::vector< DM > &res) const
Convert from/to flat vector of input/output nonzeros.
virtual bool has_spfwd() const
Is the class able to propagate seeds through the algorithm?
static bool hierarchical_sparsity
const int bvec_size

References casadi::bvec_size, casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::FunctionInternal::get_jac_sparsity_hierarchical_symm(), casadi::FunctionInternal::has_spfwd(), casadi::FunctionInternal::has_sprev(), casadi::GlobalOptions::hierarchical_sparsity, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::nz_in(), casadi::FunctionInternal::nz_out(), casadi::FunctionInternal::sp_weight(), and casadi::FunctionInternal::sparsity_out_.

Referenced by casadi::Expm::get_jac_sparsity(), casadi::GenericExternal::get_jac_sparsity(), and casadi::FunctionInternal::jac_sparsity().

◆ get_jac_sparsity_gen()

template<bool fwd>
Sparsity casadi::FunctionInternal::get_jac_sparsity_gen ( casadi_int  oind,
casadi_int  iind 
) const
inherited

Definition at line 1216 of file function_internal.cpp.

1216  {
1217  // Number of nonzero inputs and outputs
1218  casadi_int nz_in = nnz_in(iind);
1219  casadi_int nz_out = nnz_out(oind);
1220 
1221  // Evaluation buffers
1222  std::vector<typename JacSparsityTraits<fwd>::arg_t> arg(sz_arg(), nullptr);
1223  std::vector<bvec_t*> res(sz_res(), nullptr);
1224  std::vector<casadi_int> iw(sz_iw());
1225  std::vector<bvec_t> w(sz_w(), 0);
1226 
1227  // Seeds and sensitivities
1228  std::vector<bvec_t> seed(nz_in, 0);
1229  arg[iind] = get_ptr(seed);
1230  std::vector<bvec_t> sens(nz_out, 0);
1231  res[oind] = get_ptr(sens);
1232  if (!fwd) std::swap(seed, sens);
1233 
1234  // Number of forward sweeps we must make
1235  casadi_int nsweep = seed.size() / bvec_size;
1236  if (seed.size() % bvec_size) nsweep++;
1237 
1238  // Print
1239  if (verbose_) {
1240  casadi_message(str(nsweep) + std::string(fwd ? " forward" : " reverse") + " sweeps "
1241  "needed for " + str(seed.size()) + " directions");
1242  }
1243 
1244  // Progress
1245  casadi_int progress = -10;
1246 
1247  // Temporary vectors
1248  std::vector<casadi_int> jcol, jrow;
1249 
1250  // Loop over the variables, bvec_size variables at a time
1251  for (casadi_int s=0; s<nsweep; ++s) {
1252 
1253  // Print progress
1254  if (verbose_) {
1255  casadi_int progress_new = (s*100)/nsweep;
1256  // Print when entering a new decade
1257  if (progress_new / 10 > progress / 10) {
1258  progress = progress_new;
1259  casadi_message(str(progress) + " %");
1260  }
1261  }
1262 
1263  // Nonzero offset
1264  casadi_int offset = s*bvec_size;
1265 
1266  // Number of local seed directions
1267  casadi_int ndir_local = seed.size()-offset;
1268  ndir_local = std::min(static_cast<casadi_int>(bvec_size), ndir_local);
1269 
1270  for (casadi_int i=0; i<ndir_local; ++i) {
1271  seed[offset+i] |= bvec_t(1)<<i;
1272  }
1273 
1274  // Propagate the dependencies
1275  JacSparsityTraits<fwd>::sp(this, get_ptr(arg), get_ptr(res),
1276  get_ptr(iw), get_ptr(w), memory(0));
1277 
1278  // Loop over the nonzeros of the output
1279  for (casadi_int el=0; el<sens.size(); ++el) {
1280 
1281  // Get the sparsity sensitivity
1282  bvec_t spsens = sens[el];
1283 
1284  if (!fwd) {
1285  // Clear the sensitivities for the next sweep
1286  sens[el] = 0;
1287  }
1288 
1289  // If there is a dependency in any of the directions
1290  if (spsens!=0) {
1291 
1292  // Loop over seed directions
1293  for (casadi_int i=0; i<ndir_local; ++i) {
1294 
1295  // If dependents on the variable
1296  if ((bvec_t(1) << i) & spsens) {
1297  // Add to pattern
1298  jcol.push_back(el);
1299  jrow.push_back(i+offset);
1300  }
1301  }
1302  }
1303  }
1304 
1305  // Remove the seeds
1306  for (casadi_int i=0; i<ndir_local; ++i) {
1307  seed[offset+i] = 0;
1308  }
1309  }
1310 
1311  // Construct sparsity pattern and return
1312  if (!fwd) swap(jrow, jcol);
1313  Sparsity ret = Sparsity::triplet(nz_out, nz_in, jcol, jrow);
1314  if (verbose_) {
1315  casadi_message("Formed Jacobian sparsity pattern (dimension " + str(ret.size()) + ", "
1316  + str(ret.nnz()) + " (" + str(ret.density()) + " %) nonzeros.");
1317  }
1318  return ret;
1319  }
static Sparsity triplet(casadi_int nrow, casadi_int ncol, const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, std::vector< casadi_int > &mapping, bool invert_mapping)
Create a sparsity pattern given the nonzeros in sparse triplet form *.
Definition: sparsity.cpp:1127
unsigned long long bvec_t

References casadi::bvec_size, casadi::Sparsity::density(), casadi::get_ptr(), casadi::ProtoFunction::memory(), casadi::Sparsity::nnz(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::nz_in(), casadi::FunctionInternal::nz_out(), casadi::Sparsity::size(), casadi::str(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), casadi::Sparsity::triplet(), and casadi::ProtoFunction::verbose_.

◆ get_jac_sparsity_hierarchical()

Sparsity casadi::FunctionInternal::get_jac_sparsity_hierarchical ( casadi_int  oind,
casadi_int  iind 
) const
inherited

Decide which ad_mode to take

Definition at line 1556 of file function_internal.cpp.

1556  {
1557  // Number of nonzero inputs
1558  casadi_int nz_in = nnz_in(iind);
1559 
1560  // Number of nonzero outputs
1561  casadi_int nz_out = nnz_out(oind);
1562 
1563  // Seeds and sensitivities
1564  std::vector<bvec_t> s_in(nz_in, 0);
1565  std::vector<bvec_t> s_out(nz_out, 0);
1566 
1567  // Evaluation buffers
1568  std::vector<const bvec_t*> arg_fwd(sz_arg(), nullptr);
1569  std::vector<bvec_t*> arg_adj(sz_arg(), nullptr);
1570  arg_fwd[iind] = arg_adj[iind] = get_ptr(s_in);
1571  std::vector<bvec_t*> res(sz_res(), nullptr);
1572  res[oind] = get_ptr(s_out);
1573  std::vector<casadi_int> iw(sz_iw());
1574  std::vector<bvec_t> w(sz_w());
1575 
1576  // Sparsity triplet accumulator
1577  std::vector<casadi_int> jcol, jrow;
1578 
1579  // Cols of the coarse blocks
1580  std::vector<casadi_int> coarse_col(2, 0); coarse_col[1] = nz_out;
1581  // Rows of the coarse blocks
1582  std::vector<casadi_int> coarse_row(2, 0); coarse_row[1] = nz_in;
1583 
1584  // Cols of the fine blocks
1585  std::vector<casadi_int> fine_col;
1586 
1587  // Rows of the fine blocks
1588  std::vector<casadi_int> fine_row;
1589 
1590  // In each iteration, subdivide each coarse block in this many fine blocks
1591  casadi_int subdivision = bvec_size;
1592 
1593  Sparsity r = Sparsity::dense(1, 1);
1594 
1595  // The size of a block
1596  casadi_int granularity_row = nz_in;
1597  casadi_int granularity_col = nz_out;
1598 
1599  bool use_fwd = true;
1600 
1601  casadi_int nsweeps = 0;
1602 
1603  bool hasrun = false;
1604 
1605  // Get weighting factor
1606  double sp_w = sp_weight();
1607 
1608  // Lookup table for bvec_t
1609  std::vector<bvec_t> bvec_lookup;
1610  bvec_lookup.reserve(bvec_size);
1611  for (casadi_int i=0;i<bvec_size;++i) {
1612  bvec_lookup.push_back(bvec_t(1) << i);
1613  }
1614 
1615  while (!hasrun || coarse_col.size()!=nz_out+1 || coarse_row.size()!=nz_in+1) {
1616  if (verbose_) {
1617  casadi_message("Block size: " + str(granularity_col) + " x " + str(granularity_row));
1618  }
1619 
1620  // Clear the sparsity triplet acccumulator
1621  jcol.clear();
1622  jrow.clear();
1623 
1624  // Clear the fine block structure
1625  fine_row.clear();
1626  fine_col.clear();
1627 
1628  // r transpose will be needed in the algorithm
1629  Sparsity rT = r.T();
1630 
1633  // Forward mode
1634  Sparsity D1 = rT.uni_coloring(r);
1635  // Adjoint mode
1636  Sparsity D2 = r.uni_coloring(rT);
1637  if (verbose_) {
1638  casadi_message("Coloring on " + str(r.dim()) + " (fwd seeps: " + str(D1.size2()) +
1639  " , adj sweeps: " + str(D2.size1()) + ")");
1640  }
1641 
1642  // Use whatever required less colors if we tried both (with preference to forward mode)
1643  double fwd_cost = static_cast<double>(use_fwd ? granularity_row : granularity_col) *
1644  sp_w*static_cast<double>(D1.size2());
1645  double adj_cost = static_cast<double>(use_fwd ? granularity_col : granularity_row) *
1646  (1-sp_w)*static_cast<double>(D2.size2());
1647  use_fwd = fwd_cost <= adj_cost;
1648  if (verbose_) {
1649  casadi_message(std::string(use_fwd ? "Forward" : "Reverse") + " mode chosen "
1650  "(fwd cost: " + str(fwd_cost) + ", adj cost: " + str(adj_cost) + ")");
1651  }
1652 
1653  // Get seeds and sensitivities
1654  bvec_t* seed_v = use_fwd ? get_ptr(s_in) : get_ptr(s_out);
1655  bvec_t* sens_v = use_fwd ? get_ptr(s_out) : get_ptr(s_in);
1656 
1657  // The number of zeros in the seed and sensitivity directions
1658  casadi_int nz_seed = use_fwd ? nz_in : nz_out;
1659  casadi_int nz_sens = use_fwd ? nz_out : nz_in;
1660 
1661  // Clear the seeds
1662  for (casadi_int i=0; i<nz_seed; ++i) seed_v[i]=0;
1663 
1664  // Choose the active jacobian coloring scheme
1665  Sparsity D = use_fwd ? D1 : D2;
1666 
1667  // Adjoint mode amounts to swapping
1668  if (!use_fwd) {
1669  std::swap(coarse_col, coarse_row);
1670  std::swap(granularity_col, granularity_row);
1671  std::swap(r, rT);
1672  }
1673 
1674  // Subdivide the coarse block cols
1675  for (casadi_int k=0;k<coarse_col.size()-1;++k) {
1676  casadi_int diff = coarse_col[k+1]-coarse_col[k];
1677  casadi_int new_diff = diff/subdivision;
1678  if (diff%subdivision>0) new_diff++;
1679  std::vector<casadi_int> temp = range(coarse_col[k], coarse_col[k+1], new_diff);
1680  fine_col.insert(fine_col.end(), temp.begin(), temp.end());
1681  }
1682  // Subdivide the coarse block rows
1683  for (casadi_int k=0;k<coarse_row.size()-1;++k) {
1684  casadi_int diff = coarse_row[k+1]-coarse_row[k];
1685  casadi_int new_diff = diff/subdivision;
1686  if (diff%subdivision>0) new_diff++;
1687  std::vector<casadi_int> temp = range(coarse_row[k], coarse_row[k+1], new_diff);
1688  fine_row.insert(fine_row.end(), temp.begin(), temp.end());
1689  }
1690  if (fine_row.back()!=coarse_row.back()) fine_row.push_back(coarse_row.back());
1691  if (fine_col.back()!=coarse_col.back()) fine_col.push_back(coarse_col.back());
1692 
1693  granularity_col = fine_col[1] - fine_col[0];
1694  granularity_row = fine_row[1] - fine_row[0];
1695 
1696  // The index into the bvec bit vector
1697  casadi_int bvec_i = 0;
1698 
1699  // Create lookup tables for the fine blocks
1700  std::vector<casadi_int> fine_col_lookup = lookupvector(fine_col, nz_sens+1);
1701  std::vector<casadi_int> fine_row_lookup = lookupvector(fine_row, nz_seed+1);
1702 
1703  // Triplet data used as a lookup table
1704  std::vector<casadi_int> lookup_col;
1705  std::vector<casadi_int> lookup_row;
1706  std::vector<casadi_int> lookup_value;
1707 
1708 
1709  // The maximum number of fine blocks contained in one coarse block
1710  casadi_int n_fine_blocks_max = 0;
1711  for (casadi_int i=0;i<coarse_row.size()-1;++i) {
1712  casadi_int del = fine_row_lookup[coarse_row[i+1]]-fine_row_lookup[coarse_row[i]];
1713  n_fine_blocks_max = std::max(n_fine_blocks_max, del);
1714  }
1715 
1716  // Loop over all coarse seed directions from the coloring
1717  for (casadi_int csd=0; csd<D.size2(); ++csd) {
1718 
1719  casadi_int fci_offset = 0;
1720  casadi_int fci_cap = bvec_size-bvec_i;
1721 
1722  // Flag to indicate if all fine blocks have been handled
1723  bool f_finished = false;
1724 
1725  // Loop while not finished
1726  while (!f_finished) {
1727 
1728  // Loop over all coarse rows that are found in the coloring for this coarse seed direction
1729  for (casadi_int k=D.colind(csd); k<D.colind(csd+1); ++k) {
1730  casadi_int cci = D.row(k);
1731 
1732  // The first and last rows of the fine block
1733  casadi_int fci_start = fine_row_lookup[coarse_row[cci]];
1734  casadi_int fci_end = fine_row_lookup[coarse_row[cci+1]];
1735 
1736  // Local counter that modifies index into bvec
1737  casadi_int bvec_i_mod = 0;
1738 
1739  casadi_int value = -bvec_i + fci_offset + fci_start;
1740 
1741  // Loop over the rows of the fine block
1742  for (casadi_int fci = fci_offset; fci < std::min(fci_end-fci_start, fci_cap); ++fci) {
1743 
1744  // Loop over the coarse block cols that appear in the coloring
1745  // for the current coarse seed direction
1746  for (casadi_int cri=rT.colind(cci);cri<rT.colind(cci+1);++cri) {
1747  lookup_col.push_back(rT.row(cri));
1748  lookup_row.push_back(bvec_i+bvec_i_mod);
1749  lookup_value.push_back(value);
1750  }
1751 
1752  // Toggle on seeds
1753  bvec_toggle(seed_v, fine_row[fci+fci_start], fine_row[fci+fci_start+1],
1754  bvec_i+bvec_i_mod);
1755  bvec_i_mod++;
1756  }
1757  }
1758 
1759  // Bump bvec_i for next major coarse direction
1760  bvec_i+= std::min(n_fine_blocks_max, fci_cap);
1761 
1762  // Check if bvec buffer is full
1763  if (bvec_i==bvec_size || csd==D.size2()-1) {
1764  // Calculate sparsity for bvec_size directions at once
1765 
1766  // Statistics
1767  nsweeps+=1;
1768 
1769  // Construct lookup table
1770  IM lookup = IM::triplet(lookup_row, lookup_col, lookup_value, bvec_size,
1771  coarse_col.size());
1772 
1773  // Propagate the dependencies
1774  if (use_fwd) {
1775  JacSparsityTraits<true>::sp(this, get_ptr(arg_fwd), get_ptr(res),
1776  get_ptr(iw), get_ptr(w), memory(0));
1777  } else {
1778  std::fill(w.begin(), w.end(), 0);
1779  JacSparsityTraits<false>::sp(this, get_ptr(arg_adj), get_ptr(res),
1780  get_ptr(iw), get_ptr(w), memory(0));
1781  }
1782 
1783  // Temporary bit work vector
1784  bvec_t spsens;
1785 
1786  // Loop over the cols of coarse blocks
1787  for (casadi_int cri=0;cri<coarse_col.size()-1;++cri) {
1788 
1789  // Loop over the cols of fine blocks within the current coarse block
1790  for (casadi_int fri=fine_col_lookup[coarse_col[cri]];
1791  fri<fine_col_lookup[coarse_col[cri+1]];++fri) {
1792  // Lump individual sensitivities together into fine block
1793  bvec_or(sens_v, spsens, fine_col[fri], fine_col[fri+1]);
1794 
1795  // Next iteration if no sparsity
1796  if (!spsens) continue;
1797 
1798  // Loop over all bvec_bits
1799  for (casadi_int bvec_i=0;bvec_i<bvec_size;++bvec_i) {
1800  if (spsens & bvec_lookup[bvec_i]) {
1801  // if dependency is found, add it to the new sparsity pattern
1802  casadi_int ind = lookup.sparsity().get_nz(bvec_i, cri);
1803  if (ind==-1) continue;
1804  jrow.push_back(bvec_i+lookup->at(ind));
1805  jcol.push_back(fri);
1806  }
1807  }
1808  }
1809  }
1810 
1811  // Clear the forward seeds/adjoint sensitivities, ready for next bvec sweep
1812  std::fill(s_in.begin(), s_in.end(), 0);
1813 
1814  // Clear the adjoint seeds/forward sensitivities, ready for next bvec sweep
1815  std::fill(s_out.begin(), s_out.end(), 0);
1816 
1817  // Clean lookup table
1818  lookup_col.clear();
1819  lookup_row.clear();
1820  lookup_value.clear();
1821  }
1822 
1823  if (n_fine_blocks_max>fci_cap) {
1824  fci_offset += std::min(n_fine_blocks_max, fci_cap);
1825  bvec_i = 0;
1826  fci_cap = bvec_size;
1827  } else {
1828  f_finished = true;
1829  }
1830 
1831  }
1832 
1833  }
1834 
1835  // Swap results if adjoint mode was used
1836  if (use_fwd) {
1837  // Construct fine sparsity pattern
1838  r = Sparsity::triplet(fine_row.size()-1, fine_col.size()-1, jrow, jcol);
1839  coarse_col = fine_col;
1840  coarse_row = fine_row;
1841  } else {
1842  // Construct fine sparsity pattern
1843  r = Sparsity::triplet(fine_col.size()-1, fine_row.size()-1, jcol, jrow);
1844  coarse_col = fine_row;
1845  coarse_row = fine_col;
1846  }
1847  hasrun = true;
1848  }
1849  if (verbose_) {
1850  casadi_message("Number of sweeps: " + str(nsweeps));
1851  casadi_message("Formed Jacobian sparsity pattern (dimension " + str(r.size()) + ", " +
1852  str(r.nnz()) + " (" + str(r.density()) + " %) nonzeros.");
1853  }
1854 
1855  return r.T();
1856  }
static Matrix< casadi_int > triplet(const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< casadi_int > &d)
Construct a sparse matrix from triplet form.
static Sparsity dense(casadi_int nrow, casadi_int ncol=1)
Create a dense rectangular sparsity pattern *.
Definition: sparsity.cpp:1012
std::vector< casadi_int > range(casadi_int start, casadi_int stop, casadi_int step, casadi_int len)
Range function.
std::vector< casadi_int > lookupvector(const std::vector< casadi_int > &v, casadi_int size)
Returns a vector for quickly looking up entries of supplied list.
Matrix< casadi_int > IM
Definition: im_fwd.hpp:31
std::vector< T > diff(const std::vector< T > &values)
diff
bvec_t bvec_or(const bvec_t *arg, casadi_int n)
Bit-wise or operation on bvec_t array.
void bvec_toggle(bvec_t *s, casadi_int begin, casadi_int end, casadi_int j)

References casadi::bvec_or(), casadi::bvec_size, casadi::bvec_toggle(), casadi::Sparsity::colind(), casadi::D, casadi::Sparsity::dense(), casadi::Sparsity::density(), casadi::diff(), casadi::Sparsity::dim(), casadi::Sparsity::get_nz(), casadi::get_ptr(), casadi::lookupvector(), casadi::ProtoFunction::memory(), casadi::Sparsity::nnz(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::nz_in(), casadi::FunctionInternal::nz_out(), casadi::range(), casadi::Sparsity::row(), casadi::Sparsity::size(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::FunctionInternal::sp_weight(), casadi::Matrix< Scalar >::sparsity(), casadi::str(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), casadi::Sparsity::T(), casadi::Sparsity::triplet(), casadi::Matrix< casadi_int >::triplet(), casadi::Sparsity::uni_coloring(), and casadi::ProtoFunction::verbose_.

Referenced by casadi::FunctionInternal::get_jac_sparsity().

◆ get_jac_sparsity_hierarchical_symm()

Sparsity casadi::FunctionInternal::get_jac_sparsity_hierarchical_symm ( casadi_int  oind,
casadi_int  iind 
) const
inherited

A flavor of get_jac_sparsity_gen that does hierarchical block structure recognition for symmetric Jacobians

Definition at line 1321 of file function_internal.cpp.

1322  {
1323  casadi_assert_dev(has_spfwd());
1324 
1325  // Number of nonzero inputs
1326  casadi_int nz = nnz_in(iind);
1327  casadi_assert_dev(nz==nnz_out(oind));
1328 
1329  // Evaluation buffers
1330  std::vector<const bvec_t*> arg(sz_arg(), nullptr);
1331  std::vector<bvec_t*> res(sz_res(), nullptr);
1332  std::vector<casadi_int> iw(sz_iw());
1333  std::vector<bvec_t> w(sz_w());
1334 
1335  // Seeds
1336  std::vector<bvec_t> seed(nz, 0);
1337  arg[iind] = get_ptr(seed);
1338 
1339  // Sensitivities
1340  std::vector<bvec_t> sens(nz, 0);
1341  res[oind] = get_ptr(sens);
1342 
1343  // Sparsity triplet accumulator
1344  std::vector<casadi_int> jcol, jrow;
1345 
1346  // Cols/rows of the coarse blocks
1347  std::vector<casadi_int> coarse(2, 0); coarse[1] = nz;
1348 
1349  // Cols/rows of the fine blocks
1350  std::vector<casadi_int> fine;
1351 
1352  // In each iteration, subdivide each coarse block in this many fine blocks
1353  casadi_int subdivision = bvec_size;
1354 
1355  Sparsity r = Sparsity::dense(1, 1);
1356 
1357  // The size of a block
1358  casadi_int granularity = nz;
1359 
1360  casadi_int nsweeps = 0;
1361 
1362  bool hasrun = false;
1363 
1364  while (!hasrun || coarse.size()!=nz+1) {
1365  if (verbose_) casadi_message("Block size: " + str(granularity));
1366 
1367  // Clear the sparsity triplet acccumulator
1368  jcol.clear();
1369  jrow.clear();
1370 
1371  // Clear the fine block structure
1372  fine.clear();
1373 
1374  Sparsity D = r.star_coloring();
1375 
1376  if (verbose_) {
1377  casadi_message("Star coloring on " + str(r.dim()) + ": "
1378  + str(D.size2()) + " <-> " + str(D.size1()));
1379  }
1380 
1381  // Clear the seeds
1382  std::fill(seed.begin(), seed.end(), 0);
1383 
1384  // Subdivide the coarse block
1385  for (casadi_int k=0; k<coarse.size()-1; ++k) {
1386  casadi_int diff = coarse[k+1]-coarse[k];
1387  casadi_int new_diff = diff/subdivision;
1388  if (diff%subdivision>0) new_diff++;
1389  std::vector<casadi_int> temp = range(coarse[k], coarse[k+1], new_diff);
1390  fine.insert(fine.end(), temp.begin(), temp.end());
1391  }
1392  if (fine.back()!=coarse.back()) fine.push_back(coarse.back());
1393 
1394  granularity = fine[1] - fine[0];
1395 
1396  // The index into the bvec bit vector
1397  casadi_int bvec_i = 0;
1398 
1399  // Create lookup tables for the fine blocks
1400  std::vector<casadi_int> fine_lookup = lookupvector(fine, nz+1);
1401 
1402  // Triplet data used as a lookup table
1403  std::vector<casadi_int> lookup_col;
1404  std::vector<casadi_int> lookup_row;
1405  std::vector<casadi_int> lookup_value;
1406 
1407  // The maximum number of fine blocks contained in one coarse block
1408  casadi_int n_fine_blocks_max = 0;
1409  for (casadi_int i=0;i<coarse.size()-1;++i) {
1410  casadi_int del = fine_lookup[coarse[i+1]]-fine_lookup[coarse[i]];
1411  n_fine_blocks_max = std::max(n_fine_blocks_max, del);
1412  }
1413 
1414  // Loop over all coarse seed directions from the coloring
1415  for (casadi_int csd=0; csd<D.size2(); ++csd) {
1416 
1417 
1418  casadi_int fci_offset = 0;
1419  casadi_int fci_cap = bvec_size-bvec_i;
1420 
1421  // Flag to indicate if all fine blocks have been handled
1422  bool f_finished = false;
1423 
1424  // Loop while not finished
1425  while (!f_finished) {
1426 
1427  // Loop over all coarse rows that are found in the coloring for this coarse seed direction
1428  for (casadi_int k=D.colind(csd); k<D.colind(csd+1); ++k) {
1429  casadi_int cci = D.row(k);
1430 
1431  // The first and last rows of the fine block
1432  casadi_int fci_start = fine_lookup[coarse[cci]];
1433  casadi_int fci_end = fine_lookup[coarse[cci+1]];
1434 
1435  // Local counter that modifies index into bvec
1436  casadi_int bvec_i_mod = 0;
1437 
1438  casadi_int value = -bvec_i + fci_offset + fci_start;
1439 
1440  //casadi_assert_dev(value>=0);
1441 
1442  // Loop over the rows of the fine block
1443  for (casadi_int fci = fci_offset; fci<std::min(fci_end-fci_start, fci_cap); ++fci) {
1444 
1445  // Loop over the coarse block cols that appear in the
1446  // coloring for the current coarse seed direction
1447  for (casadi_int cri=r.colind(cci);cri<r.colind(cci+1);++cri) {
1448  lookup_col.push_back(r.row(cri));
1449  lookup_row.push_back(bvec_i+bvec_i_mod);
1450  lookup_value.push_back(value);
1451  }
1452 
1453  // Toggle on seeds
1454  bvec_toggle(get_ptr(seed), fine[fci+fci_start], fine[fci+fci_start+1],
1455  bvec_i+bvec_i_mod);
1456  bvec_i_mod++;
1457  }
1458  }
1459 
1460  // Bump bvec_i for next major coarse direction
1461  bvec_i += std::min(n_fine_blocks_max, fci_cap);
1462 
1463  // Check if bvec buffer is full
1464  if (bvec_i==bvec_size || csd==D.size2()-1) {
1465  // Calculate sparsity for bvec_size directions at once
1466 
1467  // Statistics
1468  nsweeps+=1;
1469 
1470  // Construct lookup table
1471  IM lookup = IM::triplet(lookup_row, lookup_col, lookup_value,
1472  bvec_size, coarse.size());
1473 
1474  std::reverse(lookup_col.begin(), lookup_col.end());
1475  std::reverse(lookup_row.begin(), lookup_row.end());
1476  std::reverse(lookup_value.begin(), lookup_value.end());
1477  IM duplicates =
1478  IM::triplet(lookup_row, lookup_col, lookup_value, bvec_size, coarse.size())
1479  - lookup;
1480  duplicates = sparsify(duplicates);
1481  lookup(duplicates.sparsity()) = -bvec_size;
1482 
1483  // Propagate the dependencies
1484  JacSparsityTraits<true>::sp(this, get_ptr(arg), get_ptr(res),
1485  get_ptr(iw), get_ptr(w), nullptr);
1486 
1487  // Temporary bit work vector
1488  bvec_t spsens;
1489 
1490  // Loop over the cols of coarse blocks
1491  for (casadi_int cri=0; cri<coarse.size()-1; ++cri) {
1492 
1493  // Loop over the cols of fine blocks within the current coarse block
1494  for (casadi_int fri=fine_lookup[coarse[cri]];fri<fine_lookup[coarse[cri+1]];++fri) {
1495  // Lump individual sensitivities together into fine block
1496  bvec_or(get_ptr(sens), spsens, fine[fri], fine[fri+1]);
1497 
1498  // Loop over all bvec_bits
1499  for (casadi_int bvec_i=0;bvec_i<bvec_size;++bvec_i) {
1500  if (spsens & (bvec_t(1) << bvec_i)) {
1501  // if dependency is found, add it to the new sparsity pattern
1502  casadi_int ind = lookup.sparsity().get_nz(bvec_i, cri);
1503  if (ind==-1) continue;
1504  casadi_int lk = lookup->at(ind);
1505  if (lk>-bvec_size) {
1506  jrow.push_back(bvec_i+lk);
1507  jcol.push_back(fri);
1508  jrow.push_back(fri);
1509  jcol.push_back(bvec_i+lk);
1510  }
1511  }
1512  }
1513  }
1514  }
1515 
1516  // Clear the forward seeds/adjoint sensitivities, ready for next bvec sweep
1517  std::fill(seed.begin(), seed.end(), 0);
1518 
1519  // Clean lookup table
1520  lookup_col.clear();
1521  lookup_row.clear();
1522  lookup_value.clear();
1523  }
1524 
1525  if (n_fine_blocks_max>fci_cap) {
1526  fci_offset += std::min(n_fine_blocks_max, fci_cap);
1527  bvec_i = 0;
1528  fci_cap = bvec_size;
1529  } else {
1530  f_finished = true;
1531  }
1532  }
1533  }
1534 
1535  // Construct fine sparsity pattern
1536  r = Sparsity::triplet(fine.size()-1, fine.size()-1, jrow, jcol);
1537 
1538  // There may be false positives here that are not present
1539  // in the reverse mode that precedes it.
1540  // This can lead to an assymetrical result
1541  // cf. #1522
1542  r=r*r.T();
1543 
1544  coarse = fine;
1545  hasrun = true;
1546  }
1547  if (verbose_) {
1548  casadi_message("Number of sweeps: " + str(nsweeps));
1549  casadi_message("Formed Jacobian sparsity pattern (dimension " + str(r.size()) +
1550  ", " + str(r.nnz()) + " (" + str(r.density()) + " %) nonzeros.");
1551  }
1552 
1553  return r.T();
1554  }

References casadi::bvec_or(), casadi::bvec_size, casadi::bvec_toggle(), casadi::Sparsity::colind(), casadi::D, casadi::Sparsity::dense(), casadi::Sparsity::density(), casadi::diff(), casadi::Sparsity::dim(), casadi::Sparsity::get_nz(), casadi::get_ptr(), casadi::FunctionInternal::has_spfwd(), casadi::lookupvector(), casadi::Sparsity::nnz(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::range(), casadi::Sparsity::row(), casadi::Sparsity::size(), casadi::Matrix< Scalar >::sparsity(), casadi::Sparsity::star_coloring(), casadi::str(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), casadi::Sparsity::T(), casadi::Sparsity::triplet(), casadi::Matrix< casadi_int >::triplet(), and casadi::ProtoFunction::verbose_.

Referenced by casadi::FunctionInternal::get_jac_sparsity().

◆ get_jacobian()

Function casadi::FunctionInternal::get_jacobian ( const std::string &  name,
const std::vector< std::string > &  inames,
const std::vector< std::string > &  onames,
const Dict opts 
) const
virtualinherited

◆ get_max_in()

virtual double casadi::FunctionInternal::get_max_in ( casadi_int  ind) const
inlinevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mm

Definition at line 1070 of file function_internal.hpp.

1070  {
1071  return inf;
1072  }

References casadi::inf.

◆ get_min_in()

virtual double casadi::FunctionInternal::get_min_in ( casadi_int  ind) const
inlinevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mn

Definition at line 1077 of file function_internal.hpp.

1077  {
1078  return -inf;
1079  }

References casadi::inf.

◆ get_n_in()

size_t casadi::Nlpsol::get_n_in ( )
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1np

Reimplemented from casadi::FunctionInternal.

Definition at line 145 of file nlpsol_impl.hpp.

145 { return NLPSOL_NUM_IN;}

References casadi::NLPSOL_NUM_IN.

◆ get_n_out()

size_t casadi::Nlpsol::get_n_out ( )
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1np

Reimplemented from casadi::FunctionInternal.

Definition at line 146 of file nlpsol_impl.hpp.

146 { return NLPSOL_NUM_OUT;}

References casadi::NLPSOL_NUM_OUT.

◆ get_name_in()

std::string casadi::Nlpsol::get_name_in ( casadi_int  i)
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1nr

Reimplemented from casadi::FunctionInternal.

Definition at line 161 of file nlpsol_impl.hpp.

161 { return nlpsol_in(i);}
std::vector< std::string > nlpsol_in()
Get input scheme of NLP solvers.
Definition: nlpsol.cpp:200

References casadi::nlpsol_in().

◆ get_name_out()

std::string casadi::Nlpsol::get_name_out ( casadi_int  i)
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1nr

Reimplemented from casadi::FunctionInternal.

Definition at line 162 of file nlpsol_impl.hpp.

162 { return nlpsol_out(i);}
std::vector< std::string > nlpsol_out()
Get NLP solver output scheme of NLP solvers.
Definition: nlpsol.cpp:206

References casadi::nlpsol_out().

◆ get_nominal_in()

virtual std::vector<double> casadi::FunctionInternal::get_nominal_in ( casadi_int  ind) const
inlinevirtualinherited

Reimplemented in casadi::FmuFunction.

Definition at line 1081 of file function_internal.hpp.

1081  {
1082  return std::vector<double>(nnz_in(ind), 1.);
1083  }

Referenced by casadi::FmuFunction::get_nominal_in().

◆ get_nominal_out()

virtual std::vector<double> casadi::FunctionInternal::get_nominal_out ( casadi_int  ind) const
inlinevirtualinherited

Reimplemented in casadi::FmuFunction.

Definition at line 1085 of file function_internal.hpp.

1085  {
1086  return std::vector<double>(nnz_out(ind), 1.);
1087  }

Referenced by casadi::FmuFunction::get_nominal_out().

◆ get_options()

const Options& casadi::Feasiblesqpmethod::get_options ( ) const
inlineoverridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 84 of file feasiblesqpmethod.hpp.

84 { return options_;}
static const Options options_
Options.

◆ get_partition()

void casadi::FunctionInternal::get_partition ( casadi_int  iind,
casadi_int  oind,
Sparsity D1,
Sparsity D2,
bool  compact,
bool  symmetric,
bool  allow_forward,
bool  allow_reverse 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_md

Definition at line 2011 of file function_internal.cpp.

2013  {
2014  if (verbose_) casadi_message(name_ + "::get_partition");
2015  casadi_assert(allow_forward || allow_reverse, "Inconsistent options");
2016 
2017  // Sparsity pattern with transpose
2018  Sparsity &AT = jac_sparsity(oind, iind, compact, symmetric);
2019  Sparsity A = symmetric ? AT : AT.T();
2020 
2021  // Get seed matrices by graph coloring
2022  if (symmetric) {
2023  casadi_assert_dev(enable_forward_ || enable_fd_);
2024  casadi_assert_dev(allow_forward);
2025 
2026  // Star coloring if symmetric
2027  if (verbose_) casadi_message("FunctionInternal::getPartition star_coloring");
2028  D1 = A.star_coloring();
2029  if (verbose_) {
2030  casadi_message("Star coloring completed: " + str(D1.size2())
2031  + " directional derivatives needed ("
2032  + str(A.size1()) + " without coloring).");
2033  }
2034 
2035  } else {
2036  casadi_assert_dev(enable_forward_ || enable_fd_ || enable_reverse_);
2037  // Get weighting factor
2038  double w = ad_weight();
2039 
2040  // Which AD mode?
2041  if (w==1) allow_forward = false;
2042  if (w==0) allow_reverse = false;
2043  casadi_assert(allow_forward || allow_reverse, "Conflicting ad weights");
2044 
2045  // Best coloring encountered so far (relatively tight upper bound)
2046  double best_coloring = std::numeric_limits<double>::infinity();
2047 
2048  // Test forward mode first?
2049  bool test_fwd_first = allow_forward && w*static_cast<double>(A.size1()) <=
2050  (1-w)*static_cast<double>(A.size2());
2051  casadi_int mode_fwd = test_fwd_first ? 0 : 1;
2052 
2053  // Test both coloring modes
2054  for (casadi_int mode=0; mode<2; ++mode) {
2055  // Is this the forward mode?
2056  bool fwd = mode==mode_fwd;
2057 
2058  // Skip?
2059  if (!allow_forward && fwd) continue;
2060  if (!allow_reverse && !fwd) continue;
2061 
2062  // Perform the coloring
2063  if (fwd) {
2064  if (verbose_) casadi_message("Unidirectional coloring (forward mode)");
2065  bool d = best_coloring>=w*static_cast<double>(A.size1());
2066  casadi_int max_colorings_to_test =
2067  d ? A.size1() : static_cast<casadi_int>(floor(best_coloring/w));
2068  D1 = AT.uni_coloring(A, max_colorings_to_test);
2069  if (D1.is_null()) {
2070  if (verbose_) {
2071  casadi_message("Forward mode coloring interrupted (more than "
2072  + str(max_colorings_to_test) + " needed).");
2073  }
2074  } else {
2075  if (verbose_) {
2076  casadi_message("Forward mode coloring completed: "
2077  + str(D1.size2()) + " directional derivatives needed ("
2078  + str(A.size1()) + " without coloring).");
2079  }
2080  D2 = Sparsity();
2081  best_coloring = w*static_cast<double>(D1.size2());
2082  }
2083  } else {
2084  if (verbose_) casadi_message("Unidirectional coloring (adjoint mode)");
2085  bool d = best_coloring>=(1-w)*static_cast<double>(A.size2());
2086  casadi_int max_colorings_to_test =
2087  d ? A.size2() : static_cast<casadi_int>(floor(best_coloring/(1-w)));
2088 
2089  D2 = A.uni_coloring(AT, max_colorings_to_test);
2090  if (D2.is_null()) {
2091  if (verbose_) {
2092  casadi_message("Adjoint mode coloring interrupted (more than "
2093  + str(max_colorings_to_test) + " needed).");
2094  }
2095  } else {
2096  if (verbose_) {
2097  casadi_message("Adjoint mode coloring completed: "
2098  + str(D2.size2()) + " directional derivatives needed ("
2099  + str(A.size2()) + " without coloring).");
2100  }
2101  D1 = Sparsity();
2102  best_coloring = (1-w)*static_cast<double>(D2.size2());
2103  }
2104  }
2105  }
2106 
2107  }
2108  }
Sparsity & jac_sparsity(casadi_int oind, casadi_int iind, bool compact, bool symmetric) const
Get Jacobian sparsity.

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::enable_reverse_, casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::jac_sparsity(), casadi::ProtoFunction::name_, casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::Sparsity::star_coloring(), casadi::str(), casadi::Sparsity::T(), casadi::Sparsity::uni_coloring(), and casadi::ProtoFunction::verbose_.

◆ get_reltol()

virtual double casadi::FunctionInternal::get_reltol ( ) const
inlinevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mo

Reimplemented in casadi::SundialsInterface.

Definition at line 1092 of file function_internal.hpp.

1092  {
1093  return eps;
1094  }

References casadi::eps.

Referenced by casadi::FiniteDiff::init().

◆ get_reverse()

Function casadi::Nlpsol::get_reverse ( casadi_int  nadj,
const std::string &  name,
const std::vector< std::string > &  inames,
const std::vector< std::string > &  onames,
const Dict opts 
) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1o3

Reimplemented from casadi::FunctionInternal.

Definition at line 999 of file nlpsol.cpp.

1003  {
1004  casadi_assert(detect_simple_bounds_is_simple_.empty(),
1005  "Simple bound detection not compatible with get_reverse");
1006 
1007  // Symbolic expression for the input
1008  std::vector<MX> arg = mx_in(), res = mx_out();
1009 
1010  // Initial guesses not used for derivative calculations
1012  std::string name = arg[i].is_symbolic() ? arg[i].name() : "tmp_get_reverse";
1013  arg[i] = MX::sym(name, Sparsity(arg[i].size()));
1014  }
1015 
1016  // Optimal solution
1017  MX x = res[NLPSOL_X];
1018  MX lam_g = res[NLPSOL_LAM_G];
1019  MX lam_x = res[NLPSOL_LAM_X];
1020  MX lam_p = res[NLPSOL_LAM_P];
1021  MX f = res[NLPSOL_F];
1022  MX g = res[NLPSOL_G];
1023 
1024  // Inputs used
1025  MX lbx = arg[NLPSOL_LBX];
1026  MX ubx = arg[NLPSOL_UBX];
1027  MX lbg = arg[NLPSOL_LBG];
1028  MX ubg = arg[NLPSOL_UBG];
1029  MX p = arg[NLPSOL_P];
1030 
1031  // Get KKT function
1032  Function kkt = this->kkt();
1033 
1034  // Hessian of the Lagrangian, Jacobian of the constraints
1035  std::vector<MX> HJ_res = kkt({x, p, 1, lam_g});
1036  MX JG = HJ_res.at(0);
1037  MX HL = HJ_res.at(1);
1038 
1039  // Active set (assumed known and given by the multiplier signs)
1040  MX ubIx = lam_x > min_lam_;
1041  MX lbIx = lam_x < -min_lam_;
1042  MX bIx = ubIx + lbIx;
1043  MX iIx = 1-bIx;
1044  MX ubIg = lam_g > min_lam_;
1045  MX lbIg = lam_g < -min_lam_;
1046  MX bIg = ubIg + lbIg;
1047  MX iIg = 1-bIg;
1048 
1049  // KKT matrix
1050  MX H_11 = mtimes(diag(iIx), HL) + diag(bIx);
1051  MX H_12 = mtimes(diag(iIx), JG.T());
1052  MX H_21 = mtimes(diag(bIg), JG);
1053  MX H_22 = diag(-iIg);
1054  MX H = MX::blockcat({{H_11, H_12}, {H_21, H_22}});
1055 
1056  // Sensitivity inputs
1057  std::vector<MX> aseed(NLPSOL_NUM_OUT);
1058  MX adj_x = aseed[NLPSOL_X] = MX::sym("adj_x", repmat(x.sparsity(), 1, nadj));
1059  MX adj_lam_g = aseed[NLPSOL_LAM_G] = MX::sym("adj_lam_g", repmat(g.sparsity(), 1, nadj));
1060  MX adj_lam_x = aseed[NLPSOL_LAM_X] = MX::sym("adj_lam_x", repmat(x.sparsity(), 1, nadj));
1061  MX adj_lam_p = aseed[NLPSOL_LAM_P] = MX::sym("adj_lam_p", repmat(p.sparsity(), 1, nadj));
1062  MX adj_f = aseed[NLPSOL_F] = MX::sym("adj_f", Sparsity::dense(1, nadj));
1063  MX adj_g = aseed[NLPSOL_G] = MX::sym("adj_g", repmat(g.sparsity(), 1, nadj));
1064 
1065  // nlp_grad has the signature
1066  // (x, p, lam_f, lam_g) -> (f, g, grad_x, grad_p)
1067  // with lam_f=1 and lam_g=lam_g, grad_x = -lam_x, grad_p=-lam_p
1068  Function nlp_grad = get_function("nlp_grad");
1069 
1070  // rev_nlp_grad has the signature
1071  // (x, p, lam_f, lam_g, f, g, grad_x, grad_p,
1072  // adj_f, adj_g, adj_grad_x, adj_grad_p)
1073  // -> (adj_x, adj_p, adj_lam_f, adj_lam_g)
1074  Function rev_nlp_grad = nlp_grad.reverse(nadj);
1075 
1076  // Calculate sensitivities from f, g and lam_x
1077  std::vector<MX> vv = {x, p, 1, lam_g, f, g, -lam_x, -lam_p,
1078  adj_f, adj_g, -adj_lam_x, -adj_lam_p};
1079  vv = rev_nlp_grad(vv);
1080  MX adj_x0 = vv.at(0);
1081  MX adj_p0 = vv.at(1);
1082  MX adj_lam_g0 = vv.at(3);
1083 
1084  // Solve to get beta_x_bar, beta_g_bar
1085  MX v = MX::vertcat({adj_x + adj_x0, adj_lam_g + adj_lam_g0});
1087  std::vector<MX> v_split = vertsplit(v, {0, nx_, nx_+ng_});
1088  MX beta_x_bar = v_split.at(0);
1089  MX beta_g_bar = v_split.at(1);
1090 
1091  // Calculate sensitivities in p
1092  vv = {x, p, 1, lam_g, f, g, -lam_x, -lam_p,
1093  0, bIg*beta_g_bar, iIx*beta_x_bar, 0};
1094  vv = rev_nlp_grad(vv);
1095  MX adj_p = vv.at(1);
1096 
1097  // Reverse sensitivities
1098  std::vector<MX> asens(NLPSOL_NUM_IN);
1099  asens[NLPSOL_UBX] = if_else(ubIx, beta_x_bar, 0);
1100  asens[NLPSOL_LBX] = if_else(lbIx, beta_x_bar, 0);
1101  asens[NLPSOL_UBG] = if_else(ubIg, beta_g_bar, 0);
1102  asens[NLPSOL_LBG] = if_else(lbIg, beta_g_bar, 0);
1103  asens[NLPSOL_P] = adj_p0 - adj_p;
1104 
1105  // Guesses are unused
1107  asens[i] = MX(repmat(Sparsity(arg[i].size()), 1, nadj));
1108  }
1109 
1110  // Gather return values
1111  arg.insert(arg.end(), res.begin(), res.end());
1112  arg.insert(arg.end(), aseed.begin(), aseed.end());
1113  res = asens;
1114 
1115  Dict options = opts;
1116  options["allow_duplicate_io_names"] = true;
1117 
1118  return Function(name, arg, res, inames, onames, options);
1119  }

References casadi::MX::blockcat(), casadi::Sparsity::dense(), casadi::Nlpsol::detect_simple_bounds_is_simple_, casadi::FunctionInternal::Function, casadi::OracleFunction::get_function(), casadi::if_else(), casadi::Nlpsol::kkt(), casadi::Nlpsol::min_lam_, casadi::FunctionInternal::mx_in(), casadi::FunctionInternal::mx_out(), casadi::Nlpsol::ng_, casadi::NLPSOL_F, casadi::NLPSOL_G, casadi::NLPSOL_LAM_G, casadi::NLPSOL_LAM_G0, casadi::NLPSOL_LAM_P, casadi::NLPSOL_LAM_X, casadi::NLPSOL_LAM_X0, casadi::NLPSOL_LBG, casadi::NLPSOL_LBX, casadi::NLPSOL_NUM_IN, casadi::NLPSOL_NUM_OUT, casadi::NLPSOL_P, casadi::NLPSOL_UBG, casadi::NLPSOL_UBX, casadi::NLPSOL_X, casadi::NLPSOL_X0, casadi::Nlpsol::nx_, casadi::Function::reverse(), casadi::Nlpsol::sens_linsol_, casadi::Nlpsol::sens_linsol_options_, casadi::MX::solve(), casadi::MX::sparsity(), casadi::GenericMatrix< MX >::sym(), casadi::MX::T(), and casadi::MX::vertcat().

◆ get_sparsity_in()

Sparsity casadi::Nlpsol::get_sparsity_in ( casadi_int  i)
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1nq

Reimplemented from casadi::FunctionInternal.

Definition at line 294 of file nlpsol.cpp.

294  {
295  switch (static_cast<NlpsolInput>(i)) {
296  case NLPSOL_X0:
297  case NLPSOL_LBX:
298  case NLPSOL_UBX:
299  case NLPSOL_LAM_X0:
300  return get_sparsity_out(NLPSOL_X);
301  case NLPSOL_LBG:
302  case NLPSOL_UBG:
303  case NLPSOL_LAM_G0:
304  return get_sparsity_out(NLPSOL_G);
305  case NLPSOL_P:
306  return oracle_.sparsity_in(NL_P);
307  case NLPSOL_NUM_IN: break;
308  }
309  return Sparsity();
310  }
const Sparsity & sparsity_in(casadi_int ind) const
Get sparsity of a given input.
Definition: function.cpp:1015
Sparsity get_sparsity_out(casadi_int i) override
Sparsities of function inputs and outputs.
Definition: nlpsol.cpp:312

References casadi::Nlpsol::get_sparsity_out(), casadi::NL_P, casadi::NLPSOL_G, casadi::NLPSOL_LAM_G0, casadi::NLPSOL_LAM_X0, casadi::NLPSOL_LBG, casadi::NLPSOL_LBX, casadi::NLPSOL_NUM_IN, casadi::NLPSOL_P, casadi::NLPSOL_UBG, casadi::NLPSOL_UBX, casadi::NLPSOL_X, casadi::NLPSOL_X0, casadi::OracleFunction::oracle_, and casadi::Function::sparsity_in().

Referenced by casadi::Nlpsol::get_sparsity_out().

◆ get_sparsity_out()

Sparsity casadi::Nlpsol::get_sparsity_out ( casadi_int  i)
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1nq

Reimplemented from casadi::FunctionInternal.

Definition at line 312 of file nlpsol.cpp.

312  {
313  switch (static_cast<NlpsolOutput>(i)) {
314  case NLPSOL_F:
315  return oracle_.sparsity_out(NL_F);
316  case NLPSOL_X:
317  case NLPSOL_LAM_X:
318  return oracle_.sparsity_in(NL_X);
319  case NLPSOL_LAM_G:
320  case NLPSOL_G:
321  if (detect_simple_bounds_is_simple_.empty()) {
322  return oracle_.sparsity_out(NL_G);
323  } else {
325  }
326  case NLPSOL_LAM_P:
327  return get_sparsity_in(NLPSOL_P);
328  case NLPSOL_NUM_OUT: break;
329  }
330  return Sparsity();
331  }
const Sparsity & sparsity_out(casadi_int ind) const
Get sparsity of a given output.
Definition: function.cpp:1031
Sparsity get_sparsity_in(casadi_int i) override
Sparsities of function inputs and outputs.
Definition: nlpsol.cpp:294
NlpsolOutput
Output arguments of an NLP Solver.
Definition: nlpsol.hpp:215

References casadi::Sparsity::dense(), casadi::Nlpsol::detect_simple_bounds_is_simple_, casadi::Nlpsol::get_sparsity_in(), casadi::NL_F, casadi::NL_G, casadi::NL_X, casadi::NLPSOL_F, casadi::NLPSOL_G, casadi::NLPSOL_LAM_G, casadi::NLPSOL_LAM_P, casadi::NLPSOL_LAM_X, casadi::NLPSOL_NUM_OUT, casadi::NLPSOL_P, casadi::NLPSOL_X, casadi::OracleFunction::oracle_, casadi::Function::sparsity_in(), and casadi::Function::sparsity_out().

Referenced by casadi::Nlpsol::get_sparsity_in().

◆ get_stats()

Dict casadi::Feasiblesqpmethod::get_stats ( void *  mem) const
overridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 2332 of file feasiblesqpmethod.cpp.

2332  {
2333  Dict stats = Nlpsol::get_stats(mem);
2334  auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
2335  stats["return_status"] = m->return_status;
2336  stats["iter_count"] = m->iter_count;
2337  return stats;
2338  }
Dict get_stats(void *mem) const override
Get all statistics.
Definition: nlpsol.cpp:1162

References casadi::Nlpsol::get_stats(), and casadi::FeasiblesqpmethodMemory::return_status.

◆ getAdaptorSolverName()

virtual std::string casadi::FunctionInternal::getAdaptorSolverName ( ) const
inlinevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_k3

Definition at line 304 of file function_internal.hpp.

304 { return ""; }

◆ getConic()

const Function casadi::Feasiblesqpmethod::getConic ( ) const
inline

Definition at line 213 of file feasiblesqpmethod.hpp.

213 { return qpsol_;}

◆ getCount()

Definition at line 60 of file generic_shared_internal.hpp.

186  {
187  return static_cast<const Internal*>(this)->count;
188  }

◆ getPlugin()

PluginInterface< Nlpsol >::Plugin & casadi::PluginInterface< Nlpsol >::getPlugin ( const std::string &  pname)
staticinherited

Definition at line 102 of file plugin_interface.hpp.

291  {
292 
293 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
294  std::lock_guard<std::mutex> lock(Derived::mutex_solvers_);
295 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
296 
297  // Check if the solver has been loaded
298  auto it=Derived::solvers_.find(pname);
299 
300  // Load the solver if needed
301  if (it==Derived::solvers_.end()) {
302  load_plugin(pname, true, false);
303  it=Derived::solvers_.find(pname);
304  }
305  casadi_assert_dev(it!=Derived::solvers_.end());
306  return it->second;
307  }
static Plugin load_plugin(const std::string &pname, bool register_plugin=true, bool needs_lock=true)
Load a plugin dynamically.

◆ getReducedHessian()

DM casadi::Nlpsol::getReducedHessian ( )
virtualinherited

Definition at line 669 of file nlpsol.cpp.

669  {
670  casadi_error("getReducedHessian not defined for class " + class_name());
671  return DM();
672  }
std::string class_name() const override
Get type name.
Matrix< double > DM
Definition: dm_fwd.hpp:33

References casadi::Nlpsol::class_name().

◆ has_codegen()

virtual bool casadi::FunctionInternal::has_codegen ( ) const
inlinevirtualinherited

◆ has_derivative()

bool casadi::FunctionInternal::has_derivative ( ) const
inherited

◆ has_eval_dm()

virtual bool casadi::FunctionInternal::has_eval_dm ( ) const
inlinevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ke

Reimplemented in casadi::CallbackInternal.

Definition at line 424 of file function_internal.hpp.

424 { return false;}

Referenced by casadi::FunctionInternal::eval().

◆ has_forward()

bool casadi::Nlpsol::has_forward ( casadi_int  nfwd) const
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1o2

Reimplemented from casadi::FunctionInternal.

Definition at line 248 of file nlpsol_impl.hpp.

248 { return true;}

◆ has_free()

virtual bool casadi::FunctionInternal::has_free ( ) const
inlinevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l8

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 743 of file function_internal.hpp.

743 { return false;}

Referenced by casadi::FunctionInternal::get_free().

◆ has_function()

bool casadi::OracleFunction::has_function ( const std::string &  fname) const
overridevirtualinherited

◆ has_jac_sparsity()

virtual bool casadi::FunctionInternal::has_jac_sparsity ( casadi_int  oind,
casadi_int  iind 
) const
inlinevirtualinherited

◆ has_jacobian()

virtual bool casadi::FunctionInternal::has_jacobian ( ) const
inlinevirtualinherited

◆ has_memory()

bool casadi::ProtoFunction::has_memory ( int  ind) const
inherited

Definition at line 3665 of file function_internal.cpp.

3665  {
3666  return ind<mem_.size();
3667  }

◆ has_option()

bool casadi::ProtoFunction::has_option ( const std::string &  option_name) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_jj

Definition at line 1004 of file function_internal.cpp.

1004  {
1005  return get_options().find(option_name) != 0;
1006  }
const Options::Entry * find(const std::string &name) const
Definition: options.cpp:32

References casadi::Options::find(), and casadi::ProtoFunction::get_options().

◆ has_plugin()

bool casadi::PluginInterface< Nlpsol >::has_plugin ( const std::string &  pname,
bool  verbose = false 
)
staticinherited

Definition at line 76 of file plugin_interface.hpp.

131  {
132 
133 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
134  std::lock_guard<std::mutex> lock(Derived::mutex_solvers_);
135 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
136 
137  // Quick return if available
138  if (Derived::solvers_.find(pname) != Derived::solvers_.end()) {
139  return true;
140  }
141 
142  // Try loading the plugin
143  try {
144  (void)load_plugin(pname, false, false);
145  return true;
146  } catch (CasadiException& ex) {
147  if (verbose) {
148  casadi_warning(ex.what());
149  }
150  return false;
151  }
152  }
std::vector< casadi_int > find(const std::vector< T > &v)
find nonzeros

◆ has_reverse()

bool casadi::Nlpsol::has_reverse ( casadi_int  nadj) const
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1o3

Reimplemented from casadi::FunctionInternal.

Definition at line 259 of file nlpsol_impl.hpp.

259 { return true;}

◆ has_spfwd()

virtual bool casadi::FunctionInternal::has_spfwd ( ) const
inlinevirtualinherited

◆ has_sprev()

virtual bool casadi::FunctionInternal::has_sprev ( ) const
inlinevirtualinherited

◆ incache()

bool casadi::FunctionInternal::incache ( const std::string &  fname,
Function f,
const std::string &  suffix = "" 
) const
inherited

◆ index_in()

casadi_int casadi::FunctionInternal::index_in ( const std::string &  name) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mu

Definition at line 1126 of file function_internal.hpp.

1126  {
1127  for (casadi_int i=0; i<name_in_.size(); ++i) {
1128  if (name_in_[i]==name) return i;
1129  }
1130  casadi_error("FunctionInternal::index_in: could not find entry \""
1131  + name + "\". Available names are: " + str(name_in_) + ".");
1132  return -1;
1133  }

References casadi::str().

Referenced by casadi::FunctionInternal::convert_arg().

◆ index_out()

casadi_int casadi::FunctionInternal::index_out ( const std::string &  name) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mv

Definition at line 1138 of file function_internal.hpp.

1138  {
1139  for (casadi_int i=0; i<name_out_.size(); ++i) {
1140  if (name_out_[i]==name) return i;
1141  }
1142  casadi_error("FunctionInternal::index_out: could not find entry \""
1143  + name + "\". Available names are: " + str(name_out_) + ".");
1144  return -1;
1145  }

References casadi::str().

Referenced by casadi::FunctionInternal::convert_res().

◆ info()

Dict casadi::FunctionInternal::info ( ) const
virtualinherited

◆ init()

void casadi::Feasiblesqpmethod::init ( const Dict opts)
overridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 197 of file feasiblesqpmethod.cpp.

197  {
198  // Call the init method of the base class
199  Nlpsol::init(opts);
200 
201  // Default options
202  min_iter_ = 0;
203  max_iter_ = 50;
204  lbfgs_memory_ = 10;
205  tol_pr_ = 1e-6;
206  tol_du_ = 1e-6;
207  std::string hessian_approximation = "exact";
208  // min_step_size_ = 1e-10;
209  std::string solve_type = "SQP";
210  std::string qpsol_plugin = "qpoases";
211  Dict qpsol_options;
212  print_header_ = true;
213  print_iteration_ = true;
214  print_status_ = true;
215  // so_corr_ = false;
216  init_feasible_ = false;
217 
218  // parameters and options for FP-SQP solver
219  optim_tol_ = 1e-8;
220  feas_tol_ = 1e-8;
221  tr_eta1_ = 0.25;
222  tr_eta2_ = 0.75;
223  tr_alpha1_ = 0.5;
224  tr_alpha2_ = 2.0;
225  tr_tol_ = 1e-8;
226  tr_acceptance_ = 1e-8;
227  tr_rad_min_ = 1e-10; //is this valid??
228  tr_rad_max_ = 10.0;
229  tr_rad0_ = 1.0;
230  tr_scale_vector_ = std::vector<double>(nx_, 1.0);
232  watchdog_ = 5;
233  max_inner_iter_ = 50;
234  use_anderson_ = false;
236 
237 
238  std::string convexify_strategy = "none";
239  double convexify_margin = 1e-7;
240  casadi_int max_iter_eig = 200;
241 
242  // Read user options
243  for (auto&& op : opts) {
244  if (op.first=="max_iter") {
245  max_iter_ = op.second;
246  } else if (op.first=="min_iter") {
247  min_iter_ = op.second;
248 
249  } else if (op.first=="use_anderson") {
250  use_anderson_ = op.second;
251  } else if (op.first=="anderson_memory") {
252  sz_anderson_memory_ = op.second;
253 
254  } else if (op.first=="lbfgs_memory") {
255  lbfgs_memory_ = op.second;
256  } else if (op.first=="tol_pr") {
257  tol_pr_ = op.second;
258  } else if (op.first=="tol_du") {
259  tol_du_ = op.second;
260  } else if (op.first=="hessian_approximation") {
261  hessian_approximation = op.second.to_string();
262  } else if (op.first=="solve_type") {
263  solve_type = op.second.to_string();
264  } else if (op.first=="qpsol") {
265  qpsol_plugin = op.second.to_string();
266  } else if (op.first=="qpsol_options") {
267  qpsol_options = op.second;
268  } else if (op.first=="print_header") {
269  print_header_ = op.second;
270  } else if (op.first=="print_iteration") {
271  print_iteration_ = op.second;
272  } else if (op.first=="print_status") {
273  print_status_ = op.second;
274  } else if (op.first=="hess_lag") {
275  Function f = op.second;
276  casadi_assert_dev(f.n_in()==4);
277  casadi_assert_dev(f.n_out()==1);
278  set_function(f, "nlp_hess_l");
279  } else if (op.first=="jac_g") {
280  Function f = op.second;
281  casadi_assert_dev(f.n_in()==2);
282  casadi_assert_dev(f.n_out()==1);
283  set_function(f, "nlp_jac_g");
284  } else if (op.first=="grad_f") {
285  Function f = op.second;
286  casadi_assert_dev(f.n_in()==2);
287  casadi_assert_dev(f.n_out()==1);
288  set_function(f, "nlp_grad_f");
289  } else if (op.first=="f") {
290  Function f = op.second;
291  casadi_assert_dev(f.n_in()==2);
292  casadi_assert_dev(f.n_out()==1);
293  set_function(f, "nlp_f");
294  } else if (op.first=="g") {
295  Function f = op.second;
296  casadi_assert_dev(f.n_in()==2);
297  casadi_assert_dev(f.n_out()==1);
298  set_function(f, "nlp_g");
299  /*
300  else if (op.first=="nlp_jac_fg") {
301  Function f = op.second;
302  casadi_assert_dev(f.n_in()==2);
303  casadi_assert_dev(f.n_out()==4);
304  set_function(f, "nlp_jac_fg");
305  }*/
306  } else if (op.first=="convexify_strategy") {
307  convexify_strategy = op.second.to_string();
308  } else if (op.first=="convexify_margin") {
309  convexify_margin = op.second;
310  } else if (op.first=="max_iter_eig") {
311  max_iter_eig = op.second;
312  } else if (op.first=="init_feasible") {
313  init_feasible_ = op.second;
314 
315  // from here FP-SQP
316  } else if (op.first == "optim_tol") {
317  optim_tol_ = op.second;
318  } else if (op.first == "feas_tol") {
319  feas_tol_ = op.second;
320  } else if (op.first == "tr_rad0") {
321  tr_rad0_ = op.second;
322  } else if (op.first == "tr_eta1") {
323  tr_eta1_ = op.second;
324  } else if (op.first == "tr_eta2") {
325  tr_eta2_ = op.second;
326  } else if (op.first == "tr_alpha1") {
327  tr_alpha1_ = op.second;
328  } else if (op.first == "tr_alpha2") {
329  tr_alpha2_ = op.second;
330  } else if (op.first == "tr_tol") {
331  tr_tol_ = op.second;
332  } else if (op.first == "tr_acceptance") {
333  tr_acceptance_ = op.second;
334  } else if (op.first == "tr_rad_min") {
335  tr_rad_min_ = op.second;
336  } else if (op.first == "tr_rad_max") {
337  tr_rad_max_ = op.second;
338  } else if (op.first == "tr_scale_vector") {
339  tr_scale_vector_ = op.second;
340  } else if (op.first == "contraction_acceptance_value") {
341  contraction_acceptance_value_ = op.second;
342  } else if (op.first == "watchdog") {
343  watchdog_ = op.second;
344  } else if (op.first == "max_inner_iter") {
345  max_inner_iter_ = op.second;
346  }
347  }
348 
349  // Use exact Hessian?
350  exact_hessian_ = hessian_approximation =="exact";
351  uout() << "print solve type" << solve_type << std::endl;
352  use_sqp_ = solve_type=="SQP";
353 
354  convexify_ = false;
355 
356  // Get/generate required functions
357  //if (max_iter_ls_ || so_corr_) create_function("nlp_fg", {"x", "p"}, {"f", "g"});
358  // First order derivative information
359 
360  if (!has_function("nlp_f")) {
361  create_function("nlp_f", {"x", "p"},
362  {"f"});
363  }
364  if (!has_function("nlp_g")) {
365  create_function("nlp_g", {"x", "p"},
366  {"g"});
367  }
368  if (!has_function("nlp_jac_g")) {
369  create_function("nlp_jac_g", {"x", "p"},
370  {"jac:g:x"});
371  }
372  if (!has_function("nlp_grad_f")) {
373  create_function("nlp_grad_f", {"x", "p"},
374  {"grad:f:x"});
375  }
376  Asp_ = get_function("nlp_jac_g").sparsity_out(0);
377 
378  /*
379  if (!has_function("nlp_jac_fg")) {
380  create_function("nlp_jac_fg", {"x", "p"},
381  {"f", "grad:f:x", "g", "jac:g:x"});
382  }
383  Asp_ = get_function("nlp_jac_fg").sparsity_out(3);*/
384  if (use_sqp_) {
385  if (exact_hessian_) {
386  if (!has_function("nlp_hess_l")) {
387  create_function("nlp_hess_l", {"x", "p", "lam:f", "lam:g"},
388  {"hess:gamma:x:x"}, {{"gamma", {"f", "g"}}});
389  }
390  Hsp_ = get_function("nlp_hess_l").sparsity_out(0);
391  uout() << "Sparsity pattern: " << Hsp_ << std::endl;
392  casadi_assert(Hsp_.is_symmetric(), "Hessian must be symmetric");
393  if (convexify_strategy!="none") {
394  convexify_ = true;
395  Dict opts;
396  opts["strategy"] = convexify_strategy;
397  opts["margin"] = convexify_margin;
398  opts["max_iter_eig"] = max_iter_eig;
399  opts["verbose"] = verbose_;
401  }
402  } else {
404  }
405  }
406 
407  casadi_assert(!qpsol_plugin.empty(), "'qpsol' option has not been set");
408  // qpsol_options["dump_in"] = true;
409  // qpsol_options["dump_out"] = true;
410  // qpsol_options["dump"] = true;
411  // qpsol_options["print_out"] = true;
412  // qpsol_options["error_on_fail"] = false;
413 
414  // Hsp_.to_file("h.mtx");
415  // Asp_.to_file("a.mtx");
416  // uout() << qpsol_options << std::endl;
417  if (use_sqp_) {
418  qpsol_ = conic("qpsol", qpsol_plugin, {{"h", Hsp_}, {"a", Asp_}},
419  qpsol_options);
420  // cout << qpsol_ <<std::endl;
421  } else {
422  Hsp_ = Sparsity(nx_, nx_);
423  uout() << "Sparsity pattern: " << Hsp_ << std::endl;
424  uout() << "Sparsity pattern: " << Asp_ << std::endl;
425  // uout() << "Nonzeros: " << Hsp_.nnz() << std::endl;
426  // qpsol_ = conic("qpsol", qpsol_plugin, {{"h", Hsp_}, {"a", Asp_}},
427  // qpsol_options);
428  qpsol_ = conic("qpsol", qpsol_plugin, {{"a", Asp_}},
429  qpsol_options);
430  // qpsol_ = Function::load("/home/david/testproblems_feasible_casadi/qpsol.casadi");
431  // cout << qpsol_ <<std::endl;
432  }
433 
434  alloc(qpsol_);
435 
436  // BFGS?
437  if (!exact_hessian_) {
438  alloc_w(2*nx_); // casadi_bfgs
439  }
440 
441  // Header
442  if (print_header_) {
443  print("-------------------------------------------\n");
444  print("This is casadi::Feasiblesqpmethod.\n");
445  if (exact_hessian_) {
446  print("Using exact Hessian\n");
447  } else {
448  print("Using limited memory BFGS Hessian approximation\n");
449  }
450  print("Number of variables: %9d\n", nx_);
451  print("Number of constraints: %9d\n", ng_);
452  print("Number of nonzeros in constraint Jacobian: %9d\n", Asp_.nnz());
453  print("Number of nonzeros in Lagrangian Hessian: %9d\n", Hsp_.nnz());
454  print("\n");
455  }
456 
457 
458  set_feasiblesqpmethod_prob();
459  // Allocate memory
460  casadi_int sz_w, sz_iw;
461  casadi_feasiblesqpmethod_work(&p_, &sz_iw, &sz_w, sz_anderson_memory_);
462  alloc_iw(sz_iw, true);
463  alloc_w(sz_w, true);
464  if (convexify_) {
467  }
468  }
static Sparsity setup(ConvexifyData &d, const Sparsity &H, const Dict &opts=Dict(), bool inplace=true)
Definition: convexify.cpp:166
bool init_feasible_
Initialize feasible qp's.
casadi_feasiblesqpmethod_prob< double > p_
void init(const Dict &opts) override
Initialize.
Definition: nlpsol.cpp:420
casadi_int nnz() const
Get the number of (structural) non-zeros.
Definition: sparsity.cpp:148
bool is_symmetric() const
Is symmetric?
Definition: sparsity.cpp:317
Function conic(const std::string &name, const std::string &solver, const SpDict &qp, const Dict &opts)
Definition: conic.cpp:44
casadi_int sz_iw
Definition: mx.hpp:62
casadi_int sz_w
Definition: mx.hpp:63

References casadi::FunctionInternal::alloc(), casadi::FunctionInternal::alloc_iw(), casadi::FunctionInternal::alloc_w(), Asp_, casadi::conic(), contraction_acceptance_value_, convexify_, convexify_data_, casadi::OracleFunction::create_function(), casadi::Sparsity::dense(), exact_hessian_, feas_tol_, casadi::OracleFunction::get_function(), casadi::OracleFunction::has_function(), Hsp_, casadi::Nlpsol::init(), init_feasible_, casadi::Sparsity::is_symmetric(), lbfgs_memory_, max_inner_iter_, max_iter_, min_iter_, casadi::Function::n_in(), casadi::Function::n_out(), casadi::Nlpsol::ng_, casadi::Sparsity::nnz(), casadi::Nlpsol::nx_, optim_tol_, p_, casadi::ProtoFunction::print(), print_header_, print_iteration_, print_status_, qpsol_, casadi::OracleFunction::set_function(), casadi::Convexify::setup(), sz_anderson_memory_, casadi::FunctionInternal::sz_iw(), casadi::ConvexifyData::sz_iw, casadi::FunctionInternal::sz_w(), casadi::ConvexifyData::sz_w, tol_du_, tol_pr_, tr_acceptance_, tr_alpha1_, tr_alpha2_, tr_eta1_, tr_eta2_, tr_rad0_, tr_rad_max_, tr_rad_min_, tr_scale_vector_, tr_tol_, casadi::uout(), use_anderson_, use_sqp_, casadi::ProtoFunction::verbose_, and watchdog_.

◆ init_mem()

int casadi::Feasiblesqpmethod::init_mem ( void *  mem) const
overridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 493 of file feasiblesqpmethod.cpp.

493  {
494  if (Nlpsol::init_mem(mem)) return 1;
495  auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
496 
497  if (convexify_) m->add_stat("convexify");
498  m->add_stat("BFGS");
499  m->add_stat("QP");
500  return 0;
501  }
int init_mem(void *mem) const override
Initalize memory block.
Definition: nlpsol.cpp:603

References casadi::ProtoFunctionMemory::add_stat(), convexify_, and casadi::Nlpsol::init_mem().

◆ initSingleton()

void casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::initSingleton ( )
inlineprotectedinherited

Called in the constructor of singletons to avoid that the counter reaches zero

Definition at line 71 of file generic_shared_internal.hpp.

71  {
72  casadi_assert_dev(static_cast<Internal*>(this)->count==0);
73  static_cast<Internal*>(this)->count++;
74  }

◆ instantiate()

Nlpsol * casadi::PluginInterface< Nlpsol >::instantiate ( const std::string &  fname,
const std::string &  pname,
Problem  problem 
)
staticinherited

Definition at line 106 of file plugin_interface.hpp.

313  {
314 
315  // Assert the plugin exists (needed for adaptors)
316  if (!has_plugin(pname, true)) {
317  casadi_error("Plugin '" + pname + "' is not found.");
318  }
319  return getPlugin(pname).creator(fname, problem);
320  }
static bool has_plugin(const std::string &pname, bool verbose=false)
Check if a plugin is available or can be loaded.
static Plugin & getPlugin(const std::string &pname)
Load and get the creator function.

◆ instruction_constant()

double casadi::FunctionInternal::instruction_constant ( casadi_int  k) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ld

Reimplemented in casadi::SXFunction.

Definition at line 3402 of file function_internal.cpp.

3402  {
3403  casadi_error("'instruction_constant' not defined for " + class_name());
3404  }

References casadi::SharedObjectInternal::class_name().

◆ instruction_id()

casadi_int casadi::FunctionInternal::instruction_id ( casadi_int  k) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lb

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3394 of file function_internal.cpp.

3394  {
3395  casadi_error("'instruction_id' not defined for " + class_name());
3396  }

References casadi::SharedObjectInternal::class_name().

◆ instruction_input()

std::vector< casadi_int > casadi::FunctionInternal::instruction_input ( casadi_int  k) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lc

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3398 of file function_internal.cpp.

3398  {
3399  casadi_error("'instruction_input' not defined for " + class_name());
3400  }

References casadi::SharedObjectInternal::class_name().

◆ instruction_MX()

MX casadi::FunctionInternal::instruction_MX ( casadi_int  k) const
virtualinherited

Reimplemented in casadi::MXFunction.

Definition at line 3410 of file function_internal.cpp.

3410  {
3411  casadi_error("'instruction_MX' not defined for " + class_name());
3412  }

References casadi::SharedObjectInternal::class_name().

◆ instruction_output()

std::vector< casadi_int > casadi::FunctionInternal::instruction_output ( casadi_int  k) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_le

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3406 of file function_internal.cpp.

3406  {
3407  casadi_error("'instruction_output' not defined for " + class_name());
3408  }

References casadi::SharedObjectInternal::class_name().

◆ instructions_sx()

SX casadi::FunctionInternal::instructions_sx ( ) const
virtualinherited

Reimplemented in casadi::SXFunction.

Definition at line 3414 of file function_internal.cpp.

3414  {
3415  casadi_error("'instructions_sx' not defined for " + class_name());
3416  }

References casadi::SharedObjectInternal::class_name().

◆ integer_support()

virtual bool casadi::Nlpsol::integer_support ( ) const
inlinevirtualinherited

Reimplemented in casadi::KnitroInterface, and casadi::BonminInterface.

Definition at line 207 of file nlpsol_impl.hpp.

207 { return false;}

Referenced by casadi::Nlpsol::init().

◆ is_a()

bool casadi::Nlpsol::is_a ( const std::string &  type,
bool  recursive 
) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1o5

Reimplemented from casadi::FunctionInternal.

Definition at line 290 of file nlpsol.cpp.

290  {
291  return type=="Nlpsol" || (recursive && OracleFunction::is_a(type, recursive));
292  }
virtual bool is_a(const std::string &type, bool recursive) const
Check if the function is of a particular type.

References casadi::FunctionInternal::is_a().

Referenced by casadi::AmplInterface::init().

◆ jac_is_symm()

bool casadi::FunctionInternal::jac_is_symm ( casadi_int  oind,
casadi_int  iind 
) const
virtualinherited

Definition at line 1858 of file function_internal.cpp.

1858  {
1859  // If derivative expression
1860  if (!derivative_of_.is_null()) {
1861  std::string n = derivative_of_.name();
1862  // Reverse move
1863  if (name_ == "adj1_" + n) {
1864  if (iind == oind) return true;
1865  }
1866  }
1867  // Not symmetric by default
1868  return false;
1869  }
const std::string & name() const
Name of the function.
Definition: function.cpp:1315

References casadi::FunctionInternal::derivative_of_, casadi::GenericShared< Shared, Internal >::is_null(), casadi::Function::name(), and casadi::ProtoFunction::name_.

◆ jac_sparsity()

Sparsity & casadi::FunctionInternal::jac_sparsity ( casadi_int  oind,
casadi_int  iind,
bool  compact,
bool  symmetric 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kz Get, if necessary generate, the sparsity of a Jacobian block

Definition at line 1946 of file function_internal.cpp.

1947  {
1948 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
1949  // Safe access to jac_sparsity_
1950  std::lock_guard<std::mutex> lock(jac_sparsity_mtx_);
1951 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
1952  // If first call, allocate cache
1953  for (bool c : {false, true}) {
1954  if (jac_sparsity_[c].empty()) jac_sparsity_[c].resize(n_in_ * n_out_);
1955  }
1956  // Flat index
1957  casadi_int ind = iind + oind * n_in_;
1958  // Reference to the block
1959  Sparsity& jsp = jac_sparsity_[compact].at(ind);
1960  // If null, generate
1961  if (jsp.is_null()) {
1962  // Use (non)-compact pattern, if given
1963  Sparsity& jsp_other = jac_sparsity_[!compact].at(ind);
1964  if (!jsp_other.is_null()) {
1965  jsp = compact ? to_compact(oind, iind, jsp_other) : from_compact(oind, iind, jsp_other);
1966  } else {
1967  // Generate pattern
1968  Sparsity sp;
1969  bool sp_is_compact;
1970  if (!is_diff_out_.at(oind) || !is_diff_in_.at(iind)) {
1971  // All-zero sparse
1972  sp = Sparsity(nnz_out(oind), nnz_in(iind));
1973  sp_is_compact = true;
1974  } else {
1975  // Use internal routine to determine sparsity
1976  if (has_spfwd() || has_sprev() || has_jac_sparsity(oind, iind)) {
1977  sp = get_jac_sparsity(oind, iind, symmetric);
1978  }
1979  // If null, dense
1980  if (sp.is_null()) sp = Sparsity::dense(nnz_out(oind), nnz_in(iind));
1981  // Is the return the compact pattern?
1982  sp_is_compact = sp.size1() == nnz_out(oind) && sp.size2() == nnz_in(iind);
1983  }
1984  // Save to cache and convert if needed
1985  if (sp_is_compact == compact) {
1986  jsp = sp;
1987  } else {
1988  jsp_other = sp;
1989  jsp = compact ? to_compact(oind, iind, sp) : from_compact(oind, iind, sp);
1990  }
1991  }
1992  }
1993 
1994  // Make sure the Jacobian is symmetric if requested, cf. #1522, #3074, #3134
1995  if (symmetric) {
1996  if (compact) {
1997  Sparsity sp = from_compact(oind, iind, jsp);
1998  if (!sp.is_symmetric()) {
1999  sp = sp * sp.T();
2000  jsp = to_compact(oind, iind, sp);
2001  }
2002  } else {
2003  if (!jsp.is_symmetric()) jsp = jsp * jsp.T();
2004  }
2005  }
2006 
2007  // Return a reference to the block
2008  return jsp;
2009  }
std::vector< Sparsity > jac_sparsity_[2]
Cache for sparsities of the Jacobian blocks.
Sparsity to_compact(casadi_int oind, casadi_int iind, const Sparsity &sp) const
Convert to compact Jacobian sparsity pattern.
virtual bool has_jac_sparsity(casadi_int oind, casadi_int iind) const
Get Jacobian sparsity.
Sparsity from_compact(casadi_int oind, casadi_int iind, const Sparsity &sp) const
Convert from compact Jacobian sparsity pattern.
virtual Sparsity get_jac_sparsity(casadi_int oind, casadi_int iind, bool symmetric) const
Get Jacobian sparsity.

References casadi::Sparsity::dense(), casadi::FunctionInternal::from_compact(), casadi::FunctionInternal::get_jac_sparsity(), casadi::FunctionInternal::has_jac_sparsity(), casadi::FunctionInternal::has_spfwd(), casadi::FunctionInternal::has_sprev(), casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::GenericShared< Shared, Internal >::is_null(), casadi::Sparsity::is_symmetric(), casadi::FunctionInternal::jac_sparsity_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::Sparsity::T(), and casadi::FunctionInternal::to_compact().

Referenced by casadi::FunctionInternal::get_partition(), casadi::FunctionInternal::sp_forward_block(), and casadi::FunctionInternal::sp_reverse().

◆ jacobian()

Function casadi::FunctionInternal::jacobian ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ky

Definition at line 2341 of file function_internal.cpp.

2341  {
2342  // Used wrapped function if jacobian not available
2343  if (!has_jacobian()) {
2344  // Derivative information must be available
2345  casadi_assert(has_derivative(),
2346  "Derivatives cannot be calculated for " + name_);
2347  return wrap().jacobian();
2348  }
2349  // Retrieve/generate cached
2350  Function f;
2351  std::string fname = "jac_" + name_;
2352  if (!incache(fname, f)) {
2353  // Names of inputs
2354  std::vector<std::string> inames;
2355  for (casadi_int i=0; i<n_in_; ++i) inames.push_back(name_in_[i]);
2356  for (casadi_int i=0; i<n_out_; ++i) inames.push_back("out_" + name_out_[i]);
2357  // Names of outputs
2358  std::vector<std::string> onames;
2359  onames.reserve(n_in_ * n_out_);
2360  for (size_t oind = 0; oind < n_out_; ++oind) {
2361  for (size_t iind = 0; iind < n_in_; ++iind) {
2362  onames.push_back("jac_" + name_out_[oind] + "_" + name_in_[iind]);
2363  }
2364  }
2365  // Options
2367  opts["derivative_of"] = self();
2368  // Generate derivative function
2369  casadi_assert_dev(enable_jacobian_);
2370  f = get_jacobian(fname, inames, onames, opts);
2371  // Consistency checks
2372  casadi_assert(f.n_in() == inames.size(),
2373  "Mismatching input signature, expected " + str(inames));
2374  casadi_assert(f.n_out() == onames.size(),
2375  "Mismatching output signature, expected " + str(onames));
2376  // Save to cache
2377  tocache_if_missing(f);
2378  }
2379  return f;
2380  }
virtual bool has_jacobian() const
Return Jacobian of all input elements with respect to all output elements.
virtual Function get_jacobian(const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const
Return Jacobian of all input elements with respect to all output elements.
Function jacobian() const
Calculate all Jacobian blocks.
Definition: function.cpp:916

References casadi::combine(), casadi::FunctionInternal::der_options_, casadi::FunctionInternal::enable_jacobian_, casadi::FunctionInternal::get_jacobian(), casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::has_jacobian(), casadi::FunctionInternal::incache(), casadi::Function::jacobian(), casadi::FunctionInternal::jacobian_options_, casadi::Function::n_in(), casadi::FunctionInternal::n_in_, casadi::Function::n_out(), casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::str(), casadi::FunctionInternal::tocache_if_missing(), and casadi::FunctionInternal::wrap().

Referenced by casadi::FunctionInternal::call_forward(), casadi::FunctionInternal::call_reverse(), and casadi::Function::jacobian().

◆ jit_dependencies()

void casadi::OracleFunction::jit_dependencies ( const std::string &  fname)
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_k

Reimplemented from casadi::FunctionInternal.

Definition at line 438 of file oracle_function.cpp.

438  {
439  if (compiler_.is_null()) {
440  if (verbose_) casadi_message("compiling to "+ fname+"'.");
441  // JIT dependent functions
442  compiler_ = Importer(generate_dependencies(fname, Dict()),
444  }
445  // Replace the Oracle functions with generated functions
446  for (auto&& e : all_functions_) {
447  if (verbose_) casadi_message("loading '" + e.second.f.name() + "' from '" + fname + "'.");
448  if (e.second.jit) {
449  e.second.f_original = e.second.f;
450  e.second.f = external(e.second.f.name(), compiler_);
451  }
452  }
453 }
std::string generate_dependencies(const std::string &fname, const Dict &opts) const override
Export / Generate C code for the generated functions.
Function external(const std::string &name, const Importer &li, const Dict &opts)
Load a just-in-time compiled external function.
Definition: external.cpp:42

References casadi::OracleFunction::all_functions_, casadi::FunctionInternal::compiler_, casadi::FunctionInternal::compiler_plugin_, casadi::external(), casadi::OracleFunction::generate_dependencies(), casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::jit_options_, and casadi::ProtoFunction::verbose_.

◆ join_results()

void casadi::OracleFunction::join_results ( OracleMemory m) const
inherited

Definition at line 168 of file oracle_function.cpp.

168  {
169  // Combine runtime statistics
170  // Note: probably not correct to simply add wall times
171  for (int i = 0; i < max_num_threads_; ++i) {
172  auto* ml = m->thread_local_mem[i];
173  for (auto&& s : ml->fstats) {
174  m->fstats.at(s.first).join(s.second);
175  }
176  }
177 }

References casadi::ProtoFunctionMemory::fstats, casadi::OracleFunction::max_num_threads_, and casadi::OracleMemory::thread_local_mem.

Referenced by casadi::Nlpsol::eval(), and casadi::Integrator::eval().

◆ kkt()

Function casadi::Nlpsol::kkt ( ) const
inherited

Definition at line 847 of file nlpsol.cpp.

847  {
848 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
849  // Safe access to kkt_
850  std::lock_guard<std::mutex> lock(kkt_mtx_);
851 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
852  // Quick return if cached
853  SharedObject temp;
854  if (kkt_.shared_if_alive(temp)) {
855  return shared_cast<Function>(temp);
856  }
857 
858  // Generate KKT function
859  Function ret = oracle_.factory("kkt", {"x", "p", "lam:f", "lam:g"},
860  {"jac:g:x", "hess:gamma:x:x"}, {{"gamma", {"f", "g"}}});
861 
862  // Cache and return
863  kkt_ = ret;
864  return ret;
865  }
bool shared_if_alive(Shared &shared) const
Thread-safe alternative to alive()/shared()
WeakRef kkt_
Cache for KKT function.

References casadi::Function::factory(), casadi::Nlpsol::kkt_, casadi::OracleFunction::oracle_, and casadi::GenericWeakRef< Shared, Internal >::shared_if_alive().

Referenced by casadi::Nlpsol::get_forward(), and casadi::Nlpsol::get_reverse().

◆ load_library()

handle_t casadi::PluginInterface< Nlpsol >::load_library ( const std::string &  libname,
std::string &  resultpath,
bool  global 
)
staticinherited

Definition at line 92 of file plugin_interface.hpp.

184  {
185 
186 #ifndef WITH_DL
187  casadi_error("WITH_DL option needed for dynamic loading");
188 #else // WITH_DL
189 
190  // Get the name of the shared library
191  std::string lib = SHARED_LIBRARY_PREFIX + libname + SHARED_LIBRARY_SUFFIX;
192 
193  // Build up search paths;
194  std::vector<std::string> search_paths = get_search_paths();
195  return open_shared_library(lib, search_paths, resultpath,
196  "PluginInterface::load_plugin", global);
197 
198 #endif // WITH_DL
199  }
std::vector< std::string > get_search_paths()
Definition: casadi_os.cpp:67

◆ load_plugin()

PluginInterface< Nlpsol >::Plugin casadi::PluginInterface< Nlpsol >::load_plugin ( const std::string &  pname,
bool  register_plugin = true,
bool  needs_lock = true 
)
staticinherited

Definition at line 88 of file plugin_interface.hpp.

204  {
205 
206 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
207  casadi::conditional_lock_guard<std::mutex> lock(Derived::mutex_solvers_, needs_lock);
208 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
209 
210  // Issue warning and quick return if already loaded
211  if (Derived::solvers_.find(pname) != Derived::solvers_.end()) {
212  casadi_warning("PluginInterface: Solver " + pname + " is already in use. Ignored.");
213  return Plugin();
214  }
215 
216  // Logger singletons are lazily instantiated on first uout()/uerr() calls
217  // This instantation may lead to a data race with potential instatiations in plugin
218  // To be safe, trigger instantatin before any plugin loading
219  uout();
220  uerr();
221 
222 #ifndef WITH_DL
223  casadi_error("WITH_DL option needed for dynamic loading");
224 #else // WITH_DL
225  // Retrieve the registration function
226  RegFcn reg;
227 
228  // Load the dll
229  std::string regName = "casadi_register_" + Derived::infix_ + "_" + pname;
230 
231  std::string searchpath;
232  handle_t handle = load_library("casadi_" + Derived::infix_ + "_" + pname, searchpath,
233  false);
234 
235 #ifdef _WIN32
236 
237 #if __GNUC__
238 #pragma GCC diagnostic push
239 #pragma GCC diagnostic ignored "-Wcast-function-type"
240 #endif
241  reg = reinterpret_cast<RegFcn>(GetProcAddress(handle, TEXT(regName.c_str())));
242 #if __GNUC__
243 #pragma GCC diagnostic pop
244 #endif
245 
246 #else // _WIN32
247  // Reset error
248  dlerror();
249 
250  // Load creator
251  reg = reinterpret_cast<RegFcn>(dlsym(handle, regName.c_str()));
252 #endif // _WIN32
253  casadi_assert(reg!=nullptr,
254  "PluginInterface::load_plugin: no \"" + regName + "\" found in " + searchpath + ".");
255 
256  // Create a temporary struct
257  Plugin plugin = pluginFromRegFcn(reg);
258  // Register the plugin
259  if (register_plugin) {
260  registerPlugin(plugin, false);
261  }
262 
263  return plugin;
264 
265 #endif // WITH_DL
266  }
static handle_t load_library(const std::string &libname, std::string &resultpath, bool global)
Load a library dynamically.
static Plugin pluginFromRegFcn(RegFcn regfcn)
Instantiate a Plugin struct from a factory function.
static void registerPlugin(const Plugin &plugin, bool needs_lock=true)
Register an integrator in the factory.
std::ostream & uerr()

◆ local_init_mem()

int casadi::OracleFunction::local_init_mem ( void *  mem) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_m

Definition at line 465 of file oracle_function.cpp.

465  {
466  if (ProtoFunction::init_mem(mem)) return 1;
467  if (!mem) return 1;
468  auto m = static_cast<LocalOracleMemory*>(mem);
469 
470  // Create statistics
471  for (auto&& e : all_functions_) {
472  m->add_stat(e.first);
473  }
474 
475  return 0;
476 }

References casadi::ProtoFunctionMemory::add_stat(), casadi::OracleFunction::all_functions_, and casadi::ProtoFunction::init_mem().

Referenced by casadi::OracleFunction::init_mem().

◆ map()

Function casadi::FunctionInternal::map ( casadi_int  n,
const std::string &  parallelization 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nd

Definition at line 1091 of file function_internal.cpp.

1091  {
1092  Function f;
1093  if (parallelization=="serial") {
1094  // Serial maps are cached
1095  std::string fname = "map" + str(n) + "_" + name_;
1096  if (!incache(fname, f)) {
1097  // Create new serial map
1098  f = Map::create(parallelization, self(), n);
1099  casadi_assert_dev(f.name()==fname);
1100  // Save in cache
1101  tocache_if_missing(f);
1102  }
1103  } else {
1104  // Non-serial maps are not cached
1105  f = Map::create(parallelization, self(), n);
1106  }
1107  return f;
1108  }
static Function create(const std::string &parallelization, const Function &f, casadi_int n)
Definition: map.cpp:39

References casadi::Map::create(), casadi::FunctionInternal::incache(), casadi::Function::name(), casadi::ProtoFunction::name_, casadi::str(), and casadi::FunctionInternal::tocache_if_missing().

Referenced by casadi::Dple::get_forward(), casadi::Dple::get_reverse(), and casadi::FunctionInternal::mapsum_mx().

◆ mapsum_mx()

std::vector< MX > casadi::FunctionInternal::mapsum_mx ( const std::vector< MX > &  arg,
const std::string &  parallelization 
)
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kw

Definition at line 3423 of file function_internal.cpp.

3424  {
3425  if (x.empty()) return x;
3426  // Check number of arguments
3427  casadi_assert(x.size()==n_in_, "mapsum_mx: Wrong number_i of arguments");
3428  // Number of parallel calls
3429  casadi_int npar = 1;
3430  // Check/replace arguments
3431  std::vector<MX> x_mod(x.size());
3432  for (casadi_int i=0; i<n_in_; ++i) {
3433  if (check_mat(x[i].sparsity(), sparsity_in_[i], npar)) {
3434  x_mod[i] = replace_mat(x[i], sparsity_in_[i], npar);
3435  } else {
3436  // Mismatching sparsity: The following will throw an error message
3437  npar = 0;
3438  check_arg(x, npar);
3439  }
3440  }
3441 
3442  casadi_int n = 1;
3443  for (casadi_int i=0; i<x_mod.size(); ++i) {
3444  n = std::max(x_mod[i].size2() / size2_in(i), n);
3445  }
3446 
3447  std::vector<casadi_int> reduce_in;
3448  for (casadi_int i=0; i<x_mod.size(); ++i) {
3449  if (x_mod[i].size2()/size2_in(i)!=n) {
3450  reduce_in.push_back(i);
3451  }
3452  }
3453 
3454  Function ms = self().map("mapsum", parallelization, n, reduce_in, range(n_out_));
3455 
3456  // Call the internal function
3457  return ms(x_mod);
3458  }
Function map(casadi_int n, const std::string &parallelization) const
Generate/retrieve cached serial map.
void check_arg(const std::vector< M > &arg, casadi_int &npar) const
Check if input arguments have correct length and dimensions.
M replace_mat(const M &arg, const Sparsity &inp, casadi_int npar)

References casadi::FunctionInternal::check_arg(), casadi::FunctionInternal::check_mat(), casadi::FunctionInternal::map(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::range(), casadi::replace_mat(), casadi::FunctionInternal::size2_in(), and casadi::FunctionInternal::sparsity_in_.

◆ matching_arg()

template<typename M >
bool casadi::FunctionInternal::matching_arg ( const std::vector< M > &  arg,
casadi_int &  npar 
) const
inherited

Raises errors

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
[out]nparmax number of horizontal repetitions across all arguments (or -1)

Extra doc: https://github.com/casadi/casadi/wiki/L_kk

Definition at line 1745 of file function_internal.hpp.

1745  {
1746  check_arg(arg, npar);
1747  for (casadi_int i=0; i<n_in_; ++i) {
1748  if (arg.at(i).size1()!=size1_in(i)) return false;
1749  if (arg.at(i).size2()!=size2_in(i) && arg.at(i).size2()!=npar*size2_in(i)) return false;
1750  }
1751  return true;
1752  }

References casadi::FunctionInternal::check_arg(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::size1_in(), and casadi::FunctionInternal::size2_in().

Referenced by casadi::MXFunction::ad_forward(), casadi::SXFunction::ad_forward(), casadi::FunctionInternal::call(), casadi::FunctionInternal::call_forward(), and casadi::FunctionInternal::nz_in().

◆ matching_res()

template<typename M >
bool casadi::FunctionInternal::matching_res ( const std::vector< M > &  arg,
casadi_int &  npar 
) const
inherited

Raises errors

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
[out]nparmax number of horizontal repetitions across all arguments (or -1)

Extra doc: https://github.com/casadi/casadi/wiki/L_kl

Definition at line 1755 of file function_internal.hpp.

1755  {
1756  check_res(res, npar);
1757  for (casadi_int i=0; i<n_out_; ++i) {
1758  if (res.at(i).size1()!=size1_out(i)) return false;
1759  if (res.at(i).size2()!=size2_out(i) && res.at(i).size2()!=npar*size2_out(i)) return false;
1760  }
1761  return true;
1762  }
void check_res(const std::vector< M > &res, casadi_int &npar) const
Check if output arguments have correct length and dimensions.

References casadi::FunctionInternal::check_res(), casadi::FunctionInternal::n_out_, casadi::FunctionInternal::size1_out(), and casadi::FunctionInternal::size2_out().

Referenced by casadi::MXFunction::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::FunctionInternal::call_reverse(), and casadi::FunctionInternal::nz_out().

◆ memory()

void * casadi::ProtoFunction::memory ( int  ind) const
inherited

Definition at line 3658 of file function_internal.cpp.

3658  {
3659 #ifdef CASADI_WITH_THREAD
3660  std::lock_guard<std::mutex> lock(mtx_);
3661 #endif //CASADI_WITH_THREAD
3662  return mem_.at(ind);
3663  }

Referenced by casadi::FunctionInternal::call_gen(), casadi::FunctionInternal::get_jac_sparsity_gen(), casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::Sqpmethod::solve_ela_QP(), and casadi::Sqpmethod::solve_QP().

◆ merge()

void casadi::FunctionInternal::merge ( const std::vector< MX > &  arg,
std::vector< MX > &  subs_from,
std::vector< MX > &  subs_to 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2b8

Reimplemented in casadi::BlazingSplineFunction.

Definition at line 3372 of file function_internal.cpp.

3373  {
3374  return;
3375  }

◆ monitored()

bool casadi::OracleFunction::monitored ( const std::string &  name) const
virtualinherited

Definition at line 548 of file oracle_function.cpp.

548  {
549  auto it = all_functions_.find(name);
550  casadi_assert(it!=all_functions_.end(),
551  "No function \"" + name + "\" in " + name_+ ". " +
552  "Available functions: " + join(get_function()) + ".");
553  return it->second.monitored;
554 }

References casadi::OracleFunction::all_functions_, casadi::OracleFunction::get_function(), casadi::join(), and casadi::ProtoFunction::name_.

Referenced by casadi::OracleFunction::calc_function().

◆ mx_in() [1/2]

const std::vector< MX > casadi::FunctionInternal::mx_in ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l7

Reimplemented in casadi::MXFunction.

Definition at line 3352 of file function_internal.cpp.

3352  {
3353  std::vector<MX> ret(n_in_);
3354  for (casadi_int i=0; i<ret.size(); ++i) {
3355  ret[i] = mx_in(i);
3356  }
3357  return ret;
3358  }

References casadi::FunctionInternal::n_in_.

Referenced by casadi::Nlpsol::get_forward(), casadi::LinearInterpolantJac::get_jacobian(), casadi::Nlpsol::get_reverse(), casadi::FunctionInternal::wrap(), and casadi::FunctionInternal::wrap_as_needed().

◆ mx_in() [2/2]

const MX casadi::FunctionInternal::mx_in ( casadi_int  ind) const
virtualinherited

◆ mx_out() [1/2]

const std::vector< MX > casadi::FunctionInternal::mx_out ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l7

Definition at line 3360 of file function_internal.cpp.

3360  {
3361  std::vector<MX> ret(n_out_);
3362  for (casadi_int i=0; i<ret.size(); ++i) {
3363  ret[i] = mx_out(i);
3364  }
3365  return ret;
3366  }

References casadi::FunctionInternal::n_out_.

Referenced by casadi::Nlpsol::get_forward(), and casadi::Nlpsol::get_reverse().

◆ mx_out() [2/2]

const MX casadi::FunctionInternal::mx_out ( casadi_int  ind) const
virtualinherited

◆ n_instructions()

casadi_int casadi::FunctionInternal::n_instructions ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_la

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3390 of file function_internal.cpp.

3390  {
3391  casadi_error("'n_instructions' not defined for " + class_name());
3392  }

References casadi::SharedObjectInternal::class_name().

◆ n_nodes()

casadi_int casadi::FunctionInternal::n_nodes ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lf

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3418 of file function_internal.cpp.

3418  {
3419  casadi_error("'n_nodes' not defined for " + class_name());
3420  }

References casadi::SharedObjectInternal::class_name().

◆ nnz_in() [1/2]

casadi_int casadi::FunctionInternal::nnz_in ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_me

Definition at line 2301 of file function_internal.cpp.

2301  {
2302  casadi_int ret=0;
2303  for (casadi_int iind=0; iind<n_in_; ++iind) ret += nnz_in(iind);
2304  return ret;
2305  }

References casadi::FunctionInternal::n_in_.

Referenced by casadi::FunctionInternal::adjViaJac(), casadi::FunctionInternal::call_gen(), casadi::JitFunction::codegen_body(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::eval_gen(), casadi::CallbackInternal::finalize(), casadi::FunctionInternal::from_compact(), casadi::FunctionInternal::fwdViaJac(), casadi::FunctionInternal::generate_in(), casadi::FunctionInternal::get_jac_sparsity(), casadi::Expm::get_jac_sparsity(), casadi::FmuFunction::get_jac_sparsity(), casadi::FunctionInternal::get_jac_sparsity_gen(), casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::FunctionInternal::get_jac_sparsity_hierarchical_symm(), casadi::JitFunction::init(), casadi::Nlpsol::init(), casadi::CbcInterface::init(), casadi::ClpInterface::init(), casadi::CplexInterface::init(), casadi::OoqpInterface::init(), casadi::ProxqpInterface::init(), casadi::QpoasesInterface::init(), casadi::ImplicitToNlp::init(), casadi::FunctionInternal::jac_sparsity(), casadi::FunctionInternal::nz_in(), casadi::ImplicitToNlp::set_work(), casadi::CbcInterface::solve(), casadi::ClpInterface::solve(), casadi::CplexInterface::solve(), casadi::OoqpInterface::solve(), casadi::ProxqpInterface::solve(), casadi::QpToNlp::solve(), casadi::KinsolInterface::solve(), casadi::FunctionInternal::sp_forward(), and casadi::FunctionInternal::sp_reverse().

◆ nnz_in() [2/2]

casadi_int casadi::FunctionInternal::nnz_in ( casadi_int  ind) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_me

Definition at line 974 of file function_internal.hpp.

974 { return sparsity_in(ind).nnz(); }

◆ nnz_out() [1/2]

casadi_int casadi::FunctionInternal::nnz_out ( ) const
inherited

◆ nnz_out() [2/2]

casadi_int casadi::FunctionInternal::nnz_out ( casadi_int  ind) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_me

Definition at line 976 of file function_internal.hpp.

976 { return sparsity_out(ind).nnz(); }

◆ numel_in() [1/2]

casadi_int casadi::FunctionInternal::numel_in ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mf

Definition at line 2313 of file function_internal.cpp.

2313  {
2314  casadi_int ret=0;
2315  for (casadi_int iind=0; iind<n_in_; ++iind) ret += numel_in(iind);
2316  return ret;
2317  }

References casadi::FunctionInternal::n_in_.

Referenced by casadi::FunctionInternal::from_compact(), and casadi::Integrator::get_reverse().

◆ numel_in() [2/2]

casadi_int casadi::FunctionInternal::numel_in ( casadi_int  ind) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mf

Definition at line 984 of file function_internal.hpp.

984 { return sparsity_in(ind).numel(); }
casadi_int numel() const
The total number of elements, including structural zeros, i.e. size2()*size1()
Definition: sparsity.cpp:132

◆ numel_out() [1/2]

casadi_int casadi::FunctionInternal::numel_out ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mf

Definition at line 2319 of file function_internal.cpp.

2319  {
2320  casadi_int ret=0;
2321  for (casadi_int oind=0; oind<n_out_; ++oind) ret += numel_out(oind);
2322  return ret;
2323  }

References casadi::FunctionInternal::n_out_.

Referenced by casadi::FunctionInternal::from_compact(), and casadi::Integrator::get_reverse().

◆ numel_out() [2/2]

casadi_int casadi::FunctionInternal::numel_out ( casadi_int  ind) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mf

Definition at line 985 of file function_internal.hpp.

985 { return sparsity_out(ind).numel(); }

◆ nz_in() [1/2]

std::vector< double > casadi::FunctionInternal::nz_in ( const std::vector< DM > &  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kt

Definition at line 3513 of file function_internal.cpp.

3513  {
3514  // Disallow parallel inputs
3515  casadi_int npar = -1;
3516  if (!matching_arg(arg, npar)) {
3517  return nz_in(replace_arg(arg, npar));
3518  }
3519 
3520  std::vector<DM> arg2 = project_arg(arg, 1);
3521  std::vector<double> ret(nnz_in());
3522  casadi_int offset = 0;
3523  for (casadi_int i=0;i<n_in_;++i) {
3524  const double* e = arg2.at(i).ptr();
3525  std::copy(e, e+nnz_in(i), ret.begin()+offset);
3526  offset+= nnz_in(i);
3527  }
3528  return ret;
3529  }

References casadi::FunctionInternal::matching_arg(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::project_arg(), and casadi::FunctionInternal::replace_arg().

Referenced by casadi::SXFunction::call_fwd(), casadi::SXFunction::call_rev(), casadi::SXFunction::call_setup(), casadi::FunctionInternal::get_jac_sparsity(), casadi::FunctionInternal::get_jac_sparsity_gen(), and casadi::FunctionInternal::get_jac_sparsity_hierarchical().

◆ nz_in() [2/2]

std::vector< DM > casadi::FunctionInternal::nz_in ( const std::vector< double > &  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kt

Definition at line 3483 of file function_internal.cpp.

3483  {
3484  casadi_assert(nnz_in()==arg.size(),
3485  "Dimension mismatch. Expecting " + str(nnz_in()) +
3486  ", got " + str(arg.size()) + " instead.");
3487 
3488  std::vector<DM> ret = dm_in();
3489  casadi_int offset = 0;
3490  for (casadi_int i=0;i<n_in_;++i) {
3491  DM& r = ret.at(i);
3492  std::copy(arg.begin()+offset, arg.begin()+offset+nnz_in(i), r.ptr());
3493  offset+= nnz_in(i);
3494  }
3495  return ret;
3496  }

References casadi::FunctionInternal::dm_in(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::nnz_in(), casadi::Matrix< Scalar >::ptr(), and casadi::str().

◆ nz_out() [1/2]

std::vector< double > casadi::FunctionInternal::nz_out ( const std::vector< DM > &  res) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kt

Definition at line 3531 of file function_internal.cpp.

3531  {
3532  // Disallow parallel inputs
3533  casadi_int npar = -1;
3534  if (!matching_res(res, npar)) {
3535  return nz_out(replace_res(res, npar));
3536  }
3537 
3538  std::vector<DM> res2 = project_res(res, 1);
3539  std::vector<double> ret(nnz_out());
3540  casadi_int offset = 0;
3541  for (casadi_int i=0;i<n_out_;++i) {
3542  const double* e = res2.at(i).ptr();
3543  std::copy(e, e+nnz_out(i), ret.begin()+offset);
3544  offset+= nnz_out(i);
3545  }
3546  return ret;
3547  }
std::vector< M > project_res(const std::vector< M > &arg, casadi_int npar) const
Project sparsities.
std::vector< M > replace_res(const std::vector< M > &res, casadi_int npar) const
Replace 0-by-0 outputs.

References casadi::FunctionInternal::matching_res(), casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::project_res(), and casadi::FunctionInternal::replace_res().

Referenced by casadi::SXFunction::call_fwd(), casadi::SXFunction::call_rev(), casadi::SXFunction::call_setup(), casadi::FunctionInternal::get_jac_sparsity(), casadi::FunctionInternal::get_jac_sparsity_gen(), and casadi::FunctionInternal::get_jac_sparsity_hierarchical().

◆ nz_out() [2/2]

std::vector< DM > casadi::FunctionInternal::nz_out ( const std::vector< double > &  res) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kt

Definition at line 3498 of file function_internal.cpp.

3498  {
3499  casadi_assert(nnz_out()==res.size(),
3500  "Dimension mismatch. Expecting " + str(nnz_out()) +
3501  ", got " + str(res.size()) + " instead.");
3502 
3503  std::vector<DM> ret = dm_out();
3504  casadi_int offset = 0;
3505  for (casadi_int i=0;i<n_out_;++i) {
3506  DM& r = ret.at(i);
3507  std::copy(res.begin()+offset, res.begin()+offset+nnz_out(i), r.ptr());
3508  offset+= nnz_out(i);
3509  }
3510  return ret;
3511  }

References casadi::FunctionInternal::dm_out(), casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_out(), casadi::Matrix< Scalar >::ptr(), and casadi::str().

◆ oracle()

const Function& casadi::OracleFunction::oracle ( ) const
inlineoverridevirtualinherited

◆ plugin_deserialize()

Deserialize casadi::PluginInterface< Nlpsol >::plugin_deserialize ( const std::string &  pname)
staticinherited

Definition at line 82 of file plugin_interface.hpp.

162  {
163  Deserialize m = getPlugin(pname).deserialize;
164  casadi_assert(m, "Plugin \"" + pname + "\" does not support deserialize");
165  return m;
166  }
ProtoFunction *(* Deserialize)(DeserializingStream &)

◆ plugin_name()

const char* casadi::Feasiblesqpmethod::plugin_name ( ) const
inlineoverridevirtual

Implements casadi::PluginInterface< Nlpsol >.

Definition at line 71 of file feasiblesqpmethod.hpp.

71 { return "feasiblesqpmethod";}

◆ plugin_options()

const Options & casadi::PluginInterface< Nlpsol >::plugin_options ( const std::string &  pname)
staticinherited

Definition at line 79 of file plugin_interface.hpp.

155  {
156  const Options *op = getPlugin(pname).options;
157  casadi_assert(op!=nullptr, "Plugin \"" + pname + "\" does not support options");
158  return *op;
159  }

◆ pluginFromRegFcn()

PluginInterface< Nlpsol >::Plugin casadi::PluginInterface< Nlpsol >::pluginFromRegFcn ( RegFcn  regfcn)
staticinherited

Definition at line 85 of file plugin_interface.hpp.

170  {
171  // Create a temporary struct
172  Plugin plugin;
173 
174  // Set the fields
175  int flag = regfcn(&plugin);
176  casadi_assert(flag==0, "Registration of plugin failed.");
177 
178  return plugin;
179  }

◆ print()

void casadi::ProtoFunction::print ( const char *  fmt,
  ... 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_jr

Definition at line 3897 of file function_internal.cpp.

3897  {
3898  // Variable number of arguments
3899  va_list args;
3900  va_start(args, fmt);
3901  // Static & dynamic buffers
3902  char buf[256];
3903  size_t buf_sz = sizeof(buf);
3904  char* buf_dyn = nullptr;
3905  // Try to print with a small buffer
3906  casadi_int n = vsnprintf(buf, buf_sz, fmt, args);
3907  // Need a larger buffer?
3908  if (n>static_cast<casadi_int>(buf_sz)) {
3909  buf_sz = static_cast<size_t>(n+1);
3910  buf_dyn = new char[buf_sz];
3911  n = vsnprintf(buf_dyn, buf_sz, fmt, args);
3912  }
3913  // Print buffer content
3914  if (n>=0) uout() << (buf_dyn ? buf_dyn : buf) << std::flush;
3915  // Cleanup
3916  delete[] buf_dyn;
3917  va_end(args);
3918  // Throw error if failure
3919  casadi_assert(n>=0, "Print failure while processing '" + std::string(fmt) + "'");
3920  }

References casadi::uout().

Referenced by anderson_acc_step_update(), casadi::Nlpsol::callback(), casadi::Blocksqp::convertHessian(), casadi::FmuFunction::eval_task(), feasibility_iterations(), casadi::Blocksqp::feasibilityRestorationPhase(), casadi::Blocksqp::fullstep(), casadi::Blocksqp::init(), init(), casadi::Ipqp::init(), casadi::Qrqp::init(), casadi::Qrsqp::init(), casadi::Sqpmethod::init(), casadi::LinsolQr::nfact(), print_iteration(), casadi::Qrsqp::print_iteration(), casadi::Sqpmethod::print_iteration(), casadi::SundialsInterface::print_stats(), casadi::ProtoFunction::print_time(), casadi::Blocksqp::printInfo(), casadi::Blocksqp::printProgress(), casadi::Blocksqp::run(), casadi::Blocksqp::solve(), solve(), casadi::Qrsqp::solve(), casadi::Sqpmethod::solve(), casadi::Sqpmethod::solve_ela_QP(), solve_LP(), solve_QP(), casadi::Qrsqp::solve_QP(), casadi::Sqpmethod::solve_QP(), and casadi::Blocksqp::solveQP().

◆ print_canonical() [1/3]

void casadi::FunctionInternal::print_canonical ( std::ostream &  stream,
casadi_int  sz,
const double *  nz 
)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2di

Definition at line 858 of file function_internal.cpp.

858  {
859  StreamStateGuard backup(stream);
860  normalized_setup(stream);
861  if (nz) {
862  stream << "[";
863  for (casadi_int i=0; i<sz; ++i) {
864  if (i>0) stream << ", ";
865  normalized_out(stream, nz[i]);
866  }
867  stream << "]";
868  } else {
869  stream << "NULL";
870  }
871  }

References casadi::normalized_out(), and casadi::normalized_setup().

◆ print_canonical() [2/3]

void casadi::FunctionInternal::print_canonical ( std::ostream &  stream,
const Sparsity sp,
const double *  nz 
)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2dh

Definition at line 873 of file function_internal.cpp.

874  {
875  StreamStateGuard backup(stream);
876  normalized_setup(stream);
877  if (nz) {
878  if (!sp.is_scalar(true)) {
879  stream << sp.dim(false) << ": ";
880  stream << "[";
881  }
882  for (casadi_int i=0; i<sp.nnz(); ++i) {
883  if (i>0) stream << ", ";
884  normalized_out(stream, nz[i]);
885  }
886  if (!sp.is_scalar(true)) {
887  stream << "]";
888  if (!sp.is_dense()) {
889  stream << ", colind: [";
890  for (casadi_int i=0; i<sp.size2(); ++i) {
891  if (i>0) stream << ", ";
892  stream << sp.colind()[i];
893  }
894  stream << "]";
895  stream << ", row: [";
896  for (casadi_int i=0; i<sp.nnz(); ++i) {
897  if (i>0) stream << ", ";
898  stream << sp.row()[i];
899  }
900  stream << "]";
901  }
902  }
903  } else {
904  stream << "NULL";
905  }
906  }

References casadi::Sparsity::colind(), casadi::Sparsity::dim(), casadi::Sparsity::is_dense(), casadi::Sparsity::is_scalar(), casadi::Sparsity::nnz(), casadi::normalized_out(), casadi::normalized_setup(), casadi::Sparsity::row(), and casadi::Sparsity::size2().

Referenced by casadi::Monitor::eval(), casadi::MXFunction::print_arg(), casadi::SXFunction::print_arg(), casadi::FunctionInternal::print_in(), casadi::FunctionInternal::print_out(), casadi::MXFunction::print_res(), and casadi::SXFunction::print_res().

◆ print_canonical() [3/3]

void casadi::FunctionInternal::print_canonical ( std::ostream &  stream,
double  a 
)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2dj

Definition at line 908 of file function_internal.cpp.

908  {
909  StreamStateGuard backup(stream);
910  normalized_setup(stream);
911  normalized_out(stream, a);
912  }

References casadi::normalized_out(), and casadi::normalized_setup().

◆ print_dimensions()

void casadi::FunctionInternal::print_dimensions ( std::ostream &  stream) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mb

Definition at line 983 of file function_internal.cpp.

983  {
984  stream << " Number of inputs: " << n_in_ << std::endl;
985  for (casadi_int i=0; i<n_in_; ++i) {
986  stream << " Input " << i << " (\"" << name_in_[i] << "\"): "
987  << sparsity_in_[i].dim() << std::endl;
988  }
989  stream << " Number of outputs: " << n_out_ << std::endl;
990  for (casadi_int i=0; i<n_out_; ++i) {
991  stream << " Output " << i << " (\"" << name_out_[i] << "\"): "
992  << sparsity_out_[i].dim() << std::endl;
993  }
994  }

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::sparsity_in_, and casadi::FunctionInternal::sparsity_out_.

◆ print_in()

void casadi::FunctionInternal::print_in ( std::ostream &  stream,
const double **  arg,
bool  truncate 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nv

Definition at line 824 of file function_internal.cpp.

824  {
825  stream << "Function " << name_ << " (" << this << ")" << std::endl;
826  for (casadi_int i=0; i<n_in_; ++i) {
827  stream << "Input " << i << " (" << name_in_[i] << "): ";
828  if (arg[i]) {
829  if (print_canonical_) {
830  print_canonical(stream, sparsity_in_[i], arg[i]);
831  } else {
832  DM::print_default(stream, sparsity_in_[i], arg[i], truncate);
833  }
834  stream << std::endl;
835  } else {
836  stream << "NULL" << std::endl;
837  }
838  }
839  }
static void print_canonical(std::ostream &stream, const Sparsity &sp, const double *nz)
Print canonical representation of a numeric matrix.
static void print_default(std::ostream &stream, const Sparsity &sp, const double *nonzeros, bool truncate=true)
Print default style.

References casadi::FunctionInternal::n_in_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::print_canonical(), casadi::FunctionInternal::print_canonical_, casadi::Matrix< double >::print_default(), and casadi::FunctionInternal::sparsity_in_.

Referenced by casadi::FunctionInternal::eval_gen().

◆ print_iteration() [1/2]

void casadi::Feasiblesqpmethod::print_iteration ( ) const

Definition at line 1316 of file feasiblesqpmethod.cpp.

1316  {
1317  print("%4s %9s %14s %9s %9s %9s %9s %7s %5s %7s\n",
1318  "iter", "m_k", "objective", "tr_ratio", "inf_pr",
1319  "inf_du", "||d||", "lg(rg)", "tr_rad", "info");
1320  }

References casadi::ProtoFunction::print().

Referenced by solve().

◆ print_iteration() [2/2]

void casadi::Feasiblesqpmethod::print_iteration ( casadi_int  iter,
double  obj,
double  m_k,
double  tr_ratio,
double  pr_inf,
double  du_inf,
double  dx_norm,
double  rg,
double  tr_rad,
std::string  info 
) const

Definition at line 1322 of file feasiblesqpmethod.cpp.

1327  {
1328  print("%4d %9.2e %14.6e %9.2e %9.2e %9.2e %9.2e ",
1329  iter, m_k, obj, tr_ratio, pr_inf, du_inf, dx_norm);
1330  if (rg>0) {
1331  print("%7.2f ", log10(rg));
1332  } else {
1333  print("%7s ", "-");
1334  }
1335 
1336  print("%9.5e", tr_rad);
1337  // if (!ls_success) {
1338  // print("F");
1339  // } else {
1340  // print (" ");
1341  // }
1342 
1343  print(" - ");
1344  print(info.c_str());
1345  print("\n");
1346  }

References casadi::FunctionInternal::info(), and casadi::ProtoFunction::print().

◆ print_option()

void casadi::ProtoFunction::print_option ( const std::string &  name,
std::ostream &  stream 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ji

Definition at line 1000 of file function_internal.cpp.

1000  {
1001  get_options().print_one(name, stream);
1002  }
void print_one(const std::string &name, std::ostream &stream) const
Print all information there is to know about a certain option.
Definition: options.cpp:274

References casadi::ProtoFunction::get_options(), and casadi::Options::print_one().

◆ print_options()

void casadi::ProtoFunction::print_options ( std::ostream &  stream) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_jh

Definition at line 996 of file function_internal.cpp.

996  {
997  get_options().print_all(stream);
998  }
void print_all(std::ostream &stream) const
Print list of options.
Definition: options.cpp:268

References casadi::ProtoFunction::get_options(), and casadi::Options::print_all().

◆ print_out()

void casadi::FunctionInternal::print_out ( std::ostream &  stream,
double **  res,
bool  truncate 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nw

Definition at line 841 of file function_internal.cpp.

841  {
842  stream << "Function " << name_ << " (" << this << ")" << std::endl;
843  for (casadi_int i=0; i<n_out_; ++i) {
844  stream << "Output " << i << " (" << name_out_[i] << "): ";
845  if (res[i]) {
846  if (print_canonical_) {
847  print_canonical(stream, sparsity_out_[i], res[i]);
848  } else {
849  DM::print_default(stream, sparsity_out_[i], res[i], truncate);
850  }
851  stream << std::endl;
852  } else {
853  stream << "NULL" << std::endl;
854  }
855  }
856  }

References casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::print_canonical(), casadi::FunctionInternal::print_canonical_, casadi::Matrix< double >::print_default(), and casadi::FunctionInternal::sparsity_out_.

Referenced by casadi::FunctionInternal::eval_gen().

◆ print_time()

void casadi::ProtoFunction::print_time ( const std::map< std::string, FStats > &  fstats) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ju

Definition at line 3817 of file function_internal.cpp.

3817  {
3818  if (!print_time_) return;
3819  // Length of the name being printed
3820  size_t name_len=0;
3821  for (auto &&s : fstats) {
3822  name_len = std::max(s.first.size(), name_len);
3823  }
3824  name_len = std::max(name_.size(), name_len);
3825 
3826  // Print name with a given length. Format: "%NNs "
3827  char namefmt[10];
3828  sprint(namefmt, sizeof(namefmt), "%%%ds ", static_cast<casadi_int>(name_len));
3829 
3830  // Print header
3831  print(namefmt, name_.c_str());
3832 
3833  print(" : %8s %10s %8s %10s %9s\n", "t_proc", "(avg)", "t_wall", "(avg)", "n_eval");
3834 
3835 
3836  char buffer_proc[10];
3837  char buffer_wall[10];
3838  char buffer_proc_avg[10];
3839  char buffer_wall_avg[10];
3840 
3841  // Print keys
3842  for (const auto &s : fstats) {
3843  if (s.second.n_call!=0) {
3844  print(namefmt, s.first.c_str());
3845  format_time(buffer_proc, s.second.t_proc);
3846  format_time(buffer_wall, s.second.t_wall);
3847  format_time(buffer_proc_avg, s.second.t_proc/s.second.n_call);
3848  format_time(buffer_wall_avg, s.second.t_wall/s.second.n_call);
3849  print(" | %s (%s) %s (%s) %9d\n",
3850  buffer_proc, buffer_proc_avg,
3851  buffer_wall, buffer_wall_avg, s.second.n_call);
3852  }
3853  }
3854  }
void format_time(char *buffer, double time) const
Format time in a fixed width 8 format.

References casadi::ProtoFunction::format_time(), casadi::ProtoFunction::name_, casadi::ProtoFunction::print(), casadi::ProtoFunction::print_time_, and casadi::ProtoFunction::sprint().

Referenced by casadi::FunctionInternal::eval_gen().

◆ project_arg()

template<typename M >
std::vector< M > casadi::FunctionInternal::project_arg ( const std::vector< M > &  arg,
casadi_int  npar 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kn

Definition at line 1617 of file function_internal.hpp.

1618  {
1619  casadi_assert_dev(arg.size()==n_in_);
1620 
1621  // Which arguments require mapped evaluation
1622  std::vector<bool> mapped(n_in_);
1623  for (casadi_int i=0; i<n_in_; ++i) {
1624  mapped[i] = arg[i].size2()!=size2_in(i);
1625  }
1626 
1627  // Check if matching input sparsity
1628  std::vector<bool> matching(n_in_);
1629  bool any_mismatch = false;
1630  for (casadi_int i=0; i<n_in_; ++i) {
1631  if (mapped[i]) {
1632  matching[i] = arg[i].sparsity().is_stacked(sparsity_in(i), npar);
1633  } else {
1634  matching[i] = arg[i].sparsity()==sparsity_in(i);
1635  }
1636  any_mismatch = any_mismatch || !matching[i];
1637  }
1638 
1639  // Correct input sparsity
1640  if (any_mismatch) {
1641  std::vector<M> arg2(arg);
1642  for (casadi_int i=0; i<n_in_; ++i) {
1643  if (!matching[i]) {
1644  if (mapped[i]) {
1645  arg2[i] = project(arg2[i], repmat(sparsity_in(i), 1, npar));
1646  } else {
1647  arg2[i] = project(arg2[i], sparsity_in(i));
1648  }
1649  }
1650  }
1651  return arg2;
1652  }
1653  return arg;
1654  }

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::size2_in(), and casadi::FunctionInternal::sparsity_in().

Referenced by casadi::FunctionInternal::call_gen(), and casadi::FunctionInternal::nz_in().

◆ project_res()

template<typename M >
std::vector< M > casadi::FunctionInternal::project_res ( const std::vector< M > &  arg,
casadi_int  npar 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ko

Definition at line 1657 of file function_internal.hpp.

1658  {
1659  return arg;
1660  }

Referenced by casadi::FunctionInternal::nz_out().

◆ purgable()

template<typename MatType >
bool casadi::FunctionInternal::purgable ( const std::vector< MatType > &  seed)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nq

Definition at line 1510 of file function_internal.hpp.

1510  {
1511  for (auto i=v.begin(); i!=v.end(); ++i) {
1512  if (!i->is_zero()) return false;
1513  }
1514  return true;
1515  }

Referenced by casadi::MXFunction::ad_forward(), and casadi::MXFunction::ad_reverse().

◆ registerPlugin() [1/2]

void casadi::PluginInterface< Nlpsol >::registerPlugin ( const Plugin &  plugin,
bool  needs_lock = true 
)
staticinherited

Definition at line 96 of file plugin_interface.hpp.

274  {
275 
276 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
277  casadi::conditional_lock_guard<std::mutex> lock(Derived::mutex_solvers_, needs_lock);
278 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
279 
280  // Check if the solver name is in use
281  typename std::map<std::string, Plugin>::iterator it=Derived::solvers_.find(plugin.name);
282  casadi_assert(it==Derived::solvers_.end(),
283  "Solver " + str(plugin.name) + " is already in use");
284 
285  // Add to list of solvers
286  Derived::solvers_[plugin.name] = plugin;
287  }

◆ registerPlugin() [2/2]

void casadi::PluginInterface< Nlpsol >::registerPlugin ( RegFcn  regfcn,
bool  needs_lock = true 
)
staticinherited

Definition at line 99 of file plugin_interface.hpp.

269  {
270  registerPlugin(pluginFromRegFcn(regfcn), needs_lock);
271  }

◆ release()

void casadi::ProtoFunction::release ( int  mem) const
inherited

Definition at line 3690 of file function_internal.cpp.

3690  {
3691 #ifdef CASADI_WITH_THREAD
3692  std::lock_guard<std::mutex> lock(mtx_);
3693 #endif //CASADI_WITH_THREAD
3694  unused_.push(mem);
3695  }

◆ replace_arg()

template<typename M >
std::vector< M > casadi::FunctionInternal::replace_arg ( const std::vector< M > &  arg,
casadi_int  npar 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_km

Definition at line 1790 of file function_internal.hpp.

1791  {
1792  std::vector<M> r(arg.size());
1793  for (casadi_int i=0; i<r.size(); ++i) r[i] = replace_mat(arg[i], sparsity_in(i), npar);
1794  return r;
1795  }

References casadi::replace_mat(), and casadi::FunctionInternal::sparsity_in().

Referenced by casadi::FunctionInternal::call(), casadi::FunctionInternal::nz_in(), and casadi::FunctionInternal::replace_fseed().

◆ replace_aseed() [1/2]

template<typename M >
std::vector<std::vector<M> > casadi::FunctionInternal::replace_aseed ( const std::vector< std::vector< M > > &  aseed,
casadi_int  npar 
) const
inherited

Definition at line 1814 of file function_internal.hpp.

1815  {
1816  std::vector<std::vector<M> > r(aseed.size());
1817  for (casadi_int d=0; d<r.size(); ++d) r[d] = replace_res(aseed[d], npar);
1818  return r;
1819  }

References casadi::FunctionInternal::replace_res().

◆ replace_aseed() [2/2]

template<typename M >
std::vector<std::vector<M> > casadi::FunctionInternal::replace_aseed ( const std::vector< std::vector< M >> &  aseed,
casadi_int  npar 
) const
inherited

◆ replace_fseed() [1/2]

template<typename M >
std::vector<std::vector<M> > casadi::FunctionInternal::replace_fseed ( const std::vector< std::vector< M > > &  fseed,
casadi_int  npar 
) const
inherited

Definition at line 1806 of file function_internal.hpp.

1807  {
1808  std::vector<std::vector<M> > r(fseed.size());
1809  for (casadi_int d=0; d<r.size(); ++d) r[d] = replace_arg(fseed[d], npar);
1810  return r;
1811  }

References casadi::FunctionInternal::replace_arg().

◆ replace_fseed() [2/2]

template<typename M >
std::vector<std::vector<M> > casadi::FunctionInternal::replace_fseed ( const std::vector< std::vector< M >> &  fseed,
casadi_int  npar 
) const
inherited

◆ replace_res()

template<typename M >
std::vector< M > casadi::FunctionInternal::replace_res ( const std::vector< M > &  res,
casadi_int  npar 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kp

Definition at line 1798 of file function_internal.hpp.

1799  {
1800  std::vector<M> r(res.size());
1801  for (casadi_int i=0; i<r.size(); ++i) r[i] = replace_mat(res[i], sparsity_out(i), npar);
1802  return r;
1803  }

References casadi::replace_mat(), and casadi::FunctionInternal::sparsity_out().

Referenced by casadi::FunctionInternal::nz_out(), and casadi::FunctionInternal::replace_aseed().

◆ reset_dump_count()

void casadi::FunctionInternal::reset_dump_count ( )
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2dx

Definition at line 461 of file function_internal.cpp.

461  {
462  dump_count_ = 0;
463  }

References casadi::FunctionInternal::dump_count_.

◆ reverse()

Function casadi::FunctionInternal::reverse ( casadi_int  nadj) const
inherited

reverse(nadj) returns a cached instance if available, and calls Function get_reverse(casadi_int nadj) if no cached version is available.

Extra doc: https://github.com/casadi/casadi/wiki/L_l1

Definition at line 2224 of file function_internal.cpp.

2224  {
2225  casadi_assert_dev(nadj>=0);
2226  // Used wrapped function if reverse not available
2227  if (!enable_reverse_) {
2228  // Derivative information must be available
2229  casadi_assert(has_derivative(), "Derivatives cannot be calculated for " + name_);
2230  return wrap().reverse(nadj);
2231  }
2232  // Retrieve/generate cached
2233  Function f;
2234  std::string fname = reverse_name(name_, nadj);
2235  if (!incache(fname, f)) {
2236  casadi_int i;
2237  // Prefix to be used for adjoint seeds, sensitivities
2238  std::string pref = diff_prefix("adj");
2239  // Names of inputs
2240  std::vector<std::string> inames;
2241  for (i=0; i<n_in_; ++i) inames.push_back(name_in_[i]);
2242  for (i=0; i<n_out_; ++i) inames.push_back("out_" + name_out_[i]);
2243  for (i=0; i<n_out_; ++i) inames.push_back(pref + name_out_[i]);
2244  // Names of outputs
2245  std::vector<std::string> onames;
2246  for (casadi_int i=0; i<n_in_; ++i) onames.push_back(pref + name_in_[i]);
2247  // Options
2249  opts = combine(opts, generate_options("reverse"));
2250  opts["derivative_of"] = self();
2251  // Generate derivative function
2252  casadi_assert_dev(enable_reverse_);
2253  f = get_reverse(nadj, fname, inames, onames, opts);
2254  // Consistency check for inputs
2255  casadi_assert_dev(f.n_in()==n_in_ + n_out_ + n_out_);
2256  casadi_int ind=0;
2257  for (i=0; i<n_in_; ++i) f.assert_size_in(ind++, size1_in(i), size2_in(i));
2258  for (i=0; i<n_out_; ++i) f.assert_size_in(ind++, size1_out(i), size2_out(i));
2259  for (i=0; i<n_out_; ++i) f.assert_size_in(ind++, size1_out(i), nadj*size2_out(i));
2260  // Consistency check for outputs
2261  casadi_assert_dev(f.n_out()==n_in_);
2262  for (i=0; i<n_in_; ++i) f.assert_sparsity_out(i, sparsity_in(i), nadj);
2263  // Save to cache
2264  tocache_if_missing(f);
2265  }
2266  return f;
2267  }
virtual Function get_reverse(casadi_int nadj, const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const
Return function that calculates adjoint derivatives.
static std::string reverse_name(const std::string &fcn, casadi_int nadj)
Helper function: Get name of adjoint derivative function.
Function reverse(casadi_int nadj) const
Get a function that calculates nadj adjoint derivatives.
Definition: function.cpp:1143

References casadi::Function::assert_size_in(), casadi::Function::assert_sparsity_out(), casadi::combine(), casadi::FunctionInternal::der_options_, casadi::FunctionInternal::diff_prefix(), casadi::FunctionInternal::enable_reverse_, casadi::FunctionInternal::generate_options(), casadi::FunctionInternal::get_reverse(), casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::incache(), casadi::Function::n_in(), casadi::FunctionInternal::n_in_, casadi::Function::n_out(), casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::Function::reverse(), casadi::FunctionInternal::reverse_name(), casadi::FunctionInternal::reverse_options_, casadi::FunctionInternal::size1_in(), casadi::FunctionInternal::size1_out(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::size2_out(), casadi::FunctionInternal::sparsity_in(), casadi::FunctionInternal::tocache_if_missing(), and casadi::FunctionInternal::wrap().

Referenced by casadi::FunctionInternal::call_reverse(), and casadi::Function::reverse().

◆ reverse_name()

static std::string casadi::FunctionInternal::reverse_name ( const std::string &  fcn,
casadi_int  nadj 
)
inlinestaticinherited

Definition at line 662 of file function_internal.hpp.

662  {
663  return "adj" + str(nadj) + "_" + fcn;
664  }

References casadi::str().

Referenced by casadi::FunctionInternal::reverse(), and casadi::FixedStepIntegrator::stepB().

◆ self()

Function casadi::FunctionInternal::self ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_k8

Definition at line 353 of file function_internal.hpp.

353 { return shared_from_this<Function>();}

◆ serialize()

void casadi::ProtoFunction::serialize ( SerializingStream s) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_jv

Definition at line 4181 of file function_internal.cpp.

4181  {
4182  serialize_type(s);
4183  serialize_body(s);
4184  }
virtual void serialize_type(SerializingStream &s) const
Serialize type information.
virtual void serialize_body(SerializingStream &s) const
Serialize an object without type information.

References casadi::ProtoFunction::serialize_body(), and casadi::ProtoFunction::serialize_type().

◆ serialize_base_function()

std::string casadi::Nlpsol::serialize_base_function ( ) const
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1no

Reimplemented from casadi::ProtoFunction.

Definition at line 133 of file nlpsol_impl.hpp.

133 { return "Nlpsol"; }

◆ serialize_body()

void casadi::Feasiblesqpmethod::serialize_body ( SerializingStream s) const
overridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 2407 of file feasiblesqpmethod.cpp.

2407  {
2409  s.version("Feasiblesqpmethod", 3);
2410  s.pack("Feasiblesqpmethod::qpsol", qpsol_);
2411  // s.pack("Feasiblesqpmethod::qpsol_ela", qpsol_ela_);
2412  s.pack("Feasiblesqpmethod::exact_hessian", exact_hessian_);
2413  s.pack("Feasiblesqpmethod::max_iter", max_iter_);
2414  s.pack("Feasiblesqpmethod::min_iter", min_iter_);
2415  s.pack("Feasiblesqpmethod::lbfgs_memory", lbfgs_memory_);
2416  s.pack("Feasiblesqpmethod::tol_pr_", tol_pr_);
2417  s.pack("Feasiblesqpmethod::tol_du_", tol_du_);
2418  s.pack("Feasiblesqpmethod::print_header", print_header_);
2419  s.pack("Feasiblesqpmethod::print_iteration", print_iteration_);
2420  s.pack("Feasiblesqpmethod::print_status", print_status_);
2421 
2422  s.pack("Feasiblesqpmethod::init_feasible", init_feasible_);
2423  s.pack("Feasiblesqpmethod::Hsp", Hsp_);
2424  s.pack("Feasiblesqpmethod::Asp", Asp_);
2425  s.pack("Feasiblesqpmethod::convexify", convexify_);
2426  if (convexify_) Convexify::serialize(s, "Feasiblesqpmethod::", convexify_data_);
2427  }
static void serialize(SerializingStream &s, const std::string &prefix, const ConvexifyData &d)
Definition: convexify.cpp:111
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
Definition: nlpsol.cpp:1306

References Asp_, convexify_, convexify_data_, exact_hessian_, Hsp_, init_feasible_, lbfgs_memory_, max_iter_, min_iter_, casadi::SerializingStream::pack(), print_header_, print_iteration_, print_status_, qpsol_, casadi::Convexify::serialize(), casadi::Nlpsol::serialize_body(), tol_du_, tol_pr_, and casadi::SerializingStream::version().

◆ serialize_type()

void casadi::Nlpsol::serialize_type ( SerializingStream s) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1nm

Reimplemented from casadi::FunctionInternal.

Definition at line 1336 of file nlpsol.cpp.

1336  {
1339  }
void serialize_type(SerializingStream &s) const override
Serialize type information.
void serialize_type(SerializingStream &s) const
Serialize type information.

References casadi::PluginInterface< Derived >::serialize_type(), and casadi::FunctionInternal::serialize_type().

◆ set_function() [1/2]

void casadi::OracleFunction::set_function ( const Function fcn)
inlineinherited

Register the function for evaluation and statistics gathering

Definition at line 183 of file oracle_function.hpp.

183 { set_function(fcn, fcn.name()); }

References casadi::Function::name(), and casadi::OracleFunction::set_function().

Referenced by casadi::OracleFunction::set_function().

◆ set_function() [2/2]

void casadi::OracleFunction::set_function ( const Function fcn,
const std::string &  fname,
bool  jit = false 
)
inherited

◆ set_jac_sparsity()

void casadi::FunctionInternal::set_jac_sparsity ( casadi_int  oind,
casadi_int  iind,
const Sparsity sp 
)
protectedinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nx

Definition at line 3761 of file function_internal.cpp.

3761  {
3762 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
3763  // Safe access to jac_sparsity_
3764  std::lock_guard<std::mutex> lock(jac_sparsity_mtx_);
3765 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
3766  casadi_int ind = iind + oind * n_in_;
3767  jac_sparsity_[false].resize(n_in_ * n_out_);
3768  jac_sparsity_[false].at(ind) = sp;
3769  jac_sparsity_[true].resize(n_in_ * n_out_);
3770  jac_sparsity_[true].at(ind) = to_compact(oind, iind, sp);
3771  }

References casadi::FunctionInternal::jac_sparsity_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, and casadi::FunctionInternal::to_compact().

◆ set_temp()

void casadi::OracleFunction::set_temp ( void *  mem,
const double **  arg,
double **  res,
casadi_int *  iw,
double *  w 
) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_q

Reimplemented from casadi::FunctionInternal.

Definition at line 505 of file oracle_function.cpp.

506  {
507 
508  auto m = static_cast<OracleMemory*>(mem);
509  m->arg = arg;
510  m->res = res;
511  m->iw = iw;
512  m->w = w;
513  m->d_oracle.arg = arg;
514  m->d_oracle.res = res;
515  m->d_oracle.iw = iw;
516  m->d_oracle.w = w;
517  for (int i = 0; i < max_num_threads_; ++i) {
518  auto* ml = m->thread_local_mem[i];
519  for (auto&& s : ml->fstats) s.second.reset();
520  ml->arg = arg;
521  ml->res = res;
522  ml->iw = iw;
523  ml->w = w;
524  arg += stride_arg_;
525  res += stride_res_;
526  iw += stride_iw_;
527  w += stride_w_;
528  }
529 }

References casadi::OracleMemory::arg, casadi::OracleFunction::max_num_threads_, casadi::OracleFunction::stride_arg_, casadi::OracleFunction::stride_iw_, casadi::OracleFunction::stride_res_, and casadi::OracleFunction::stride_w_.

◆ set_work()

void casadi::Feasiblesqpmethod::set_work ( void *  mem,
const double **&  arg,
double **&  res,
casadi_int *&  iw,
double *&  w 
) const
overridevirtual

Reimplemented from casadi::Nlpsol.

Definition at line 480 of file feasiblesqpmethod.cpp.

481  {
482  auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
483 
484  // Set work in base classes
485  Nlpsol::set_work(mem, arg, res, iw, w);
486 
487  m->d.prob = &p_;
488  casadi_feasiblesqpmethod_init(&m->d, &iw, &w, sz_anderson_memory_);
489 
490  m->iter_count = -1;
491  }
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
Definition: nlpsol.cpp:795

References p_, casadi::Nlpsol::set_work(), and sz_anderson_memory_.

◆ setOptionsFromFile()

void casadi::Nlpsol::setOptionsFromFile ( const std::string &  file)
virtualinherited

Definition at line 674 of file nlpsol.cpp.

674  {
675  casadi_error("setOptionsFromFile not defined for class " + class_name());
676  }

References casadi::Nlpsol::class_name().

◆ setup()

void casadi::FunctionInternal::setup ( void *  mem,
const double **  arg,
double **  res,
casadi_int *  iw,
double *  w 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nb

Definition at line 3549 of file function_internal.cpp.

3550  {
3551  set_work(mem, arg, res, iw, w);
3552  set_temp(mem, arg, res, iw, w);
3553  auto m = static_cast<FunctionMemory*>(mem);
3554  m->stats_available = true;
3555  }
virtual void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const
Set the (persistent) work vectors.
virtual void set_temp(void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
Set the (temporary) work vectors.

References casadi::FunctionInternal::set_temp(), casadi::FunctionInternal::set_work(), and casadi::FunctionMemory::stats_available.

Referenced by casadi::Conic::eval(), casadi::Nlpsol::eval(), casadi::CallbackInternal::eval(), casadi::FiniteDiff::eval(), casadi::FmuFunction::eval(), casadi::Integrator::eval(), casadi::Map::eval(), casadi::OmpMap::eval(), casadi::ThreadMap::eval(), casadi::MapSum::eval(), casadi::MXFunction::eval(), casadi::Rootfinder::eval(), casadi::Switch::eval(), casadi::SXFunction::eval(), casadi::SlicotDple::eval(), casadi::SlicotExpm::eval(), casadi::BSplineInterpolant::eval(), and casadi::LinearInterpolant::eval().

◆ shared_from_this() [1/2]

B casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::shared_from_this ( )
inlineprotectedinherited

Definition at line 83 of file generic_shared_internal.hpp.

83  {
84  casadi_assert_dev(B::test_cast(static_cast<Internal*>(this)));
85  B ret;
86  ret.own(static_cast<Internal*>(this));
87  return ret;
88  }

◆ shared_from_this() [2/2]

const B casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::shared_from_this ( ) const
inlineprotectedinherited

Definition at line 92 of file generic_shared_internal.hpp.

92  {
93  casadi_assert_dev(B::test_cast(static_cast<const Internal*>(this)));
94  B ret;
95  ret.own(const_cast<Internal*>(static_cast<const Internal*>(this)));
96  return ret;
97  }

◆ shortname()

static std::string casadi::Nlpsol::shortname ( )
inlinestaticinherited

Definition at line 293 of file nlpsol_impl.hpp.

293 { return "nlpsol";}

◆ signature()

std::string casadi::FunctionInternal::signature ( const std::string &  fname) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ly

Definition at line 2413 of file function_internal.cpp.

2413  {
2414  return "int " + fname + "(const casadi_real** arg, casadi_real** res, "
2415  "casadi_int* iw, casadi_real* w, int mem)";
2416  }

Referenced by casadi::CodeGenerator::add(), casadi::FunctionInternal::codegen(), and casadi::External::codegen_declarations().

◆ signature_unrolled()

std::string casadi::FunctionInternal::signature_unrolled ( const std::string &  fname) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_27o

Definition at line 2418 of file function_internal.cpp.

2418  {
2419  std::vector<std::string> args;
2420  for (auto e : name_in_) {
2421  args.push_back("const casadi_real* " + str(e));
2422  }
2423  for (auto e : name_out_) {
2424  args.push_back("casadi_real* " + str(e));
2425  }
2426  args.push_back("const casadi_real** arg");
2427  args.push_back("casadi_real** res");
2428  args.push_back("casadi_int* iw");
2429  args.push_back("casadi_real* w");
2430  args.push_back("int mem");
2431  return "int " + fname + "_unrolled(" + join(args, ", ") + ")";
2432  }

References casadi::join(), casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, and casadi::str().

Referenced by casadi::CodeGenerator::add().

◆ size1_in()

casadi_int casadi::FunctionInternal::size1_in ( casadi_int  ind) const
inlineinherited

◆ size1_out()

casadi_int casadi::FunctionInternal::size1_out ( casadi_int  ind) const
inlineinherited

◆ size2_in()

casadi_int casadi::FunctionInternal::size2_in ( casadi_int  ind) const
inlineinherited

◆ size2_out()

casadi_int casadi::FunctionInternal::size2_out ( casadi_int  ind) const
inlineinherited

◆ size_in()

std::pair<casadi_int, casadi_int> casadi::FunctionInternal::size_in ( casadi_int  ind) const
inlineinherited

◆ size_out()

std::pair<casadi_int, casadi_int> casadi::FunctionInternal::size_out ( casadi_int  ind) const
inlineinherited

◆ slice()

Function casadi::FunctionInternal::slice ( const std::string &  name,
const std::vector< casadi_int > &  order_in,
const std::vector< casadi_int > &  order_out,
const Dict opts 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l2

Reimplemented in casadi::XFunction< DerivedType, MatType, NodeType >, casadi::XFunction< MXFunction, MX, MXNode >, and casadi::XFunction< SXFunction, Matrix< SXElem >, SXNode >.

Definition at line 3742 of file function_internal.cpp.

3744  {
3745  return wrap().slice(name, order_in, order_out, opts);
3746  }
Function slice(const std::string &name, const std::vector< casadi_int > &order_in, const std::vector< casadi_int > &order_out, const Dict &opts=Dict()) const
returns a new function with a selection of inputs/outputs of the original
Definition: function.cpp:747

References casadi::Function::slice(), and casadi::FunctionInternal::wrap().

Referenced by casadi::Function::slice().

◆ solve()

int casadi::Feasiblesqpmethod::solve ( void *  mem) const
overridevirtual

Implements casadi::Nlpsol.

Definition at line 957 of file feasiblesqpmethod.cpp.

957  {
958  auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
959  auto d_nlp = &m->d_nlp;
960  auto d = &m->d;
961 
962  // DM(std::vector<double>(d_nlp->z, d_nlp->z+nx_)).to_file("x0.mtx");
963  // Number of SQP iterations
964  m->iter_count = 0;
965 
966  // Reset
967  // m->merit_ind = 0;
968  // m->sigma = 0.; // NOTE: Move this into the main optimization loop
969  // m->reg = 0;
970  int step_accepted = 0;
971 
972  // Default quadratic model value of objective
973  double m_k = -1.0;
974 
975  double tr_ratio = 0.0;
976 
977  double tr_rad = tr_rad0_;
978  double tr_rad_prev = tr_rad0_;
979 
980  // transfer the scale vector to the problem
981  casadi_copy(get_ptr(tr_scale_vector_), nx_, d->tr_scale_vector);
982 
983  for (casadi_int i=0;i<nx_;++i) {
984  d->tr_mask[i] = d->tr_scale_vector[i]!=0;
985  }
986 
987  // For seeds ---- This is so far needed!!! ------------------
988  const double one = 1.;
989 
990  // Info for printing
991  std::string info = "";
992 
993  casadi_clear(d->dx, nx_);
994 
995  // ------------------------------------------------------------------------
996  // MAIN OPTIMIZATION LOOP
997  // ------------------------------------------------------------------------
998  while (true) {
999  // Evaluate f, g and first order derivative information
1000  /*m->arg[0] = d_nlp->z;
1001  m->arg[1] = d_nlp->p;
1002  m->res[0] = &d_nlp->objective;
1003  m->res[1] = d->gf;
1004  m->res[2] = d_nlp->z + nx_;
1005  m->res[3] = d->Jk;
1006  switch (calc_function(m, "nlp_jac_fg")) {
1007  case -1:
1008  m->return_status = "Non_Regular_Sensitivities";
1009  m->unified_return_status = SOLVER_RET_NAN;
1010  if (print_status_)
1011  print("MESSAGE(feasiblesqpmethod): No regularity of sensitivities at current point.\n");
1012  return 1;
1013  case 0:
1014  break;
1015  default:
1016  return 1;
1017  }*/
1018  if (m->iter_count == 0) {
1019  // Evaluate the sensitivities -------------------------------------------
1020  // Evaluate f
1021  m->arg[0] = d_nlp->z;
1022  m->arg[1] = d_nlp->p;
1023  m->res[0] = &d_nlp->objective;
1024  if (calc_function(m, "nlp_f")) {
1025  uout() << "What does it mean that calc_function fails here??" << std::endl;
1026  }
1027  // Evaluate g
1028  m->arg[0] = d_nlp->z;
1029  m->arg[1] = d_nlp->p;
1030  m->res[0] = d_nlp->z + nx_;
1031  if (calc_function(m, "nlp_g")) {
1032  uout() << "What does it mean that calc_function fails here??" << std::endl;
1033  }
1034  // Evaluate grad_f
1035  m->arg[0] = d_nlp->z;
1036  m->arg[1] = d_nlp->p;
1037  m->res[0] = d->gf;
1038  if (calc_function(m, "nlp_grad_f")) {
1039  uout() << "What does it mean that calc_function fails here??" << std::endl;
1040  }
1041  // Evaluate jac_g
1042  m->arg[0] = d_nlp->z;
1043  m->arg[1] = d_nlp->p;
1044  m->res[0] = d->Jk;
1045  switch (calc_function(m, "nlp_jac_g")) {
1046  case -1:
1047  m->return_status = "Non_Regular_Sensitivities";
1048  m->unified_return_status = SOLVER_RET_NAN;
1049  if (print_status_)
1050  print("MESSAGE(feasiblesqpmethod): "
1051  "No regularity of sensitivities at current point.\n");
1052  return 1;
1053  case 0:
1054  break;
1055  default:
1056  return 1;
1057 
1058  }
1059  // uout() << "x0: " << *d_nlp->z << std::endl;
1060  // uout() << "nlp_f: " << d_nlp->objective << std::endl;
1061  // uout() << "nlp_g: " << *(d_nlp->z + nx_) << std::endl;
1062 
1063  if (use_sqp_) {
1064  if (exact_hessian_) {
1065  // Update/reset exact Hessian
1066  m->arg[0] = d_nlp->z;
1067  m->arg[1] = d_nlp->p;
1068  m->arg[2] = &one;
1069  m->arg[3] = d_nlp->lam + nx_;
1070  m->res[0] = d->Bk;
1071  if (calc_function(m, "nlp_hess_l")) return 1;
1072  if (convexify_) {
1073  ScopedTiming tic(m->fstats.at("convexify"));
1074  if (convexify_eval(&convexify_data_.config, d->Bk, d->Bk, m->iw, m->w)) return 1;
1075  }
1076  } else if (m->iter_count==0) {
1077  ScopedTiming tic(m->fstats.at("BFGS"));
1078  // Initialize BFGS
1079  casadi_fill(d->Bk, Hsp_.nnz(), 1.);
1080  casadi_bfgs_reset(Hsp_, d->Bk);
1081  } else {
1082  ScopedTiming tic(m->fstats.at("BFGS"));
1083  // Update BFGS
1084  if (m->iter_count % lbfgs_memory_ == 0) casadi_bfgs_reset(Hsp_, d->Bk);
1085  // Update the Hessian approximation
1086  casadi_bfgs(Hsp_, d->Bk, d->dx, d->gLag, d->gLag_old, m->w);
1087  }
1088 
1089  // test if initialization is feasible
1090  if (casadi_max_viol(nx_ + ng_, d_nlp->z, d_nlp->lbz, d_nlp->ubz) > feas_tol_) {
1091  if (print_status_)print("MESSAGE(feasiblesqpmethod): "
1092  "No feasible initialization given! "
1093  "Find feasible initialization.\n");
1094  m->return_status = "No_Feasible_Initialization";
1095  break;
1096  }
1097  }
1098 
1099  } else if (step_accepted == 0) {
1100  // Evaluate grad_f
1101  m->arg[0] = d_nlp->z;
1102  m->arg[1] = d_nlp->p;
1103  m->res[0] = d->gf;
1104  if (calc_function(m, "nlp_grad_f")) {
1105  uout() << "What does it mean that calc_function fails here??" << std::endl;
1106  }
1107  // Evaluate jac_g
1108  m->arg[0] = d_nlp->z;
1109  m->arg[1] = d_nlp->p;
1110  m->res[0] = d->Jk;
1111  switch (calc_function(m, "nlp_jac_g")) {
1112  case -1:
1113  m->return_status = "Non_Regular_Sensitivities";
1114  m->unified_return_status = SOLVER_RET_NAN;
1115  if (print_status_)
1116  print("MESSAGE(feasiblesqpmethod): "
1117  "No regularity of sensitivities at current point.\n");
1118  return 1;
1119  case 0:
1120  break;
1121  default:
1122  return 1;
1123  }
1124  // uout() << "x0: " << *d_nlp->z << std::endl;
1125  // uout() << "nlp_f: " << d_nlp->objective << std::endl;
1126  // uout() << "nlp_g: " << *(d_nlp->z + nx_) << std::endl;
1127 
1128  if (use_sqp_) {
1129  if (exact_hessian_) {
1130  // Update/reset exact Hessian
1131  m->arg[0] = d_nlp->z;
1132  m->arg[1] = d_nlp->p;
1133  m->arg[2] = &one;
1134  m->arg[3] = d_nlp->lam + nx_;
1135  m->res[0] = d->Bk;
1136  if (calc_function(m, "nlp_hess_l")) return 1;
1137  if (convexify_) {
1138  ScopedTiming tic(m->fstats.at("convexify"));
1139  if (convexify_eval(&convexify_data_.config, d->Bk, d->Bk, m->iw, m->w)) return 1;
1140  }
1141  } else if (m->iter_count==0) {
1142  ScopedTiming tic(m->fstats.at("BFGS"));
1143  // Initialize BFGS
1144  casadi_fill(d->Bk, Hsp_.nnz(), 1.);
1145  casadi_bfgs_reset(Hsp_, d->Bk);
1146  } else {
1147  ScopedTiming tic(m->fstats.at("BFGS"));
1148  // Update BFGS
1149  if (m->iter_count % lbfgs_memory_ == 0) casadi_bfgs_reset(Hsp_, d->Bk);
1150  // Update the Hessian approximation
1151  casadi_bfgs(Hsp_, d->Bk, d->dx, d->gLag, d->gLag_old, m->w);
1152  }
1153  }
1154  }
1155 
1156  // Evaluate the gradient of the Lagrangian
1157  casadi_copy(d->gf, nx_, d->gLag);
1158  casadi_mv(d->Jk, Asp_, d_nlp->lam+nx_, d->gLag, true);
1159  casadi_axpy(nx_, 1., d_nlp->lam, d->gLag);
1160 
1161  // Primal infeasability
1162  double pr_inf = casadi_max_viol(nx_+ng_, d_nlp->z, d_nlp->lbz, d_nlp->ubz);
1163  // uout() << "pr_inf: " << pr_inf << std::endl;
1164  // inf-norm of Lagrange gradient
1165  // uout() << "grad Lag: " << std::vector<double>(*d->gLag,0,nx_) << std::endl;
1166  double du_inf = casadi_norm_inf(nx_, d->gLag);
1167  // uout() << "du_inf: " << du_inf << std::endl;
1168 
1169  // inf-norm of step, d->dx is a nullptr???
1170  // uout() << "HERE!!!!" << *d->dx << std::endl;
1171  double dx_norminf = casadi_norm_inf(nx_, d->dx);
1172 
1173  // uout() << "objective value: " << d_nlp->objective << std::endl;
1174  // Printing information about the actual iterate
1175  if (print_iteration_) {
1176  // if (m->iter_count % 10 == 0) print_iteration();
1177  print_iteration();
1178  print_iteration(m->iter_count, d_nlp->objective, m_k, tr_ratio,
1179  pr_inf, du_inf, dx_norminf, m->reg, tr_rad_prev, info);
1180  info = "";
1181  }
1182  tr_rad_prev = tr_rad;
1183 
1184  // Callback function
1185  if (callback(m)) {
1186  if (print_status_) print("WARNING(feasiblesqpmethod): Aborted by callback...\n");
1187  m->return_status = "User_Requested_Stop";
1188  break;
1189  }
1190 
1191  // Checking convergence criteria
1192  // Where is the complementarity condition??
1193  // if (m->iter_count >= min_iter_ && pr_inf < tol_pr_ && du_inf < tol_du_) {
1194  // if (print_status_)
1195  // print("MESSAGE(feasiblesqpmethod): "
1196  // "Convergence achieved after %d iterations\n", m->iter_count);
1197  // m->return_status = "Solve_Succeeded";
1198  // m->success = true;
1199  // break;
1200  // }
1201 
1202  if (m->iter_count >= max_iter_) {
1203  if (print_status_) {
1204  print("MESSAGE(feasiblesqpmethod): Maximum number of iterations reached.\n");
1205  }
1206  m->return_status = "Maximum_Iterations_Exceeded";
1207  m->unified_return_status = SOLVER_RET_LIMITED;
1208  break;
1209  }
1210 
1211  // Formulate the QP
1212  // Define lower bounds
1213  casadi_copy(d_nlp->lbz, nx_+ng_, d->lbdz);
1214  casadi_axpy(nx_+ng_, -1., d_nlp->z, d->lbdz);
1215  casadi_clip_min(d->lbdz, nx_, -tr_rad, d->tr_mask);
1216  // uout() << "lbdz: " << std::vector<double>(d->lbdz, d->lbdz+nx_) << std::endl;
1217 
1218 
1219  // Define upper bounds
1220  casadi_copy(d_nlp->ubz, nx_+ng_, d->ubdz);
1221  casadi_axpy(nx_+ng_, -1., d_nlp->z, d->ubdz);
1222  casadi_clip_max(d->ubdz, nx_, tr_rad, d->tr_mask);
1223  // uout() << "ubdz: " << std::vector<double>(d->ubdz, d->ubdz+nx_) << std::endl;
1224 
1225  // Initial guess
1226  casadi_copy(d_nlp->lam, nx_+ng_, d->dlam);
1227  //casadi_clear(d->dx, nx_);
1228 
1229  // Increase counter
1230  m->iter_count++;
1231 
1232  // DM(std::vector<double>(d->gf,d->gf+nx_)).to_file("gf.mtx");
1233  // DM(std::vector<double>(d->lbdz, d->lbdz+nx_)).to_file("lb_var.mtx");
1234  // DM(std::vector<double>(d->ubdz, d->ubdz+nx_)).to_file("ub_var.mtx");
1235  // DM(std::vector<double>(d->lbdz+nx_, d->lbdz+nx_+ng_)).to_file("lba.mtx");
1236  // DM(std::vector<double>(d->ubdz+nx_, d->ubdz+nx_+ng_)).to_file("uba.mtx");
1237  // // DM(std::vector<double>(d->Bk, d->Bk+Hsp_.nnz())).to_file("Bk.mtx");
1238  // DM(std::vector<double>(d->Jk, d->Jk+Asp_.nnz())).to_file("Jk.mtx");
1239  // DM(std::vector<double>(d->dlam, d->dlam+nx_)).to_file("lam_x.mtx");
1240  // DM(std::vector<double>(d->dx, d->dx+nx_)).to_file("dx_input.mtx");
1241  // DM(std::vector<double>(d->dlam+nx_, d->dlam+nx_+ng_)).to_file("lam_g.mtx");
1242 
1243  int ret = 0;
1244  // Solve the QP
1245  if (use_sqp_) {
1246  ret = solve_QP(m, d->Bk, d->gf, d->lbdz, d->ubdz, d->Jk,
1247  d->dx, d->dlam, 0);
1248  } else {
1249  ret = solve_LP(m, d->gf, d->lbdz, d->ubdz, d->Jk,
1250  d->dx, d->dlam, 0);
1251  }
1252 
1253  // DM(std::vector<double>(d->dx,d->dx+nx_)).to_file("dx_out.mtx");
1254  // Eval quadratic model and check for convergence
1255  m_k = eval_m_k(mem);
1256  if (fabs(m_k) < optim_tol_) {
1257  if (print_status_)
1258  print("MESSAGE(feasiblesqpmethod): "
1259  "Optimal Point Found? Quadratic model is zero. "
1260  "After %d iterations\n", m->iter_count-1);
1261  m->return_status = "Solve_Succeeded";
1262  m->success = true;
1263  break;
1264  }
1265 
1266  // uout() << "QP step: " << std::vector<double>(d->dx, d->dx+nx_) << std::endl;
1267  // Detecting indefiniteness
1268  if (use_sqp_) {
1269  double gain = casadi_bilin(d->Bk, Hsp_, d->dx, d->dx);
1270  if (gain < 0) {
1271  if (print_status_) print("WARNING(feasiblesqpmethod): Indefinite Hessian detected\n");
1272  }
1273  }
1274 
1275  // Do the feasibility iterations here
1276  ret = feasibility_iterations(mem, tr_rad);
1277 
1278  // Check if step was accepted or not
1279  if (ret < 0) {
1280  uout() << "Rejected inner iterates" << std::endl;
1281  // uout() << casadi_masked_norm_inf(nx_, d->dx, d->tr_mask) << std::endl;
1282 
1283  tr_rad = 0.5 * casadi_masked_norm_inf(nx_, d->dx, d->tr_mask);
1284  } else {
1285  // Evaluate f
1286  m->arg[0] = d->z_feas;
1287  m->arg[1] = d_nlp->p;
1288  m->res[0] = &d->f_feas;
1289  if (calc_function(m, "nlp_f")) {
1290  uout() << "What does it mean that calc_function fails here??" << std::endl;
1291  }
1292  tr_ratio = eval_tr_ratio(d_nlp->objective, d->f_feas, m_k);
1293  tr_update(mem, tr_rad, tr_ratio);
1294  if (tr_rad < feas_tol_) {
1295  if (print_status_) print("MESSAGE(feasiblesqpmethod): "
1296  "Trust-region radius smaller than feasibility!! "
1297  "Abort!!.\n");
1298  m->return_status = "Trust_Region_Radius_Becomes_Too_Small";
1299  break;
1300  }
1301 
1302  step_accepted = step_update(mem, tr_ratio);
1303  }
1304 
1305  if (!exact_hessian_) {
1306  // Evaluate the gradient of the Lagrangian with the old x but new lam (for BFGS)
1307  casadi_copy(d->gf, nx_, d->gLag_old);
1308  casadi_mv(d->Jk, Asp_, d_nlp->lam+nx_, d->gLag_old, true);
1309  casadi_axpy(nx_, 1., d_nlp->lam, d->gLag_old);
1310  }
1311  }
1312 
1313  return 0;
1314  }
int step_update(void *mem, double tr_ratio) const
void print_iteration() const
Print iteration header.
int feasibility_iterations(void *mem, double tr_rad) const
void tr_update(void *mem, double &tr_rad, double tr_ratio) const
double eval_tr_ratio(double val_f, double val_f_corr, double val_m_k) const
double eval_m_k(void *mem) const
int callback(NlpsolMemory *m) const
Definition: nlpsol.cpp:1121
T1 casadi_norm_inf(casadi_int n, const T1 *x)
@ SOLVER_RET_NAN
@ SOLVER_RET_LIMITED
casadi_convexify_config< double > config
Definition: mx.hpp:61

References Asp_, casadi::OracleFunction::calc_function(), casadi::Nlpsol::callback(), casadi::casadi_axpy(), casadi::casadi_bilin(), casadi::casadi_clear(), casadi::casadi_copy(), casadi::casadi_fill(), casadi::casadi_max_viol(), casadi::casadi_mv(), casadi::casadi_norm_inf(), casadi::ConvexifyData::config, convexify_, convexify_data_, casadi::NlpsolMemory::d_nlp, eval_m_k(), eval_tr_ratio(), exact_hessian_, feas_tol_, feasibility_iterations(), casadi::get_ptr(), Hsp_, casadi::FunctionInternal::info(), lbfgs_memory_, max_iter_, casadi::Nlpsol::ng_, casadi::Sparsity::nnz(), casadi::Nlpsol::nx_, optim_tol_, casadi::ProtoFunction::print(), print_iteration(), print_iteration_, print_status_, solve_LP(), solve_QP(), casadi::SOLVER_RET_LIMITED, casadi::SOLVER_RET_NAN, step_update(), tr_rad0_, tr_scale_vector_, tr_update(), casadi::uout(), and use_sqp_.

◆ solve_LP()

int casadi::Feasiblesqpmethod::solve_LP ( FeasiblesqpmethodMemory m,
const double *  g,
const double *  lbdz,
const double *  ubdz,
const double *  A,
double *  x_opt,
double *  dlam,
int  mode 
) const
virtual

Definition at line 1348 of file feasiblesqpmethod.cpp.

1350  {
1351  ScopedTiming tic(m->fstats.at("QP"));
1352  // Inputs
1353  std::fill_n(m->arg, qpsol_.n_in(), nullptr);
1354  // double lol;
1355  m->arg[CONIC_H] = nullptr;
1356  m->arg[CONIC_G] = g;
1357  m->arg[CONIC_X0] = x_opt;
1358  m->arg[CONIC_LAM_X0] = dlam;
1359  m->arg[CONIC_LAM_A0] = dlam + nx_;
1360  m->arg[CONIC_LBX] = lbdz;
1361  m->arg[CONIC_UBX] = ubdz;
1362  m->arg[CONIC_A] = A;
1363  m->arg[CONIC_LBA] = lbdz+nx_;
1364  m->arg[CONIC_UBA] = ubdz+nx_;
1365 
1366  // Outputs
1367  std::fill_n(m->res, qpsol_.n_out(), nullptr);
1368  m->res[CONIC_X] = x_opt;
1369  m->res[CONIC_LAM_X] = dlam;
1370  m->res[CONIC_LAM_A] = dlam + nx_;
1371  double obj;
1372  m->res[CONIC_COST] = &obj;
1373  // m->res[CONIC_COST] = nullptr;
1374 
1375 
1376  // Solve the QP
1377  qpsol_(m->arg, m->res, m->iw, m->w);
1378 
1379  if (verbose_) print("QP solved\n");
1380  return 0;
1381  }
@ CONIC_COST
The optimal cost.
Definition: conic.hpp:203

References casadi::OracleMemory::arg, casadi::CONIC_A, casadi::CONIC_COST, casadi::CONIC_G, casadi::CONIC_H, casadi::CONIC_LAM_A, casadi::CONIC_LAM_A0, casadi::CONIC_LAM_X, casadi::CONIC_LAM_X0, casadi::CONIC_LBA, casadi::CONIC_LBX, casadi::CONIC_UBA, casadi::CONIC_UBX, casadi::CONIC_X, casadi::CONIC_X0, casadi::ProtoFunctionMemory::fstats, casadi::OracleMemory::iw, casadi::Function::n_in(), casadi::Function::n_out(), casadi::Nlpsol::nx_, casadi::ProtoFunction::print(), qpsol_, casadi::OracleMemory::res, casadi::ProtoFunction::verbose_, and casadi::OracleMemory::w.

Referenced by feasibility_iterations(), and solve().

◆ solve_QP()

int casadi::Feasiblesqpmethod::solve_QP ( FeasiblesqpmethodMemory m,
const double *  H,
const double *  g,
const double *  lbdz,
const double *  ubdz,
const double *  A,
double *  x_opt,
double *  dlam,
int  mode 
) const
virtual

Definition at line 1383 of file feasiblesqpmethod.cpp.

1385  {
1386  ScopedTiming tic(m->fstats.at("QP"));
1387  // Inputs
1388  std::fill_n(m->arg, qpsol_.n_in(), nullptr);
1389  m->arg[CONIC_H] = H;
1390  m->arg[CONIC_G] = g;
1391  m->arg[CONIC_X0] = x_opt;
1392  m->arg[CONIC_LAM_X0] = dlam;
1393  m->arg[CONIC_LAM_A0] = dlam + nx_;
1394  m->arg[CONIC_LBX] = lbdz;
1395  m->arg[CONIC_UBX] = ubdz;
1396  m->arg[CONIC_A] = A;
1397  m->arg[CONIC_LBA] = lbdz+nx_;
1398  m->arg[CONIC_UBA] = ubdz+nx_;
1399 
1400  // Outputs
1401  std::fill_n(m->res, qpsol_.n_out(), nullptr);
1402  m->res[CONIC_X] = x_opt;
1403  m->res[CONIC_LAM_X] = dlam;
1404  m->res[CONIC_LAM_A] = dlam + nx_;
1405  double obj;
1406  m->res[CONIC_COST] = &obj;
1407  // m->res[CONIC_COST] = nullptr;
1408 
1409 
1410  // Solve the QP
1411  qpsol_(m->arg, m->res, m->iw, m->w);
1412 
1413  if (verbose_) print("QP solved\n");
1414  return 0;
1415  }

References casadi::OracleMemory::arg, casadi::CONIC_A, casadi::CONIC_COST, casadi::CONIC_G, casadi::CONIC_H, casadi::CONIC_LAM_A, casadi::CONIC_LAM_A0, casadi::CONIC_LAM_X, casadi::CONIC_LAM_X0, casadi::CONIC_LBA, casadi::CONIC_LBX, casadi::CONIC_UBA, casadi::CONIC_UBX, casadi::CONIC_X, casadi::CONIC_X0, casadi::ProtoFunctionMemory::fstats, casadi::OracleMemory::iw, casadi::Function::n_in(), casadi::Function::n_out(), casadi::Nlpsol::nx_, casadi::ProtoFunction::print(), qpsol_, casadi::OracleMemory::res, casadi::ProtoFunction::verbose_, and casadi::OracleMemory::w.

Referenced by feasibility_iterations(), and solve().

◆ sp_forward()

int casadi::FunctionInternal::sp_forward ( const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w,
void *  mem 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mw

Reimplemented in casadi::BSplineInterpolant, casadi::SXFunction, casadi::Rootfinder, casadi::MXFunction, casadi::MapSum, casadi::Map, and casadi::Integrator.

Definition at line 2838 of file function_internal.cpp.

2839  {
2840  // Loop over outputs
2841  for (casadi_int oind=0; oind<n_out_; ++oind) {
2842  // Skip if nothing to assign
2843  if (res[oind]==nullptr || nnz_out(oind)==0) continue;
2844  // Clear result
2845  casadi_clear(res[oind], nnz_out(oind));
2846  // Loop over inputs
2847  for (casadi_int iind=0; iind<n_in_; ++iind) {
2848  // Skip if no seeds
2849  if (arg[iind]==nullptr || nnz_in(iind)==0) continue;
2850  // Propagate sparsity for the specific block
2851  if (sp_forward_block(arg, res, iw, w, mem, oind, iind)) return 1;
2852  }
2853  }
2854  return 0;
2855  }
virtual int sp_forward_block(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem, casadi_int oind, casadi_int iind) const
Propagate sparsity forward, specific block.

References casadi::casadi_clear(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), and casadi::FunctionInternal::sp_forward_block().

Referenced by casadi::MXFunction::sp_forward(), casadi::SXFunction::sp_forward(), and casadi::BSplineInterpolant::sp_forward().

◆ sp_forward_block()

int casadi::FunctionInternal::sp_forward_block ( const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w,
void *  mem,
casadi_int  oind,
casadi_int  iind 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mx

Definition at line 2857 of file function_internal.cpp.

2858  {
2859  // Get the sparsity of the Jacobian block
2860  Sparsity sp = jac_sparsity(oind, iind, true, false);
2861  if (sp.is_null() || sp.nnz() == 0) return 0; // Skip if zero
2862  // Carry out the sparse matrix-vector multiplication
2863  casadi_int d1 = sp.size2();
2864  const casadi_int *colind = sp.colind(), *row = sp.row();
2865  for (casadi_int cc=0; cc<d1; ++cc) {
2866  for (casadi_int el = colind[cc]; el < colind[cc+1]; ++el) {
2867  res[oind][row[el]] |= arg[iind][cc];
2868  }
2869  }
2870  return 0;
2871  }

References casadi::Sparsity::colind(), casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::jac_sparsity(), casadi::Sparsity::nnz(), casadi::Sparsity::row(), and casadi::Sparsity::size2().

Referenced by casadi::FunctionInternal::sp_forward().

◆ sp_reverse()

int casadi::FunctionInternal::sp_reverse ( bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w,
void *  mem 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_my

Reimplemented in casadi::BSplineInterpolant, casadi::SXFunction, casadi::Rootfinder, casadi::MXFunction, casadi::MapSum, casadi::Map, and casadi::Integrator.

Definition at line 2873 of file function_internal.cpp.

2874  {
2875  // Loop over outputs
2876  for (casadi_int oind=0; oind<n_out_; ++oind) {
2877  // Skip if nothing to assign
2878  if (res[oind]==nullptr || nnz_out(oind)==0) continue;
2879 
2880  // Loop over inputs
2881  for (casadi_int iind=0; iind<n_in_; ++iind) {
2882  // Skip if no seeds
2883  if (arg[iind]==nullptr || nnz_in(iind)==0) continue;
2884 
2885  // Get the sparsity of the Jacobian block
2886  Sparsity sp = jac_sparsity(oind, iind, true, false);
2887  if (sp.is_null() || sp.nnz() == 0) continue; // Skip if zero
2888 
2889  // Carry out the sparse matrix-vector multiplication
2890  casadi_int d1 = sp.size2();
2891  const casadi_int *colind = sp.colind(), *row = sp.row();
2892  for (casadi_int cc=0; cc<d1; ++cc) {
2893  for (casadi_int el = colind[cc]; el < colind[cc+1]; ++el) {
2894  arg[iind][cc] |= res[oind][row[el]];
2895  }
2896  }
2897  }
2898 
2899  // Clear seeds
2900  casadi_clear(res[oind], nnz_out(oind));
2901  }
2902  return 0;
2903  }

References casadi::casadi_clear(), casadi::Sparsity::colind(), casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::jac_sparsity(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::Sparsity::nnz(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::Sparsity::row(), and casadi::Sparsity::size2().

Referenced by casadi::MXFunction::sp_reverse(), casadi::SXFunction::sp_reverse(), and casadi::BSplineInterpolant::sp_reverse().

◆ sp_weight()

double casadi::FunctionInternal::sp_weight ( ) const
virtualinherited

sparsity propagation

Extra doc: https://github.com/casadi/casadi/wiki/L_l6

Definition at line 3285 of file function_internal.cpp.

3285  {
3286  // If reverse mode propagation unavailable, use forward
3287  if (!has_sprev()) return 0;
3288 
3289  // If forward mode propagation unavailable, use reverse
3290  if (!has_spfwd()) return 1;
3291 
3292  // Use the (potentially user set) option
3293  return ad_weight_sp_;
3294  }

References casadi::FunctionInternal::ad_weight_sp_, casadi::FunctionInternal::has_spfwd(), and casadi::FunctionInternal::has_sprev().

Referenced by casadi::FunctionInternal::get_jac_sparsity(), casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::MXFunction::sp_forward(), casadi::SXFunction::sp_forward(), casadi::MXFunction::sp_reverse(), casadi::SXFunction::sp_reverse(), casadi::FunctionInternal::wrap(), and casadi::FunctionInternal::wrap_as_needed().

◆ sparsity_in()

const Sparsity& casadi::FunctionInternal::sparsity_in ( casadi_int  ind) const
inlineinherited

◆ sparsity_out()

const Sparsity& casadi::FunctionInternal::sparsity_out ( casadi_int  ind) const
inlineinherited

◆ sprint()

void casadi::ProtoFunction::sprint ( char *  buf,
size_t  buf_sz,
const char *  fmt,
  ... 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_js

Definition at line 3885 of file function_internal.cpp.

3885  {
3886  // Variable number of arguments
3887  va_list args;
3888  va_start(args, fmt);
3889  // Print to buffer
3890  casadi_int n = vsnprintf(buf, buf_sz, fmt, args);
3891  // Cleanup
3892  va_end(args);
3893  // Throw error if failure
3894  casadi_assert(n>=0 && n<buf_sz, "Print failure while processing '" + std::string(fmt) + "'");
3895  }

Referenced by casadi::ProtoFunction::format_time(), and casadi::ProtoFunction::print_time().

◆ step_update()

int casadi::Feasiblesqpmethod::step_update ( void *  mem,
double  tr_ratio 
) const

Definition at line 530 of file feasiblesqpmethod.cpp.

530  {
531  auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
532  auto d_nlp = &m->d_nlp;
533  auto d = &m->d;
534 
535  if (tr_ratio > tr_acceptance_) {
536  // This is not properly implemented yet: d_nlp->z_old = d_mlp->z;
537  casadi_copy(d->z_feas, nx_ + ng_, d_nlp->z);
538  d_nlp->objective = d->f_feas;
539  casadi_copy(d->dlam_feas, nx_ + ng_, d_nlp->lam);
540 
541  uout() << "ACCEPTED" << std::endl;
542  return 0;
543  } else {
544  uout() << "REJECTED" << std::endl;
545  return -1;
546  }
547 }

References casadi::casadi_copy(), casadi::NlpsolMemory::d_nlp, casadi::Nlpsol::ng_, casadi::Nlpsol::nx_, tr_acceptance_, and casadi::uout().

Referenced by solve().

◆ string_from_UnifiedReturnStatus()

std::string casadi::FunctionInternal::string_from_UnifiedReturnStatus ( UnifiedReturnStatus  status)
staticinherited

Definition at line 3953 of file function_internal.cpp.

3953  {
3954  switch (status) {
3955  case SOLVER_RET_LIMITED: return "SOLVER_RET_LIMITED";
3956  case SOLVER_RET_NAN: return "SOLVER_RET_NAN";
3957  case SOLVER_RET_SUCCESS: return "SOLVER_RET_SUCCESS";
3958  default: return "SOLVER_RET_UNKNOWN";
3959  }
3960  }

References casadi::SOLVER_RET_LIMITED, casadi::SOLVER_RET_NAN, and casadi::SOLVER_RET_SUCCESS.

Referenced by casadi::Conic::get_stats(), casadi::Nlpsol::get_stats(), and casadi::Rootfinder::get_stats().

◆ sx_in() [1/2]

const std::vector< SX > casadi::FunctionInternal::sx_in ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l7

Reimplemented in casadi::SXFunction.

Definition at line 3312 of file function_internal.cpp.

3312  {
3313  std::vector<SX> ret(n_in_);
3314  for (casadi_int i=0; i<ret.size(); ++i) {
3315  ret[i] = sx_in(i);
3316  }
3317  return ret;
3318  }
virtual const std::vector< SX > sx_in() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_in_.

◆ sx_in() [2/2]

const SX casadi::FunctionInternal::sx_in ( casadi_int  ind) const
virtualinherited

◆ sx_out() [1/2]

const std::vector< SX > casadi::FunctionInternal::sx_out ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l7

Definition at line 3320 of file function_internal.cpp.

3320  {
3321  std::vector<SX> ret(n_out_);
3322  for (casadi_int i=0; i<ret.size(); ++i) {
3323  ret[i] = sx_out(i);
3324  }
3325  return ret;
3326  }
virtual const std::vector< SX > sx_out() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_out_.

◆ sx_out() [2/2]

const SX casadi::FunctionInternal::sx_out ( casadi_int  ind) const
virtualinherited

◆ symbolic_output()

std::vector< MX > casadi::FunctionInternal::symbolic_output ( const std::vector< MX > &  arg) const
virtualinherited

Reimplemented in casadi::MXFunction.

Definition at line 1150 of file function_internal.cpp.

1150  {
1151  return self()(arg);
1152  }

Referenced by casadi::MXFunction::symbolic_output().

◆ symbolicAdjSeed()

template<typename MatType >
std::vector< std::vector< MatType > > casadi::FunctionInternal::symbolicAdjSeed ( casadi_int  nadj,
const std::vector< MatType > &  v 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ns

Definition at line 1535 of file function_internal.hpp.

1536  {
1537  std::vector<std::vector<MatType> > aseed(nadj, v);
1538  for (casadi_int dir=0; dir<nadj; ++dir) {
1539  // Replace symbolic inputs
1540  casadi_int oind=0;
1541  for (typename std::vector<MatType>::iterator i=aseed[dir].begin();
1542  i!=aseed[dir].end();
1543  ++i, ++oind) {
1544  // Name of the adjoint seed
1545  std::stringstream ss;
1546  ss << "a";
1547  if (nadj>1) ss << dir << "_";
1548  ss << oind;
1549 
1550  // Save to matrix
1551  *i = MatType::sym(ss.str(), is_diff_out_[oind] ? i->sparsity() : Sparsity(i->size()));
1552 
1553  }
1554  }
1555  return aseed;
1556  }

References casadi::FunctionInternal::is_diff_out_.

◆ sz_arg()

size_t casadi::FunctionInternal::sz_arg ( ) const
inlineinherited

◆ sz_iw()

size_t casadi::FunctionInternal::sz_iw ( ) const
inlineinherited

◆ sz_res()

size_t casadi::FunctionInternal::sz_res ( ) const
inlineinherited

◆ sz_w()

size_t casadi::FunctionInternal::sz_w ( ) const
inlineinherited

◆ sz_work()

void casadi::FunctionInternal::sz_work ( size_t &  sz_arg,
size_t &  sz_res,
size_t &  sz_iw,
size_t &  sz_w 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mz

Definition at line 2905 of file function_internal.cpp.

2906  {
2907  sz_arg = this->sz_arg();
2908  sz_res = this->sz_res();
2909  sz_iw = this->sz_iw();
2910  sz_w = this->sz_w();
2911  }

References casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), and casadi::FunctionInternal::sz_w().

◆ to_compact()

Sparsity casadi::FunctionInternal::to_compact ( casadi_int  oind,
casadi_int  iind,
const Sparsity sp 
) const
inherited

Definition at line 1921 of file function_internal.cpp.

1922  {
1923  // Strip rows and columns
1924  std::vector<casadi_int> mapping;
1925  return sp.sub(sparsity_out(oind).find(), sparsity_in(iind).find(), mapping);
1926  }

References casadi::FunctionInternal::find(), casadi::FunctionInternal::sparsity_in(), casadi::FunctionInternal::sparsity_out(), and casadi::Sparsity::sub().

Referenced by casadi::FunctionInternal::jac_sparsity(), and casadi::FunctionInternal::set_jac_sparsity().

◆ tocache()

void casadi::FunctionInternal::tocache ( const Function f,
const std::string &  suffix = "" 
) const
inherited

◆ tocache_if_missing()

void casadi::FunctionInternal::tocache_if_missing ( Function f,
const std::string &  suffix = "" 
) const
inherited

◆ tr_update()

void casadi::Feasiblesqpmethod::tr_update ( void *  mem,
double &  tr_rad,
double  tr_ratio 
) const

Definition at line 517 of file feasiblesqpmethod.cpp.

517  {
518  auto m = static_cast<FeasiblesqpmethodMemory*>(mem);
519  auto d = &m->d;
520 
521  if (tr_ratio < tr_eta1_) {
522  tr_rad = tr_alpha1_ * casadi_masked_norm_inf(nx_, d->dx, d->tr_mask);
523  } else if (tr_ratio > tr_eta2_ &&
524  abs(casadi_masked_norm_inf(nx_, d->dx, d->tr_mask) - tr_rad) < optim_tol_) {
525  tr_rad = fmin(tr_alpha2_*tr_rad, tr_rad_max_);
526  }
527  // else: keep trust-region as it is....
528 }

References casadi::FeasiblesqpmethodMemory::d, casadi::Nlpsol::nx_, optim_tol_, tr_alpha1_, tr_alpha2_, tr_eta1_, tr_eta2_, and tr_rad_max_.

Referenced by solve().

◆ uses_output()

bool casadi::Nlpsol::uses_output ( ) const
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1o1

Reimplemented from casadi::FunctionInternal.

Definition at line 239 of file nlpsol_impl.hpp.

239 {return true;}

◆ weak()

Extra doc: https://github.com/casadi/casadi/wiki/L_1ai

Definition at line 67 of file generic_shared_internal.hpp.

191  {
192  if (weak_ref_==nullptr) {
193  weak_ref_ = new GenericWeakRef<Shared, Internal>(static_cast<Internal*>(this));
194  }
195  return weak_ref_;
196  }

◆ which_depends()

std::vector< bool > casadi::FunctionInternal::which_depends ( const std::string &  s_in,
const std::vector< std::string > &  s_out,
casadi_int  order,
bool  tr = false 
) const
virtualinherited
Parameters
[in]s_inInput name
[in]s_outOutput name(s)
[in]orderOnly 1 (linear) and 2 (nonlinear) allowed
[in]trFlip the relationship. Return which expressions contain the variables

Extra doc: https://github.com/casadi/casadi/wiki/L_k9

Reimplemented in casadi::XFunction< DerivedType, MatType, NodeType >, casadi::XFunction< MXFunction, MX, MXNode >, and casadi::XFunction< SXFunction, Matrix< SXElem >, SXNode >.

Definition at line 3728 of file function_internal.cpp.

3730  {
3731  Function f = shared_from_this<Function>();
3732  f = f.wrap();
3733  return f.which_depends(s_in, s_out, order, tr);
3734  }

References casadi::Function::which_depends(), and casadi::Function::wrap().

◆ wrap()

Function casadi::FunctionInternal::wrap ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_li

Definition at line 1128 of file function_internal.cpp.

1128  {
1129  Function f;
1130  std::string fname = "wrap_" + name_;
1131  if (!incache(fname, f)) {
1132  // Options
1133  Dict opts;
1134  opts["derivative_of"] = derivative_of_;
1135  opts["ad_weight"] = ad_weight();
1136  opts["ad_weight_sp"] = sp_weight();
1137  opts["max_num_dir"] = max_num_dir_;
1138  opts["is_diff_in"] = is_diff_in_;
1139  opts["is_diff_out"] = is_diff_out_;
1140  // Wrap the function
1141  std::vector<MX> arg = mx_in();
1142  std::vector<MX> res = self()(arg);
1143  f = Function(fname, arg, res, name_in_, name_out_, opts);
1144  // Save in cache
1145  tocache_if_missing(f);
1146  }
1147  return f;
1148  }

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::derivative_of_, casadi::FunctionInternal::Function, casadi::FunctionInternal::incache(), casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::mx_in(), casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::sp_weight(), and casadi::FunctionInternal::tocache_if_missing().

Referenced by casadi::FunctionInternal::eval_mx(), casadi::FunctionInternal::factory(), casadi::FunctionInternal::forward(), casadi::FunctionInternal::jacobian(), casadi::FunctionInternal::reverse(), casadi::FunctionInternal::slice(), and casadi::Function::wrap().

◆ wrap_as_needed()

Function casadi::FunctionInternal::wrap_as_needed ( const Dict opts) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lj

Definition at line 1110 of file function_internal.cpp.

1110  {
1111  if (opts.empty()) return shared_from_this<Function>();
1112  std::string fname = "wrap_" + name_;
1113  // Options
1114  Dict my_opts = opts;
1115  my_opts["derivative_of"] = derivative_of_;
1116  if (my_opts.find("ad_weight")==my_opts.end())
1117  my_opts["ad_weight"] = ad_weight();
1118  if (my_opts.find("ad_weight_sp")==my_opts.end())
1119  my_opts["ad_weight_sp"] = sp_weight();
1120  if (my_opts.find("max_num_dir")==my_opts.end())
1121  my_opts["max_num_dir"] = max_num_dir_;
1122  // Wrap the function
1123  std::vector<MX> arg = mx_in();
1124  std::vector<MX> res = self()(arg);
1125  return Function(fname, arg, res, name_in_, name_out_, my_opts);
1126  }

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::derivative_of_, casadi::FunctionInternal::Function, casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::mx_in(), casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, and casadi::FunctionInternal::sp_weight().

Referenced by casadi::Function::wrap_as_needed().

Member Data Documentation

◆ ad_weight_

double casadi::FunctionInternal::ad_weight_
inherited

◆ ad_weight_sp_

double casadi::FunctionInternal::ad_weight_sp_
inherited

◆ all_functions_

std::map<std::string, RegFun> casadi::OracleFunction::all_functions_
protectedinherited

◆ always_inline_

bool casadi::FunctionInternal::always_inline_
inherited

◆ Asp_

Sparsity casadi::Feasiblesqpmethod::Asp_

Definition at line 177 of file feasiblesqpmethod.hpp.

Referenced by codegen_body(), Feasiblesqpmethod(), init(), serialize_body(), and solve().

◆ block_size_

casadi_int casadi::Feasiblesqpmethod::block_size_ = 0

Definition at line 145 of file feasiblesqpmethod.hpp.

◆ bound_consistency_

bool casadi::Nlpsol::bound_consistency_
inherited

◆ cache_

WeakCache<std::string, Function> casadi::FunctionInternal::cache_
mutableinherited

◆ cache_init_

Dict casadi::FunctionInternal::cache_init_
inherited

◆ calc_f_

bool casadi::Nlpsol::calc_f_
inherited

◆ calc_g_

bool casadi::Nlpsol::calc_g_
inherited

◆ calc_lam_p_

bool casadi::Nlpsol::calc_lam_p_
inherited

◆ calc_lam_x_

bool casadi::Nlpsol::calc_lam_x_
inherited

◆ calc_multipliers_

bool casadi::Nlpsol::calc_multipliers_
inherited

◆ callback_step_

casadi_int casadi::Nlpsol::callback_step_
inherited

◆ checkout_

casadi_checkout_t casadi::FunctionInternal::checkout_
inherited

◆ common_options_

Dict casadi::OracleFunction::common_options_
protectedinherited

◆ compiler_

Importer casadi::FunctionInternal::compiler_
inherited

◆ compiler_plugin_

std::string casadi::FunctionInternal::compiler_plugin_
inherited

◆ contraction_acceptance_value_

double casadi::Feasiblesqpmethod::contraction_acceptance_value_

◆ convexify_

bool casadi::Feasiblesqpmethod::convexify_

Definition at line 183 of file feasiblesqpmethod.hpp.

Referenced by Feasiblesqpmethod(), init(), init_mem(), serialize_body(), and solve().

◆ convexify_data_

ConvexifyData casadi::Feasiblesqpmethod::convexify_data_

Definition at line 180 of file feasiblesqpmethod.hpp.

Referenced by Feasiblesqpmethod(), init(), serialize_body(), and solve().

◆ custom_jacobian_

Function casadi::FunctionInternal::custom_jacobian_
inherited

◆ der_options_

Dict casadi::FunctionInternal::der_options_
inherited

◆ derivative_of_

Function casadi::FunctionInternal::derivative_of_
inherited

◆ deserialize_map

std::map< std::string, ProtoFunction *(*)(DeserializingStream &)> casadi::FunctionInternal::deserialize_map
staticinherited
Initial value:
= {
{"MXFunction", MXFunction::deserialize},
{"SXFunction", SXFunction::deserialize},
{"Interpolant", Interpolant::deserialize},
{"Switch", Switch::deserialize},
{"Map", Map::deserialize},
{"MapSum", MapSum::deserialize},
{"Nlpsol", Nlpsol::deserialize},
{"Rootfinder", Rootfinder::deserialize},
{"Integrator", Integrator::deserialize},
{"External", External::deserialize},
{"Conic", Conic::deserialize},
{"FmuFunction", FmuFunction::deserialize},
{"BlazingSplineFunction", BlazingSplineFunction::deserialize}
}
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
void deserialize(DeserializingStream &s, SDPToSOCPMem &m)
Definition: conic.cpp:728
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
Definition: external.cpp:512
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize without type information.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Definition: mapsum.cpp:85
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Definition: map.cpp:103
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
Definition: nlpsol.cpp:1341
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
Definition: rootfinder.cpp:592
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize without type information.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize without type information.
Definition: switch.hpp:150

Definition at line 1455 of file function_internal.hpp.

Referenced by casadi::FunctionInternal::deserialize().

◆ detect_simple_bounds_is_simple_

std::vector<char> casadi::Nlpsol::detect_simple_bounds_is_simple_
inherited

◆ detect_simple_bounds_parts_

Function casadi::Nlpsol::detect_simple_bounds_parts_
inherited

◆ detect_simple_bounds_target_g_

std::vector<casadi_int> casadi::Nlpsol::detect_simple_bounds_target_g_
inherited

◆ detect_simple_bounds_target_x_

std::vector<casadi_int> casadi::Nlpsol::detect_simple_bounds_target_x_
inherited

◆ discrete_

std::vector<bool> casadi::Nlpsol::discrete_
inherited

◆ dump_

bool casadi::FunctionInternal::dump_
inherited

◆ dump_count_

casadi_int casadi::FunctionInternal::dump_count_
mutableinherited

◆ dump_dir_

std::string casadi::FunctionInternal::dump_dir_
inherited

◆ dump_format_

std::string casadi::FunctionInternal::dump_format_
inherited

◆ dump_in_

bool casadi::FunctionInternal::dump_in_
inherited

◆ dump_out_

bool casadi::FunctionInternal::dump_out_
inherited

◆ enable_fd_

bool casadi::FunctionInternal::enable_fd_
inherited

◆ enable_fd_op_

bool casadi::FunctionInternal::enable_fd_op_
inherited

◆ enable_forward_

bool casadi::FunctionInternal::enable_forward_
inherited

◆ enable_forward_op_

bool casadi::FunctionInternal::enable_forward_op_
inherited

◆ enable_jacobian_

bool casadi::FunctionInternal::enable_jacobian_
inherited

◆ enable_jacobian_op_

bool casadi::FunctionInternal::enable_jacobian_op_
inherited

◆ enable_reverse_

bool casadi::FunctionInternal::enable_reverse_
inherited

◆ enable_reverse_op_

bool casadi::FunctionInternal::enable_reverse_op_
inherited

◆ equality_

std::vector<bool> casadi::Nlpsol::equality_
inherited

◆ error_on_fail_

bool casadi::ProtoFunction::error_on_fail_
inherited

◆ eval_

eval_t casadi::FunctionInternal::eval_
inherited

◆ eval_errors_fatal_

bool casadi::Nlpsol::eval_errors_fatal_
inherited

◆ exact_hessian_

bool casadi::Feasiblesqpmethod::exact_hessian_

◆ fcallback_

Function casadi::Nlpsol::fcallback_
inherited

◆ fd_method_

std::string casadi::FunctionInternal::fd_method_
inherited

◆ fd_options_

Dict casadi::FunctionInternal::fd_options_
inherited

◆ fd_step_

double casadi::FunctionInternal::fd_step_
inherited

◆ feas_tol_

double casadi::Feasiblesqpmethod::feas_tol_

◆ forward_options_

Dict casadi::FunctionInternal::forward_options_
inherited

◆ has_refcount_

bool casadi::FunctionInternal::has_refcount_
inherited

◆ Hsp_

Sparsity casadi::Feasiblesqpmethod::Hsp_

◆ infix_

const std::string casadi::Nlpsol::infix_ = "nlpsol"
staticinherited

Definition at line 290 of file nlpsol_impl.hpp.

◆ init_feasible_

bool casadi::Feasiblesqpmethod::init_feasible_

Definition at line 160 of file feasiblesqpmethod.hpp.

Referenced by init(), and serialize_body().

◆ inputs_check_

bool casadi::FunctionInternal::inputs_check_
inherited

◆ is_diff_in_

std::vector<bool> casadi::FunctionInternal::is_diff_in_
inherited

◆ is_diff_out_

std::vector<bool> casadi::FunctionInternal::is_diff_out_
inherited

◆ iteration_callback_ignore_errors_

bool casadi::Nlpsol::iteration_callback_ignore_errors_
inherited

◆ jac_penalty_

double casadi::FunctionInternal::jac_penalty_
inherited

◆ jac_sparsity_

std::vector<Sparsity> casadi::FunctionInternal::jac_sparsity_[2]
mutableinherited

◆ jacobian_options_

Dict casadi::FunctionInternal::jacobian_options_
inherited

◆ jit_

bool casadi::FunctionInternal::jit_
inherited

◆ jit_base_name_

std::string casadi::FunctionInternal::jit_base_name_
inherited

◆ jit_cleanup_

bool casadi::FunctionInternal::jit_cleanup_
inherited

◆ jit_name_

std::string casadi::FunctionInternal::jit_name_
inherited

◆ jit_options_

Dict casadi::FunctionInternal::jit_options_
inherited

◆ jit_serialize_

std::string casadi::FunctionInternal::jit_serialize_
inherited

◆ jit_temp_suffix_

bool casadi::FunctionInternal::jit_temp_suffix_
inherited

◆ kkt_

WeakRef casadi::Nlpsol::kkt_
mutableinherited

Definition at line 109 of file nlpsol_impl.hpp.

Referenced by casadi::Nlpsol::kkt().

◆ lbfgs_memory_

casadi_int casadi::Feasiblesqpmethod::lbfgs_memory_

Definition at line 151 of file feasiblesqpmethod.hpp.

Referenced by Feasiblesqpmethod(), init(), serialize_body(), and solve().

◆ max_inner_iter_

casadi_int casadi::Feasiblesqpmethod::max_inner_iter_

◆ max_io_

casadi_int casadi::FunctionInternal::max_io_
inherited

◆ max_iter_

casadi_int casadi::Feasiblesqpmethod::max_iter_

Definition at line 148 of file feasiblesqpmethod.hpp.

Referenced by codegen_body(), Feasiblesqpmethod(), init(), serialize_body(), and solve().

◆ max_num_dir_

casadi_int casadi::FunctionInternal::max_num_dir_
inherited

◆ max_num_threads_

int casadi::OracleFunction::max_num_threads_
protectedinherited

◆ meta_doc

const std::string casadi::Feasiblesqpmethod::meta_doc
static

◆ mi_

bool casadi::Nlpsol::mi_
inherited

◆ min_iter_

casadi_int casadi::Feasiblesqpmethod::min_iter_

Definition at line 148 of file feasiblesqpmethod.hpp.

Referenced by Feasiblesqpmethod(), init(), and serialize_body().

◆ min_lam_

double casadi::Nlpsol::min_lam_
inherited

◆ monitor_

std::vector<std::string> casadi::OracleFunction::monitor_
protectedinherited

◆ n_in_

size_t casadi::FunctionInternal::n_in_
inherited

Definition at line 1266 of file function_internal.hpp.

Referenced by casadi::SXFunction::ad_forward(), casadi::Rootfinder::ad_reverse(), casadi::MXFunction::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::FunctionInternal::all_scalar(), casadi::KinsolInterface::bjac(), casadi::FunctionInternal::call_forward(), casadi::FunctionInternal::call_gen(), casadi::FunctionInternal::call_reverse(), casadi::SXFunction::call_setup(), casadi::FunctionInternal::check_arg(), casadi::JitFunction::codegen_body(), casadi::Map::codegen_body(), casadi::OmpMap::codegen_body(), casadi::MapSum::codegen_body(), casadi::MXFunction::codegen_body(), casadi::Switch::codegen_body(), casadi::SXFunction::codegen_body(), casadi::FastNewton::codegen_body(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::convert_arg(), casadi::FunctionInternal::definition(), casadi::KinsolInterface::djac(), casadi::FunctionInternal::dm_in(), casadi::FunctionInternal::eval(), casadi::OmpMap::eval(), casadi::MXFunction::eval(), casadi::Switch::eval(), casadi::FunctionInternal::eval_gen(), casadi::Map::eval_gen(), casadi::MapSum::eval_gen(), casadi::MXFunction::eval_mx(), casadi::SXFunction::eval_mx(), casadi::Switch::eval_sx(), casadi::SXFunction::export_code_body(), casadi::CallbackInternal::finalize(), casadi::FmuFunction::FmuFunction(), casadi::FunctionInternal::forward(), casadi::KinsolInterface::func(), casadi::FunctionInternal::FunctionInternal(), casadi::FunctionInternal::fwd_seed(), casadi::FunctionInternal::generate_in(), casadi::GenericExternal::get_jac_sparsity(), casadi::GenericExternal::has_jac_sparsity(), casadi::FunctionInternal::init(), casadi::MXFunction::init(), casadi::Switch::init(), casadi::SXFunction::init(), casadi::ImplicitToNlp::init(), casadi::FunctionInternal::jac_sparsity(), casadi::FunctionInternal::jacobian(), casadi::KinsolInterface::jtimes(), casadi::FunctionInternal::mapsum_mx(), casadi::FunctionInternal::matching_arg(), casadi::FunctionInternal::mx_in(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::numel_in(), casadi::FunctionInternal::nz_in(), casadi::SXFunction::print_arg(), casadi::FunctionInternal::print_dimensions(), casadi::FunctionInternal::print_in(), casadi::FunctionInternal::project_arg(), casadi::KinsolInterface::psetup(), casadi::FunctionInternal::reverse(), casadi::FmuFunction::serialize_body(), casadi::FunctionInternal::set_jac_sparsity(), casadi::Rootfinder::set_work(), casadi::QpToNlp::solve(), casadi::KinsolInterface::solve(), casadi::FastNewton::solve(), casadi::ImplicitToNlp::solve(), casadi::Newton::solve(), casadi::FunctionInternal::sp_forward(), casadi::Integrator::sp_forward(), casadi::MXFunction::sp_forward(), casadi::Rootfinder::sp_forward(), casadi::FunctionInternal::sp_reverse(), casadi::Integrator::sp_reverse(), casadi::Map::sp_reverse(), casadi::MapSum::sp_reverse(), casadi::MXFunction::sp_reverse(), casadi::Rootfinder::sp_reverse(), and casadi::FunctionInternal::sx_in().

◆ n_out_

size_t casadi::FunctionInternal::n_out_
inherited

Definition at line 1266 of file function_internal.hpp.

Referenced by casadi::Rootfinder::ad_forward(), casadi::MXFunction::ad_forward(), casadi::SXFunction::ad_forward(), casadi::Rootfinder::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::FunctionInternal::all_scalar(), casadi::KinsolInterface::bjac(), casadi::FunctionInternal::call(), casadi::FunctionInternal::call_forward(), casadi::FunctionInternal::call_gen(), casadi::FunctionInternal::call_reverse(), casadi::SXFunction::call_setup(), casadi::FunctionInternal::check_res(), casadi::JitFunction::codegen_body(), casadi::Map::codegen_body(), casadi::OmpMap::codegen_body(), casadi::MapSum::codegen_body(), casadi::MXFunction::codegen_body(), casadi::Switch::codegen_body(), casadi::SXFunction::codegen_body(), casadi::FastNewton::codegen_body(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::convert_res(), casadi::FunctionInternal::definition(), casadi::KinsolInterface::djac(), casadi::FunctionInternal::dm_out(), casadi::FunctionInternal::eval(), casadi::OmpMap::eval(), casadi::MXFunction::eval(), casadi::Switch::eval(), casadi::FunctionInternal::eval_gen(), casadi::Map::eval_gen(), casadi::MapSum::eval_gen(), casadi::Switch::eval_sx(), casadi::CallbackInternal::finalize(), casadi::FmuFunction::FmuFunction(), casadi::FunctionInternal::forward(), casadi::KinsolInterface::func(), casadi::FunctionInternal::FunctionInternal(), casadi::FunctionInternal::generate_out(), casadi::LinearInterpolantJac::get_jacobian(), casadi::FunctionInternal::init(), casadi::MapSum::init(), casadi::Nlpsol::init(), casadi::Switch::init(), casadi::FunctionInternal::jac_sparsity(), casadi::FunctionInternal::jacobian(), casadi::FunctionInternal::mapsum_mx(), casadi::FunctionInternal::matching_res(), casadi::FunctionInternal::mx_out(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::numel_out(), casadi::FunctionInternal::nz_out(), casadi::FunctionInternal::print_dimensions(), casadi::FunctionInternal::print_out(), casadi::KinsolInterface::psetup(), casadi::FunctionInternal::reverse(), casadi::FmuFunction::serialize_body(), casadi::FunctionInternal::set_jac_sparsity(), casadi::Rootfinder::set_work(), casadi::QpToNlp::solve(), casadi::KinsolInterface::solve(), casadi::FastNewton::solve(), casadi::ImplicitToNlp::solve(), casadi::Newton::solve(), casadi::FunctionInternal::sp_forward(), casadi::Integrator::sp_forward(), casadi::MXFunction::sp_forward(), casadi::Rootfinder::sp_forward(), casadi::FunctionInternal::sp_reverse(), casadi::Integrator::sp_reverse(), casadi::Map::sp_reverse(), casadi::MapSum::sp_reverse(), casadi::MXFunction::sp_reverse(), casadi::Rootfinder::sp_reverse(), and casadi::FunctionInternal::sx_out().

◆ name_

std::string casadi::ProtoFunction::name_
inherited

Definition at line 246 of file function_internal.hpp.

Referenced by casadi::MXFunction::ad_forward(), casadi::SXFunction::ad_forward(), casadi::MXFunction::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::Integrator::augmented_dae(), casadi::OracleFunction::calc_function(), casadi::FunctionInternal::call_forward(), casadi::FunctionInternal::call_reverse(), casadi::FunctionInternal::codegen_body(), casadi::External::codegen_body(), casadi::External::codegen_checkout(), casadi::External::codegen_declarations(), casadi::MXFunction::codegen_declarations(), casadi::SXFunction::codegen_declarations(), casadi::External::codegen_decref(), casadi::External::codegen_incref(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::codegen_name(), casadi::External::codegen_release(), casadi::FunctionInternal::codegen_sparsities(), casadi::ProtoFunction::construct(), casadi::OracleFunction::create_function(), casadi::FunctionInternal::definition(), casadi::FunctionInternal::eval(), casadi::MXFunction::eval(), casadi::SXFunction::eval(), casadi::FunctionInternal::eval_mx(), casadi::MXFunction::eval_mx(), casadi::SXFunction::eval_mx(), casadi::SXFunction::eval_sx(), casadi::FmuFunction::factory(), casadi::FunctionInternal::finalize(), casadi::FunctionInternal::forward(), casadi::FunctionInternal::FunctionInternal(), casadi::Integrator::get_forward(), casadi::Integrator::get_forward_dae(), casadi::Map::get_function(), casadi::MapSum::get_function(), casadi::OracleFunction::get_function(), casadi::GenericExternal::get_jac_sparsity(), casadi::BlazingSplineFunction::get_jacobian(), casadi::FunctionInternal::get_n_in(), casadi::External::get_n_in(), casadi::FunctionInternal::get_n_out(), casadi::External::get_n_out(), casadi::FunctionInternal::get_name_in(), casadi::External::get_name_in(), casadi::FunctionInternal::get_name_out(), casadi::External::get_name_out(), casadi::FunctionInternal::get_partition(), casadi::Integrator::get_reverse(), casadi::FunctionInternal::get_sparsity_in(), casadi::GenericExternal::get_sparsity_in(), casadi::FunctionInternal::get_sparsity_out(), casadi::GenericExternal::get_sparsity_out(), casadi::FunctionInternal::get_stats(), casadi::External::has_forward(), casadi::GenericExternal::has_jac_sparsity(), casadi::External::has_jacobian(), casadi::External::has_reverse(), casadi::External::init(), casadi::FunctionInternal::init(), casadi::MXFunction::init(), casadi::SXFunction::init(), casadi::CvodesInterface::init(), casadi::IdasInterface::init(), casadi::External::init_external(), casadi::GenericExternal::init_external(), casadi::FunctionInternal::jac_is_symm(), casadi::FunctionInternal::jacobian(), casadi::FunctionInternal::map(), casadi::OracleFunction::monitored(), casadi::MXFunction::print_arg(), casadi::SXFunction::print_arg(), casadi::FunctionInternal::print_in(), casadi::FunctionInternal::print_out(), casadi::MXFunction::print_res(), casadi::SXFunction::print_res(), casadi::ProtoFunction::print_time(), casadi::ProtoFunction::ProtoFunction(), casadi::CvodesInterface::reset(), casadi::IdasInterface::reset(), casadi::IdasInterface::resetB(), casadi::FunctionInternal::reverse(), casadi::ProtoFunction::serialize_body(), casadi::GurobiInterface::solve(), casadi::SnoptInterface::solve(), casadi::Integrator::sp_forward(), casadi::Integrator::sp_reverse(), casadi::FunctionInternal::wrap(), and casadi::FunctionInternal::wrap_as_needed().

◆ name_in_

std::vector<std::string> casadi::FunctionInternal::name_in_
inherited

◆ name_out_

std::vector<std::string> casadi::FunctionInternal::name_out_
inherited

◆ never_inline_

bool casadi::FunctionInternal::never_inline_
inherited

◆ ng_

casadi_int casadi::Nlpsol::ng_
inherited

Definition at line 69 of file nlpsol_impl.hpp.

Referenced by casadi::Blocksqp::acceptStep(), casadi::AlpaqaProblem::AlpaqaProblem(), casadi::BonminUserClass::BonminUserClass(), casadi::Blocksqp::calcOptTol(), codegen_body(), casadi::Sqpmethod::codegen_body(), casadi::Nlpsol::codegen_body_enter(), casadi::Nlpsol::codegen_body_exit(), codegen_feasibility_iterations(), casadi::Sqpmethod::codegen_qp_ela_solve(), casadi::Sqpmethod::codegen_solve_elastic_mode(), codegen_step_update(), casadi::Nlpsol::eval(), casadi::Scpgen::eval_vec(), casadi::Blocksqp::evaluate(), feasibility_iterations(), casadi::Blocksqp::feasibilityRestorationPhase(), casadi::IpoptUserClass::finalize_metadata(), casadi::BonminInterface::finalize_solution(), casadi::IpoptInterface::finalize_solution(), casadi::BonminInterface::get_bounds_info(), casadi::BonminUserClass::get_bounds_info(), casadi::IpoptUserClass::get_bounds_info(), casadi::IpoptInterface::get_bounds_info(), casadi::Nlpsol::get_forward(), casadi::BonminInterface::get_nlp_info(), casadi::IpoptInterface::get_nlp_info(), casadi::Nlpsol::get_reverse(), casadi::BonminInterface::get_starting_point(), casadi::BonminUserClass::get_starting_point(), casadi::IpoptUserClass::get_starting_point(), casadi::IpoptInterface::get_starting_point(), casadi::Nlpsol::init(), casadi::AlpaqaInterface::init(), casadi::AmplInterface::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::FatropInterface::init(), casadi::IpoptInterface::init(), casadi::KnitroInterface::init(), casadi::SLEQPInterface::init(), casadi::SnoptInterface::init(), init(), casadi::Qrsqp::init(), casadi::Scpgen::init(), casadi::Sqpmethod::init(), casadi::IpoptInterface::init_mem(), casadi::SnoptInterface::init_mem(), casadi::BonminInterface::intermediate_callback(), casadi::IpoptInterface::intermediate_callback(), casadi::IpoptUserClass::IpoptUserClass(), casadi::Blocksqp::kktErrorReduction(), casadi::Scpgen::line_search(), casadi::Blocksqp::lInfConstraintNorm(), casadi::Nlpsol::Nlpsol(), casadi::Scpgen::primalInfeasibility(), casadi::Blocksqp::reduceSOCStepsize(), casadi::Blocksqp::reset_sqp(), casadi::Blocksqp::secondOrderCorrection(), casadi::Nlpsol::serialize_body(), casadi::Blocksqp::set_work(), casadi::BonminInterface::set_work(), casadi::IpoptInterface::set_work(), casadi::KnitroInterface::set_work(), casadi::SLEQPInterface::set_work(), casadi::SnoptInterface::set_work(), casadi::WorhpInterface::set_work(), casadi::Qrsqp::set_work(), casadi::Scpgen::set_work(), casadi::AlpaqaInterface::solve(), casadi::AmplInterface::solve(), casadi::Blocksqp::solve(), casadi::BonminInterface::solve(), casadi::IpoptInterface::solve(), casadi::KnitroInterface::solve(), casadi::SnoptInterface::solve(), casadi::WorhpInterface::solve(), solve(), casadi::Qrsqp::solve(), casadi::Scpgen::solve(), casadi::Sqpmethod::solve(), casadi::Sqpmethod::solve_ela_QP(), casadi::Sqpmethod::solve_elastic_mode(), casadi::Scpgen::solve_qp(), casadi::Blocksqp::solveQP(), step_update(), and casadi::Blocksqp::updateStepBounds().

◆ no_nlp_grad_

bool casadi::Nlpsol::no_nlp_grad_
inherited

◆ np_

casadi_int casadi::Nlpsol::np_
inherited

◆ nx_

casadi_int casadi::Nlpsol::nx_
inherited

Definition at line 66 of file nlpsol_impl.hpp.

Referenced by casadi::Blocksqp::acceptStep(), casadi::AlpaqaProblem::AlpaqaProblem(), anderson_acc_init_memory(), anderson_acc_step_update(), anderson_acc_update_memory(), casadi::BonminUserClass::BonminUserClass(), casadi::Sqpmethod::calc_gamma_1(), casadi::Blocksqp::calcHessianUpdateLimitedMemory(), casadi::Blocksqp::calcLagrangeGradient(), casadi::Blocksqp::calcOptTol(), casadi::Nlpsol::callback(), casadi::Nlpsol::check_inputs(), codegen_body(), casadi::Sqpmethod::codegen_body(), casadi::Nlpsol::codegen_body_enter(), casadi::Nlpsol::codegen_body_exit(), casadi::Sqpmethod::codegen_calc_gamma_1(), codegen_eval_m_k(), codegen_feasibility_iterations(), casadi::Sqpmethod::codegen_qp_ela_solve(), codegen_qp_solve(), casadi::Sqpmethod::codegen_qp_solve(), casadi::Sqpmethod::codegen_solve_elastic_mode(), codegen_step_update(), codegen_tr_update(), casadi::Blocksqp::convertHessian(), casadi::Scpgen::dualInfeasibility(), casadi::Nlpsol::eval(), casadi::Scpgen::eval_exp(), eval_m_k(), casadi::Scpgen::eval_mat(), casadi::Scpgen::eval_res(), casadi::Scpgen::eval_vec(), casadi::Blocksqp::evaluate(), feasibility_iterations(), casadi::Blocksqp::feasibilityRestorationHeuristic(), casadi::Blocksqp::feasibilityRestorationPhase(), casadi::Blocksqp::filterLineSearch(), casadi::IpoptUserClass::finalize_metadata(), casadi::BonminInterface::finalize_solution(), casadi::IpoptInterface::finalize_solution(), casadi::Blocksqp::fullstep(), casadi::BonminInterface::get_bounds_info(), casadi::BonminUserClass::get_bounds_info(), casadi::IpoptUserClass::get_bounds_info(), casadi::IpoptInterface::get_bounds_info(), casadi::Nlpsol::get_forward(), casadi::BonminInterface::get_nlp_info(), casadi::IpoptInterface::get_nlp_info(), casadi::Nlpsol::get_reverse(), casadi::BonminInterface::get_starting_point(), casadi::BonminUserClass::get_starting_point(), casadi::IpoptUserClass::get_starting_point(), casadi::IpoptInterface::get_starting_point(), casadi::Nlpsol::init(), casadi::AlpaqaInterface::init(), casadi::AmplInterface::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::FatropInterface::init(), casadi::IpoptInterface::init(), casadi::KnitroInterface::init(), casadi::SLEQPInterface::init(), casadi::SnoptInterface::init(), casadi::WorhpInterface::init(), init(), casadi::Qrsqp::init(), casadi::Scpgen::init(), casadi::Sqpmethod::init(), casadi::IpoptInterface::init_mem(), casadi::SnoptInterface::init_mem(), casadi::BonminInterface::intermediate_callback(), casadi::IpoptInterface::intermediate_callback(), casadi::IpoptUserClass::IpoptUserClass(), casadi::Blocksqp::kktErrorReduction(), casadi::Scpgen::line_search(), casadi::Blocksqp::lInfConstraintNorm(), casadi::Nlpsol::Nlpsol(), casadi::Scpgen::primalInfeasibility(), casadi::Blocksqp::printProgress(), casadi::Blocksqp::reduceSOCStepsize(), casadi::Scpgen::regularize(), casadi::Blocksqp::reset_sqp(), casadi::Blocksqp::resetHessian(), casadi::Blocksqp::secondOrderCorrection(), casadi::Nlpsol::serialize_body(), casadi::Blocksqp::set_work(), casadi::BonminInterface::set_work(), casadi::IpoptInterface::set_work(), casadi::KnitroInterface::set_work(), casadi::SLEQPInterface::set_work(), casadi::SnoptInterface::set_work(), casadi::WorhpInterface::set_work(), casadi::Qrsqp::set_work(), casadi::Scpgen::set_work(), casadi::AlpaqaInterface::solve(), casadi::AmplInterface::solve(), casadi::Blocksqp::solve(), casadi::BonminInterface::solve(), casadi::IpoptInterface::solve(), casadi::KnitroInterface::solve(), casadi::SLEQPInterface::solve(), casadi::SnoptInterface::solve(), casadi::WorhpInterface::solve(), solve(), casadi::Qrsqp::solve(), casadi::Scpgen::solve(), casadi::Sqpmethod::solve(), casadi::Sqpmethod::solve_ela_QP(), casadi::Sqpmethod::solve_elastic_mode(), solve_LP(), solve_QP(), casadi::Qrsqp::solve_QP(), casadi::Scpgen::solve_qp(), casadi::Sqpmethod::solve_QP(), casadi::Blocksqp::solveQP(), step_update(), tr_update(), casadi::Blocksqp::updateDeltaGamma(), casadi::Blocksqp::updateStepBounds(), and casadi::SnoptInterface::userfun().

◆ optim_tol_

double casadi::Feasiblesqpmethod::optim_tol_

Definition at line 188 of file feasiblesqpmethod.hpp.

Referenced by codegen_body(), codegen_tr_update(), init(), solve(), and tr_update().

◆ options_

const Options casadi::Feasiblesqpmethod::options_
static

◆ oracle_

Function casadi::OracleFunction::oracle_
protectedinherited

◆ p_

casadi_feasiblesqpmethod_prob<double> casadi::Feasiblesqpmethod::p_

Definition at line 127 of file feasiblesqpmethod.hpp.

Referenced by init(), and set_work().

◆ p_nlp_

casadi_nlpsol_prob<double> casadi::Nlpsol::p_nlp_
inherited

◆ post_expand_

bool casadi::OracleFunction::post_expand_
protectedinherited

◆ print_canonical_

bool casadi::FunctionInternal::print_canonical_
inherited

◆ print_header_

bool casadi::Feasiblesqpmethod::print_header_

Linesearch parameters

Definition at line 171 of file feasiblesqpmethod.hpp.

Referenced by Feasiblesqpmethod(), init(), and serialize_body().

◆ print_in_

bool casadi::FunctionInternal::print_in_
inherited

◆ print_iteration_

bool casadi::Feasiblesqpmethod::print_iteration_

Definition at line 171 of file feasiblesqpmethod.hpp.

Referenced by codegen_body(), Feasiblesqpmethod(), init(), serialize_body(), and solve().

◆ print_out_

bool casadi::FunctionInternal::print_out_
inherited

◆ print_status_

bool casadi::Feasiblesqpmethod::print_status_

Definition at line 171 of file feasiblesqpmethod.hpp.

Referenced by codegen_body(), Feasiblesqpmethod(), init(), serialize_body(), and solve().

◆ print_time_

bool casadi::ProtoFunction::print_time_
inherited

◆ qpsol_

Function casadi::Feasiblesqpmethod::qpsol_

◆ qpsol_ela_

Function casadi::Feasiblesqpmethod::qpsol_ela_

Definition at line 133 of file feasiblesqpmethod.hpp.

Referenced by Feasiblesqpmethod().

◆ record_time_

bool casadi::ProtoFunction::record_time_
inherited

◆ regularity_check_

bool casadi::ProtoFunction::regularity_check_
inherited

◆ release_

casadi_release_t casadi::FunctionInternal::release_
inherited

◆ reverse_options_

Dict casadi::FunctionInternal::reverse_options_
inherited

◆ sens_linsol_

std::string casadi::Nlpsol::sens_linsol_
inherited

◆ sens_linsol_options_

Dict casadi::Nlpsol::sens_linsol_options_
inherited

◆ show_eval_warnings_

bool casadi::OracleFunction::show_eval_warnings_
protectedinherited

◆ solvers_

std::map< std::string, Nlpsol::Plugin > casadi::Nlpsol::solvers_
staticinherited

Definition at line 283 of file nlpsol_impl.hpp.

◆ sparsity_in_

std::vector<Sparsity> casadi::FunctionInternal::sparsity_in_
inherited

◆ sparsity_out_

std::vector<Sparsity> casadi::FunctionInternal::sparsity_out_
inherited

◆ specific_options_

Dict casadi::OracleFunction::specific_options_
protectedinherited

◆ stats_

Dict casadi::FunctionInternal::stats_
inherited

◆ stride_arg_

size_t casadi::OracleFunction::stride_arg_
protectedinherited

◆ stride_iw_

size_t casadi::OracleFunction::stride_iw_
protectedinherited

◆ stride_res_

size_t casadi::OracleFunction::stride_res_
protectedinherited

◆ stride_w_

size_t casadi::OracleFunction::stride_w_
protectedinherited

◆ sz_anderson_memory_

casadi_int casadi::Feasiblesqpmethod::sz_anderson_memory_

◆ tol_du_

double casadi::Feasiblesqpmethod::tol_du_

Definition at line 157 of file feasiblesqpmethod.hpp.

Referenced by Feasiblesqpmethod(), init(), and serialize_body().

◆ tol_pr_

double casadi::Feasiblesqpmethod::tol_pr_

Definition at line 157 of file feasiblesqpmethod.hpp.

Referenced by Feasiblesqpmethod(), init(), and serialize_body().

◆ tr_acceptance_

double casadi::Feasiblesqpmethod::tr_acceptance_

Definition at line 195 of file feasiblesqpmethod.hpp.

Referenced by codegen_step_update(), init(), and step_update().

◆ tr_alpha1_

double casadi::Feasiblesqpmethod::tr_alpha1_

Definition at line 192 of file feasiblesqpmethod.hpp.

Referenced by codegen_tr_update(), init(), and tr_update().

◆ tr_alpha2_

double casadi::Feasiblesqpmethod::tr_alpha2_

Definition at line 192 of file feasiblesqpmethod.hpp.

Referenced by codegen_tr_update(), init(), and tr_update().

◆ tr_eta1_

double casadi::Feasiblesqpmethod::tr_eta1_

Definition at line 191 of file feasiblesqpmethod.hpp.

Referenced by codegen_tr_update(), init(), and tr_update().

◆ tr_eta2_

double casadi::Feasiblesqpmethod::tr_eta2_

Definition at line 191 of file feasiblesqpmethod.hpp.

Referenced by codegen_tr_update(), init(), and tr_update().

◆ tr_rad0_

double casadi::Feasiblesqpmethod::tr_rad0_

Definition at line 194 of file feasiblesqpmethod.hpp.

Referenced by codegen_body(), init(), and solve().

◆ tr_rad_max_

double casadi::Feasiblesqpmethod::tr_rad_max_

Definition at line 196 of file feasiblesqpmethod.hpp.

Referenced by codegen_tr_update(), init(), and tr_update().

◆ tr_rad_min_

double casadi::Feasiblesqpmethod::tr_rad_min_

Definition at line 196 of file feasiblesqpmethod.hpp.

Referenced by init().

◆ tr_scale_vector_

std::vector<double> casadi::Feasiblesqpmethod::tr_scale_vector_

Definition at line 198 of file feasiblesqpmethod.hpp.

Referenced by codegen_body(), init(), and solve().

◆ tr_tol_

double casadi::Feasiblesqpmethod::tr_tol_

Definition at line 193 of file feasiblesqpmethod.hpp.

Referenced by init().

◆ use_anderson_

bool casadi::Feasiblesqpmethod::use_anderson_

Definition at line 142 of file feasiblesqpmethod.hpp.

Referenced by feasibility_iterations(), and init().

◆ use_sqp_

bool casadi::Feasiblesqpmethod::use_sqp_

Definition at line 139 of file feasiblesqpmethod.hpp.

Referenced by eval_m_k(), feasibility_iterations(), init(), and solve().

◆ user_data_

void* casadi::FunctionInternal::user_data_
inherited

◆ verbose_

bool casadi::ProtoFunction::verbose_
inherited

Definition at line 249 of file function_internal.hpp.

Referenced by casadi::MXFunction::ad_forward(), casadi::SXFunction::ad_forward(), casadi::MXFunction::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::Integrator::advance(), casadi::ProtoFunction::change_option(), casadi::BSplineInterpolant::construct_graph(), casadi::OracleFunction::create_function(), casadi::FmuFunction::eval(), casadi::Integrator::eval(), casadi::MXFunction::eval(), casadi::SXFunction::eval(), casadi::MXFunction::eval_mx(), casadi::SXFunction::eval_mx(), casadi::SXFunction::eval_sx(), casadi::FmuFunction::factory(), casadi::FunctionInternal::finalize(), casadi::KinsolInterface::func(), casadi::ProtoFunction::generate_options(), casadi::FmuFunction::get_forward(), casadi::Integrator::get_forward(), casadi::Integrator::get_forward_dae(), casadi::FunctionInternal::get_jac_sparsity_gen(), casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::FunctionInternal::get_jac_sparsity_hierarchical_symm(), casadi::FmuFunction::get_jacobian(), casadi::FunctionInternal::get_partition(), casadi::FmuFunction::get_reverse(), casadi::Integrator::get_reverse(), casadi::ProtoFunction::init(), casadi::FiniteDiff::init(), casadi::FmuFunction::init(), casadi::FunctionInternal::init(), casadi::MXFunction::init(), casadi::SXFunction::init(), casadi::Blocksqp::init(), casadi::FatropConicInterface::init(), casadi::FatropInterface::init(), casadi::HpipmInterface::init(), casadi::HpmpcInterface::init(), casadi::IpoptInterface::init(), casadi::MadnlpInterface::init(), casadi::CvodesInterface::init(), casadi::IdasInterface::init(), init(), casadi::Scpgen::init(), casadi::Sqpmethod::init(), casadi::IpoptInterface::init_mem(), casadi::IdasInterface::init_mem(), casadi::SXFunction::instructions_sx(), casadi::BonminInterface::intermediate_callback(), casadi::OracleFunction::jit_dependencies(), casadi::CsparseInterface::nfact(), casadi::LapackLu::nfact(), casadi::LapackQr::nfact(), casadi::LinsolQr::nfact(), casadi::Integrator::predict_events(), casadi::ProtoFunction::ProtoFunction(), casadi::CvodesInterface::reset(), casadi::IdasInterface::reset(), casadi::IdasInterface::resetB(), casadi::ProtoFunction::serialize_body(), casadi::CbcInterface::solve(), casadi::ClpInterface::solve(), casadi::CplexInterface::solve(), casadi::GurobiInterface::solve(), casadi::HpipmInterface::solve(), casadi::QpoasesInterface::solve(), casadi::Ipqp::solve(), casadi::Qrqp::solve(), casadi::AlpaqaInterface::solve(), casadi::AmplInterface::solve(), casadi::SnoptInterface::solve(), casadi::KinsolInterface::solve(), casadi::WorhpInterface::solve(), casadi::Newton::solve(), casadi::Qrsqp::solve(), casadi::Scpgen::solve(), casadi::Sqpmethod::solve(), casadi::Sqpmethod::solve_ela_QP(), solve_LP(), solve_QP(), casadi::Qrsqp::solve_QP(), casadi::Sqpmethod::solve_QP(), casadi::Integrator::sp_forward(), casadi::Integrator::sp_reverse(), and casadi::Integrator::trigger_event().

◆ warn_initial_bounds_

bool casadi::Nlpsol::warn_initial_bounds_
inherited

◆ watchdog_

casadi_int casadi::Feasiblesqpmethod::watchdog_

The documentation for this class was generated from the following files: