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 <IpIpoptApplication.hpp>
31 #include <IpSolveStatistics.hpp>
32 #include <IpTNLP.hpp>
33 
34 #include <ifopt/problem.h>
35 
42 namespace Ipopt {
43 
54 class IpoptAdapter : public TNLP {
55  public:
56  using Problem = ifopt::Problem;
59 
66  IpoptAdapter(Problem& nlp, bool finite_diff = false);
67  virtual ~IpoptAdapter() = default;
68 
69  private:
70  Problem* nlp_;
71  bool
72  finite_diff_;
73 
75  virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
76  Index& nnz_h_lag, IndexStyleEnum& index_style);
77 
79  virtual bool get_bounds_info(Index n, double* x_l, double* x_u, Index m,
80  double* g_l, double* g_u);
81 
83  virtual bool get_starting_point(Index n, bool init_x, double* x, bool init_z,
84  double* z_L, double* z_U, Index m,
85  bool init_lambda, double* lambda);
86 
88  virtual bool eval_f(Index n, const double* x, bool new_x, double& obj_value);
89 
91  virtual bool eval_grad_f(Index n, const double* x, bool new_x,
92  double* grad_f);
93 
95  virtual bool eval_g(Index n, const double* x, bool new_x, Index m, double* g);
96 
101  virtual bool eval_jac_g(Index n, const double* x, bool new_x, Index m,
102  Index nele_jac, Index* iRow, Index* jCol,
103  double* values);
104 
107  virtual bool intermediate_callback(AlgorithmMode mode, Index iter,
108  double obj_value, double inf_pr,
109  double inf_du, double mu, double d_norm,
110  double regularization_size,
111  double alpha_du, double alpha_pr,
112  Index ls_trials, const IpoptData* ip_data,
113  IpoptCalculatedQuantities* ip_cq);
114 
117  virtual void finalize_solution(SolverReturn status, Index n, const double* x,
118  const double* z_L, const double* z_U, Index m,
119  const double* g, const double* lambda,
120  double obj_value, const IpoptData* ip_data,
121  IpoptCalculatedQuantities* ip_cq);
122 };
123 
124 } // namespace Ipopt
125 
126 #endif /* IFOPT_INCLUDE_OPT_IPOPT_ADAPTER_H_ */
ifopt::Problem::VectorXd
Component::VectorXd VectorXd
Definition: problem.h:127
Ipopt::IpoptAdapter::Jacobian
Problem::Jacobian Jacobian
Definition: ipopt_adapter.h:106
Ipopt
namespace defined by the Ipopt solver.
Definition: ipopt_adapter.h:42
Ipopt::IpoptAdapter::~IpoptAdapter
virtual ~IpoptAdapter()=default
ifopt::Problem::Jacobian
Component::Jacobian Jacobian
Definition: problem.h:126
Ipopt::IpoptAdapter::nlp_
Problem * nlp_
The solver independent problem definition.
Definition: ipopt_adapter.h:118
Ipopt::IpoptAdapter::eval_jac_g
virtual bool eval_jac_g(Index n, const double *x, bool new_x, Index m, Index nele_jac, Index *iRow, Index *jCol, double *values)
Definition: ipopt_adapter.cc:137
Ipopt::IpoptAdapter
Solves the optimization problem using the IPOPT solver.
Definition: ipopt_adapter.h:78
problem.h
ifopt::Problem
A generic optimization problem with variables, costs and constraints.
Definition: problem.h:123
Ipopt::IpoptAdapter::get_nlp_info
virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag, IndexStyleEnum &index_style)
Definition: ipopt_adapter.cc:61
Ipopt::IpoptAdapter::eval_f
virtual bool eval_f(Index n, const double *x, bool new_x, double &obj_value)
Definition: ipopt_adapter.cc:114
Ipopt::IpoptAdapter::IpoptAdapter
IpoptAdapter(Problem &nlp, bool finite_diff=false)
Creates an IpoptAdapter wrapping the nlp.
Definition: ipopt_adapter.cc:55
Ipopt::IpoptAdapter::finite_diff_
bool finite_diff_
Flag that indicates the "finite-difference-values" option is set.
Definition: ipopt_adapter.h:120
Ipopt::IpoptAdapter::get_bounds_info
virtual bool get_bounds_info(Index n, double *x_l, double *x_u, Index m, double *g_l, double *g_u)
Definition: ipopt_adapter.cc:80
Ipopt::IpoptAdapter::finalize_solution
virtual void finalize_solution(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 IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq)
Definition: ipopt_adapter.cc:184
Ipopt::IpoptAdapter::Problem
ifopt::Problem Problem
Definition: ipopt_adapter.h:104
Ipopt::IpoptAdapter::get_starting_point
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)
Definition: ipopt_adapter.cc:99
Ipopt::IpoptAdapter::VectorXd
Problem::VectorXd VectorXd
Definition: ipopt_adapter.h:105
Ipopt::IpoptAdapter::eval_g
virtual bool eval_g(Index n, const double *x, bool new_x, Index m, double *g)
Definition: ipopt_adapter.cc:129
Ipopt::IpoptAdapter::eval_grad_f
virtual bool eval_grad_f(Index n, const double *x, bool new_x, double *grad_f)
Definition: ipopt_adapter.cc:121
Ipopt::IpoptAdapter::intermediate_callback
virtual bool intermediate_callback(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 IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq)
Definition: ipopt_adapter.cc:174


ifopt
Author(s): Alexander W. Winkler
autogenerated on Mon Sep 18 2023 02:14:38