DART 6.8.5
Loading...
Searching...
No Matches
IpoptSolver.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2019, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef DART_OPTIMIZER_IPOPT_IPOPTSOLVER_HPP_
34#define DART_OPTIMIZER_IPOPT_IPOPTSOLVER_HPP_
35
36#include <coin/IpTNLP.hpp>
37#include <coin/IpIpoptApplication.hpp>
38
39#include <memory>
40
42
43namespace dart {
44namespace optimizer {
45
46class Problem;
47class DartTNLP;
48
50class IpoptSolver : public Solver
51{
52public:
53
56
58 explicit IpoptSolver(std::shared_ptr<Problem> _problem);
59
61 virtual ~IpoptSolver();
62
63 // Documentation inherited
64 bool solve() override;
65
66 // Documentation inherited
67 std::string getType() const override;
68
69 // Documentation inherited
70 std::shared_ptr<Solver> clone() const override;
71
73 const Ipopt::SmartPtr<Ipopt::IpoptApplication>& getApplication();
74
76 Ipopt::SmartPtr<const Ipopt::IpoptApplication> getApplication() const;
77
78private:
79
81 IpoptSolver(const Properties& _properties,
82 const Ipopt::SmartPtr<Ipopt::IpoptApplication>& _app);
83
85 Ipopt::SmartPtr<Ipopt::TNLP> mNlp;
86
88 Ipopt::SmartPtr<Ipopt::IpoptApplication> mIpoptApp;
89};
90
92class DartTNLP : public Ipopt::TNLP
93{
94public:
95
96 friend class IpoptSolver;
97
99 virtual ~DartTNLP();
100
101 //------------------------- Ipopt::TNLP --------------------------------------
103 bool get_nlp_info(Ipopt::Index& n,
104 Ipopt::Index& m,
105 Ipopt::Index& nnz_jac_g,
106 Ipopt::Index& nnz_h_lag,
107 Ipopt::TNLP::IndexStyleEnum& index_style) override;
108
110 bool get_bounds_info(Ipopt::Index n,
111 Ipopt::Number* x_l,
112 Ipopt::Number* x_u,
113 Ipopt::Index m,
114 Ipopt::Number* g_l,
115 Ipopt::Number* g_u) override;
116
118 bool get_starting_point(Ipopt::Index n,
119 bool init_x,
120 Ipopt::Number* x,
121 bool init_z,
122 Ipopt::Number* z_L,
123 Ipopt::Number* z_U,
124 Ipopt::Index m,
125 bool init_lambda,
126 Ipopt::Number* lambda) override;
127
129 bool eval_f(Ipopt::Index _n,
130 const Ipopt::Number* _x,
131 bool _new_x,
132 Ipopt::Number&
133 _obj_value) override;
134
136 bool eval_grad_f(Ipopt::Index _n,
137 const Ipopt::Number* _x,
138 bool _new_x,
139 Ipopt::Number* _grad_f) override;
140
142 bool eval_g(Ipopt::Index _n,
143 const Ipopt::Number* _x,
144 bool _new_x,
145 Ipopt::Index _m,
146 Ipopt::Number* _g) override;
147
151 bool eval_jac_g(Ipopt::Index _n,
152 const Ipopt::Number* _x,
153 bool _new_x,
154 Ipopt::Index _m,
155 Ipopt::Index _nele_jac,
156 Ipopt::Index* _iRow,
157 Ipopt::Index* _jCol,
158 Ipopt::Number* _values) override;
159
165 bool eval_h(Ipopt::Index _n,
166 const Ipopt::Number* _x,
167 bool _new_x,
168 Ipopt::Number _obj_factor,
169 Ipopt::Index _m,
170 const Ipopt::Number* _lambda,
171 bool _new_lambda,
172 Ipopt::Index _nele_hess,
173 Ipopt::Index* _iRow,
174 Ipopt::Index* _jCol,
175 Ipopt::Number* _values) override;
176
179 void finalize_solution(Ipopt::SolverReturn _status,
180 Ipopt::Index _n,
181 const Ipopt::Number* _x,
182 const Ipopt::Number* _z_L,
183 const Ipopt::Number* _z_U,
184 Ipopt::Index _m,
185 const Ipopt::Number* _g,
186 const Ipopt::Number* _lambda,
187 Ipopt::Number _obj_value,
188 const Ipopt::IpoptData* _ip_data,
189 Ipopt::IpoptCalculatedQuantities* _ip_cq) override;
190
191private:
192
194 explicit DartTNLP(IpoptSolver* _solver);
195
198
200 Ipopt::Number mObjValue;
201
203 Eigen::VectorXd mObjGradient;
204
206 Eigen::MatrixXd mObjHessian;
207};
208
209} // namespace optimizer
210} // namespace dart
211
212#endif // DART_OPTIMIZER_IPOPT_IPOPTSOLVER_HPP_
class DartTNLP
Definition IpoptSolver.hpp:93
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) override
Method to return the starting point for the algorithm.
Definition IpoptSolver.cpp:236
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) override
This method is called when the algorithm is complete so the TNLP can store/write the solution.
Definition IpoptSolver.cpp:427
bool eval_grad_f(Ipopt::Index _n, const Ipopt::Number *_x, bool _new_x, Ipopt::Number *_grad_f) override
Method to return the gradient of the objective.
Definition IpoptSolver.cpp:293
bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, Ipopt::TNLP::IndexStyleEnum &index_style) override
Method to return some info about the nlp.
Definition IpoptSolver.cpp:164
virtual ~DartTNLP()
Definition IpoptSolver.cpp:158
IpoptSolver * mSolver
DART optimization problem.
Definition IpoptSolver.hpp:197
Eigen::VectorXd mObjGradient
Objective gradient.
Definition IpoptSolver.hpp:203
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) override
Method to return the bounds for my problem.
Definition IpoptSolver.cpp:191
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) override
Method to return: 1) The structure of the hessian of the lagrangian (if "values" is nullptr) 2) The v...
Definition IpoptSolver.cpp:407
Eigen::MatrixXd mObjHessian
Objective Hessian.
Definition IpoptSolver.hpp:206
bool eval_f(Ipopt::Index _n, const Ipopt::Number *_x, bool _new_x, Ipopt::Number &_obj_value) override
Method to return the objective value.
Definition IpoptSolver.cpp:277
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) override
Method to return: 1) The structure of the jacobian (if "values" is nullptr) 2) The values of the jaco...
Definition IpoptSolver.cpp:348
Ipopt::Number mObjValue
Objective value.
Definition IpoptSolver.hpp:200
bool eval_g(Ipopt::Index _n, const Ipopt::Number *_x, bool _new_x, Ipopt::Index _m, Ipopt::Number *_g) override
Method to return the constraint residuals.
Definition IpoptSolver.cpp:308
class IpoptSolver
Definition IpoptSolver.hpp:51
std::shared_ptr< Solver > clone() const override
Create an identical clone of this Solver.
Definition IpoptSolver.cpp:121
Ipopt::SmartPtr< Ipopt::IpoptApplication > mIpoptApp
Main application class for making calls to Ipopt.
Definition IpoptSolver.hpp:88
const Ipopt::SmartPtr< Ipopt::IpoptApplication > & getApplication()
Get the application interface for this IpoptSolver.
Definition IpoptSolver.cpp:130
std::string getType() const override
Get the type (implementation) of this Solver.
Definition IpoptSolver.cpp:115
bool solve() override
Solve optimization problem.
Definition IpoptSolver.cpp:77
virtual ~IpoptSolver()
Destructor.
Definition IpoptSolver.cpp:71
Ipopt::SmartPtr< Ipopt::TNLP > mNlp
IPOPT nonlinear programming problem.
Definition IpoptSolver.hpp:85
Abstract class that provides a common interface for different Solvers.
Definition Solver.hpp:53
Definition BulletCollisionDetector.cpp:63
The Solver::Properties class contains Solver parameters that are common to all Solver types.
Definition Solver.hpp:61