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