hs071_nlp.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright (C) 2005, 2007 International Business Machines and others.
  2. // All Rights Reserved.
  3. // This code is published under the Eclipse Public License.
  4. //
  5. // $Id: hs071_nlp.hpp 1861 2010-12-21 21:34:47Z andreasw $
  6. //
  7. // Authors: Carl Laird, Andreas Waechter IBM 2005-08-09
  8. #ifndef __HS071_NLP_HPP__
  9. #define __HS071_NLP_HPP__
  10. #include "IpTNLP.hpp"
  11. using namespace Ipopt;
  12. /** C++ Example NLP for interfacing a problem with IPOPT.
  13. * HS071_NLP implements a C++ example of problem 71 of the
  14. * Hock-Schittkowski test suite. This example is designed to go
  15. * along with the tutorial document and show how to interface
  16. * with IPOPT through the TNLP interface.
  17. *
  18. * Problem hs071 looks like this
  19. *
  20. * min x1*x4*(x1 + x2 + x3) + x3
  21. * s.t. x1*x2*x3*x4 >= 25
  22. * x1**2 + x2**2 + x3**2 + x4**2 = 40
  23. * 1 <= x1,x2,x3,x4 <= 5
  24. *
  25. * Starting point:
  26. * x = (1, 5, 5, 1)
  27. *
  28. * Optimal solution:
  29. * x = (1.00000000, 4.74299963, 3.82114998, 1.37940829)
  30. *
  31. *
  32. */
  33. class HS071_NLP : public TNLP
  34. {
  35. public:
  36. /** default constructor */
  37. HS071_NLP();
  38. /** default destructor */
  39. virtual ~HS071_NLP();
  40. /**@name Overloaded from TNLP */
  41. //@{
  42. /** Method to return some info about the nlp */
  43. virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
  44. Index& nnz_h_lag, IndexStyleEnum& index_style);
  45. /** Method to return the bounds for my problem */
  46. virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
  47. Index m, Number* g_l, Number* g_u);
  48. /** Method to return the starting point for the algorithm */
  49. virtual bool get_starting_point(Index n, bool init_x, Number* x,
  50. bool init_z, Number* z_L, Number* z_U,
  51. Index m, bool init_lambda,
  52. Number* lambda);
  53. /** Method to return the objective value */
  54. virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
  55. /** Method to return the gradient of the objective */
  56. virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
  57. /** Method to return the constraint residuals */
  58. virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
  59. /** Method to return:
  60. * 1) The structure of the jacobian (if "values" is NULL)
  61. * 2) The values of the jacobian (if "values" is not NULL)
  62. */
  63. virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
  64. Index m, Index nele_jac, Index* iRow, Index *jCol,
  65. Number* values);
  66. /** Method to return:
  67. * 1) The structure of the hessian of the lagrangian (if "values" is NULL)
  68. * 2) The values of the hessian of the lagrangian (if "values" is not NULL)
  69. */
  70. virtual bool eval_h(Index n, const Number* x, bool new_x,
  71. Number obj_factor, Index m, const Number* lambda,
  72. bool new_lambda, Index nele_hess, Index* iRow,
  73. Index* jCol, Number* values);
  74. //@}
  75. /** @name Solution Methods */
  76. //@{
  77. /** This method is called when the algorithm is complete so the TNLP can store/write the solution */
  78. virtual void finalize_solution(SolverReturn status,
  79. Index n, const Number* x, const Number* z_L, const Number* z_U,
  80. Index m, const Number* g, const Number* lambda,
  81. Number obj_value,
  82. const IpoptData* ip_data,
  83. IpoptCalculatedQuantities* ip_cq);
  84. //@}
  85. private:
  86. /**@name Methods to block default compiler methods.
  87. * The compiler automatically generates the following three methods.
  88. * Since the default compiler implementation is generally not what
  89. * you want (for all but the most simple classes), we usually
  90. * put the declarations of these methods in the private section
  91. * and never implement them. This prevents the compiler from
  92. * implementing an incorrect "default" behavior without us
  93. * knowing. (See Scott Meyers book, "Effective C++")
  94. *
  95. */
  96. //@{
  97. // HS071_NLP();
  98. HS071_NLP(const HS071_NLP&);
  99. HS071_NLP& operator=(const HS071_NLP&);
  100. //@}
  101. };
  102. #endif