Ipopt Documentation  
IpStdInterfaceTNLP.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2010 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6 
7 #ifndef __IPSTDINTERFACETNLP_HPP__
8 #define __IPSTDINTERFACETNLP_HPP__
9 
10 #include "IpUtils.hpp"
11 #include "IpTNLP.hpp"
12 #include "IpJournalist.hpp"
13 #include "IpException.hpp"
14 #include "IpStdCInterface.h"
15 #include "IpSmartPtr.hpp"
16 
17 namespace Ipopt
18 {
20 DECLARE_STD_EXCEPTION(INVALID_STDINTERFACE_NLP);
21 
28 class StdInterfaceTNLP : public TNLP
29 {
30 public:
40  Index n_var,
41  const Number* x_L,
42  const Number* x_U,
43  Index n_con,
44  const Number* g_L,
45  const Number* g_U,
46  Index nele_jac,
47  Index nele_hess,
48  Index index_style,
49  const Number* start_x,
50  const Number* start_lam,
51  const Number* start_z_L,
52  const Number* start_z_U,
58  Intermediate_CB intermediate_cb,
59  Number* x_sol,
60  Number* z_L_sol,
61  Number* z_U_sol,
62  Number* g_sol,
63  Number* lam_sol,
64  Number* obj_sol,
65  UserDataPtr user_data,
66  Number obj_scaling = 1,
67  const Number* x_scaling = NULL,
68  const Number* g_scaling = NULL
69  );
70 
72  virtual ~StdInterfaceTNLP();
74 
80  virtual bool get_nlp_info(
81  Index& n,
82  Index& m,
83  Index& nnz_jac_g,
84  Index& nnz_h_lag,
85  IndexStyleEnum& index_style
86  );
87 
88  virtual bool get_bounds_info(
89  Index n,
90  Number* x_l,
91  Number* x_u,
92  Index m,
93  Number* g_l,
94  Number* g_u
95  );
96 
97  virtual bool get_scaling_parameters(
98  Number& obj_scaling,
99  bool& use_x_scaling,
100  Index n,
101  Number* x_scaling,
102  bool& use_g_scaling,
103  Index m,
104  Number* g_scaling
105  );
106 
107  virtual bool get_starting_point(
108  Index n,
109  bool init_x,
110  Number* x,
111  bool init_z,
112  Number* z_L,
113  Number* z_U,
114  Index m,
115  bool init_lambda,
116  Number* lambda
117  );
118 
119  virtual bool eval_f(
120  Index n,
121  const Number* x,
122  bool new_x,
123  Number& obj_value
124  );
125 
126  virtual bool eval_grad_f(
127  Index n,
128  const Number* x,
129  bool new_x,
130  Number* grad_f
131  );
132 
133  virtual bool eval_g(
134  Index n,
135  const Number* x,
136  bool new_x,
137  Index m,
138  Number* g
139  );
140 
141  virtual bool eval_jac_g(
142  Index n,
143  const Number* x,
144  bool new_x,
145  Index m,
146  Index nele_jac,
147  Index* iRow,
148  Index* jCol,
149  Number* values
150  );
151 
152  virtual bool eval_h(
153  Index n,
154  const Number* x,
155  bool new_x,
156  Number obj_factor,
157  Index m,
158  const Number* lambda,
159  bool new_lambda,
160  Index nele_hess,
161  Index* iRow,
162  Index* jCol,
163  Number* values
164  );
165 
166  virtual bool intermediate_callback(
167  AlgorithmMode mode,
168  Index iter,
169  Number obj_value,
170  Number inf_pr,
171  Number inf_du,
172  Number mu,
173  Number d_norm,
174  Number regularization_size,
175  Number alpha_du,
176  Number alpha_pr,
177  Index ls_trials,
178  const IpoptData* ip_data,
180  );
182 
185  virtual void finalize_solution(
186  SolverReturn status,
187  Index n,
188  const Number* x,
189  const Number* z_L,
190  const Number* z_U,
191  Index m,
192  const Number* g,
193  const Number* lambda,
194  Number obj_value,
195  const IpoptData* ip_data,
197  );
199 
200 private:
203 
207  const Index n_var_;
209  const Index n_con_;
211  const Number* x_L_;
213  const Number* x_U_;
215  const Number* g_L_;
217  const Number* g_U_;
225  const Number* start_x_;
253 
256 
266 
269  bool new_x,
270  Index n,
271  const Number* x
272  );
273 
284 
287  const StdInterfaceTNLP&
288  );
289 
291  void operator=(
292  const StdInterfaceTNLP&
293  );
295 
296 };
297 
298 } // namespace Ipopt
299 
300 #endif
Ipopt::StdInterfaceTNLP::start_z_U_
const Number * start_z_U_
Pointer to Number array containing starting values for upper bound multipliers.
Definition: IpStdInterfaceTNLP.hpp:231
Eval_H_CB
Bool(* Eval_H_CB)(Index n, Number *x, Bool new_x, Number obj_factor, Index m, Number *lambda, Bool new_lambda, Index nele_hess, Index *iRow, Index *jCol, Number *values, UserDataPtr user_data)
Type defining the callback function for evaluating the Hessian of the Lagrangian function.
Definition: IpStdCInterface.h:132
Ipopt::StdInterfaceTNLP::get_scaling_parameters
virtual bool get_scaling_parameters(Number &obj_scaling, bool &use_x_scaling, Index n, Number *x_scaling, bool &use_g_scaling, Index m, Number *g_scaling)
Method to request scaling parameters.
IpUtils.hpp
Ipopt::StdInterfaceTNLP::start_z_L_
const Number * start_z_L_
Pointer to Number array containing starting values for lower bound multipliers.
Definition: IpStdInterfaceTNLP.hpp:229
Ipopt::StdInterfaceTNLP::index_style_
const Index index_style_
Starting value of the iRow and jCol parameters for matrices.
Definition: IpStdInterfaceTNLP.hpp:223
Ipopt::StdInterfaceTNLP::n_var_
const Index n_var_
Number of variables.
Definition: IpStdInterfaceTNLP.hpp:207
Ipopt::StdInterfaceTNLP::non_const_x_
Number * non_const_x_
A non-const copy of x - this is kept up-to-date in apply_new_x.
Definition: IpStdInterfaceTNLP.hpp:255
Ipopt::StdInterfaceTNLP::x_scaling_
const Number * x_scaling_
Scaling factors for variables (if not NULL)
Definition: IpStdInterfaceTNLP.hpp:249
Ipopt::IpoptData
Class to organize all the data required by the algorithm.
Definition: IpIpoptData.hpp:98
Ipopt::StdInterfaceTNLP::eval_grad_f
virtual bool eval_grad_f(Index n, const Number *x, bool new_x, Number *grad_f)
Method to request the gradient of the objective function.
Ipopt::StdInterfaceTNLP::g_L_
const Number * g_L_
Pointer to Number array containing lower bounds for constraints.
Definition: IpStdInterfaceTNLP.hpp:215
IpStdCInterface.h
Eval_F_CB
Bool(* Eval_F_CB)(Index n, Number *x, Bool new_x, Number *obj_value, UserDataPtr user_data)
Type defining the callback function for evaluating the value of the objective function.
Definition: IpStdCInterface.h:71
Ipopt::StdInterfaceTNLP::n_con_
const Index n_con_
Number of constraints.
Definition: IpStdInterfaceTNLP.hpp:209
UserDataPtr
void * UserDataPtr
A pointer for anything that is to be passed between the called and individual callback function.
Definition: IpStdCInterface.h:63
Ipopt::StdInterfaceTNLP::x_L_
const Number * x_L_
Pointer to Number array containing lower bounds for variables.
Definition: IpStdInterfaceTNLP.hpp:211
Ipopt::IpoptCalculatedQuantities
Class for all IPOPT specific calculated quantities.
Definition: IpIpoptCalculatedQuantities.hpp:89
IpSmartPtr.hpp
Eval_G_CB
Bool(* Eval_G_CB)(Index n, Number *x, Bool new_x, Index m, Number *g, UserDataPtr user_data)
Type defining the callback function for evaluating the value of the constraint functions.
Definition: IpStdCInterface.h:99
Ipopt
This file contains a base class for all exceptions and a set of macros to help with exceptions.
Definition: IpInexactAlgBuilder.hpp:14
Ipopt::Number
double Number
Type of all numbers.
Definition: IpTypes.hpp:15
Ipopt::StdInterfaceTNLP::x_sol_
Number * x_sol_
Definition: IpStdInterfaceTNLP.hpp:259
Ipopt::StdInterfaceTNLP::z_L_sol_
Number * z_L_sol_
Definition: IpStdInterfaceTNLP.hpp:260
IpJournalist.hpp
Ipopt::StdInterfaceTNLP::start_x_
const Number * start_x_
Pointer to Number array containing starting point for variables.
Definition: IpStdInterfaceTNLP.hpp:225
Ipopt::StdInterfaceTNLP::StdInterfaceTNLP
StdInterfaceTNLP(Index n_var, const Number *x_L, const Number *x_U, Index n_con, const Number *g_L, const Number *g_U, Index nele_jac, Index nele_hess, Index index_style, const Number *start_x, const Number *start_lam, const Number *start_z_L, const Number *start_z_U, Eval_F_CB eval_f, Eval_G_CB eval_g, Eval_Grad_F_CB eval_grad_f, Eval_Jac_G_CB eval_jac_g, Eval_H_CB eval_h, Intermediate_CB intermediate_cb, Number *x_sol, Number *z_L_sol, Number *z_U_sol, Number *g_sol, Number *lam_sol, Number *obj_sol, UserDataPtr user_data, Number obj_scaling=1, const Number *x_scaling=NULL, const Number *g_scaling=NULL)
Constructor, given dimensions of problem, function pointers for evaluation callback functions,...
Ipopt::StdInterfaceTNLP::obj_sol_
Number * obj_sol_
Definition: IpStdInterfaceTNLP.hpp:264
Ipopt::StdInterfaceTNLP::nele_hess_
const Index nele_hess_
Number of non-zero elements in the Hessian.
Definition: IpStdInterfaceTNLP.hpp:221
Ipopt::StdInterfaceTNLP::g_scaling_
const Number * g_scaling_
Scaling factors for constraints (if not NULL)
Definition: IpStdInterfaceTNLP.hpp:251
Ipopt::StdInterfaceTNLP::z_U_sol_
Number * z_U_sol_
Definition: IpStdInterfaceTNLP.hpp:261
Ipopt::StdInterfaceTNLP::eval_f_
Eval_F_CB eval_f_
Pointer to callback function evaluating value of objective function.
Definition: IpStdInterfaceTNLP.hpp:233
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
Ipopt::StdInterfaceTNLP::jnlst_
SmartPtr< const Journalist > jnlst_
Journalist.
Definition: IpStdInterfaceTNLP.hpp:202
Eval_Jac_G_CB
Bool(* Eval_Jac_G_CB)(Index n, Number *x, Bool new_x, Index m, Index nele_jac, Index *iRow, Index *jCol, Number *values, UserDataPtr user_data)
Type defining the callback function for evaluating the Jacobian of the constrant functions.
Definition: IpStdCInterface.h:114
Ipopt::StdInterfaceTNLP::eval_f
virtual bool eval_f(Index n, const Number *x, bool new_x, Number &obj_value)
Method to request the value of the objective function.
Ipopt::StdInterfaceTNLP::get_starting_point
virtual bool get_starting_point(Index n, bool init_x, Number *x, bool init_z, Number *z_L, Number *z_U, Index m, bool init_lambda, Number *lambda)
Method to request the starting point before iterating.
Ipopt::StdInterfaceTNLP::eval_g
virtual bool eval_g(Index n, const Number *x, bool new_x, Index m, Number *g)
Method to request the constraint values.
IpTNLP.hpp
Ipopt::SmartPtr
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
Ipopt::StdInterfaceTNLP::obj_scaling_
Number obj_scaling_
Objective scaling factor.
Definition: IpStdInterfaceTNLP.hpp:247
Intermediate_CB
Bool(* Intermediate_CB)(Index alg_mod, Index iter_count, Number obj_value, Number inf_pr, Number inf_du, Number mu, Number d_norm, Number regularization_size, Number alpha_du, Number alpha_pr, Index ls_trials, UserDataPtr user_data)
Type defining the callback function for giving intermediate execution control to the user.
Definition: IpStdCInterface.h:157
Ipopt::StdInterfaceTNLP::StdInterfaceTNLP
StdInterfaceTNLP(const StdInterfaceTNLP &)
Copy Constructor.
Ipopt::StdInterfaceTNLP::g_U_
const Number * g_U_
Pointer to Number array containing upper bounds for constraints.
Definition: IpStdInterfaceTNLP.hpp:217
Ipopt::StdInterfaceTNLP::lambda_sol_
Number * lambda_sol_
Definition: IpStdInterfaceTNLP.hpp:263
Ipopt::StdInterfaceTNLP::StdInterfaceTNLP
StdInterfaceTNLP()
Default Constructor.
Ipopt::StdInterfaceTNLP::nele_jac_
const Index nele_jac_
Number of non-zero elements in the constraint Jacobian.
Definition: IpStdInterfaceTNLP.hpp:219
Ipopt::StdInterfaceTNLP::start_lam_
const Number * start_lam_
Pointer to Number array containing starting values for constraint multipliers.
Definition: IpStdInterfaceTNLP.hpp:227
Ipopt::StdInterfaceTNLP::eval_grad_f_
Eval_Grad_F_CB eval_grad_f_
Pointer to callback function evaluating gradient of objective function.
Definition: IpStdInterfaceTNLP.hpp:237
Ipopt::StdInterfaceTNLP::intermediate_cb_
Intermediate_CB intermediate_cb_
Pointer to intermediate callback function giving control to user.
Definition: IpStdInterfaceTNLP.hpp:243
Ipopt::TNLP
Base class for all NLP's that use standard triplet matrix form and dense vectors.
Definition: IpTNLP.hpp:48
Ipopt::StdInterfaceTNLP::user_data_
UserDataPtr user_data_
Pointer to user data.
Definition: IpStdInterfaceTNLP.hpp:245
Ipopt::StdInterfaceTNLP::x_U_
const Number * x_U_
Pointer to Number array containing upper bounds for variables.
Definition: IpStdInterfaceTNLP.hpp:213
Eval_Grad_F_CB
Bool(* Eval_Grad_F_CB)(Index n, Number *x, Bool new_x, Number *grad_f, UserDataPtr user_data)
Type defining the callback function for evaluating the gradient of the objective function.
Definition: IpStdCInterface.h:85
Ipopt::TNLP::IndexStyleEnum
IndexStyleEnum
Definition: IpTNLP.hpp:74
Ipopt::StdInterfaceTNLP
Implementation of a TNLP for the Standard C interface.
Definition: IpStdInterfaceTNLP.hpp:29
Ipopt::StdInterfaceTNLP::eval_h_
Eval_H_CB eval_h_
Pointer to callback function evaluating Hessian of Lagrangian.
Definition: IpStdInterfaceTNLP.hpp:241
Ipopt::StdInterfaceTNLP::operator=
void operator=(const StdInterfaceTNLP &)
Default Assignment Operator.
Ipopt::StdInterfaceTNLP::eval_h
virtual bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor, Index m, const Number *lambda, bool new_lambda, Index nele_hess, Index *iRow, Index *jCol, Number *values)
Method to request either the sparsity structure or the values of the Hessian of the Lagrangian.
Ipopt::StdInterfaceTNLP::get_bounds_info
virtual bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m, Number *g_l, Number *g_u)
Method to request bounds on the variables and constraints.
Ipopt::StdInterfaceTNLP::~StdInterfaceTNLP
virtual ~StdInterfaceTNLP()
Default destructor.
IpException.hpp
Ipopt::DECLARE_STD_EXCEPTION
DECLARE_STD_EXCEPTION(FATAL_ERROR_IN_LINEAR_SOLVER)
Ipopt::SolverReturn
SolverReturn
enum for the return from the optimize algorithm
Definition: IpAlgTypes.hpp:20
Ipopt::StdInterfaceTNLP::g_sol_
Number * g_sol_
Definition: IpStdInterfaceTNLP.hpp:262
Ipopt::StdInterfaceTNLP::get_nlp_info
virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag, IndexStyleEnum &index_style)
Method to request the initial information about the problem.
Ipopt::StdInterfaceTNLP::intermediate_callback
virtual bool intermediate_callback(AlgorithmMode mode, Index iter, Number obj_value, Number inf_pr, Number inf_du, Number mu, Number d_norm, Number regularization_size, Number alpha_du, Number alpha_pr, Index ls_trials, const IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq)
Intermediate Callback method for the user.
Ipopt::StdInterfaceTNLP::apply_new_x
void apply_new_x(bool new_x, Index n, const Number *x)
Update the internal state if the x value changes.
Ipopt::StdInterfaceTNLP::eval_g_
Eval_G_CB eval_g_
Pointer to callback function evaluating value of constraints.
Definition: IpStdInterfaceTNLP.hpp:235
AlgorithmMode
AlgorithmMode
enum to indicate the mode in which the algorithm is
Definition: IpReturnCodes_inc.h:41
Ipopt::StdInterfaceTNLP::eval_jac_g
virtual bool eval_jac_g(Index n, const Number *x, bool new_x, Index m, Index nele_jac, Index *iRow, Index *jCol, Number *values)
Method to request either the sparsity structure or the values of the Jacobian of the constraints.
Ipopt::StdInterfaceTNLP::eval_jac_g_
Eval_Jac_G_CB eval_jac_g_
Pointer to callback function evaluating Jacobian of constraints.
Definition: IpStdInterfaceTNLP.hpp:239
Ipopt::StdInterfaceTNLP::finalize_solution
virtual void finalize_solution(SolverReturn status, Index n, const Number *x, const Number *z_L, const Number *z_U, Index m, const Number *g, const Number *lambda, Number obj_value, const IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq)
This method is called when the algorithm has finished (successfully or not) so the TNLP can digest th...