ROL
ROL_HS29.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_HS29_HPP
16#define ROL_HS29_HPP
17
18#include "ROL_StdVector.hpp"
19#include "ROL_TestProblem.hpp"
20#include "ROL_Bounds.hpp"
21
22
23namespace ROL {
24namespace ZOO {
25
26template<class Real>
27class Objective_HS29 : public Objective<Real> {
28
29 typedef std::vector<Real> vector;
30 typedef Vector<Real> V;
32
33private:
34
35 Ptr<const vector> getVector( const V& x ) {
36
37 return dynamic_cast<const SV&>(x).getVector();
38 }
39
40 Ptr<vector> getVector( V& x ) {
41
42 return dynamic_cast<SV&>(x).getVector();
43 }
44
45public:
46
47 Real value( const Vector<Real> &x, Real &tol ) {
48
49
50 Ptr<const vector> xp = getVector(x);
51
52 return -(*xp)[0]*(*xp)[1]*(*xp)[2];
53
54 }
55
56 void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
57
58
59 Ptr<const vector> xp = getVector(x);
60 Ptr<vector> gp = getVector(g);
61
62 (*gp)[0] = -(*xp)[1]*(*xp)[2];
63 (*gp)[1] = -(*xp)[0]*(*xp)[2];
64 (*gp)[2] = -(*xp)[0]*(*xp)[1];
65
66 }
67
68 void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
69
70
71 Ptr<const vector> xp = getVector(x);
72 Ptr<const vector> vp = getVector(v);
73 Ptr<vector> hvp = getVector(hv);
74
75 (*hvp)[0] = -( (*xp)[2]*(*vp)[1] + (*xp)[1]*(*vp)[2] );
76 (*hvp)[1] = -( (*xp)[2]*(*vp)[0] + (*xp)[0]*(*vp)[2] );
77 (*hvp)[2] = -( (*xp)[1]*(*vp)[0] + (*xp)[0]*(*vp)[1] );
78
79 }
80
81}; // class Objective_HS29
82
83
84template<class Real>
86
87 typedef std::vector<Real> vector;
88 typedef Vector<Real> V;
90
91private:
92
93 Ptr<const vector> getVector( const V& x ) {
94
95 return dynamic_cast<const SV&>(x).getVector();
96 }
97
98 Ptr<vector> getVector( V& x ) {
99
100 return dynamic_cast<SV&>(x).getVector();
101 }
102
103public:
104
105 void value( Vector<Real> &c, const Vector<Real> &x, Real &tol ) {
106
107
108
109 Ptr<vector> cp = getVector(c);
110 Ptr<const vector> xp = getVector(x);
111
112 (*cp)[0] = -std::pow((*xp)[0],2) - 2*std::pow((*xp)[1],2) - 4*std::pow((*xp)[2],2) + 48;
113
114 }
115
117 const Vector<Real> &x, Real &tol ) {
118
119
120
121 Ptr<vector> jvp = getVector(jv);
122 Ptr<const vector> vp = getVector(v);
123 Ptr<const vector> xp = getVector(x);
124
125 (*jvp)[0] = -2*(*xp)[0]*(*vp)[0] - 4*(*xp)[1]*(*vp)[1] - 8*(*xp)[2]*(*vp)[2];
126
127 }
128
130 const Vector<Real> &x, Real &tol ) {
131
132
133
134 Ptr<vector> ajvp = getVector(ajv);
135 Ptr<const vector> vp = getVector(v);
136 Ptr<const vector> xp = getVector(x);
137
138 (*ajvp)[0] = -2*(*xp)[0]*(*vp)[0];
139 (*ajvp)[1] = -4*(*xp)[1]*(*vp)[0];
140 (*ajvp)[2] = -8*(*xp)[2]*(*vp)[0];
141
142 }
143
145 const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
146
147
148
149 Ptr<vector> ahuvp = getVector(ahuv);
150 Ptr<const vector> up = getVector(u);
151 Ptr<const vector> vp = getVector(v);
152 Ptr<const vector> xp = getVector(x);
153
154 (*ahuvp)[0] = -2*(*up)[0]*(*vp)[0];
155 (*ahuvp)[1] = -4*(*up)[0]*(*vp)[1];
156 (*ahuvp)[2] = -8*(*up)[0]*(*vp)[2];
157
158 }
159
160}; // class InequalityConstraint_HS29
161
162
163template<class Real>
164class getHS29 : public TestProblem<Real> {
165public:
166 getHS29(void) {}
167
168 Ptr<Objective<Real> > getObjective( void ) const {
169 return makePtr<Objective_HS29<Real>>();
170 }
171
172 Ptr<Constraint<Real> > getInequalityConstraint( void ) const {
173 return makePtr<InequalityConstraint_HS29<Real>>();
174 }
175
176 Ptr<BoundConstraint<Real> > getBoundConstraint( void ) const {
177 // No Lower bound
178 Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(3, ROL_NINF<Real>());
179
180 // No upper bound
181 Ptr<std::vector<Real> > up = makePtr<std::vector<Real>>(3, ROL_INF<Real>());
182
183 Ptr<Vector<Real> > l = makePtr<StdVector<Real>>(lp);
184 Ptr<Vector<Real> > u = makePtr<StdVector<Real>>(up);
185
186 return makePtr<Bounds<Real>>(l,u);
187 }
188
189 Ptr<Vector<Real> > getInitialGuess( void ) const {
190 Ptr<std::vector<Real> > x0p = makePtr<std::vector<Real>>(3);
191 (*x0p)[0] = 1.0;
192 (*x0p)[1] = 1.0;
193 (*x0p)[2] = 1.0;
194
195 return makePtr<StdVector<Real>>(x0p);
196 }
197
198 Ptr<Vector<Real> > getSolution( const int i = 0 ) const {
199 Ptr<std::vector<Real> > xp = makePtr<std::vector<Real>>(3);
200 if (i == 0) {
201 (*xp)[0] = 4.0;
202 (*xp)[1] = 2.0*std::sqrt(2.0);
203 (*xp)[2] = 2.0;
204 }
205 else if (i == 1) {
206 (*xp)[0] = 4.0;
207 (*xp)[1] = -2.0*std::sqrt(2.0);
208 (*xp)[2] = -2.0;
209 }
210 else if (i == 2) {
211 (*xp)[0] = -4.0;
212 (*xp)[1] = 2.0*std::sqrt(2.0);
213 (*xp)[2] = -2.0;
214 }
215 else if (i == 3) {
216 (*xp)[0] = -4.0;
217 (*xp)[1] = -2.0*std::sqrt(2.0);
218 (*xp)[2] = 2.0;
219 }
220 else {
221 throw Exception::NotImplemented(">>> ROL::HS29 : The index i must be between 0 and 3!");
222 }
223
224 return makePtr<StdVector<Real>>(xp);
225 }
226
227 int getNumSolutions(void) const {
228 return 4;
229 }
230
231 Ptr<Vector<Real> > getInequalityMultiplier( void ) const {
232 Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(1,0.0);
233 return makePtr<StdVector<Real>>(lp);
234 }
235
236 Ptr<BoundConstraint<Real>> getSlackBoundConstraint(void) const {
237 // Lower bound is zero
238 Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(1,0.0);
239
240 // No upper bound
241 Ptr<std::vector<Real> > up = makePtr<std::vector<Real>>(1,ROL_INF<Real>());
242
243 Ptr<Vector<Real> > l = makePtr<StdVector<Real>>(lp);
244 Ptr<Vector<Real> > u = makePtr<StdVector<Real>>(up);
245
246 return makePtr<Bounds<Real>>(l,u);
247 }
248};
249
250}
251} // namespace ROL
252
253
254#endif // ROL_HS29_HPP
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.
Ptr< const vector > getVector(const V &x)
Definition ROL_HS29.hpp:93
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Definition ROL_HS29.hpp:105
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
Definition ROL_HS29.hpp:116
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_HS29.hpp:129
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_HS29.hpp:144
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Definition ROL_HS29.hpp:56
std::vector< Real > vector
Definition ROL_HS29.hpp:29
Ptr< vector > getVector(V &x)
Definition ROL_HS29.hpp:40
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Definition ROL_HS29.hpp:47
StdVector< Real > SV
Definition ROL_HS29.hpp:31
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Definition ROL_HS29.hpp:68
Ptr< const vector > getVector(const V &x)
Definition ROL_HS29.hpp:35
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Definition ROL_HS29.hpp:236
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Definition ROL_HS29.hpp:231
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Definition ROL_HS29.hpp:172
Ptr< Objective< Real > > getObjective(void) const
Definition ROL_HS29.hpp:168
int getNumSolutions(void) const
Definition ROL_HS29.hpp:227
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition ROL_HS29.hpp:198
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition ROL_HS29.hpp:176
Ptr< Vector< Real > > getInitialGuess(void) const
Definition ROL_HS29.hpp:189