# source:trunk/Ipopt/tutorial/CodingExercise/Cpp/2-mistake/TutorialCpp_nlp.hpp

Last change on this file was 1861, checked in by andreasw, 3 years ago

moved Ipopt trunk from Common Public License to successor Eclispe Public License (see e.g. http://www.ibm.com/developerworks/library/os-cplfaq.html)

• Property svn:eol-style set to `native`
• Property svn:keywords set to `"Author Date Id Revision"`
File size: 4.2 KB
Line
3// This code is published under the Eclipse Public License.
4//
5// \$Id\$
6//
7// Author:  Andreas Waechter               IBM    2009-04-02
8
9// This file is part of the Ipopt tutorial.  It is a version with
10// mistakes for the C++ implemention of the coding exercise problem
11// (in AMPL formulation):
12//
13// param n := 4;
14//
15// var x {1..n} <= 0, >= -1.5, := -0.5;
16//
17// minimize obj:
18//   sum{i in 1..n} (x[i]-1)^2;
19//
20// subject to constr {i in 2..n-1}:
21//   (x[i]^2+1.5*x[i]-i/n)*cos(x[i+1]) - x[i-1] = 0;
22//
23// The constant term "i/n" in the constraint is supposed to be input data
24//
25
26#ifndef __TUTORIALCPP_NLP_HPP__
27#define __TUTORIALCPP_NLP_HPP__
28
29#include "IpTNLP.hpp"
30
31using namespace Ipopt;
32
33// This inherits from Ipopt's TNLP
34class TutorialCpp_NLP : public TNLP
35{
36public:
37  /** constructor that takes in problem data */
38  TutorialCpp_NLP(Index N, const Number* a);
39
40  /** default destructor */
41  virtual ~TutorialCpp_NLP();
42
43  /**@name Overloaded from TNLP */
44  //@{
45  /** Method to return some info about the nlp */
46  virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
47                            Index& nnz_h_lag, IndexStyleEnum& index_style);
48
49  /** Method to return the bounds for my problem */
50  virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
51                               Index m, Number* g_l, Number* g_u);
52
53  /** Method to return the starting point for the algorithm */
54  virtual bool get_starting_point(Index n, bool init_x, Number* x,
55                                  bool init_z, Number* z_L, Number* z_U,
56                                  Index m, bool init_lambda,
57                                  Number* lambda);
58
59  /** Method to return the objective value */
60  virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
61
62  /** Method to return the gradient of the objective */
63  virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
64
65  /** Method to return the constraint residuals */
66  virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
67
68  /** Method to return:
69   *   1) The structure of the jacobian (if "values" is NULL)
70   *   2) The values of the jacobian (if "values" is not NULL)
71   */
72  virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
73                          Index m, Index nele_jac, Index* iRow, Index *jCol,
74                          Number* values);
75
76  /** Method to return:
77   *   1) The structure of the hessian of the lagrangian (if "values" is NULL)
78   *   2) The values of the hessian of the lagrangian (if "values" is not NULL)
79   */
80  virtual bool eval_h(Index n, const Number* x, bool new_x,
81                      Number obj_factor, Index m, const Number* lambda,
82                      bool new_lambda, Index nele_hess, Index* iRow,
83                      Index* jCol, Number* values);
84
85  //@}
86
87  /** @name Solution Methods */
88  //@{
89  /** This method is called when the algorithm is complete so the TNLP can store/write the solution */
90  virtual void finalize_solution(SolverReturn status,
91                                 Index n, const Number* x, const Number* z_L, const Number* z_U,
92                                 Index m, const Number* g, const Number* lambda,
93                                 Number obj_value,
94                                 const IpoptData* ip_data,
95                                 IpoptCalculatedQuantities* ip_cq);
96  //@}
97
98private:
99  /**@name Methods to block default compiler methods.
100   * The compiler automatically generates the following three methods.
101   *  Since the default compiler implementation is generally not what
102   *  you want (for all but the most simple classes), we usually
103   *  put the declarations of these methods in the private section
104   *  and never implement them. This prevents the compiler from
105   *  implementing an incorrect "default" behavior without us
106   *  knowing. (See Scott Meyers book, "Effective C++")
107   *
108   */
109  //@{
110  TutorialCpp_NLP();
111  TutorialCpp_NLP(const TutorialCpp_NLP&);
112  TutorialCpp_NLP& operator=(const TutorialCpp_NLP&);
113  //@}
114
115  /** @name NLP data */
116  //@{
117  /** Number of variables */
118  Index N_;
119  /** Value of constants in constraints */
120  Number* a_;
121  //@}
122};
123
124
125#endif
Note: See TracBrowser for help on using the repository browser.