ROL
ROL_HS14.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_HS14_HPP
17 #define ROL_HS14_HPP
18 
19 #include "ROL_StdVector.hpp"
20 #include "ROL_StdObjective.hpp"
21 #include "ROL_StdConstraint.hpp"
22 #include "ROL_TestProblem.hpp"
23 #include "ROL_Bounds.hpp"
25 #include "ROL_Types.hpp"
26 
27 namespace ROL {
28 namespace ZOO {
29 
36 template<class Real>
37 class Objective_HS14 : public StdObjective<Real> {
38 public:
39 
40  Real value( const std::vector<Real> &x, Real &tol ) {
41  const Real c1(1), c2(2);
42  return std::pow(x[0]-c2,c2) + std::pow(x[1]-c1,c2);
43  }
44 
45  void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
46  const Real c1(1), c2(2);
47  g[0] = c2*(x[0]-c2);
48  g[1] = c2*(x[1]-c1);
49  }
50 
51  void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
52  const Real c2(2);
53  hv[0] = c2*v[0];
54  hv[1] = c2*v[1];
55  }
56 };
57 
58 template<class Real>
59 class Constraint_HS14a : public StdConstraint<Real> {
60 public:
62 
63  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
64  const Real c1(1), c2(2);
65  c[0] = x[0] - c2*x[1] + c1;
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 c2(2);
71  jv[0] = v[0] - c2*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 c2(2);
77  ajv[0] = v[0];
78  ajv[1] = -c2*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 Constraint_HS14b : public StdConstraint<Real> {
90 public:
92 
93  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
94  const Real c0(0.25), c1(1), c2(2);
95  c[0] = -c0*std::pow(x[0],c2) - std::pow(x[1],c2) + c1;
96  }
97 
98  void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
99  const std::vector<Real> &x, Real &tol) {
100  const Real c0(0.25), c2(2);
101  jv[0] = -c0*c2*x[0]*v[0] - c2*x[1]*v[1];
102  }
103 
104  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
105  const std::vector<Real> &x, Real &tol ) {
106  const Real c0(0.25), c2(2);
107  ajv[0] = -c0*c2*x[0]*v[0];
108  ajv[1] = -c2*x[1]*v[0];
109  }
110 
111  void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
112  const std::vector<Real> &v, const std::vector<Real> &x,
113  Real &tol) {
114  const Real c0(0.25), c2(2);
115  ahuv[0] = -c0*c2*v[0]*u[0];
116  ahuv[1] = -c2*v[1]*u[0];
117  }
118 };
119 
120 template<class Real>
121 class getHS14 : public TestProblem<Real> {
122 public:
123  getHS14(void) {}
124 
125  Ptr<Objective<Real>> getObjective(void) const {
126  return ROL::makePtr<Objective_HS14<Real>>();
127  }
128 
129  Ptr<Vector<Real>> getInitialGuess(void) const {
130  int n = 2;
131  return ROL::makePtr<StdVector<Real>>(n,2.0);
132  }
133 
134  Ptr<Vector<Real>> getSolution(const int i = 0) const {
135  int n = 2;
136  ROL::Ptr<std::vector<Real> > xp = ROL::makePtr<std::vector<Real>>(n,0.0);
137  (*xp)[0] = static_cast<Real>(0.5 *(std::sqrt(7)-1));
138  (*xp)[1] = static_cast<Real>(0.25*(std::sqrt(7)+1));
139  return ROL::makePtr<StdVector<Real>>(xp);
140  }
141 
142  Ptr<Constraint<Real>> getEqualityConstraint(void) const {
143  return makePtr<Constraint_HS14a<Real>>();
144  }
145 
146  Ptr<Vector<Real>> getEqualityMultiplier(void) const {
147  return makePtr<StdVector<Real>>(1,0.0);
148  }
149 
150  Ptr<Constraint<Real>> getInequalityConstraint(void) const {
151  return makePtr<Constraint_HS14b<Real>>();
152  }
153 
154  Ptr<Vector<Real>> getInequalityMultiplier(void) const {
155  return makePtr<StdVector<Real>>(1,0.0);
156  }
157 
158  Ptr<BoundConstraint<Real>> getSlackBoundConstraint(void) const {
159  Ptr<Vector<Real>> lb = makePtr<StdVector<Real>>(1,0.0);
160  return makePtr<Bounds<Real>>(*lb,true);
161  }
162 };
163 
164 } // End ZOO Namespace
165 } // End ROL Namespace
166 
167 #endif
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_HS14.hpp:81
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:40
Contains definitions of custom data types in ROL.
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS14.hpp:125
Defines the equality constraint operator interface for StdVectors.
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:74
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:93
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:45
W. Hock and K. Schittkowski 14th test function.
Definition: ROL_HS14.hpp:37
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition: ROL_HS14.hpp:146
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector&#39;s.
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:51
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:98
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:68
Contains definitions of test objective functions.
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:104
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_HS14.hpp:111
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Definition: ROL_HS14.hpp:158
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition: ROL_HS14.hpp:142
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Definition: ROL_HS14.hpp:154
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS14.hpp:129
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS14.hpp:134
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Definition: ROL_HS14.hpp:150
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:63