ROL
ROL_HS29.hpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Rapid Optimization Library (ROL) Package
5// Copyright (2014) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact lead developers:
38// Drew Kouri (dpkouri@sandia.gov) and
39// Denis Ridzal (dridzal@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
49#ifndef ROL_HS29_HPP
50#define ROL_HS29_HPP
51
52#include "ROL_StdVector.hpp"
53#include "ROL_TestProblem.hpp"
54#include "ROL_Bounds.hpp"
55
56
57namespace ROL {
58namespace ZOO {
59
60template<class Real>
61class Objective_HS29 : public Objective<Real> {
62
63 typedef std::vector<Real> vector;
64 typedef Vector<Real> V;
66
67private:
68
69 Ptr<const vector> getVector( const V& x ) {
70
71 return dynamic_cast<const SV&>(x).getVector();
72 }
73
74 Ptr<vector> getVector( V& x ) {
75
76 return dynamic_cast<SV&>(x).getVector();
77 }
78
79public:
80
81 Real value( const Vector<Real> &x, Real &tol ) {
82
83
84 Ptr<const vector> xp = getVector(x);
85
86 return -(*xp)[0]*(*xp)[1]*(*xp)[2];
87
88 }
89
90 void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
91
92
93 Ptr<const vector> xp = getVector(x);
94 Ptr<vector> gp = getVector(g);
95
96 (*gp)[0] = -(*xp)[1]*(*xp)[2];
97 (*gp)[1] = -(*xp)[0]*(*xp)[2];
98 (*gp)[2] = -(*xp)[0]*(*xp)[1];
99
100 }
101
102 void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
103
104
105 Ptr<const vector> xp = getVector(x);
106 Ptr<const vector> vp = getVector(v);
107 Ptr<vector> hvp = getVector(hv);
108
109 (*hvp)[0] = -( (*xp)[2]*(*vp)[1] + (*xp)[1]*(*vp)[2] );
110 (*hvp)[1] = -( (*xp)[2]*(*vp)[0] + (*xp)[0]*(*vp)[2] );
111 (*hvp)[2] = -( (*xp)[1]*(*vp)[0] + (*xp)[0]*(*vp)[1] );
112
113 }
114
115}; // class Objective_HS29
116
117
118template<class Real>
120
121 typedef std::vector<Real> vector;
124
125private:
126
127 Ptr<const vector> getVector( const V& x ) {
128
129 return dynamic_cast<const SV&>(x).getVector();
130 }
131
132 Ptr<vector> getVector( V& x ) {
133
134 return dynamic_cast<SV&>(x).getVector();
135 }
136
137public:
138
139 void value( Vector<Real> &c, const Vector<Real> &x, Real &tol ) {
140
141
142
143 Ptr<vector> cp = getVector(c);
144 Ptr<const vector> xp = getVector(x);
145
146 (*cp)[0] = -std::pow((*xp)[0],2) - 2*std::pow((*xp)[1],2) - 4*std::pow((*xp)[2],2) + 48;
147
148 }
149
151 const Vector<Real> &x, Real &tol ) {
152
153
154
155 Ptr<vector> jvp = getVector(jv);
156 Ptr<const vector> vp = getVector(v);
157 Ptr<const vector> xp = getVector(x);
158
159 (*jvp)[0] = -2*(*xp)[0]*(*vp)[0] - 4*(*xp)[1]*(*vp)[1] - 8*(*xp)[2]*(*vp)[2];
160
161 }
162
164 const Vector<Real> &x, Real &tol ) {
165
166
167
168 Ptr<vector> ajvp = getVector(ajv);
169 Ptr<const vector> vp = getVector(v);
170 Ptr<const vector> xp = getVector(x);
171
172 (*ajvp)[0] = -2*(*xp)[0]*(*vp)[0];
173 (*ajvp)[1] = -4*(*xp)[1]*(*vp)[0];
174 (*ajvp)[2] = -8*(*xp)[2]*(*vp)[0];
175
176 }
177
179 const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
180
181
182
183 Ptr<vector> ahuvp = getVector(ahuv);
184 Ptr<const vector> up = getVector(u);
185 Ptr<const vector> vp = getVector(v);
186 Ptr<const vector> xp = getVector(x);
187
188 (*ahuvp)[0] = -2*(*up)[0]*(*vp)[0];
189 (*ahuvp)[1] = -4*(*up)[0]*(*vp)[1];
190 (*ahuvp)[2] = -8*(*up)[0]*(*vp)[2];
191
192 }
193
194}; // class InequalityConstraint_HS29
195
196
197template<class Real>
198class getHS29 : public TestProblem<Real> {
199public:
200 getHS29(void) {}
201
202 Ptr<Objective<Real> > getObjective( void ) const {
203 return makePtr<Objective_HS29<Real>>();
204 }
205
206 Ptr<Constraint<Real> > getInequalityConstraint( void ) const {
207 return makePtr<InequalityConstraint_HS29<Real>>();
208 }
209
210 Ptr<BoundConstraint<Real> > getBoundConstraint( void ) const {
211 // No Lower bound
212 Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(3, ROL_NINF<Real>());
213
214 // No upper bound
215 Ptr<std::vector<Real> > up = makePtr<std::vector<Real>>(3, ROL_INF<Real>());
216
217 Ptr<Vector<Real> > l = makePtr<StdVector<Real>>(lp);
218 Ptr<Vector<Real> > u = makePtr<StdVector<Real>>(up);
219
220 return makePtr<Bounds<Real>>(l,u);
221 }
222
223 Ptr<Vector<Real> > getInitialGuess( void ) const {
224 Ptr<std::vector<Real> > x0p = makePtr<std::vector<Real>>(3);
225 (*x0p)[0] = 1.0;
226 (*x0p)[1] = 1.0;
227 (*x0p)[2] = 1.0;
228
229 return makePtr<StdVector<Real>>(x0p);
230 }
231
232 Ptr<Vector<Real> > getSolution( const int i = 0 ) const {
233 Ptr<std::vector<Real> > xp = makePtr<std::vector<Real>>(3);
234 if (i == 0) {
235 (*xp)[0] = 4.0;
236 (*xp)[1] = 2.0*std::sqrt(2.0);
237 (*xp)[2] = 2.0;
238 }
239 else if (i == 1) {
240 (*xp)[0] = 4.0;
241 (*xp)[1] = -2.0*std::sqrt(2.0);
242 (*xp)[2] = -2.0;
243 }
244 else if (i == 2) {
245 (*xp)[0] = -4.0;
246 (*xp)[1] = 2.0*std::sqrt(2.0);
247 (*xp)[2] = -2.0;
248 }
249 else if (i == 3) {
250 (*xp)[0] = -4.0;
251 (*xp)[1] = -2.0*std::sqrt(2.0);
252 (*xp)[2] = 2.0;
253 }
254 else {
255 throw Exception::NotImplemented(">>> ROL::HS29 : The index i must be between 0 and 3!");
256 }
257
258 return makePtr<StdVector<Real>>(xp);
259 }
260
261 int getNumSolutions(void) const {
262 return 4;
263 }
264
265 Ptr<Vector<Real> > getInequalityMultiplier( void ) const {
266 Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(1,0.0);
267 return makePtr<StdVector<Real>>(lp);
268 }
269
270 Ptr<BoundConstraint<Real>> getSlackBoundConstraint(void) const {
271 // Lower bound is zero
272 Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(1,0.0);
273
274 // No upper bound
275 Ptr<std::vector<Real> > up = makePtr<std::vector<Real>>(1,ROL_INF<Real>());
276
277 Ptr<Vector<Real> > l = makePtr<StdVector<Real>>(lp);
278 Ptr<Vector<Real> > u = makePtr<StdVector<Real>>(up);
279
280 return makePtr<Bounds<Real>>(l,u);
281 }
282};
283
284}
285} // namespace ROL
286
287
288#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:127
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Definition ROL_HS29.hpp:139
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:150
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:163
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:178
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Definition ROL_HS29.hpp:90
std::vector< Real > vector
Definition ROL_HS29.hpp:63
Ptr< vector > getVector(V &x)
Definition ROL_HS29.hpp:74
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Definition ROL_HS29.hpp:81
StdVector< Real > SV
Definition ROL_HS29.hpp:65
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Definition ROL_HS29.hpp:102
Ptr< const vector > getVector(const V &x)
Definition ROL_HS29.hpp:69
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Definition ROL_HS29.hpp:270
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Definition ROL_HS29.hpp:265
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Definition ROL_HS29.hpp:206
Ptr< Objective< Real > > getObjective(void) const
Definition ROL_HS29.hpp:202
int getNumSolutions(void) const
Definition ROL_HS29.hpp:261
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition ROL_HS29.hpp:232
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition ROL_HS29.hpp:210
Ptr< Vector< Real > > getInitialGuess(void) const
Definition ROL_HS29.hpp:223