ROL
ROL_HS21.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 
15 #ifndef ROL_HS21_HPP
16 #define ROL_HS21_HPP
17 
18 #include "ROL_StdObjective.hpp"
19 #include "ROL_StdConstraint.hpp"
20 #include "ROL_StdVector.hpp"
21 #include "ROL_TestProblem.hpp"
22 #include "ROL_Bounds.hpp"
23 
24 namespace ROL {
25 namespace ZOO {
26 
27 template<class Real>
28 class Objective_HS21 : public StdObjective<Real> {
29 public:
30  Real value( const std::vector<Real> &x, Real &tol ) {
31  const Real c1(0.1), c2(100);
32  return c1*x[0]*x[0] + x[1]*x[1] - c2;
33  }
34 
35  void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
36  const Real two(2), c1(0.1);
37  g[0] = two*c1*x[0];
38  g[1] = two*x[1];
39  }
40 
41  void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
42  const Real two(2), c1(0.1);
43  hv[0] = two*c1*v[0];
44  hv[1] = two*v[1];
45  }
46 }; // class Objective_HS21
47 
48 template<class Real>
49 class Constraint_HS21 : public StdConstraint<Real> {
50 public:
51  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
52  const Real c1(10);
53  c[0] = c1*x[0] - x[1] - c1;
54  }
55 
56  void applyJacobian( std::vector<Real> &jv, const std::vector<Real> &v,
57  const std::vector<Real> &x, Real &tol ) {
58  const Real c1(10);
59  jv[0] = c1*v[0] - v[1];
60  }
61 
62  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
63  const std::vector<Real> &x, Real &tol ) {
64  const Real c1(10);
65  ajv[0] = c1*v[0];
66  ajv[1] = -v[0];
67  }
68 
69  void applyAdjointHessian( std::vector<Real> &ahuv, const std::vector<Real> &u,
70  const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
71  ahuv.assign(ahuv.size(),static_cast<Real>(0));
72  }
73 }; // class Constraint_HS21
74 
75 template<class Real>
76 class getHS21 : public TestProblem<Real> {
77 public:
78  getHS21(void) {}
79 
80  Ptr<Objective<Real> > getObjective( void ) const {
81  return makePtr<Objective_HS21<Real>>();
82  }
83 
84  Ptr<Constraint<Real> > getInequalityConstraint( void ) const {
85  return makePtr<Constraint_HS21<Real>>();
86  }
87 
88  Ptr<BoundConstraint<Real>> getBoundConstraint( void ) const {
89  Ptr<std::vector<Real>> lp = makePtr<std::vector<Real>>(2,2.0);
90  (*lp)[1] = static_cast<Real>(-50);
91 
92  Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(lp);
93  Ptr<Vector<Real>> u = makePtr<StdVector<Real>>(2,50.0);
94 
95  return makePtr<Bounds<Real>>(l,u);
96  }
97 
98  Ptr<Vector<Real>> getInitialGuess( void ) const {
99  return makePtr<StdVector<Real>>(2,-1.0);
100  }
101 
102  Ptr<Vector<Real>> getSolution( const int i = 0 ) const {
103  Ptr<std::vector<Real> > xp = makePtr<std::vector<Real>>(2,0.0);
104  (*xp)[0] = static_cast<Real>(2);
105  return makePtr<StdVector<Real>>(xp);
106  }
107 
108  Ptr<Vector<Real>> getInequalityMultiplier( void ) const {
109  return makePtr<StdVector<Real>>(1,0.0);
110  }
111 
112  Ptr<BoundConstraint<Real>> getSlackBoundConstraint(void) const {
113  Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(1,0.0);
114  Ptr<Vector<Real>> u = makePtr<StdVector<Real>>(1,ROL_INF<Real>());
115  return makePtr<Bounds<Real>>(l,u);
116  }
117 };
118 
119 } // namespace ZOO
120 } // namespace ROL
121 
122 #endif // ROL_HS21_HPP
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS21.hpp:35
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS21.hpp:80
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS21.hpp:41
Defines the equality constraint operator interface for StdVectors.
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_HS21.hpp:30
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_HS21.hpp:69
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector&#39;s.
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Definition: ROL_HS21.hpp:84
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS21.hpp:62
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Definition: ROL_HS21.hpp:112
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS21.hpp:102
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition: ROL_HS21.hpp:88
Contains definitions of test objective functions.
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS21.hpp:56
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS21.hpp:98
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS21.hpp:51
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Definition: ROL_HS21.hpp:108