ROL
ROL_HS24.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_HS24_HPP
16#define ROL_HS24_HPP
17
18#include "ROL_StdVector.hpp"
19#include "ROL_TestProblem.hpp"
20#include "ROL_Bounds.hpp"
21
22namespace ROL {
23namespace ZOO {
24
25template<class Real>
26class Objective_HS24 : public Objective<Real> {
27
28 typedef std::vector<Real> vector;
29 typedef Vector<Real> V;
31
32private:
33 const Real rt3_;
34
35public:
36
37 Objective_HS24() : rt3_(std::sqrt(3)) {}
38
39 Real value( const Vector<Real> &x, Real &tol ) {
40
41 Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
42
43 return rt3_*(*xp)[0]*std::pow((*xp)[1],3)*((*xp)[0]-6)/81.0;
44 }
45
46 void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
47
48 Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
49
50 Ptr<vector> gp = dynamic_cast<SV&>(g).getVector();
51
52 (*gp)[0] = 2*rt3_*std::pow((*xp)[1],3)*((*xp)[0]-3)/81.0;
53 (*gp)[1] = rt3_*(*xp)[0]*std::pow((*xp)[1],2)*((*xp)[0]-6)/27.0;
54
55 }
56
57
58 void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
59
60 Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
61 Ptr<const vector> vp = dynamic_cast<const SV&>(v).getVector();
62 Ptr<vector> hvp = dynamic_cast<SV&>(hv).getVector();
63
64 Real a00 = pow((*xp)[1],3)/81.0;
65 Real a01 = pow((*xp)[1],2)*((*xp)[0]-3)/27.0;
66 Real a11 = (*xp)[1]*(std::pow((*xp)[0]-3,2)-9)/27.0;
67
68 (*hvp)[0] = a00*(*vp)[0] + a01*(*vp)[1];
69 (*hvp)[1] = a01*(*vp)[0] + a11*(*vp)[1];
70 hv.scale(2*rt3_);
71
72 }
73}; // class Objective_HS24
74
75
76template<class Real>
77class Constraint_HS24 : public Constraint<Real> {
78
79 typedef std::vector<Real> vector;
80 typedef Vector<Real> V;
82
83private:
84 const Real rt3_;
85
86public:
87 Constraint_HS24() : rt3_(std::sqrt(3)) {}
88
89 void value( Vector<Real> &c, const Vector<Real> &x, Real &tol ) {
90
91 Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
92 Ptr<vector> cp = dynamic_cast<SV&>(c).getVector();
93
94 (*cp)[0] = (*xp)[0]/rt3_ - (*xp)[1];
95 (*cp)[1] = (*xp)[0] + rt3_*(*xp)[1];
96 (*cp)[2] = -(*xp)[0] - rt3_*(*xp)[1] + 6;
97
98 }
99
101 const Vector<Real> &x, Real &tol ) {
102
103 Ptr<const vector> vp = dynamic_cast<const SV&>(v).getVector();
104 Ptr<vector> jvp = dynamic_cast<SV&>(jv).getVector();
105
106 (*jvp)[0] = (*vp)[0]/rt3_ - (*vp)[1];
107 (*jvp)[1] = (*vp)[0] + rt3_*(*vp)[1];
108 (*jvp)[2] = -(*vp)[0] - rt3_*(*vp)[1];
109
110
111 }
112
114 const Vector<Real> &x, Real &tol ) {
115
116 Ptr<const vector> vp = dynamic_cast<const SV&>(v).getVector();
117 Ptr<vector> ajvp = dynamic_cast<SV&>(ajv).getVector();
118
119 (*ajvp)[0] = rt3_*(*vp)[0]/3 + (*vp)[1] - (*vp)[2];
120 (*ajvp)[1] = -(*vp)[0] + rt3_*(*vp)[1] - rt3_*(*vp)[2];
121
122 }
123
124
126 const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
127 ahuv.zero();
128 }
129
130}; // class Constraint_HS24
131
132
133
134template<class Real>
135class getHS24 : public TestProblem<Real> {
136public:
137 getHS24(void) {}
138
139 Ptr<Objective<Real> > getObjective( void ) const {
140 return makePtr<Objective_HS24<Real>>();
141 }
142
143 Ptr<Constraint<Real> > getInequalityConstraint( void ) const {
144 return makePtr<Constraint_HS24<Real>>();
145 }
146
147 Ptr<BoundConstraint<Real>> getBoundConstraint( void ) const {
148 // Lower bound is zero
149 Ptr<std::vector<Real>> lp = makePtr<std::vector<Real>>(2,0.0);
150
151 // No upper bound
152 Ptr<std::vector<Real>> up = makePtr<std::vector<Real>>(2,ROL_INF<Real>());
153
154 Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(lp);
155 Ptr<Vector<Real>> u = makePtr<StdVector<Real>>(up);
156
157 return makePtr<Bounds<Real>>(l,u);
158 }
159
160 Ptr<Vector<Real>> getInitialGuess( void ) const {
161 Ptr<std::vector<Real> > x0p = makePtr<std::vector<Real>>(2);
162 (*x0p)[0] = 1.0;
163 (*x0p)[1] = 0.5;
164
165 return makePtr<StdVector<Real>>(x0p);
166 }
167
168 Ptr<Vector<Real>> getSolution( const int i = 0 ) const {
169 Ptr<std::vector<Real> > xp = makePtr<std::vector<Real>>(2);
170 (*xp)[0] = 3.0;
171 (*xp)[1] = std::sqrt(3.0);
172
173 return makePtr<StdVector<Real>>(xp);
174 }
175
176 Ptr<Vector<Real>> getInequalityMultiplier( void ) const {
177 Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(3,0.0);
178 return makePtr<StdVector<Real>>(lp);
179 }
180
181 Ptr<BoundConstraint<Real>> getSlackBoundConstraint(void) const {
182 // Lower bound is zero
183 Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(3,0.0);
184
185 // No upper bound
186 Ptr<std::vector<Real> > up = makePtr<std::vector<Real>>(3,ROL_INF<Real>());
187
188 Ptr<Vector<Real> > l = makePtr<StdVector<Real>>(lp);
189 Ptr<Vector<Real> > u = makePtr<StdVector<Real>>(up);
190
191 return makePtr<Bounds<Real>>(l,u);
192 }
193};
194
195
196} // namespace ZOO
197} // namespace ROL
198
199#endif // ROL_HS24_HPP
200
Contains definitions of test objective functions.
Defines the general constraint operator interface.
Provides the interface to evaluate objective functions.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Defines the linear algebra or vector space interface.
virtual void scale(const Real alpha)=0
Compute where .
virtual void zero()
Set to zero vector.
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
Definition ROL_HS24.hpp:100
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Definition ROL_HS24.hpp:89
void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the adjoint of the the constraint Jacobian at , , to vector .
Definition ROL_HS24.hpp:113
StdVector< Real > SV
Definition ROL_HS24.hpp:81
std::vector< Real > vector
Definition ROL_HS24.hpp:79
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ,...
Definition ROL_HS24.hpp:125
std::vector< Real > vector
Definition ROL_HS24.hpp:28
StdVector< Real > SV
Definition ROL_HS24.hpp:30
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Definition ROL_HS24.hpp:46
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Definition ROL_HS24.hpp:39
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Definition ROL_HS24.hpp:58
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Definition ROL_HS24.hpp:181
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Definition ROL_HS24.hpp:143
Ptr< Vector< Real > > getInitialGuess(void) const
Definition ROL_HS24.hpp:160
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Definition ROL_HS24.hpp:176
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition ROL_HS24.hpp:168
Ptr< Objective< Real > > getObjective(void) const
Definition ROL_HS24.hpp:139
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition ROL_HS24.hpp:147