ROL
ROL_HS49.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_HS49_HPP
17 #define ROL_HS49_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_HS49 : public StdObjective<Real> {
36 public:
37  Real value( const std::vector<Real> &x, Real &tol ) {
38  const Real c1(1), c2(2), c4(4), c6(6);
39  return std::pow(x[0]-x[1],c2) + std::pow(x[2]-c1,c2)
40  + std::pow(x[3]-c1,c4) + std::pow(x[4]-c1,c6);
41  }
42 
43  void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
44  const Real c1(1), c2(2), c3(3), c4(4), c5(5), c6(6);
45  g[0] = c2*(x[0]-x[1]);
46  g[1] = c2*(x[1]-x[0]);
47  g[2] = c2*(x[2]-c1);
48  g[3] = c4*std::pow(x[3]-c1,c3);
49  g[4] = c6*std::pow(x[4]-c1,c5);
50  }
51 
52  void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
53  const Real c1(1), c2(2), c3(3), c4(4), c5(5), c6(6);
54  hv[0] = c2*v[0] - c2*v[1];
55  hv[1] = c2*v[1] - c2*v[0];
56  hv[2] = c2*v[2];
57  hv[3] = c4*c3*std::pow(x[3]-c1,c2)*v[3];
58  hv[4] = c6*c5*std::pow(x[4]-c1,c4)*v[4];
59  }
60 };
61 
62 template<class Real>
63 class Constraint_HS49 : public StdConstraint<Real> {
64 public:
65  Constraint_HS49(void) {}
66 
67  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
68  const Real c4(4), c5(5), c6(6), c7(7);
69  c[0] = x[0]+x[1]+x[2]+c4*x[3]-c7;
70  c[1] = x[2]+c5*x[4]-c6;
71  }
72 
73  void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
74  const std::vector<Real> &x, Real &tol) {
75  const Real c4(4), c5(5);
76  jv[0] = v[0]+v[1]+v[2]+c4*v[3];
77  jv[1] = v[2]+c5*v[4];
78  }
79 
80  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
81  const std::vector<Real> &x, Real &tol ) {
82  const Real c4(4), c5(5);
83  ajv[0] = v[0];
84  ajv[1] = v[0];
85  ajv[2] = v[0] + v[1];
86  ajv[3] = c4*v[0];
87  ajv[4] = c5*v[1];
88  }
89 
90  void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
91  const std::vector<Real> &v, const std::vector<Real> &x,
92  Real &tol) {
93  ahuv.assign(ahuv.size(),static_cast<Real>(0));
94  }
95 
96 
97 };
98 
99 template<class Real>
100 class getHS49 : public TestProblem<Real> {
101 public:
102  getHS49(void) {}
103 
104  Ptr<Objective<Real>> getObjective(void) const {
105  return ROL::makePtr<Objective_HS49<Real>>();
106  }
107 
108  Ptr<Vector<Real>> getInitialGuess(void) const {
109  int n = 5;
110  ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n,0.0);
111  (*xp)[0] = static_cast<Real>(10);
112  (*xp)[1] = static_cast<Real>(7);
113  (*xp)[2] = static_cast<Real>(2);
114  (*xp)[3] = static_cast<Real>(-3);
115  (*xp)[4] = static_cast<Real>(0.8);
116  return ROL::makePtr<StdVector<Real>>(xp);
117  }
118 
119  Ptr<Vector<Real>> getSolution(const int i = 0) const {
120  int n = 5;
121  return ROL::makePtr<StdVector<Real>>(n,1.0);
122  }
123 
124  Ptr<Constraint<Real>> getEqualityConstraint(void) const {
125  return ROL::makePtr<Constraint_HS49<Real>>();
126  }
127 
128  Ptr<Vector<Real>> getEqualityMultiplier(void) const {
129  int n = 2;
130  return ROL::makePtr<StdVector<Real>>(n,0.0);
131  }
132 };
133 
134 } // End ZOO Namespace
135 } // End ROL Namespace
136 
137 #endif
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS49.hpp:43
Contains definitions of custom data types in ROL.
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_HS49.hpp:90
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS49.hpp:52
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS49.hpp:67
Defines the equality constraint operator interface for StdVectors.
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_HS49.hpp:37
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition: ROL_HS49.hpp:128
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector&#39;s.
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS49.hpp:73
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition: ROL_HS49.hpp:124
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS49.hpp:108
Contains definitions of test objective functions.
W. Hock and K. Schittkowski 49th test function.
Definition: ROL_HS49.hpp:35
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS49.hpp:119
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS49.hpp:80
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS49.hpp:104