1 // Copyright (C) 2005, 2006 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // $Id$
6 //
7 // Authors:  Andreas Waechter              IBM    2005-10-127
8 
9 #ifndef __LUKSANVLCEK7_HPP__
10 #define __LUKSANVLCEK7_HPP__
11 
12 #include "RegisteredTNLP.hpp"
13 
14 using namespace Ipopt;
15 
16 /** Implementation of Example 5.7 from "Sparse and Parially Separable
17  *  Test Problems for Unconstrained and Equality Constrained
18  *  Optimization" by L. Luksan and J. Vlcek. */
19 class LuksanVlcek7 : public RegisteredTNLP
20 {
21 public:
22   /** Constructor.  Here, g_l and g_u are the bounds for the
23    *  constraints.  The original formulation is obtained by setting
24    *  g_l and g_u to zero.  Using g_l<g_u allows the obtain a problem
25    *  formulation with inequality constraints. */
26   LuksanVlcek7(Number g_l, Number g_u);
27 
28   /** Default destructor */
~LuksanVlcek7()29   virtual ~LuksanVlcek7()
30   {}
31   ;
32 
33   /** Overloaded from RegisteredTNLP. */
34   virtual bool InitializeProblem(Index N);
35 
36   /**@name Overloaded from TNLP */
37   //@{
38   /** Method to return some info about the nlp */
39   virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
40                             Index& nnz_h_lag, IndexStyleEnum& index_style);
41 
42   /** Method to return the bounds for my problem */
43   virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
44                                Index m, Number* g_l, Number* g_u);
45 
46   /** Method to return the starting point for the algorithm */
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 
52   /** Method to return the objective value */
53   virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
54 
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 
58   /** Method to return the constraint residuals */
59   virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
60 
61   /** Method to return:
62    *   1) The structure of the jacobian (if "values" is NULL)
63    *   2) The values of the jacobian (if "values" is not NULL)
64    */
65   virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
66                           Index m, Index nele_jac, Index* iRow, Index *jCol,
67                           Number* values);
68 
69   /** Method to return:
70    *   1) The structure of the hessian of the lagrangian (if "values" is NULL)
71    *   2) The values of the hessian of the lagrangian (if "values" is not NULL)
72    */
73   virtual bool eval_h(Index n, const Number* x, bool new_x,
74                       Number obj_factor, Index m, const Number* lambda,
75                       bool new_lambda, Index nele_hess, Index* iRow,
76                       Index* jCol, Number* values);
77 
78   //@}
79 
80   /** @name Solution Methods */
81   //@{
82   /** This method is called when the algorithm is complete so the TNLP can store/write the solution */
83   virtual void finalize_solution(SolverReturn status,
84                                  Index n, const Number* x, const Number* z_L, const Number* z_U,
85                                  Index m, const Number* g, const Number* lambda,
86                                  Number obj_value,
87 				 const IpoptData* ip_data,
88 				 IpoptCalculatedQuantities* ip_cq);
89   //@}
90 
91 private:
92   /**@name Methods to block default compiler methods.
93    * The compiler automatically generates the following three methods.
94    *  Since the default compiler implementation is generally not what
95    *  you want (for all but the most simple classes), we usually
96    *  put the declarations of these methods in the private section
97    *  and never implement them. This prevents the compiler from
98    *  implementing an incorrect "default" behavior without us
99    *  knowing. (See Scott Meyers book, "Effective C++")
100    *
101    */
102   //@{
103   LuksanVlcek7();
104   LuksanVlcek7(const LuksanVlcek7&);
105   LuksanVlcek7& operator=(const LuksanVlcek7&);
106   //@}
107 
108   /** Parameter determining problem size */
109   Index N_;
110 
111   /** General lower bound for all constraints */
112   Number g_l_;
113   /** General upper bound for all constraints */
114   Number g_u_;
115 };
116 
117 #endif
118