ROL
ROL_HS63.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_HS63_HPP
17 #define ROL_HS63_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 
32 template<class Real>
33 class Objective_HS63 : public StdObjective<Real> {
34 public:
35  Real value( const std::vector<Real> &x, Real &tol ) {
36  const Real c1(1000), c2(2);
37  return c1 - x[0]*x[0] - c2*x[1]*x[1] - x[2]*x[2] - x[0]*x[1] - x[0]*x[2];
38  }
39 
40  void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
41  const Real c2(2);
42  g[0] = -c2*x[0]-x[1]-x[2];
43  g[1] = -c2*c2*x[1]-x[0];
44  g[2] = -c2*x[2]-x[0];
45  }
46 
47  void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
48  const Real c2(2);
49  hv[0] = -c2*v[0]-v[1]-v[2];
50  hv[1] = -c2*c2*v[1]-v[0];
51  hv[2] = -c2*v[2]-v[0];
52  }
53 };
54 
55 template<class Real>
56 class Constraint_HS63a : public StdConstraint<Real> {
57 public:
58  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
59  const Real c1(8), c2(14), c3(7), c4(56);
60  c[0] = c1*x[0] + c2*x[1] + c3*x[2] - c4;
61  }
62 
63  void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
64  const std::vector<Real> &x, Real &tol) {
65  const Real c1(8), c2(14), c3(7);
66  jv[0] = c1*v[0] + c2*v[1] + c3*v[2];
67  }
68 
69  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
70  const std::vector<Real> &x, Real &tol ) {
71  const Real c1(8), c2(14), c3(7);
72  ajv[0] = c1*v[0];
73  ajv[1] = c2*v[0];
74  ajv[2] = c3*v[0];
75  }
76 
77  void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
78  const std::vector<Real> &v, const std::vector<Real> &x,
79  Real &tol) {
80  ahuv.assign(ahuv.size(),static_cast<Real>(0));
81  }
82 };
83 
84 template<class Real>
85 class Constraint_HS63b : public StdConstraint<Real> {
86 public:
87  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
88  const Real c1(25);
89  c[0] = x[0]*x[0] + x[1]*x[1] + x[2]*x[2] - c1;
90  }
91 
92  void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
93  const std::vector<Real> &x, Real &tol) {
94  const Real c1(2);
95  jv[0] = c1*(x[0]*v[0] + x[1]*v[1] + x[2]*v[2]);
96  }
97 
98  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
99  const std::vector<Real> &x, Real &tol ) {
100  const Real c1(2);
101  ajv[0] = c1*x[0]*v[0];
102  ajv[1] = c1*x[1]*v[0];
103  ajv[2] = c1*x[2]*v[0];
104  }
105 
106  void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
107  const std::vector<Real> &v, const std::vector<Real> &x,
108  Real &tol) {
109  const Real c1(2);
110  ahuv[0] = c1*v[0]*u[0];
111  ahuv[1] = c1*v[1]*u[0];
112  ahuv[2] = c1*v[2]*u[0];
113  }
114 };
115 
116 template<class Real>
117 class getHS63 : public TestProblem<Real> {
118 public:
119  getHS63(void) {}
120 
121  Ptr<Objective<Real>> getObjective(void) const {
122  return ROL::makePtr<Objective_HS63<Real>>();
123  }
124 
125  Ptr<Vector<Real>> getInitialGuess(void) const {
126  int n = 3;
127  return ROL::makePtr<StdVector<Real>>(n,static_cast<Real>(2));
128  }
129 
130  Ptr<Vector<Real>> getSolution(const int i = 0) const {
131  int n = 3;
132  ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n);
133  (*xp)[0] = static_cast<Real>(3.512118414);
134  (*xp)[1] = static_cast<Real>(0.2169881741);
135  (*xp)[2] = static_cast<Real>(3.552174034);
136  return ROL::makePtr<StdVector<Real>>(xp);
137  }
138 
139  Ptr<Constraint<Real>> getEqualityConstraint(void) const {
140  std::vector<Ptr<Constraint<Real>>> cvec(2);
141  cvec[0] = makePtr<Constraint_HS63a<Real>>();
142  cvec[1] = makePtr<Constraint_HS63b<Real>>();
143  return ROL::makePtr<Constraint_Partitioned<Real>>(cvec);
144  }
145 
146  Ptr<Vector<Real>> getEqualityMultiplier(void) const {
147  std::vector<Ptr<Vector<Real>>> lvec(2);
148  lvec[0] = makePtr<StdVector<Real>>(1,static_cast<Real>(0));
149  lvec[1] = makePtr<StdVector<Real>>(1,static_cast<Real>(0));
150  return ROL::makePtr<PartitionedVector<Real>>(lvec);
151  }
152 
153  Ptr<BoundConstraint<Real>> getBoundConstraint(void) const {
154  int n = 3;
155  Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(n,static_cast<Real>(0.0));
156  return makePtr<Bounds<Real>>(*l,true);
157  }
158 };
159 
160 } // End ZOO Namespace
161 } // End ROL Namespace
162 
163 #endif
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS63.hpp:130
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition: ROL_HS63.hpp:146
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS63.hpp:121
Contains definitions of custom data types in ROL.
Defines the equality constraint operator interface for StdVectors.
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS63.hpp:92
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS63.hpp:98
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector&#39;s.
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS63.hpp:40
Contains definitions of test objective functions.
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS63.hpp:47
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS63.hpp:58
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition: ROL_HS63.hpp:153
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_HS63.hpp:106
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS63.hpp:125
W. Hock and K. Schittkowski 63rd test function.
Definition: ROL_HS63.hpp:33
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS63.hpp:87
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS63.hpp:69
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition: ROL_HS63.hpp:139
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_HS63.hpp:35
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_HS63.hpp:77
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS63.hpp:63