Ipopt Documentation  
IpTNLPAdapter.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2008 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 __IPTNLPADAPTER_HPP__
8 #define __IPTNLPADAPTER_HPP__
9 
10 #include "IpNLP.hpp"
11 #include "IpTNLP.hpp"
12 #include "IpOrigIpoptNLP.hpp"
13 #include <list>
14 
15 namespace Ipopt
16 {
17 
18 // forward declarations
19 class ExpansionMatrix;
20 class ExpansionMatrixSpace;
21 class IteratesVector;
22 class TDependencyDetector;
23 
30 {
31 public:
33 
36  const SmartPtr<TNLP> tnlp,
37  const SmartPtr<const Journalist> jnlst = NULL
38  );
39 
41  virtual ~TNLPAdapter();
43 
45  DECLARE_STD_EXCEPTION(INVALID_TNLP);
47  DECLARE_STD_EXCEPTION(ERROR_IN_TNLP_DERIVATIVE_TEST);
49 
51  virtual bool ProcessOptions(
53  const OptionsList& options,
54  const std::string& prefix
55  );
56 
61  virtual bool GetSpaces(
65  SmartPtr<const VectorSpace>& x_l_space,
66  SmartPtr<const MatrixSpace>& px_l_space,
67  SmartPtr<const VectorSpace>& x_u_space,
68  SmartPtr<const MatrixSpace>& px_u_space,
69  SmartPtr<const VectorSpace>& d_l_space,
70  SmartPtr<const MatrixSpace>& pd_l_space,
71  SmartPtr<const VectorSpace>& d_u_space,
72  SmartPtr<const MatrixSpace>& pd_u_space,
73  SmartPtr<const MatrixSpace>& Jac_c_space,
74  SmartPtr<const MatrixSpace>& Jac_d_space,
75  SmartPtr<const SymMatrixSpace>& Hess_lagrangian_space
76  );
77 
79  virtual bool GetBoundsInformation(
80  const Matrix& Px_L,
81  Vector& x_L,
82  const Matrix& Px_U,
83  Vector& x_U,
84  const Matrix& Pd_L,
85  Vector& d_L,
86  const Matrix& Pd_U,
87  Vector& d_U
88  );
89 
91  virtual bool GetStartingPoint(
93  bool need_x,
94  SmartPtr<Vector> y_c,
95  bool need_y_c,
96  SmartPtr<Vector> y_d,
97  bool need_y_d,
98  SmartPtr<Vector> z_L,
99  bool need_z_L,
100  SmartPtr<Vector> z_U,
101  bool need_z_U
102  );
103 
108  virtual bool GetWarmStartIterate(
109  IteratesVector& warm_start_iterate
110  );
112 
114  virtual bool Eval_f(
116  const Vector& x,
117  Number& f
118  );
119 
120  virtual bool Eval_grad_f(
121  const Vector& x,
122  Vector& g_f
123  );
124 
125  virtual bool Eval_c(
126  const Vector& x,
127  Vector& c
128  );
129 
130  virtual bool Eval_jac_c(
131  const Vector& x,
132  Matrix& jac_c
133  );
134 
135  virtual bool Eval_d(
136  const Vector& x,
137  Vector& d
138  );
139 
140  virtual bool Eval_jac_d(
141  const Vector& x,
142  Matrix& jac_d
143  );
144 
145  virtual bool Eval_h(
146  const Vector& x,
147  Number obj_factor,
148  const Vector& yc,
149  const Vector& yd,
150  SymMatrix& h
151  );
152 
153  virtual void GetScalingParameters(
154  const SmartPtr<const VectorSpace> x_space,
155  const SmartPtr<const VectorSpace> c_space,
156  const SmartPtr<const VectorSpace> d_space,
157  Number& obj_scaling,
158  SmartPtr<Vector>& x_scaling,
159  SmartPtr<Vector>& c_scaling,
160  SmartPtr<Vector>& d_scaling
161  ) const;
163 
165  virtual void FinalizeSolution(
167  SolverReturn status,
168  const Vector& x,
169  const Vector& z_L,
170  const Vector& z_U,
171  const Vector& c,
172  const Vector& d,
173  const Vector& y_c,
174  const Vector& y_d,
175  Number obj_value,
176  const IpoptData* ip_data,
178  );
179 
180  virtual bool IntermediateCallBack(
181  AlgorithmMode mode,
182  Index iter,
183  Number obj_value,
184  Number inf_pr,
185  Number inf_du,
186  Number mu,
187  Number d_norm,
188  Number regularization_size,
189  Number alpha_du,
190  Number alpha_pr,
191  Index ls_trials,
192  const IpoptData* ip_data,
194  );
196 
198  virtual void GetQuasiNewtonApproximationSpaces(
199  SmartPtr<VectorSpace>& approx_space,
200  SmartPtr<Matrix>& P_approx
201  );
202 
205  {
206  MAKE_PARAMETER = 0,
208  RELAX_BOUNDS
209  };
210 
213  {
214  NO_TEST = 0,
217  ONLY_SECOND_ORDER_TEST
218  };
219 
222  {
223  JAC_EXACT = 0,
224  JAC_FINDIFF_VALUES
225  };
226 
228  bool CheckDerivatives(
229  DerivativeTestEnum deriv_test,
230  Index deriv_test_start_index
231  );
232 
233  static void RegisterOptions(
235  );
236 
239  {
240  return tnlp_;
241  }
242 
248 
250  void ResortX(
251  const Vector& x,
252  Number* x_orig
253  );
254 
255  void ResortG(
256  const Vector& c,
257  const Vector& d,
258  Number* g_orig
259  );
260 
265  void ResortBnds(
266  const Vector& x_L,
267  Number* x_L_orig,
268  const Vector& x_U,
269  Number* x_U_orig,
270  bool clearorig = true
271  );
273 
274 private:
284 
286  TNLPAdapter(
287  const TNLPAdapter&
288  );
289 
291  void operator=(
292  const TNLPAdapter&
293  );
295 
297  bool DetermineDependentConstraints(
298  Index n_x_var,
299  const Index* x_not_fixed_map,
300  const Number* x_l,
301  const Number* x_u,
302  const Number* g_l,
303  const Number* g_u,
304  Index n_c,
305  const Index* c_map,
306  std::list<Index>& c_deps);
307 
310 
313 
316 
318 
331  /* Took this out: Number max_onesided_bound_slack_; */
356 
360 
362 
382 
385 
403 
405  Number* full_x_;
411 
414  TaggedObject::Tag x_tag_for_iterates_;
421 
423  bool update_local_x(const Vector& x);
425  bool update_local_lambda(const Vector& y_c, const Vector& y_d);
427 
432  bool internal_eval_g(bool new_x);
434  bool internal_eval_jac_g(bool new_x);
436 
438 
440  void initialize_findiff_jac(const Index* iRow, const Index* jCol);
442 
445 
449 
453 
457 
461 
465 
468 
472 
474 
488 };
489 
490 } // namespace Ipopt
491 
492 #endif
Number nlp_upper_bound_inf_
Value for a upper bound that denotes infinity.
Number tol_
Overall convergence tolerance.
Index n_x_fixed_
Number of fixed variables.
Index derivative_test_first_index_
Index of first quantity to be checked.
This class adapts the TNLP interface so it looks like an NLP interface.
Index findiff_jac_nnz_
Number of unique nonzeros in constraint Jacobian.
Number findiff_perturbation_
Size of the perturbation for the derivative approximation.
Number * c_rhs_
the values for the full jacobian of g
TaggedObject::Tag x_tag_for_jac_g_
Specialized CompoundVector class specifically for the algorithm iterates.
Class for all IPOPT specific calculated quantities.
FixedVariableTreatmentEnum
Enum for treatment of fixed variables option.
Number bound_relax_factor_
Determines relaxation of fixing bound for RELAX_BOUNDS.
JacobianApproxEnum
Enum for specifying technique for computing Jacobian.
TNLP::IndexStyleEnum index_style_
Numbering style of variables and constraints.
JacobianApproxEnum jacobian_approximation_
Flag indicating how Jacobian is computed.
DerivativeTestEnum derivative_test_
Maximal slack for one-sidedly bounded variables.
SmartPtr< const MatrixSpace > pd_u_space_
Number * jac_g_
copy of g (c & d)
Index * x_fixed_map_
Position of fixed variables.
AlgorithmMode
enum to indicate the mode in which the algorithm is
DECLARE_STD_EXCEPTION(FATAL_ERROR_IN_LINEAR_SOLVER)
SmartPtr< ExpansionMatrix > P_d_g_
double Number
Type of all numbers.
Definition: IpTypes.hpp:15
FixedVariableTreatmentEnum fixed_variable_treatment_
Flag indicating how fixed variables should be handled.
Vector Base Class.
Definition: IpVector.hpp:47
SmartPtr< TDependencyDetector > dependency_detector_
Object that can be used to detect linearly dependent rows in the equality constraint Jacobian...
SmartPtr< const MatrixSpace > Jac_d_space_
SmartPtr< ExpansionMatrix > P_x_x_U_
Expansion from fixed x_U (ipopt) to full x.
Index * findiff_jac_ia_
Start position for nonzero indices in ja for each column of Jacobian.
Index * findiff_jac_ja_
Ordered by columns, for each column the row indices in Jacobian.
SmartPtr< const VectorSpace > x_l_space_
Index n_full_x_
full dimension of x (fixed + non-fixed)
bool warm_start_same_structure_
Flag indicating whether the TNLP with identical structure has already been solved before...
This file contains a base class for all exceptions and a set of macros to help with exceptions...
SmartPtr< ExpansionMatrix > P_x_x_L_
Expansion from fixed x_L (ipopt) to full x.
SmartPtr< const MatrixSpace > pd_l_space_
TaggedObject::Tag y_d_tag_for_iterates_
This is the base class for all derived symmetric matrix types.
Definition: IpSymMatrix.hpp:20
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:171
TaggedObject::Tag x_tag_for_g_
Number derivative_test_tol_
Relative threshold for marking deviation from finite difference test.
This class stores a list of user set options.
SmartPtr< ExpansionMatrixSpace > P_d_g_space_
Expansion from d only (ipopt) to full ampl d.
bool derivative_test_print_all_
Flag indicating if all test values should be printed, or only those violating the threshold...
SolverReturn
enum for the return from the optimize algorithm
Definition: IpAlgTypes.hpp:19
Number * findiff_x_l_
Copy of the lower bounds.
TaggedObject::Tag y_c_tag_for_iterates_
SmartPtr< const Journalist > jnlst_
Journalist.
Matrix Base Class.
Definition: IpMatrix.hpp:27
Index nz_jac_c_
non-zeros of the jacobian of c
HessianApproximationType
enumeration for the Hessian information type.
Index * findiff_jac_postriplet_
Position of entry in original triplet matrix.
Index n_full_g_
full dimension of g (c + d)
Class to organize all the data required by the algorithm.
Definition: IpIpoptData.hpp:97
Index nz_jac_d_
non-zeros of the jacobian of d
DerivativeTestEnum
Enum for specifying which derivative test is to be performed.
Index num_linear_variables_
Number of linear variables.
SmartPtr< const MatrixSpace > px_u_space_
SmartPtr< ExpansionMatrixSpace > P_x_full_x_space_
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
SmartPtr< ExpansionMatrixSpace > P_x_x_U_space_
SmartPtr< ExpansionMatrix > P_c_g_
Number nlp_lower_bound_inf_
Value for a lower bound that denotes -infinity.
unsigned int Tag
Type for the Tag values.
SmartPtr< const VectorSpace > c_space_
SmartPtr< TNLP > tnlp_
Pointer to the TNLP class (class specific to Number* vectors and triplet matrices) ...
#define IPOPTLIB_EXPORT
HessianApproximationType hessian_approximation_
Flag indicating what Hessian information is to be used.
Index nz_jac_c_no_extra_
non-zeros of the jacobian of c without added constraints for fixed variables.
SmartPtr< ExpansionMatrixSpace > P_c_g_space_
Expansion from c only (ipopt) to full ampl c.
bool dependency_detection_with_rhs_
Flag indicating if rhs should be considered during dependency detection.
SmartPtr< const VectorSpace > d_l_space_
SmartPtr< const VectorSpace > d_u_space_
Index nz_full_jac_g_
number of non-zeros in full-size Jacobian of g
Number derivative_test_perturbation_
Size of the perturbation for the derivative test.
SmartPtr< ExpansionMatrix > P_x_full_x_
Expansion from fixed x (ipopt) to full x.
SmartPtr< TNLP > tnlp() const
Accessor method for the underlying TNLP.
SmartPtr< const SymMatrixSpace > Hess_lagrangian_space_
SmartPtr< ExpansionMatrixSpace > P_x_x_L_space_
SmartPtr< const MatrixSpace > Jac_c_space_
Number * full_lambda_
copy of the full x vector (fixed & non-fixed)
Index nz_h_
number of non-zeros in the non-fixed-size Hessian
Number * findiff_x_u_
Copy of the upper bounds.
SmartPtr< const VectorSpace > d_space_
Number point_perturbation_radius_
Maximal perturbation of the initial point.
Index nz_full_h_
number of non-zeros in full-size Hessian
Number * full_g_
copy of lambda (yc & yd)
SmartPtr< const VectorSpace > x_u_space_
SmartPtr< const MatrixSpace > px_l_space_