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