ROL
ROL_HS41.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_HS41_HPP
17 #define ROL_HS41_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 #include "ROL_Bounds.hpp"
25 
26 namespace ROL {
27 namespace ZOO {
28 
35 template<class Real>
36 class Objective_HS41 : public StdObjective<Real> {
37 public:
38  Real value( const std::vector<Real> &x, Real &tol ) {
39  const Real c2(2);
40  return c2 - x[0]*x[1]*x[2];
41  }
42 
43  void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
44  g[0] = -x[1]*x[2];
45  g[1] = -x[0]*x[2];
46  g[2] = -x[0]*x[1];
47  g[3] = static_cast<Real>(0);
48  }
49 
50  void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
51  hv[0] = -x[2]*v[1] - x[1]*v[2];
52  hv[1] = -x[2]*v[0] - x[0]*v[2];
53  hv[2] = -x[1]*v[0] - x[0]*v[1];
54  hv[3] = static_cast<Real>(0);
55  }
56 };
57 
58 template<class Real>
59 class Constraint_HS41 : public StdConstraint<Real> {
60 public:
61  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
62  const Real c2(2);
63  c[0] = x[0] + c2*x[1] + c2*x[2] - x[3];
64  }
65 
66  void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
67  const std::vector<Real> &x, Real &tol) {
68  const Real c2(2);
69  jv[0] = v[0] + c2*v[1] + c2*v[2] - v[3];
70  }
71 
72  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
73  const std::vector<Real> &x, Real &tol ) {
74  const Real c2(2);
75  ajv[0] = v[0];
76  ajv[1] = c2*v[0];
77  ajv[2] = c2*v[0];
78  ajv[3] = -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 template<class Real>
89 class getHS41 : public TestProblem<Real> {
90 public:
91  getHS41(void) {}
92 
93  Ptr<Objective<Real>> getObjective(void) const {
94  return ROL::makePtr<Objective_HS41<Real>>();
95  }
96 
97  Ptr<Vector<Real>> getInitialGuess(void) const {
98  int n = 4;
99  return ROL::makePtr<StdVector<Real>>(n,2.0);
100  }
101 
102  Ptr<Vector<Real>> getSolution(const int i = 0) const {
103  int n = 4;
104  ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n,1.0/3.0);
105  (*xp)[0] = static_cast<Real>(2.0/3.0);
106  (*xp)[3] = static_cast<Real>(2.0);
107  return ROL::makePtr<StdVector<Real>>(xp);
108  }
109 
110  Ptr<Constraint<Real>> getEqualityConstraint(void) const {
111  return ROL::makePtr<Constraint_HS41<Real>>();
112  }
113 
114  Ptr<Vector<Real>> getEqualityMultiplier(void) const {
115  int n = 1;
116  return ROL::makePtr<StdVector<Real>>(n,0.0);
117  }
118 
119  Ptr<BoundConstraint<Real>> getBoundConstraint(void) const {
120  int n = 4;
121  Ptr<std::vector<Real>> up = makePtr<std::vector<Real>>(n,1.0);
122  (*up)[3] = static_cast<Real>(2.0);
123  Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(n,0.0);
124  Ptr<Vector<Real>> u = makePtr<StdVector<Real>>(up);
125  return makePtr<Bounds<Real>>(l,u);
126  }
127 };
128 
129 } // End ZOO Namespace
130 } // End ROL Namespace
131 
132 #endif
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS41.hpp:102
Contains definitions of custom data types in ROL.
Defines the equality constraint operator interface for StdVectors.
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition: ROL_HS41.hpp:110
W. Hock and K. Schittkowski 41th test function.
Definition: ROL_HS41.hpp:36
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_HS41.hpp:38
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition: ROL_HS41.hpp:119
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_HS41.hpp:72
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS41.hpp:50
Contains definitions of test objective functions.
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS41.hpp:61
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS41.hpp:43
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS41.hpp:93
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS41.hpp:66
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS41.hpp:97
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_HS41.hpp:81
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition: ROL_HS41.hpp:114