1 #ifndef NLP2_h
2 #define NLP2_h
3 
4 #include "NLP1.h"
5 #include "Teuchos_SerialDenseMatrix.hpp"
6 #include "Teuchos_SerialDenseVector.hpp"
7 #include "Teuchos_SerialSymDenseMatrix.hpp"
8 
9 /**
10  * NLP2: NLP1 + Second derivatives
11  * NLP2 is derived from NLP1 by adding the necessary
12  * information to compute and store the Hessian.
13  * @author J.C. Meza, Lawrence Berkeley National Laboratory,
14  *
15  * @note Modified by P. J. Williams to incorporate namespaces
16  * @date 02/2006
17  */
18 
19 namespace OPTPP {
20 
21 class NLP2: public NLP1 {
22 protected:
23   /// Hessian of objective fcn (or approx.)
24   Teuchos::SerialSymDenseMatrix<int,double> Hessian;
25   /// Number of Hessian evaluations
26   int     nhevals;
27 
28 public:
29  /**
30   * Default Constructor
31   * @see NLP2(int dim)
32   * @see NLP2(int dim, int nlncons)
33   * @see NLP2(int dim, CompoundConstraint* constraint)
34   */
NLP2()35   NLP2():
36      NLP1(), Hessian(0), nhevals(0) {;}
37  /**
38   * @param ndim an int
39   * @see NLP2()
40   * @see NLP2(int dim, int nlncons)
41   * @see NLP2(int dim, CompoundConstraint* constraint)
42   */
NLP2(int ndim)43   NLP2(int ndim):
44      NLP1(ndim), Hessian(ndim), nhevals(0) {;}
45  /**
46   * @param ndim  problem dimension
47   * @param nlncons number of nonlinear constraints
48   * @see NLP2()
49   * @see NLP2(int dim)
50   * @see NLP2(int dim, CompoundConstraint* constraint)
51   */
NLP2(int ndim,int nlncons)52   NLP2(int ndim, int nlncons):
53      NLP1(ndim, nlncons), Hessian(ndim), nhevals(0) {;}
54  /**
55   * @param ndim  problem dimension
56   * @param constraint pointer to a CompoundConstraint
57   * @see NLP2()
58   * @see NLP2(int dim)
59   * @see NLP2(int dim, int nlncons)
60   */
NLP2(int ndim,CompoundConstraint * constraint)61   NLP2(int ndim, CompoundConstraint* constraint):
62      NLP1(ndim,constraint), Hessian(ndim), nhevals(0) {;}
63 
64  /**
65   * Destructor
66   */
~NLP2()67   virtual ~NLP2() {}
68 
69  /**
70   * @return Hessian of the objective function
71   */
getHess()72   Teuchos::SerialSymDenseMatrix<int,double> getHess() const {return Hessian;}
73 
74  /**
75   * @return Number of Hessian evaluations
76   */
getHevals()77   int getHevals()           const {return nhevals;}
78 
79 /// Reset the parameter values
80   virtual void reset() = 0;
81 /// Initialize the function
82   virtual void initFcn() = 0;
83 /// Evaluate the function at the current point
84   virtual real evalF() = 0;
85 /// Evaluate the function at x
86   virtual real evalF(const Teuchos::SerialDenseVector<int,double>& x) = 0;
87 /// Evaluate the function, gradient, and Hessian at the current point
88   virtual void eval() = 0;
89 
90 /// Evaluate the gradient at the current point
91   virtual Teuchos::SerialDenseVector<int,double> evalG() = 0;
92 /// Evaluate the gradient at x
93   virtual Teuchos::SerialDenseVector<int,double> evalG(const Teuchos::SerialDenseVector<int,double>& x) = 0;
94 
95 /// Evaluate the Hessian at the current point
96   virtual Teuchos::SerialSymDenseMatrix<int,double> evalH() = 0;
97 /// Evaluate the Hessian at x
98   virtual Teuchos::SerialSymDenseMatrix<int,double> evalH(Teuchos::SerialDenseVector<int,double>& x) = 0;
99 
100 
101 /// Evaluate the Lagrangian at the x
102   virtual real evalLagrangian(const Teuchos::SerialDenseVector<int,double>& x, Teuchos::SerialDenseVector<int,double>& mult,
103                               const Teuchos::SerialDenseVector<int,double>& type) = 0;
104 /// Evaluate the gradient of the Lagrangian at x
105   virtual Teuchos::SerialDenseVector<int,double> evalLagrangianGradient(const Teuchos::SerialDenseVector<int,double>& x,
106                                               const Teuchos::SerialDenseVector<int,double>& mult,
107 					      const Teuchos::SerialDenseVector<int,double>& type) = 0;
108 
109 /// Evaluate the constraint at x
110   virtual Teuchos::SerialDenseVector<int,double> evalCF(const Teuchos::SerialDenseVector<int,double>& x) = 0;
111 /// Evaluate the constraint gradient at x
112   virtual Teuchos::SerialDenseMatrix<int,double> evalCG(const Teuchos::SerialDenseVector<int,double>& x) = 0;
113   virtual Teuchos::SerialSymDenseMatrix<int,double> evalCH(Teuchos::SerialDenseVector<int,double>& x) = 0;
114 /// Evaluate the constraint Hessian at x
115   virtual OptppArray<Teuchos::SerialSymDenseMatrix<int,double> > evalCH(Teuchos::SerialDenseVector<int,double>& x, int darg) = 0;
116   virtual void evalC(const Teuchos::SerialDenseVector<int,double>& x) = 0;
117 
118 
119 /// Print state of NLP2 object to screen
120   virtual void printState(const char* s) ;
121 /// Print state of NLP2 object to file
122   virtual void fPrintState(std::ostream *nlpout, const char* s ) ;
123 
124 };
125 
126 /**
127  * Print various quantities in newmat classes
128  */
129 
130 void Print(const Teuchos::SerialDenseMatrix<int,double>& X);
131 void Print(const Teuchos::SerialSymDenseMatrix<int,double>& X);
132 
133 void FPrint(std::ostream *fout, const Teuchos::SerialDenseMatrix<int,double>& X);
134 void FPrint(std::ostream *fout, const Teuchos::SerialSymDenseMatrix<int,double>& X);
135 
136 } // namespace OPTPP
137 
138 #endif
139