ipopt_adapter.h
Go to the documentation of this file.
1 /******************************************************************************
2 Copyright (c) 2017, Alexander W. Winkler, ETH Zurich. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6  * Redistributions of source code must retain the above copyright notice,
7  this list of conditions and the following disclaimer.
8  * Redistributions in binary form must reproduce the above copyright notice,
9  this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of ETH ZURICH nor the names of its contributors may be
12  used to endorse or promote products derived from this software without
13  specific prior written permission.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 DISCLAIMED. IN NO EVENT SHALL ETH ZURICH BE LIABLE FOR ANY DIRECT, INDIRECT,
19 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 ******************************************************************************/
26 
27 #ifndef IFOPT_INCLUDE_OPT_IPOPT_ADAPTER_H_
28 #define IFOPT_INCLUDE_OPT_IPOPT_ADAPTER_H_
29 
30 #include <IpTNLP.hpp>
31 #include <IpIpoptApplication.hpp>
32 #include <IpSolveStatistics.hpp>
33 
34 #include <ifopt/problem.h>
35 
36 namespace ifopt {
37 
50 class IpoptAdapter : public Ipopt::TNLP {
51 public:
52  using Index = Ipopt::Index;
55 
63  static void Solve(Problem& nlp);
64 
65 private:
77  static void SetOptions(Ipopt::SmartPtr<Ipopt::IpoptApplication> app);
78 
80 
81 private:
88  IpoptAdapter(Problem& nlp);
89  virtual ~IpoptAdapter() = default;
90 
92  virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
93  Index& nnz_h_lag, IndexStyleEnum& index_style);
94 
96  virtual bool get_bounds_info(Index n, double* x_l, double* x_u,
97  Index m, double* g_l, double* g_u);
98 
100  virtual bool get_starting_point(Index n, bool init_x, double* x,
101  bool init_z, double* z_L, double* z_U,
102  Index m, bool init_lambda,
103  double* lambda);
104 
106  virtual bool eval_f(Index n, const double* x, bool new_x, double& obj_value);
107 
109  virtual bool eval_grad_f(Index n, const double* x, bool new_x, double* grad_f);
110 
112  virtual bool eval_g(Index n, const double* x, bool new_x, Index m, double* g);
113 
118  virtual bool eval_jac_g(Index n, const double* x, bool new_x,
119  Index m, Index nele_jac, Index* iRow, Index *jCol,
120  double* values);
121 
124  virtual bool intermediate_callback(Ipopt::AlgorithmMode mode,
125  Index iter, double obj_value,
126  double inf_pr, double inf_du,
127  double mu, double d_norm,
128  double regularization_size,
129  double alpha_du, double alpha_pr,
130  Index ls_trials,
131  const Ipopt::IpoptData* ip_data,
132  Ipopt::IpoptCalculatedQuantities* ip_cq);
133 
136  virtual void finalize_solution(Ipopt::SolverReturn status,
137  Index n, const double* x, const double* z_L, const double* z_U,
138  Index m, const double* g, const double* lambda,
139  double obj_value,
140  const Ipopt::IpoptData* ip_data,
141  Ipopt::IpoptCalculatedQuantities* ip_cq);
142 };
143 
144 } // namespace opt
145 
146 #endif /* IFOPT_INCLUDE_OPT_IPOPT_ADAPTER_H_ */
virtual ~IpoptAdapter()=default
static void SetOptions(Ipopt::SmartPtr< Ipopt::IpoptApplication > app)
Defines settings for the Ipopt solver app.
virtual bool get_starting_point(Index n, bool init_x, double *x, bool init_z, double *z_L, double *z_U, Index m, bool init_lambda, double *lambda)
virtual bool get_bounds_info(Index n, double *x_l, double *x_u, Index m, double *g_l, double *g_u)
Problem::VectorXd VectorXd
Definition: ipopt_adapter.h:53
virtual bool eval_jac_g(Index n, const double *x, bool new_x, Index m, Index nele_jac, Index *iRow, Index *jCol, double *values)
Component::Jacobian Jacobian
virtual bool eval_g(Index n, const double *x, bool new_x, Index m, double *g)
Problem::Jacobian Jacobian
Definition: ipopt_adapter.h:54
virtual bool eval_f(Index n, const double *x, bool new_x, double &obj_value)
Component::VectorXd VectorXd
Ipopt::Index Index
Definition: ipopt_adapter.h:52
virtual bool eval_grad_f(Index n, const double *x, bool new_x, double *grad_f)
IpoptAdapter(Problem &nlp)
Creates an IpoptAdapter wrapping the nlp.
virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag, IndexStyleEnum &index_style)
virtual bool intermediate_callback(Ipopt::AlgorithmMode mode, Index iter, double obj_value, double inf_pr, double inf_du, double mu, double d_norm, double regularization_size, double alpha_du, double alpha_pr, Index ls_trials, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
Problem * nlp_
The solver independent problem definition.
Definition: ipopt_adapter.h:79
Solves the optimization problem using the IPOPT solver.
Definition: ipopt_adapter.h:50
virtual void finalize_solution(Ipopt::SolverReturn status, Index n, const double *x, const double *z_L, const double *z_U, Index m, const double *g, const double *lambda, double obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
static void Solve(Problem &nlp)
Creates an IpoptAdapter and solves the NLP.


ifopt_ipopt
Author(s): Alexander W. Winkler
autogenerated on Thu Apr 19 2018 02:47:38