ROL
ROL_HS9.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
16 #ifndef ROL_HS9_HPP
17 #define ROL_HS9_HPP
18 
19 #include "ROL_StdVector.hpp"
20 #include "ROL_TestProblem.hpp"
21 #include "ROL_Types.hpp"
22 #include "ROL_StdObjective.hpp"
23 #include "ROL_StdConstraint.hpp"
24 
25 namespace ROL {
26 namespace ZOO {
27 
34 template<class Real>
35 class Objective_HS9 : public StdObjective<Real> {
36 public:
37  Real value( const std::vector<Real> &x, Real &tol ) {
38  const Real pi(M_PI), c12(12), c16(16);
39  return std::sin(x[0]*pi/c12)*std::cos(x[1]*pi/c16);
40  }
41 
42  void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
43  const Real pi(M_PI), c12(12), c16(16);
44  g[0] = pi/c12*std::cos(x[0]*pi/c12)*std::cos(x[1]*pi/c16);
45  g[1] = -pi/c16*std::sin(x[0]*pi/c12)*std::sin(x[1]*pi/c16);
46  }
47 
48  void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
49  const Real pi(M_PI), c12(12), c16(16);
50  Real h11 = -pi/c12*pi/c12*std::sin(x[0]*pi/c12)*std::cos(x[1]*pi/c16);
51  Real h12 = -pi/c12*pi/c16*std::cos(x[0]*pi/c12)*std::sin(x[1]*pi/c16);
52  Real h22 = -pi/c16*pi/c16*std::sin(x[0]*pi/c12)*std::cos(x[1]*pi/c16);
53  hv[0] = h11*v[0] + h12*v[1];
54  hv[1] = h12*v[0] + h22*v[1];
55  }
56 };
57 
58 template<class Real>
59 class Constraint_HS9 : public StdConstraint<Real> {
60 public:
61  Constraint_HS9(void) {}
62 
63  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
64  const Real c3(3), c4(4);
65  c[0] = c4*x[0] - c3*x[1];
66  }
67 
68  void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
69  const std::vector<Real> &x, Real &tol) {
70  const Real c3(3), c4(4);
71  jv[0] = c4*v[0] - c3*v[1];
72  }
73 
74  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
75  const std::vector<Real> &x, Real &tol ) {
76  const Real c3(3), c4(4);
77  ajv[0] = c4*v[0];
78  ajv[1] = -c3*v[0];
79  }
80 
81  void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
82  const std::vector<Real> &v, const std::vector<Real> &x,
83  Real &tol) {
84  ahuv.assign(ahuv.size(),static_cast<Real>(0));
85  }
86 
87 
88 };
89 
90 template<class Real>
91 class getHS9 : public TestProblem<Real> {
92 public:
93  getHS9(void) {}
94 
95  Ptr<Objective<Real>> getObjective(void) const {
96  // Instantiate Objective Function
97  return ROL::makePtr<Objective_HS9<Real>>();
98  }
99 
100  Ptr<Vector<Real>> getInitialGuess(void) const {
101  // Problem dimension
102  int n = 2;
103  return ROL::makePtr<StdVector<Real>>(n,0.0);
104  }
105 
106  Ptr<Vector<Real>> getSolution(const int i = 0) const {
107  // Problem dimension
108  int n = 2;
109  // Get Solution
110  ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n,0.0);
111  (*xp)[0] = static_cast<Real>(-3);
112  (*xp)[1] = static_cast<Real>(-4);
113  return ROL::makePtr<StdVector<Real>>(xp);
114  }
115 
116  Ptr<Constraint<Real>> getEqualityConstraint(void) const {
117  return ROL::makePtr<Constraint_HS9<Real>>();
118  }
119 
120  Ptr<Vector<Real>> getEqualityMultiplier(void) const {
121  // Problem dimension
122  int n = 1;
123  return ROL::makePtr<StdVector<Real>>(n,0.0);
124  }
125 };
126 
127 
128 
129 } // End ZOO Namespace
130 } // End ROL Namespace
131 
132 #endif
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS9.hpp:100
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_HS9.hpp:37
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition: ROL_HS9.hpp:120
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS9.hpp:42
Contains definitions of custom data types in ROL.
Defines the equality constraint operator interface for StdVectors.
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS9.hpp:106
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS9.hpp:68
W. Hock and K. Schittkowski 9th test function.
Definition: ROL_HS9.hpp:35
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector&#39;s.
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS9.hpp:74
Contains definitions of test objective functions.
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS9.hpp:63
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition: ROL_HS9.hpp:116
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS9.hpp:95
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS9.hpp:48
void applyAdjointHessian(std::vector< Real > &ahuv, const std::vector< Real > &u, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS9.hpp:81