IpIpoptNLP.hpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. // Copyright (C) 2004, 2006 International Business Machines and others.
  2. // All Rights Reserved.
  3. // This code is published under the Eclipse Public License.
  4. //
  5. // $Id: IpIpoptNLP.hpp 1861 2010-12-21 21:34:47Z andreasw $
  6. //
  7. // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
  8. #ifndef __IPIPOPTNLP_HPP__
  9. #define __IPIPOPTNLP_HPP__
  10. #include "IpNLP.hpp"
  11. #include "IpJournalist.hpp"
  12. #include "IpNLPScaling.hpp"
  13. namespace Ipopt
  14. {
  15. // forward declarations
  16. class IteratesVector;
  17. /** This is the abstract base class for classes that map
  18. * the traditional NLP into
  19. * something that is more useful by Ipopt.
  20. * This class takes care of storing the
  21. * calculated model results, handles cacheing,
  22. * and (some day) takes care of addition of slacks.
  23. */
  24. class IpoptNLP : public ReferencedObject
  25. {
  26. public:
  27. /**@name Constructors/Destructors */
  28. //@{
  29. IpoptNLP(const SmartPtr<NLPScalingObject> nlp_scaling)
  30. :
  31. nlp_scaling_(nlp_scaling)
  32. {}
  33. /** Default destructor */
  34. virtual ~IpoptNLP()
  35. {}
  36. //@}
  37. /** Initialization method. Set the internal options and
  38. * initialize internal data structures. */
  39. virtual bool Initialize(const Journalist& jnlst,
  40. const OptionsList& options,
  41. const std::string& prefix)
  42. {
  43. bool ret = true;
  44. if (IsValid(nlp_scaling_)) {
  45. ret = nlp_scaling_->Initialize(jnlst, options, prefix);
  46. }
  47. return ret;
  48. }
  49. /**@name Possible Exceptions */
  50. //@{
  51. /** thrown if there is any error evaluating values from the nlp */
  52. DECLARE_STD_EXCEPTION(Eval_Error);
  53. //@}
  54. /** Initialize (create) structures for
  55. * the iteration data */
  56. virtual bool InitializeStructures(SmartPtr<Vector>& x,
  57. bool init_x,
  58. SmartPtr<Vector>& y_c,
  59. bool init_y_c,
  60. SmartPtr<Vector>& y_d,
  61. bool init_y_d,
  62. SmartPtr<Vector>& z_L,
  63. bool init_z_L,
  64. SmartPtr<Vector>& z_U,
  65. bool init_z_U,
  66. SmartPtr<Vector>& v_L,
  67. SmartPtr<Vector>& v_U
  68. ) = 0;
  69. /** Method accessing the GetWarmStartIterate of the NLP */
  70. virtual bool GetWarmStartIterate(IteratesVector& warm_start_iterate)=0;
  71. /** Accessor methods for model data */
  72. //@{
  73. /** Objective value */
  74. virtual Number f(const Vector& x) = 0;
  75. /** Gradient of the objective */
  76. virtual SmartPtr<const Vector> grad_f(const Vector& x) = 0;
  77. /** Equality constraint residual */
  78. virtual SmartPtr<const Vector> c(const Vector& x) = 0;
  79. /** Jacobian Matrix for equality constraints */
  80. virtual SmartPtr<const Matrix> jac_c(const Vector& x) = 0;
  81. /** Inequality constraint residual (reformulated
  82. * as equalities with slacks */
  83. virtual SmartPtr<const Vector> d(const Vector& x) = 0;
  84. /** Jacobian Matrix for inequality constraints */
  85. virtual SmartPtr<const Matrix> jac_d(const Vector& x) = 0;
  86. /** Hessian of the Lagrangian */
  87. virtual SmartPtr<const SymMatrix> h(const Vector& x,
  88. Number obj_factor,
  89. const Vector& yc,
  90. const Vector& yd
  91. ) = 0;
  92. /** Lower bounds on x */
  93. virtual SmartPtr<const Vector> x_L() const = 0;
  94. /** Permutation matrix (x_L_ -> x) */
  95. virtual SmartPtr<const Matrix> Px_L() const = 0;
  96. /** Upper bounds on x */
  97. virtual SmartPtr<const Vector> x_U() const = 0;
  98. /** Permutation matrix (x_U_ -> x */
  99. virtual SmartPtr<const Matrix> Px_U() const = 0;
  100. /** Lower bounds on d */
  101. virtual SmartPtr<const Vector> d_L() const = 0;
  102. /** Permutation matrix (d_L_ -> d) */
  103. virtual SmartPtr<const Matrix> Pd_L() const = 0;
  104. /** Upper bounds on d */
  105. virtual SmartPtr<const Vector> d_U() const = 0;
  106. /** Permutation matrix (d_U_ -> d */
  107. virtual SmartPtr<const Matrix> Pd_U() const = 0;
  108. /** Accessor method to obtain the MatrixSpace for the Hessian
  109. * matrix (or it's approximation) */
  110. virtual SmartPtr<const SymMatrixSpace> HessianMatrixSpace() const = 0;
  111. //@}
  112. /** Accessor method for vector/matrix spaces pointers. */
  113. virtual void GetSpaces(SmartPtr<const VectorSpace>& x_space,
  114. SmartPtr<const VectorSpace>& c_space,
  115. SmartPtr<const VectorSpace>& d_space,
  116. SmartPtr<const VectorSpace>& x_l_space,
  117. SmartPtr<const MatrixSpace>& px_l_space,
  118. SmartPtr<const VectorSpace>& x_u_space,
  119. SmartPtr<const MatrixSpace>& px_u_space,
  120. SmartPtr<const VectorSpace>& d_l_space,
  121. SmartPtr<const MatrixSpace>& pd_l_space,
  122. SmartPtr<const VectorSpace>& d_u_space,
  123. SmartPtr<const MatrixSpace>& pd_u_space,
  124. SmartPtr<const MatrixSpace>& Jac_c_space,
  125. SmartPtr<const MatrixSpace>& Jac_d_space,
  126. SmartPtr<const SymMatrixSpace>& Hess_lagrangian_space) = 0;
  127. /** Method for adapting the variable bounds. This is called if
  128. * slacks are becoming too small */
  129. virtual void AdjustVariableBounds(const Vector& new_x_L,
  130. const Vector& new_x_U,
  131. const Vector& new_d_L,
  132. const Vector& new_d_U)=0;
  133. /** @name Counters for the number of function evaluations. */
  134. //@{
  135. virtual Index f_evals() const = 0;
  136. virtual Index grad_f_evals() const = 0;
  137. virtual Index c_evals() const = 0;
  138. virtual Index jac_c_evals() const = 0;
  139. virtual Index d_evals() const = 0;
  140. virtual Index jac_d_evals() const = 0;
  141. virtual Index h_evals() const = 0;
  142. //@}
  143. /** @name Special method for dealing with the fact that the
  144. * restoration phase objective function depends on the barrier
  145. * parameter */
  146. //@{
  147. /** Method for telling the IpoptCalculatedQuantities class whether
  148. * the objective function depends on the barrier function. This
  149. * is only used for the restoration phase NLP
  150. * formulation. Probably only RestoIpoptNLP should overwrite
  151. * this. */
  152. virtual bool objective_depends_on_mu() const
  153. {
  154. return false;
  155. }
  156. /** Replacement for the default objective function method which
  157. * knows about the barrier parameter */
  158. virtual Number f(const Vector& x, Number mu) = 0;
  159. /** Replacement for the default objective gradient method which
  160. * knows about the barrier parameter */
  161. virtual SmartPtr<const Vector> grad_f(const Vector& x, Number mu) = 0;
  162. /** Replacement for the default Lagrangian Hessian method which
  163. * knows about the barrier parameter */
  164. virtual SmartPtr<const SymMatrix> h(const Vector& x,
  165. Number obj_factor,
  166. const Vector& yc,
  167. const Vector& yd,
  168. Number mu) = 0;
  169. /** Provides a Hessian matrix from the correct matrix space with
  170. * uninitialized values. This can be used in LeastSquareMults to
  171. * obtain a "zero Hessian". */
  172. virtual SmartPtr<const SymMatrix> uninitialized_h() = 0;
  173. //@}
  174. /**@name solution routines */
  175. //@{
  176. virtual void FinalizeSolution(SolverReturn status,
  177. const Vector& x, const Vector& z_L, const Vector& z_U,
  178. const Vector& c, const Vector& d,
  179. const Vector& y_c, const Vector& y_d,
  180. Number obj_value,
  181. const IpoptData* ip_data,
  182. IpoptCalculatedQuantities* ip_cq)=0;
  183. virtual bool IntermediateCallBack(AlgorithmMode mode,
  184. Index iter, Number obj_value,
  185. Number inf_pr, Number inf_du,
  186. Number mu, Number d_norm,
  187. Number regularization_size,
  188. Number alpha_du, Number alpha_pr,
  189. Index ls_trials,
  190. SmartPtr<const IpoptData> ip_data,
  191. SmartPtr<IpoptCalculatedQuantities> ip_cq)=0;
  192. //@}
  193. /** Returns the scaling strategy object */
  194. SmartPtr<NLPScalingObject> NLP_scaling() const
  195. {
  196. DBG_ASSERT(IsValid(nlp_scaling_));
  197. return nlp_scaling_;
  198. }
  199. private:
  200. /**@name Default Compiler Generated Methods
  201. * (Hidden to avoid implicit creation/calling).
  202. * These methods are not implemented and
  203. * we do not want the compiler to implement
  204. * them for us, so we declare them private
  205. * and do not define them. This ensures that
  206. * they will not be implicitly created/called. */
  207. //@{
  208. /** Copy Constructor */
  209. IpoptNLP(const IpoptNLP&);
  210. /** Overloaded Equals Operator */
  211. void operator=(const IpoptNLP&);
  212. //@}
  213. SmartPtr<NLPScalingObject> nlp_scaling_;
  214. };
  215. } // namespace Ipopt
  216. #endif