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 "IpExpansionMatrix.hpp"
14 #include <list>
15 
16 namespace Ipopt
17 {
18 
19 // forward declarations
20 class ExpansionMatrixSpace;
21 class IteratesVector;
22 class TDependencyDetector;
23 
66 {
67 public:
69 
72  const SmartPtr<TNLP> tnlp,
73  const SmartPtr<const Journalist> jnlst = NULL
74  );
75 
77  virtual ~TNLPAdapter();
79 
81  DECLARE_STD_EXCEPTION(INVALID_TNLP);
83  DECLARE_STD_EXCEPTION(ERROR_IN_TNLP_DERIVATIVE_TEST);
85 
87  virtual bool ProcessOptions(
89  const OptionsList& options,
90  const std::string& prefix
91  );
92 
97  virtual bool GetSpaces(
101  SmartPtr<const VectorSpace>& x_l_space,
102  SmartPtr<const MatrixSpace>& px_l_space,
103  SmartPtr<const VectorSpace>& x_u_space,
104  SmartPtr<const MatrixSpace>& px_u_space,
105  SmartPtr<const VectorSpace>& d_l_space,
106  SmartPtr<const MatrixSpace>& pd_l_space,
107  SmartPtr<const VectorSpace>& d_u_space,
108  SmartPtr<const MatrixSpace>& pd_u_space,
109  SmartPtr<const MatrixSpace>& Jac_c_space,
110  SmartPtr<const MatrixSpace>& Jac_d_space,
111  SmartPtr<const SymMatrixSpace>& Hess_lagrangian_space
112  );
113 
115  virtual bool GetBoundsInformation(
116  const Matrix& Px_L,
117  Vector& x_L,
118  const Matrix& Px_U,
119  Vector& x_U,
120  const Matrix& Pd_L,
121  Vector& d_L,
122  const Matrix& Pd_U,
123  Vector& d_U
124  );
125 
127  virtual bool GetStartingPoint(
129  bool need_x,
130  SmartPtr<Vector> y_c,
131  bool need_y_c,
132  SmartPtr<Vector> y_d,
133  bool need_y_d,
134  SmartPtr<Vector> z_L,
135  bool need_z_L,
136  SmartPtr<Vector> z_U,
137  bool need_z_U
138  );
139 
144  virtual bool GetWarmStartIterate(
145  IteratesVector& warm_start_iterate
146  );
148 
150  virtual bool Eval_f(
152  const Vector& x,
153  Number& f
154  );
155 
156  virtual bool Eval_grad_f(
157  const Vector& x,
158  Vector& g_f
159  );
160 
161  virtual bool Eval_c(
162  const Vector& x,
163  Vector& c
164  );
165 
166  virtual bool Eval_jac_c(
167  const Vector& x,
168  Matrix& jac_c
169  );
170 
171  virtual bool Eval_d(
172  const Vector& x,
173  Vector& d
174  );
175 
176  virtual bool Eval_jac_d(
177  const Vector& x,
178  Matrix& jac_d
179  );
180 
181  virtual bool Eval_h(
182  const Vector& x,
183  Number obj_factor,
184  const Vector& yc,
185  const Vector& yd,
186  SymMatrix& h
187  );
188 
189  virtual void GetScalingParameters(
190  const SmartPtr<const VectorSpace> x_space,
191  const SmartPtr<const VectorSpace> c_space,
192  const SmartPtr<const VectorSpace> d_space,
193  Number& obj_scaling,
194  SmartPtr<Vector>& x_scaling,
195  SmartPtr<Vector>& c_scaling,
196  SmartPtr<Vector>& d_scaling
197  ) const;
199 
201  virtual void FinalizeSolution(
203  SolverReturn status,
204  const Vector& x,
205  const Vector& z_L,
206  const Vector& z_U,
207  const Vector& c,
208  const Vector& d,
209  const Vector& y_c,
210  const Vector& y_d,
211  Number obj_value,
212  const IpoptData* ip_data,
214  );
215 
216  virtual bool IntermediateCallBack(
217  AlgorithmMode mode,
218  Index iter,
219  Number obj_value,
220  Number inf_pr,
221  Number inf_du,
222  Number mu,
223  Number d_norm,
224  Number regularization_size,
225  Number alpha_du,
226  Number alpha_pr,
227  Index ls_trials,
228  const IpoptData* ip_data,
230  );
232 
234  virtual void GetQuasiNewtonApproximationSpaces(
235  SmartPtr<VectorSpace>& approx_space,
236  SmartPtr<Matrix>& P_approx
237  );
238 
241  {
242  MAKE_PARAMETER = 0,
245  RELAX_BOUNDS
246  };
247 
250  {
251  NO_TEST = 0,
254  ONLY_SECOND_ORDER_TEST
255  };
256 
259  {
260  JAC_EXACT = 0,
261  JAC_FINDIFF_VALUES
262  };
263 
266  {
267  OBJGRAD_EXACT = 0,
268  OBJGRAD_FINDIFF_VALUES
269  };
270 
272  bool CheckDerivatives(
273  DerivativeTestEnum deriv_test,
274  Index deriv_test_start_index
275  );
276 
277  static void RegisterOptions(
279  );
280 
283  {
284  return tnlp_;
285  }
286 
292 
294  void ResortX(
295  const Vector& x,
296  Number* x_orig,
297  bool usefixedvals = true
298  );
299 
305  void ResortG(
306  const Vector& c,
307  const Vector& d,
308  Number* g_orig,
309  bool correctrhs = false
310  );
311 
317  void ResortBounds(
318  const Vector& x_L,
319  Number* x_L_orig,
320  const Vector& x_U,
321  Number* x_U_orig
322  );
323 
332  const Vector& x_L,
333  Number* x_L_orig,
334  const Vector& x_U,
335  Number* x_U_orig,
336  bool clearorig = true
337  )
338  {
339  ResortBounds(x_L, x_L_orig, x_U, x_U_orig);
340  (void) clearorig;
341  }
342 
355  bool ResortBoundMultipliers(
356  const Vector& x,
357  const Vector& y_c,
358  const Vector& y_d,
359  const Vector& z_L,
360  Number* z_L_orig,
361  const Vector& z_U,
362  Number* z_U_orig
363  );
364 
369  Index& n,
370  Index& m
371  ) const
372  {
373  n = n_full_x_;
374  m = n_full_g_;
375  }
376 
381  Index& n_x_fixed,
382  Index*& x_fixed_map,
383  FixedVariableTreatmentEnum& fixed_variable_treatment
384  ) const
385  {
386  n_x_fixed = n_x_fixed_;
387  x_fixed_map = x_fixed_map_;
388  fixed_variable_treatment = fixed_variable_treatment_;
389  }
390 
399  SmartPtr<const ExpansionMatrix>& P_x_full_x,
404  ) const
405  {
406  P_x_full_x = ConstPtr(P_x_full_x_);
407  P_x_x_L = ConstPtr(P_x_x_L_);
408  P_x_x_U = ConstPtr(P_x_x_U_);
409  P_c_g = ConstPtr(P_c_g_);
410  P_d_g = ConstPtr(P_d_g_);
411  }
412 
416  const Number* GetC_Rhs() const
417  {
418  return c_rhs_;
419  }
420 
422 
423 private:
433 
435  TNLPAdapter(
436  const TNLPAdapter&
437  );
438 
440  void operator=(
441  const TNLPAdapter&
442  );
444 
446  bool DetermineDependentConstraints(
447  Index n_x_var,
448  const Index* x_not_fixed_map,
449  const Number* x_l,
450  const Number* x_u,
451  const Number* g_l,
452  const Number* g_u,
453  Index n_c,
454  const Index* c_map,
455  std::list<Index>& c_deps);
456 
459 
462 
465 
467 
480  /* Took this out: Number max_onesided_bound_slack_; */
507 
511 
513 
533 
536 
554 
556  Number* full_x_;
562 
565  TaggedObject::Tag x_tag_for_iterates_;
572 
574  bool update_local_x(const Vector& x);
576  bool update_local_lambda(const Vector& y_c, const Vector& y_d);
578 
583  bool internal_eval_g(bool new_x);
585  bool internal_eval_jac_g(bool new_x);
587 
589 
591  void initialize_findiff_jac(const Index* iRow, const Index* jCol);
593 
596 
600 
604 
608 
612 
616 
619 
622 
624  std::vector<Index> jac_fixed_idx_map_;
625  std::vector<Index> jac_fixed_iRow_;
626  std::vector<Index> jac_fixed_jCol_;
628 
630 
644 };
645 
646 } // namespace Ipopt
647 
648 #endif
Number nlp_upper_bound_inf_
Value for a upper bound that denotes infinity.
Number tol_
Overall convergence tolerance.
IPOPT_DEPRECATED void ResortBnds(const Vector &x_L, Number *x_L_orig, const Vector &x_U, Number *x_U_orig, bool clearorig=true)
Provides values for lower and upper bounds on variables for given Ipopt-internal vectors.
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.
std::vector< Index > jac_fixed_idx_map_
Index mapping of Jacobian w.r.t.
std::vector< Index > jac_fixed_iRow_
#define IPOPTLIB_EXPORT
Definition: config.h:94
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_
void GetPermutationMatrices(SmartPtr< const ExpansionMatrix > &P_x_full_x, SmartPtr< const ExpansionMatrix > &P_x_x_L, SmartPtr< const ExpansionMatrix > &P_x_x_U, SmartPtr< const ExpansionMatrix > &P_c_g, SmartPtr< const ExpansionMatrix > &P_d_g) const
Get mappings between TNLP indices and Ipopt internal indices for variables and constraints.
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_
const Number * GetC_Rhs() const
Get right-hand-sides that are added into c(x)
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.
void GetFixedVariables(Index &n_x_fixed, Index *&x_fixed_map, FixedVariableTreatmentEnum &fixed_variable_treatment) const
Get number and indices of fixed variables.
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)
ipindex Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:20
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:164
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.
ipnumber Number
Type of all numbers.
Definition: IpTypes.hpp:17
Index num_linear_variables_
Number of linear variables.
SmartPtr< const MatrixSpace > px_u_space_
SmartPtr< ExpansionMatrixSpace > P_x_full_x_space_
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.
GradientApproxEnum gradient_approximation_
Flag indicating how objective Gradient is computed.
void GetFullDimensions(Index &n, Index &m) const
Get number of variables and number of constraints in TNLP.
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) ...
SmartPtr< const U > ConstPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:663
Traditional NLP.
Definition: IpNLP.hpp:41
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_
GradientApproxEnum
Enum for specifying technique for computing objective Gradient.
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)
#define IPOPT_DEPRECATED
macro to declare symbols as deprecated
Definition: IpTypes.h:25
std::vector< Index > jac_fixed_jCol_
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_