Ipopt Documentation  
IpTNLP.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2009 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 __IPTNLP_HPP__
8 #define __IPTNLP_HPP__
9 
10 #include "IpoptConfig.h"
11 #include "IpUtils.hpp"
12 #include "IpReferenced.hpp"
13 #include "IpException.hpp"
14 #include "IpAlgTypes.hpp"
15 #include "IpReturnCodes.hpp"
16 
17 #include <map>
18 
19 namespace Ipopt
20 {
21 // forward declarations
22 class IpoptData;
23 class IpoptCalculatedQuantities;
24 class IteratesVector;
25 
48 {
49 public:
50 
53  {
55  NON_LINEAR
56  };
57 
59  TNLP()
61  { }
62 
64  virtual ~TNLP()
65  { }
67 
68  DECLARE_STD_EXCEPTION(INVALID_TNLP);
69 
70  typedef std::map<std::string, std::vector<std::string> > StringMetaDataMapType;
71  typedef std::map<std::string, std::vector<Index> > IntegerMetaDataMapType;
72  typedef std::map<std::string, std::vector<Number> > NumericMetaDataMapType;
73 
75  {
76  C_STYLE = 0,
77  FORTRAN_STYLE = 1
78  };
79 
81 
98  // [TNLP_get_nlp_info]
99  virtual bool get_nlp_info(
100  Index& n,
101  Index& m,
102  Index& nnz_jac_g,
103  Index& nnz_h_lag,
104  IndexStyleEnum& index_style
105  ) = 0;
106  // [TNLP_get_nlp_info]
107 
125  // [TNLP_get_var_con_metadata]
126  virtual bool get_var_con_metadata(
127  Index n,
128  StringMetaDataMapType& var_string_md,
129  IntegerMetaDataMapType& var_integer_md,
130  NumericMetaDataMapType& var_numeric_md,
131  Index m,
132  StringMetaDataMapType& con_string_md,
133  IntegerMetaDataMapType& con_integer_md,
134  NumericMetaDataMapType& con_numeric_md
135  )
136  // [TNLP_get_var_con_metadata]
137  {
138  (void) n;
139  (void) var_string_md;
140  (void) var_integer_md;
141  (void) var_numeric_md;
142  (void) m;
143  (void) con_string_md;
144  (void) con_integer_md;
145  (void) con_numeric_md;
146  return false;
147  }
148 
169  // [TNLP_get_bounds_info]
170  virtual bool get_bounds_info(
171  Index n,
172  Number* x_l,
173  Number* x_u,
174  Index m,
175  Number* g_l,
176  Number* g_u
177  ) = 0;
178  // [TNLP_get_bounds_info]
179 
210  // [TNLP_get_scaling_parameters]
212  Number& obj_scaling,
213  bool& use_x_scaling,
214  Index n,
215  Number* x_scaling,
216  bool& use_g_scaling,
217  Index m,
218  Number* g_scaling
219  )
220  // [TNLP_get_scaling_parameters]
221  {
222  (void) obj_scaling;
223  (void) use_x_scaling;
224  (void) n;
225  (void) x_scaling;
226  (void) use_g_scaling;
227  (void) m;
228  (void) g_scaling;
229  return false;
230  }
231 
242  // [TNLP_get_variables_linearity]
244  Index n,
245  LinearityType* var_types
246  )
247  // [TNLP_get_variables_linearity]
248  {
249  (void) n;
250  (void) var_types;
251  return false;
252  }
253 
264  // [TNLP_get_constraints_linearity]
266  Index m,
267  LinearityType* const_types
268  )
269  // [TNLP_get_constraints_linearity]
270  {
271  (void) m;
272  (void) const_types;
273  return false;
274  }
275 
300  // [TNLP_get_starting_point]
301  virtual bool get_starting_point(
302  Index n,
303  bool init_x,
304  Number* x,
305  bool init_z,
306  Number* z_L,
307  Number* z_U,
308  Index m,
309  bool init_lambda,
310  Number* lambda
311  ) = 0;
312  // [TNLP_get_starting_point]
313 
321  // [TNLP_get_warm_start_iterate]
323  IteratesVector& warm_start_iterate
324  )
325  {
326  (void) warm_start_iterate;
327  return false;
328  }
329  // [TNLP_get_warm_start_iterate]
330 
342  // [TNLP_eval_f]
343  virtual bool eval_f(
344  Index n,
345  const Number* x,
346  bool new_x,
347  Number& obj_value
348  ) = 0;
349  // [TNLP_eval_f]
350 
362  // [TNLP_eval_grad_f]
363  virtual bool eval_grad_f(
364  Index n,
365  const Number* x,
366  bool new_x,
367  Number* grad_f
368  ) = 0;
369  // [TNLP_eval_grad_f]
370 
381  // [TNLP_eval_g]
382  virtual bool eval_g(
383  Index n,
384  const Number* x,
385  bool new_x,
386  Index m,
387  Number* g
388  ) = 0;
389  // [TNLP_eval_g]
390 
420  // [TNLP_eval_jac_g]
421  virtual bool eval_jac_g(
422  Index n,
423  const Number* x,
424  bool new_x,
425  Index m,
426  Index nele_jac,
427  Index* iRow,
428  Index* jCol,
429  Number* values
430  ) = 0;
431  // [TNLP_eval_jac_g]
432 
471  // [TNLP_eval_h]
472  virtual bool eval_h(
473  Index n,
474  const Number* x,
475  bool new_x,
476  Number obj_factor,
477  Index m,
478  const Number* lambda,
479  bool new_lambda,
480  Index nele_hess,
481  Index* iRow,
482  Index* jCol,
483  Number* values
484  )
485  // [TNLP_eval_h]
486  {
487  (void) n;
488  (void) x;
489  (void) new_x;
490  (void) obj_factor;
491  (void) m;
492  (void) lambda;
493  (void) new_lambda;
494  (void) nele_hess;
495  (void) iRow;
496  (void) jCol;
497  (void) values;
498  return false;
499  }
500 
525  // [TNLP_get_number_of_nonlinear_variables]
527  // [TNLP_get_number_of_nonlinear_variables]
528  {
529  return -1;
530  }
531 
542  // [TNLP_get_list_of_nonlinear_variables]
544  Index num_nonlin_vars,
545  Index* pos_nonlin_vars
546  )
547  // [TNLP_get_list_of_nonlinear_variables]
548  {
549  (void) num_nonlin_vars;
550  (void) pos_nonlin_vars;
551  return false;
552  }
555 
557 
587  // [TNLP_finalize_solution]
588  virtual void finalize_solution(
589  SolverReturn status,
590  Index n,
591  const Number* x,
592  const Number* z_L,
593  const Number* z_U,
594  Index m,
595  const Number* g,
596  const Number* lambda,
597  Number obj_value,
598  const IpoptData* ip_data,
600  ) = 0;
601  // [TNLP_finalize_solution]
602 
618  // [TNLP_finalize_metadata]
619  virtual void finalize_metadata(
620  Index n,
621  const StringMetaDataMapType& var_string_md,
622  const IntegerMetaDataMapType& var_integer_md,
623  const NumericMetaDataMapType& var_numeric_md,
624  Index m,
625  const StringMetaDataMapType& con_string_md,
626  const IntegerMetaDataMapType& con_integer_md,
627  const NumericMetaDataMapType& con_numeric_md
628  )
629  // [TNLP_finalize_metadata]
630  {
631  (void) n;
632  (void) var_string_md;
633  (void) var_integer_md;
634  (void) var_numeric_md;
635  (void) m;
636  (void) con_string_md;
637  (void) con_integer_md;
638  (void) con_numeric_md;
639  }
640 
664  // [TNLP_intermediate_callback]
665  virtual bool intermediate_callback(
666  AlgorithmMode mode,
667  Index iter,
668  Number obj_value,
669  Number inf_pr,
670  Number inf_du,
671  Number mu,
672  Number d_norm,
673  Number regularization_size,
674  Number alpha_du,
675  Number alpha_pr,
676  Index ls_trials,
677  const IpoptData* ip_data,
679  )
680  // [TNLP_intermediate_callback]
681  {
682  (void) mode;
683  (void) iter;
684  (void) obj_value;
685  (void) inf_pr;
686  (void) inf_du;
687  (void) mu;
688  (void) d_norm;
689  (void) regularization_size;
690  (void) alpha_du;
691  (void) alpha_pr;
692  (void) ls_trials;
693  (void) ip_data;
694  (void) ip_cq;
695  return true;
696  }
698 
700 
730  // [TNLP_get_curr_iterate]
731  bool get_curr_iterate(
732  const IpoptData* ip_data,
734  bool scaled,
735  Index n,
736  Number* x,
737  Number* z_L,
738  Number* z_U,
739  Index m,
740  Number* g,
741  Number* lambda
742  ) const;
743  // [TNLP_get_curr_iterate]
744 
778  // [TNLP_get_curr_violations]
779  bool get_curr_violations(
780  const IpoptData* ip_data,
782  bool scaled,
783  Index n,
784  Number* x_L_violation,
785  Number* x_U_violation,
786  Number* compl_x_L,
787  Number* compl_x_U,
788  Number* grad_lag_x,
789  Index m,
790  Number* nlp_constraint_violation,
791  Number* compl_g
792  ) const;
793  // [TNLP_get_curr_violations]
795 
796 private:
805 
807  TNLP(
808  const TNLP&
809  );
810 
812  void operator=(
813  const TNLP&
814  );
816 };
817 
818 } // namespace Ipopt
819 
820 #endif
std::map< std::string, std::vector< Number > > NumericMetaDataMapType
Definition: IpTNLP.hpp:72
Specialized CompoundVector class specifically for the algorithm iterates.
Class for all IPOPT specific calculated quantities.
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...
Definition: IpTNLP.hpp:472
#define IPOPTLIB_EXPORT
Definition: config.h:94
virtual bool get_variables_linearity(Index n, LinearityType *var_types)
Method to request the variables linearity.
Definition: IpTNLP.hpp:243
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.
Definition: IpTNLP.hpp:665
AlgorithmMode
enum to indicate the mode in which the algorithm is
DECLARE_STD_EXCEPTION(FATAL_ERROR_IN_LINEAR_SOLVER)
Constraint/Variable is linear.
Definition: IpTNLP.hpp:54
virtual bool get_warm_start_iterate(IteratesVector &warm_start_iterate)
Method to provide an Ipopt warm start iterate which is already in the form Ipopt requires it internal...
Definition: IpTNLP.hpp:322
virtual ~TNLP()
Default destructor.
Definition: IpTNLP.hpp:64
virtual void finalize_metadata(Index n, const StringMetaDataMapType &var_string_md, const IntegerMetaDataMapType &var_integer_md, const NumericMetaDataMapType &var_numeric_md, Index m, const StringMetaDataMapType &con_string_md, const IntegerMetaDataMapType &con_integer_md, const NumericMetaDataMapType &con_numeric_md)
This method returns any metadata collected during the run of the algorithm.
Definition: IpTNLP.hpp:619
ipindex Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:20
LinearityType
Linearity-types of variables and constraints.
Definition: IpTNLP.hpp:52
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.
Definition: IpTNLP.hpp:211
This file contains a base class for all exceptions and a set of macros to help with exceptions...
Storing the reference count of all the smart pointers that currently reference it.
virtual bool get_var_con_metadata(Index n, StringMetaDataMapType &var_string_md, IntegerMetaDataMapType &var_integer_md, NumericMetaDataMapType &var_numeric_md, Index m, StringMetaDataMapType &con_string_md, IntegerMetaDataMapType &con_integer_md, NumericMetaDataMapType &con_numeric_md)
Method to request meta data for the variables and the constraints.
Definition: IpTNLP.hpp:126
SolverReturn
enum for the return from the optimize algorithm
Definition: IpAlgTypes.hpp:19
virtual bool get_list_of_nonlinear_variables(Index num_nonlin_vars, Index *pos_nonlin_vars)
Return the indices of all nonlinear variables.
Definition: IpTNLP.hpp:543
Class to organize all the data required by the algorithm.
Definition: IpIpoptData.hpp:97
virtual Index get_number_of_nonlinear_variables()
Return the number of variables that appear nonlinearly in the objective function or in at least one c...
Definition: IpTNLP.hpp:526
ipnumber Number
Type of all numbers.
Definition: IpTypes.hpp:17
virtual bool get_constraints_linearity(Index m, LinearityType *const_types)
Method to request the constraints linearity.
Definition: IpTNLP.hpp:265
std::map< std::string, std::vector< Index > > IntegerMetaDataMapType
Definition: IpTNLP.hpp:71
std::map< std::string, std::vector< std::string > > StringMetaDataMapType
Definition: IpTNLP.hpp:70
Base class for all NLP&#39;s that use standard triplet matrix form and dense vectors. ...
Definition: IpTNLP.hpp:47