9#ifndef __CROCODDYL_CORE_SOLVERS_IPOPT_IPOPT_IFACE_HPP__ 10#define __CROCODDYL_CORE_SOLVERS_IPOPT_IPOPT_IFACE_HPP__ 16#include "crocoddyl/core/optctrl/shooting.hpp" 59template <
typename _Scalar>
62 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
64 typedef _Scalar Scalar;
66 typedef typename ShootingProblem::ActionModelAbstract ActionModelAbstract;
67 typedef typename ShootingProblem::ActionDataAbstract ActionDataAbstract;
70 typedef typename MathBase::VectorXs VectorXs;
97 Ipopt::Index& nnz_jac_g, Ipopt::Index& nnz_h_lag,
98 IndexStyleEnum& index_style);
128 Ipopt::Number* x_u, Ipopt::Index m,
129 Ipopt::Number* g_l, Ipopt::Number* g_u);
165 bool init_z, Ipopt::Number* z_L,
166 Ipopt::Number* z_U, Ipopt::Index m,
167 bool init_lambda, Ipopt::Number* lambda);
186 virtual bool eval_f(Ipopt::Index n,
const Ipopt::Number* x,
bool new_x,
187 Ipopt::Number& obj_value);
206 virtual bool eval_grad_f(Ipopt::Index n,
const Ipopt::Number* x,
bool new_x,
207 Ipopt::Number* grad_f);
226 virtual bool eval_g(Ipopt::Index n,
const Ipopt::Number* x,
bool new_x,
227 Ipopt::Index m, Ipopt::Number* g);
272 virtual bool eval_jac_g(Ipopt::Index n,
const Ipopt::Number* x,
bool new_x,
273 Ipopt::Index m, Ipopt::Index nele_jac,
274 Ipopt::Index* iRow, Ipopt::Index* jCol,
275 Ipopt::Number* values);
331 virtual bool eval_h(Ipopt::Index n,
const Ipopt::Number* x,
bool new_x,
332 Ipopt::Number obj_factor, Ipopt::Index m,
333 const Ipopt::Number* lambda,
bool new_lambda,
334 Ipopt::Index nele_hess, Ipopt::Index* iRow,
335 Ipopt::Index* jCol, Ipopt::Number* values);
383 Ipopt::SolverReturn status, Ipopt::Index n,
const Ipopt::Number* x,
384 const Ipopt::Number* z_L,
const Ipopt::Number* z_U, Ipopt::Index m,
385 const Ipopt::Number* g,
const Ipopt::Number* lambda,
386 Ipopt::Number obj_value,
const Ipopt::IpoptData* ip_data,
387 Ipopt::IpoptCalculatedQuantities* ip_cq);
412 Ipopt::AlgorithmMode mode, Ipopt::Index iter, Ipopt::Number obj_value,
413 Ipopt::Number inf_pr, Ipopt::Number inf_du, Ipopt::Number mu,
414 Ipopt::Number d_norm, Ipopt::Number regularization_size,
415 Ipopt::Number alpha_du, Ipopt::Number alpha_pr, Ipopt::Index ls_trials,
416 const Ipopt::IpoptData* ip_data, Ipopt::IpoptCalculatedQuantities* ip_cq);
423 std::shared_ptr<IpoptInterfaceData>
createData(
const std::size_t nx,
424 const std::size_t ndx,
425 const std::size_t nu);
443 const std::vector<VectorXs>&
get_xs()
const;
448 const std::vector<VectorXs>&
get_us()
const;
455 Scalar get_cost()
const;
460 void set_xs(
const std::vector<VectorXs>& xs);
465 void set_us(
const std::vector<VectorXs>& us);
468 std::shared_ptr<ShootingProblem> problem_;
469 std::vector<VectorXs> xs_;
470 std::vector<VectorXs> us_;
471 std::vector<std::size_t> ixu_;
474 std::vector<std::shared_ptr<IpoptInterfaceData>> datas_;
482template <
typename _Scalar>
483struct IpoptInterfaceDataTpl {
484 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
486 typedef _Scalar Scalar;
488 typedef typename MathBase::VectorXs VectorXs;
489 typedef typename MathBase::MatrixXs MatrixXs;
491 IpoptInterfaceDataTpl(
const std::size_t nx,
const std::size_t ndx,
492 const std::size_t nu)
531 void resize(
const std::size_t nx,
const std::size_t ndx,
532 const std::size_t nu) {
533 x.conservativeResize(nx);
534 xnext.conservativeResize(nx);
535 dx.conservativeResize(ndx);
536 dxnext.conservativeResize(ndx);
537 x_diff.conservativeResize(ndx);
538 u.conservativeResize(nu);
539 Jint_dx.conservativeResize(ndx, ndx);
541 Jdiff_x.conservativeResize(ndx, ndx);
543 Jg_dx.conservativeResize(ndx, ndx);
545 Jg_u.conservativeResize(ndx, ndx);
546 Jg_ic.conservativeResize(ndx, ndx);
548 Ldx.conservativeResize(ndx);
549 Ldxdx.conservativeResize(ndx, ndx);
550 Ldxu.conservativeResize(ndx, nu);
580#include "crocoddyl/core/solvers/ipopt/ipopt-iface.hxx" virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number *x, bool init_z, Ipopt::Number *z_L, Ipopt::Number *z_U, Ipopt::Index m, bool init_lambda, Ipopt::Number *lambda)
Method to request the starting point before iterating.
virtual bool eval_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)
Method to request the constraint values.
const std::vector< VectorXs > & get_us() const
Return the control vector.
std::size_t get_nvar() const
Return the total number of optimization variables (states and controls).
void set_us(const std::vector< VectorXs > &us)
Modify the control vector.
void set_xs(const std::vector< VectorXs > &xs)
Modify the state vector.
virtual bool eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)
Method to request the value of the objective function.
virtual bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, IndexStyleEnum &index_style)
Methods to gather information about the NLP.
virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
Method to request either the sparsity structure or the values of the Jacobian of the constraints.
virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)
Method to request the gradient of the objective function.
virtual bool eval_h(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number *lambda, bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
Method to request either the sparsity structure or the values of the Hessian of the Lagrangian.
IpoptInterfaceTpl(const std::shared_ptr< ShootingProblem > &problem)
Initialize the Ipopt interface.
std::size_t get_nconst() const
Return the total number of constraints in the NLP.
const std::vector< VectorXs > & get_xs() const
Return the state vector.
bool intermediate_callback(Ipopt::AlgorithmMode mode, Ipopt::Index iter, Ipopt::Number obj_value, Ipopt::Number inf_pr, Ipopt::Number inf_du, Ipopt::Number mu, Ipopt::Number d_norm, Ipopt::Number regularization_size, Ipopt::Number alpha_du, Ipopt::Number alpha_pr, Ipopt::Index ls_trials, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
Intermediate Callback method for the user.
virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number *x_l, Ipopt::Number *x_u, Ipopt::Index m, Ipopt::Number *g_l, Ipopt::Number *g_u)
Method to request bounds on the variables and constraints. T.
std::shared_ptr< IpoptInterfaceData > createData(const std::size_t nx, const std::size_t ndx, const std::size_t nu)
Create the data structure to store temporary computations.
const std::shared_ptr< ShootingProblem > & get_problem() const
Return the crocoddyl::ShootingProblem to be solved.
virtual void finalize_solution(Ipopt::SolverReturn status, Ipopt::Index n, const Ipopt::Number *x, const Ipopt::Number *z_L, const Ipopt::Number *z_U, Ipopt::Index m, const Ipopt::Number *g, const Ipopt::Number *lambda, Ipopt::Number obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
This method is called when the algorithm has finished (successfully or not) so the TNLP can digest th...
This class encapsulates a shooting problem.
VectorXs xnext
Integrated state at next node.
MatrixXs Jg_dxnext
Jacobian of the dynamic constraint w.r.t dxnext.
VectorXs Ldx
Jacobian of the cost w.r.t dx.
MatrixXs Jg_u
Jacobian of the dynamic constraint w.r.t u.
MatrixXs Jg_ic
Jacobian of the initial condition constraint w.r.t dx.
MatrixXs Ldxu
Hessian of the cost w.r.t dxu.
VectorXs x_diff
State difference.
MatrixXs Jg_dx
Jacobian of the dynamic constraint w.r.t dx.
VectorXs x
Integrated state.
MatrixXs FxJint_dx
Intermediate computation needed for Jg_ic.
MatrixXs Ldxdx
Hessian of the cost w.r.t dxdx.
MatrixXs Jint_dx
Jacobian of the sum operation w.r.t dx.
VectorXs dx
Increment in the tangent space.
MatrixXs Jdiff_x
Jacobian of the diff operation w.r.t the first element.
MatrixXs Jint_dxnext
Jacobian of the sum operation w.r.t dx at next node.
VectorXs dxnext
Increment in the tangent space at next node.