IpNLP.hpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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: IpNLP.hpp 1861 2010-12-21 21:34:47Z andreasw $
  6. //
  7. // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
  8. #ifndef __IPNLP_HPP__
  9. #define __IPNLP_HPP__
  10. #include "IpUtils.hpp"
  11. #include "IpVector.hpp"
  12. #include "IpSmartPtr.hpp"
  13. #include "IpMatrix.hpp"
  14. #include "IpSymMatrix.hpp"
  15. #include "IpOptionsList.hpp"
  16. #include "IpAlgTypes.hpp"
  17. #include "IpReturnCodes.hpp"
  18. namespace Ipopt
  19. {
  20. // forward declarations
  21. class IpoptData;
  22. class IpoptCalculatedQuantities;
  23. class IteratesVector;
  24. /** Brief Class Description.
  25. * Detailed Class Description.
  26. */
  27. class NLP : public ReferencedObject
  28. {
  29. public:
  30. /**@name Constructors/Destructors */
  31. //@{
  32. /** Default constructor */
  33. NLP()
  34. {}
  35. /** Default destructor */
  36. virtual ~NLP()
  37. {}
  38. //@}
  39. /** Exceptions */
  40. //@{
  41. DECLARE_STD_EXCEPTION(USER_SCALING_NOT_IMPLEMENTED);
  42. DECLARE_STD_EXCEPTION(INVALID_NLP);
  43. //@}
  44. /** @name NLP Initialization (overload in
  45. * derived classes).*/
  46. //@{
  47. /** Overload if you want the chance to process options or parameters that
  48. * may be specific to the NLP */
  49. virtual bool ProcessOptions(const OptionsList& options,
  50. const std::string& prefix)
  51. {
  52. return true;
  53. }
  54. /** Method for creating the derived vector / matrix types. The
  55. * Hess_lagrangian_space pointer can be NULL if a quasi-Newton
  56. * options is chosen. */
  57. virtual bool GetSpaces(SmartPtr<const VectorSpace>& x_space,
  58. SmartPtr<const VectorSpace>& c_space,
  59. SmartPtr<const VectorSpace>& d_space,
  60. SmartPtr<const VectorSpace>& x_l_space,
  61. SmartPtr<const MatrixSpace>& px_l_space,
  62. SmartPtr<const VectorSpace>& x_u_space,
  63. SmartPtr<const MatrixSpace>& px_u_space,
  64. SmartPtr<const VectorSpace>& d_l_space,
  65. SmartPtr<const MatrixSpace>& pd_l_space,
  66. SmartPtr<const VectorSpace>& d_u_space,
  67. SmartPtr<const MatrixSpace>& pd_u_space,
  68. SmartPtr<const MatrixSpace>& Jac_c_space,
  69. SmartPtr<const MatrixSpace>& Jac_d_space,
  70. SmartPtr<const SymMatrixSpace>& Hess_lagrangian_space)=0;
  71. /** Method for obtaining the bounds information */
  72. virtual bool GetBoundsInformation(const Matrix& Px_L,
  73. Vector& x_L,
  74. const Matrix& Px_U,
  75. Vector& x_U,
  76. const Matrix& Pd_L,
  77. Vector& d_L,
  78. const Matrix& Pd_U,
  79. Vector& d_U)=0;
  80. /** Method for obtaining the starting point for all the
  81. * iterates. ToDo it might not make sense to ask for initial
  82. * values for v_L and v_U? */
  83. virtual bool GetStartingPoint(
  84. SmartPtr<Vector> x,
  85. bool need_x,
  86. SmartPtr<Vector> y_c,
  87. bool need_y_c,
  88. SmartPtr<Vector> y_d,
  89. bool need_y_d,
  90. SmartPtr<Vector> z_L,
  91. bool need_z_L,
  92. SmartPtr<Vector> z_U,
  93. bool need_z_U
  94. )=0;
  95. /** Method for obtaining an entire iterate as a warmstart point.
  96. * The incoming IteratesVector has to be filled. The default
  97. * dummy implementation returns false. */
  98. virtual bool GetWarmStartIterate(IteratesVector& warm_start_iterate)
  99. {
  100. return false;
  101. }
  102. //@}
  103. /** @name NLP evaluation routines (overload
  104. * in derived classes. */
  105. //@{
  106. virtual bool Eval_f(const Vector& x, Number& f) = 0;
  107. virtual bool Eval_grad_f(const Vector& x, Vector& g_f) = 0;
  108. virtual bool Eval_c(const Vector& x, Vector& c) = 0;
  109. virtual bool Eval_jac_c(const Vector& x, Matrix& jac_c) = 0;
  110. virtual bool Eval_d(const Vector& x, Vector& d) = 0;
  111. virtual bool Eval_jac_d(const Vector& x, Matrix& jac_d) = 0;
  112. virtual bool Eval_h(const Vector& x,
  113. Number obj_factor,
  114. const Vector& yc,
  115. const Vector& yd,
  116. SymMatrix& h) = 0;
  117. //@}
  118. /** @name NLP solution routines. Have default dummy
  119. * implementations that can be overloaded. */
  120. //@{
  121. /** This method is called at the very end of the optimization. It
  122. * provides the final iterate to the user, so that it can be
  123. * stored as the solution. The status flag indicates the outcome
  124. * of the optimization, where SolverReturn is defined in
  125. * IpAlgTypes.hpp. */
  126. virtual void FinalizeSolution(SolverReturn status,
  127. const Vector& x, const Vector& z_L,
  128. const Vector& z_U,
  129. const Vector& c, const Vector& d,
  130. const Vector& y_c, const Vector& y_d,
  131. Number obj_value,
  132. const IpoptData* ip_data,
  133. IpoptCalculatedQuantities* ip_cq)
  134. {}
  135. /** This method is called once per iteration, after the iteration
  136. * summary output has been printed. It provides the current
  137. * information to the user to do with it anything she wants. It
  138. * also allows the user to ask for a premature termination of the
  139. * optimization by returning false, in which case Ipopt will
  140. * terminate with a corresponding return status. The basic
  141. * information provided in the argument list has the quantities
  142. * values printed in the iteration summary line. If more
  143. * information is required, a user can obtain it from the IpData
  144. * and IpCalculatedQuantities objects. However, note that the
  145. * provided quantities are all for the problem that Ipopt sees,
  146. * i.e., the quantities might be scaled, fixed variables might be
  147. * sorted out, etc. The status indicates things like whether the
  148. * algorithm is in the restoration phase... In the restoration
  149. * phase, the dual variables are probably not not changing. */
  150. virtual bool IntermediateCallBack(AlgorithmMode mode,
  151. Index iter, Number obj_value,
  152. Number inf_pr, Number inf_du,
  153. Number mu, Number d_norm,
  154. Number regularization_size,
  155. Number alpha_du, Number alpha_pr,
  156. Index ls_trials,
  157. const IpoptData* ip_data,
  158. IpoptCalculatedQuantities* ip_cq)
  159. {
  160. return true;
  161. }
  162. //@}
  163. /** Routines to get the scaling parameters. These do not need to
  164. * be overloaded unless the options are set for User scaling
  165. */
  166. //@{
  167. virtual void GetScalingParameters(
  168. const SmartPtr<const VectorSpace> x_space,
  169. const SmartPtr<const VectorSpace> c_space,
  170. const SmartPtr<const VectorSpace> d_space,
  171. Number& obj_scaling,
  172. SmartPtr<Vector>& x_scaling,
  173. SmartPtr<Vector>& c_scaling,
  174. SmartPtr<Vector>& d_scaling) const
  175. {
  176. THROW_EXCEPTION(USER_SCALING_NOT_IMPLEMENTED,
  177. "You have set options for user provided scaling, but have"
  178. " not implemented GetScalingParameters in the NLP interface");
  179. }
  180. //@}
  181. /** Method for obtaining the subspace in which the limited-memory
  182. * Hessian approximation should be done. This is only called if
  183. * the limited-memory Hessian approximation is chosen. Since the
  184. * Hessian is zero in the space of all variables that appear in
  185. * the problem functions only linearly, this allows the user to
  186. * provide a VectorSpace for all nonlinear variables, and an
  187. * ExpansionMatrix to lift from this VectorSpace to the
  188. * VectorSpace of the primal variables x. If the returned values
  189. * are NULL, it is assumed that the Hessian is to be approximated
  190. * in the space of all x variables. The default instantiation of
  191. * this method returns NULL, and a user only has to overwrite
  192. * this method if the approximation is to be done only in a
  193. * subspace. */
  194. virtual void
  195. GetQuasiNewtonApproximationSpaces(SmartPtr<VectorSpace>& approx_space,
  196. SmartPtr<Matrix>& P_approx)
  197. {
  198. approx_space = NULL;
  199. P_approx = NULL;
  200. }
  201. private:
  202. /**@name Default Compiler Generated Methods
  203. * (Hidden to avoid implicit creation/calling).
  204. * These methods are not implemented and
  205. * we do not want the compiler to implement
  206. * them for us, so we declare them private
  207. * and do not define them. This ensures that
  208. * they will not be implicitly created/called. */
  209. //@{
  210. /** Copy Constructor */
  211. NLP(const NLP&);
  212. /** Overloaded Equals Operator */
  213. void operator=(const NLP&);
  214. //@}
  215. };
  216. } // namespace Ipopt
  217. #endif