ROL
ROL_HS39.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_HS39_HPP
17 #define ROL_HS39_HPP
18 
19 #include "ROL_StdVector.hpp"
20 #include "ROL_TestProblem.hpp"
21 #include "ROL_Bounds.hpp"
23 #include "ROL_Types.hpp"
24 
25 namespace ROL {
26 namespace ZOO {
27 
34 template<class Real>
35 class Objective_HS39 : public Objective<Real> {
36 
37  typedef std::vector<Real> vector;
38 
40 
41 
42 
43 public:
44 
45  Real value( const Vector<Real> &x, Real &tol ) {
46  ROL::Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
47  return -(*xp)[0];
48  }
49 
50  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
51  ROL::Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
52  ROL::Ptr<vector> gp = dynamic_cast<SV&>(g).getVector();
53 
54  (*gp)[0] = -1.0;
55  (*gp)[1] = 0.0;
56  (*gp)[2] = 0.0;
57  (*gp)[3] = 0.0;
58 
59  }
60 
61  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
62  hv.zero();
63  }
64 };
65 
66 // First of two equality constraints
67 template<class Real>
68 class Constraint_HS39a : public Constraint<Real> {
69 
70  typedef std::vector<Real> vector;
72 
73 public:
75 
76  void value( Vector<Real> &c, const Vector<Real> &x, Real &tol ) {
77 
78  ROL::Ptr<vector> cp = dynamic_cast<SV&>(c).getVector();
79  ROL::Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
80 
81  (*cp)[0] = (*xp)[1]-std::pow((*xp)[0],3)-std::pow((*xp)[2],2);
82  }
83 
85  const Vector<Real> &x, Real &tol) {
86 
87  ROL::Ptr<vector> jvp = dynamic_cast<SV&>(jv).getVector();
88  ROL::Ptr<const vector> vp = dynamic_cast<const SV&>(v).getVector();
89  ROL::Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
90 
91  (*jvp)[0] = (*vp)[1] - 3.0*(*xp)[0]*(*xp)[0]*(*vp)[0] - 2.0*(*xp)[2]*(*vp)[2];
92 
93  }
94 
96  const Vector<Real> &x, Real &tol ) {
97 
98  ROL::Ptr<vector> ajvp = dynamic_cast<SV&>(ajv).getVector();
99  ROL::Ptr<const vector> vp = dynamic_cast<const SV&>(v).getVector();
100  ROL::Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
101 
102  (*ajvp)[0] = -3.0*(*xp)[0]*(*xp)[0]*(*vp)[0];
103  (*ajvp)[1] = (*vp)[0];
104  (*ajvp)[2] = -2.0*(*xp)[2]*(*vp)[0];
105  (*ajvp)[3] = 0.0;
106  }
107 
109  const Vector<Real> &v, const Vector<Real> &x,
110  Real &tol) {
111 
112  ROL::Ptr<vector> ahuvp = dynamic_cast<SV&>(ahuv).getVector();
113  ROL::Ptr<const vector> up = dynamic_cast<const SV&>(u).getVector();
114  ROL::Ptr<const vector> vp = dynamic_cast<const SV&>(v).getVector();
115  ROL::Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
116 
117  (*ahuvp)[0] = -6.0*(*up)[0]*(*xp)[0]*(*vp)[0];
118  (*ahuvp)[1] = 0.0;
119  (*ahuvp)[2] = -2.0*(*up)[0]*(*vp)[2];
120  (*ahuvp)[3] = 0.0;
121 
122  }
123 
124 
125 };
126 
127 // Second of two equality constraints
128 template<class Real>
129 class Constraint_HS39b : public Constraint<Real> {
130 
131  typedef std::vector<Real> vector;
133 
134 public:
136 
137  void value( Vector<Real> &c, const Vector<Real> &x, Real &tol ) {
138  ROL::Ptr<vector> cp = dynamic_cast<SV&>(c).getVector();
139  ROL::Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
140 
141  (*cp)[0] = std::pow((*xp)[0],2)-(*xp)[1]-std::pow((*xp)[3],2);
142  }
143 
145  const Vector<Real> &x, Real &tol) {
146 
147  ROL::Ptr<vector> jvp = dynamic_cast<SV&>(jv).getVector();
148  ROL::Ptr<const vector> vp = dynamic_cast<const SV&>(v).getVector();
149  ROL::Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
150 
151  (*jvp)[0] = 2.0*(*xp)[0]*(*vp)[0] - (*vp)[1] - 2.0*(*xp)[3]*(*vp)[3];
152 
153  }
154 
156  const Vector<Real> &x, Real &tol ) {
157 
158  ROL::Ptr<vector> ajvp = dynamic_cast<SV&>(ajv).getVector();
159  ROL::Ptr<const vector> vp = dynamic_cast<const SV&>(v).getVector();
160  ROL::Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
161 
162  (*ajvp)[0] = 2.0*(*xp)[0]*(*vp)[0];
163  (*ajvp)[1] = -(*vp)[0];
164  (*ajvp)[2] = 0.0;
165  (*ajvp)[3] = -2.0*(*vp)[0]*(*xp)[3];
166  }
167 
169  const Vector<Real> &v, const Vector<Real> &x,
170  Real &tol) {
171 
172  ROL::Ptr<vector> ahuvp = dynamic_cast<SV&>(ahuv).getVector();
173  ROL::Ptr<const vector> up = dynamic_cast<const SV&>(u).getVector();
174  ROL::Ptr<const vector> vp = dynamic_cast<const SV&>(v).getVector();
175  ROL::Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
176 
177  // (*cp)[0] = std::pow((*xp)[0],2)-(*xp)[1]-std::pow((*xp)[3],2);
178 
179  (*ahuvp)[0] = 2.0*(*up)[0]*(*vp)[0];
180  (*ahuvp)[1] = 0.0;
181  (*ahuvp)[2] = 0.0;
182  (*ahuvp)[3] = -2.0*(*up)[0]*(*vp)[3];
183  }
184 
185 
186 };
187 
188 template<class Real>
189 class getHS39 : public TestProblem<Real> {
190 public:
191  getHS39(void) {}
192 
193  Ptr<Objective<Real>> getObjective(void) const {
194  // Instantiate Objective Function
195  return ROL::makePtr<Objective_HS39<Real>>();
196  }
197 
198  Ptr<Vector<Real>> getInitialGuess(void) const {
199  // Problem dimension
200  int n = 4;
201  // Get Initial Guess
202  ROL::Ptr<std::vector<Real> > x0p = ROL::makePtr<std::vector<Real>>(n,2.0);
203  return ROL::makePtr<StdVector<Real>>(x0p);
204  }
205 
206  Ptr<Vector<Real>> getSolution(const int i = 0) const {
207  // Problem dimension
208  int n = 4;
209  // Get Solution
210  ROL::Ptr<std::vector<Real> > xp = ROL::makePtr<std::vector<Real>>(n,0.0);
211  (*xp)[0] = static_cast<Real>(1);
212  (*xp)[1] = static_cast<Real>(1);
213  (*xp)[2] = static_cast<Real>(0);
214  (*xp)[3] = static_cast<Real>(0);
215  return ROL::makePtr<StdVector<Real>>(xp);
216  }
217 
218  Ptr<Constraint<Real>> getEqualityConstraint(void) const {
219  std::vector<Ptr<Constraint<Real>>> cvec(2);
220  cvec[0] = makePtr<Constraint_HS39a<Real>>();
221  cvec[1] = makePtr<Constraint_HS39b<Real>>();
222  return ROL::makePtr<Constraint_Partitioned<Real>>(cvec);
223  }
224 
225  Ptr<Vector<Real>> getEqualityMultiplier(void) const {
226  std::vector<Ptr<Vector<Real>>> lvec(2);
227  lvec[0] = makePtr<StdVector<Real>>(makePtr<std::vector<Real>>(1,0.0));
228  lvec[1] = makePtr<StdVector<Real>>(makePtr<std::vector<Real>>(1,0.0));
229  return ROL::makePtr<PartitionedVector<Real>>(lvec);
230  }
231 };
232 
233 
234 
235 } // End ZOO Namespace
236 } // End ROL Namespace
237 
238 #endif
Provides the interface to evaluate objective functions.
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
Definition: ROL_HS39.hpp:144
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_HS39.hpp:108
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Definition: ROL_HS39.hpp:61
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_HS39.hpp:95
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS39.hpp:206
Contains definitions of custom data types in ROL.
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS39.hpp:193
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:133
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
std::vector< Real > vector
Definition: ROL_HS39.hpp:37
std::vector< Real > vector
Definition: ROL_HS39.hpp:70
std::vector< Real > vector
Definition: ROL_HS39.hpp:131
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Definition: ROL_HS39.hpp:50
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS39.hpp:198
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_HS39.hpp:168
Contains definitions of test objective functions.
StdVector< Real > SV
Definition: ROL_HS39.hpp:39
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition: ROL_HS39.hpp:225
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Definition: ROL_HS39.hpp:137
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition: ROL_HS39.hpp:218
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Definition: ROL_HS39.hpp:76
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Definition: ROL_HS39.hpp:45
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_HS39.hpp:155
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
Definition: ROL_HS39.hpp:84
StdVector< Real > SV
Definition: ROL_HS39.hpp:71
Defines the general constraint operator interface.
StdVector< Real > SV
Definition: ROL_HS39.hpp:132
W. Hock and K. Schittkowski 39th test function.
Definition: ROL_HS39.hpp:35