IpTNLPReducer.hpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // Copyright (C) 2008 International Business Machines and others.
  2. // All Rights Reserved.
  3. // This code is published under the Eclipse Public License.
  4. //
  5. // $Id: IpTNLPReducer.hpp 1861 2010-12-21 21:34:47Z andreasw $
  6. //
  7. // Authors: Andreas Waechter IBM 2008-08-10
  8. #ifndef __IPTNLPREDUCER_HPP__
  9. #define __IPTNLPREDUCER_HPP__
  10. #include "IpTNLP.hpp"
  11. namespace Ipopt
  12. {
  13. /** This is a wrapper around a given TNLP class that takes out a
  14. * list of constraints that are given to the constructor. It is
  15. * provided for convenience, if one wants to experiment with
  16. * problems that consist of only a subset of the constraints. But
  17. * keep in mind that this is not efficient, since behind the scenes
  18. * we are still evaluation all functions and derivatives, and are
  19. * making copies of the original data. */
  20. class TNLPReducer : public TNLP
  21. {
  22. public:
  23. /**@name Constructors/Destructors */
  24. //@{
  25. /** Constructor is given the indices of the constraints that
  26. * should be taken out of the problem statement, as well as the
  27. * original TNLP. */
  28. TNLPReducer(TNLP& tnlp, Index n_g_skip, const Index* index_g_skip,
  29. Index n_xL_skip, const Index* index_xL_skip,
  30. Index n_xU_skip, const Index* index_xU_skip,
  31. Index n_x_fix, const Index* index_f_fix);
  32. /** Default destructor */
  33. virtual ~TNLPReducer();
  34. //@}
  35. /** @name Overloaded methods from TNLP */
  36. virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
  37. Index& nnz_h_lag, IndexStyleEnum& index_style);
  38. virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
  39. Index m, Number* g_l, Number* g_u);
  40. virtual bool get_scaling_parameters(Number& obj_scaling,
  41. bool& use_x_scaling, Index n,
  42. Number* x_scaling,
  43. bool& use_g_scaling, Index m,
  44. Number* g_scaling);
  45. virtual bool get_variables_linearity(Index n, LinearityType* var_types);
  46. virtual bool get_constraints_linearity(Index m, LinearityType* const_types);
  47. virtual bool get_starting_point(Index n, bool init_x, Number* x,
  48. bool init_z, Number* z_L, Number* z_U,
  49. Index m, bool init_lambda,
  50. Number* lambda);
  51. virtual bool get_warm_start_iterate(IteratesVector& warm_start_iterate);
  52. virtual bool eval_f(Index n, const Number* x, bool new_x,
  53. Number& obj_value);
  54. virtual bool eval_grad_f(Index n, const Number* x, bool new_x,
  55. Number* grad_f);
  56. virtual bool eval_g(Index n, const Number* x, bool new_x,
  57. Index m, Number* g);
  58. virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
  59. Index m, Index nele_jac, Index* iRow,
  60. Index *jCol, Number* values);
  61. virtual bool eval_h(Index n, const Number* x, bool new_x,
  62. Number obj_factor, Index m, const Number* lambda,
  63. bool new_lambda, Index nele_hess,
  64. Index* iRow, Index* jCol, Number* values);
  65. virtual void finalize_solution(SolverReturn status,
  66. Index n, const Number* x, const Number* z_L, const Number* z_U,
  67. Index m, const Number* g, const Number* lambda,
  68. Number obj_value,
  69. const IpoptData* ip_data,
  70. IpoptCalculatedQuantities* ip_cq);
  71. virtual bool intermediate_callback(AlgorithmMode mode,
  72. Index iter, Number obj_value,
  73. Number inf_pr, Number inf_du,
  74. Number mu, Number d_norm,
  75. Number regularization_size,
  76. Number alpha_du, Number alpha_pr,
  77. Index ls_trials,
  78. const IpoptData* ip_data,
  79. IpoptCalculatedQuantities* ip_cq);
  80. virtual Index get_number_of_nonlinear_variables();
  81. virtual bool get_list_of_nonlinear_variables(Index num_nonlin_vars,
  82. Index* pos_nonlin_vars);
  83. //@}
  84. private:
  85. /**@name Default Compiler Generated Methods
  86. * (Hidden to avoid implicit creation/calling).
  87. * These methods are not implemented and
  88. * we do not want the compiler to implement
  89. * them for us, so we declare them private
  90. * and do not define them. This ensures that
  91. * they will not be implicitly created/called. */
  92. //@{
  93. /** Default Constructor */
  94. TNLPReducer();
  95. /** Copy Constructor */
  96. TNLPReducer(const TNLPReducer&);
  97. /** Overloaded Equals Operator */
  98. void operator=(const TNLPReducer&);
  99. //@}
  100. /** @name original TNLP */
  101. //@{
  102. SmartPtr<TNLP> tnlp_;
  103. Index m_orig_;
  104. Index nnz_jac_g_orig_;
  105. //@}
  106. /** Number of constraints to be skipped */
  107. Index n_g_skip_;
  108. /** Array of indices of the constraints that are to be skipped.
  109. * This is provided at the beginning in the constructor. */
  110. Index* index_g_skip_;
  111. /** Index style for original problem. Internally, we use C-Style
  112. * now. */
  113. IndexStyleEnum index_style_orig_;
  114. /** Map from original constraints to new constraints. A -1 means
  115. * that a constraint is skipped. */
  116. Index* g_keep_map_;
  117. /** Number of constraints in reduced NLP */
  118. Index m_reduced_;
  119. /** Number of Jacobian nonzeros in the reduced NLP */
  120. Index nnz_jac_g_reduced_;
  121. /** Number of Jacobian nonzeros that are skipped */
  122. Index nnz_jac_g_skipped_;
  123. /** Array of Jacobian elements that are to be skipped. This is in
  124. * increasing order. */
  125. Index* jac_g_skipped_;
  126. /** Number of lower variable bounds to be skipped. */
  127. Index n_xL_skip_;
  128. /** Array of indices of the lower variable bounds to be skipped. */
  129. Index* index_xL_skip_;
  130. /** Number of upper variable bounds to be skipped. */
  131. Index n_xU_skip_;
  132. /** Array of indices of the upper variable bounds to be skipped. */
  133. Index* index_xU_skip_;
  134. /** Number of variables that are to be fixed to initial value. */
  135. Index n_x_fix_;
  136. /** Array of indices of the variables that are to be fixed. */
  137. Index* index_x_fix_;
  138. };
  139. } // namespace Ipopt
  140. #endif