ROL
ROL_HS24.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_HS24_HPP
50 #define ROL_HS24_HPP
51 
52 #include "ROL_StdVector.hpp"
53 #include "ROL_TestProblem.hpp"
54 #include "ROL_Bounds.hpp"
55 
56 namespace ROL {
57 namespace ZOO {
58 
59 template<class Real>
60 class Objective_HS24 : public Objective<Real> {
61 
62  typedef std::vector<Real> vector;
63  typedef Vector<Real> V;
65 
66 private:
67  const Real rt3_;
68 
69 public:
70 
71  Objective_HS24() : rt3_(std::sqrt(3)) {}
72 
73  Real value( const Vector<Real> &x, Real &tol ) {
74 
75  Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
76 
77  return rt3_*(*xp)[0]*std::pow((*xp)[1],3)*((*xp)[0]-6)/81.0;
78  }
79 
80  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
81 
82  Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
83 
84  Ptr<vector> gp = dynamic_cast<SV&>(g).getVector();
85 
86  (*gp)[0] = 2*rt3_*std::pow((*xp)[1],3)*((*xp)[0]-3)/81.0;
87  (*gp)[1] = rt3_*(*xp)[0]*std::pow((*xp)[1],2)*((*xp)[0]-6)/27.0;
88 
89  }
90 
91 
92  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
93 
94  Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
95  Ptr<const vector> vp = dynamic_cast<const SV&>(v).getVector();
96  Ptr<vector> hvp = dynamic_cast<SV&>(hv).getVector();
97 
98  Real a00 = pow((*xp)[1],3)/81.0;
99  Real a01 = pow((*xp)[1],2)*((*xp)[0]-3)/27.0;
100  Real a11 = (*xp)[1]*(std::pow((*xp)[0]-3,2)-9)/27.0;
101 
102  (*hvp)[0] = a00*(*vp)[0] + a01*(*vp)[1];
103  (*hvp)[1] = a01*(*vp)[0] + a11*(*vp)[1];
104  hv.scale(2*rt3_);
105 
106  }
107 }; // class Objective_HS24
108 
109 
110 template<class Real>
111 class Constraint_HS24 : public Constraint<Real> {
112 
113  typedef std::vector<Real> vector;
114  typedef Vector<Real> V;
116 
117 private:
118  const Real rt3_;
119 
120 public:
121  Constraint_HS24() : rt3_(std::sqrt(3)) {}
122 
123  void value( Vector<Real> &c, const Vector<Real> &x, Real &tol ) {
124 
125  Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
126  Ptr<vector> cp = dynamic_cast<SV&>(c).getVector();
127 
128  (*cp)[0] = (*xp)[0]/rt3_ - (*xp)[1];
129  (*cp)[1] = (*xp)[0] + rt3_*(*xp)[1];
130  (*cp)[2] = -(*xp)[0] - rt3_*(*xp)[1] + 6;
131 
132  }
133 
135  const Vector<Real> &x, Real &tol ) {
136 
137  Ptr<const vector> vp = dynamic_cast<const SV&>(v).getVector();
138  Ptr<vector> jvp = dynamic_cast<SV&>(jv).getVector();
139 
140  (*jvp)[0] = (*vp)[0]/rt3_ - (*vp)[1];
141  (*jvp)[1] = (*vp)[0] + rt3_*(*vp)[1];
142  (*jvp)[2] = -(*vp)[0] - rt3_*(*vp)[1];
143 
144 
145  }
146 
148  const Vector<Real> &x, Real &tol ) {
149 
150  Ptr<const vector> vp = dynamic_cast<const SV&>(v).getVector();
151  Ptr<vector> ajvp = dynamic_cast<SV&>(ajv).getVector();
152 
153  (*ajvp)[0] = rt3_*(*vp)[0]/3 + (*vp)[1] - (*vp)[2];
154  (*ajvp)[1] = -(*vp)[0] + rt3_*(*vp)[1] - rt3_*(*vp)[2];
155 
156  }
157 
158 
160  const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
161  ahuv.zero();
162  }
163 
164 }; // class Constraint_HS24
165 
166 
167 
168 template<class Real>
169 class getHS24 : public TestProblem<Real> {
170 public:
171  getHS24(void) {}
172 
173  Ptr<Objective<Real> > getObjective( void ) const {
174  return makePtr<Objective_HS24<Real>>();
175  }
176 
177  Ptr<Constraint<Real> > getInequalityConstraint( void ) const {
178  return makePtr<Constraint_HS24<Real>>();
179  }
180 
181  Ptr<BoundConstraint<Real>> getBoundConstraint( void ) const {
182  // Lower bound is zero
183  Ptr<std::vector<Real>> lp = makePtr<std::vector<Real>>(2,0.0);
184 
185  // No upper bound
186  Ptr<std::vector<Real>> up = makePtr<std::vector<Real>>(2,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  Ptr<Vector<Real>> getInitialGuess( void ) const {
195  Ptr<std::vector<Real> > x0p = makePtr<std::vector<Real>>(2);
196  (*x0p)[0] = 1.0;
197  (*x0p)[1] = 0.5;
198 
199  return makePtr<StdVector<Real>>(x0p);
200  }
201 
202  Ptr<Vector<Real>> getSolution( const int i = 0 ) const {
203  Ptr<std::vector<Real> > xp = makePtr<std::vector<Real>>(2);
204  (*xp)[0] = 3.0;
205  (*xp)[1] = std::sqrt(3.0);
206 
207  return makePtr<StdVector<Real>>(xp);
208  }
209 
210  Ptr<Vector<Real>> getInequalityMultiplier( void ) const {
211  Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(3,0.0);
212  return makePtr<StdVector<Real>>(lp);
213  }
214 
215  Ptr<BoundConstraint<Real>> getSlackBoundConstraint(void) const {
216  // Lower bound is zero
217  Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(3,0.0);
218 
219  // No upper bound
220  Ptr<std::vector<Real> > up = makePtr<std::vector<Real>>(3,ROL_INF<Real>());
221 
222  Ptr<Vector<Real> > l = makePtr<StdVector<Real>>(lp);
223  Ptr<Vector<Real> > u = makePtr<StdVector<Real>>(up);
224 
225  return makePtr<Bounds<Real>>(l,u);
226  }
227 };
228 
229 
230 } // namespace ZOO
231 } // namespace ROL
232 
233 #endif // ROL_HS24_HPP
234 
Provides the interface to evaluate objective functions.
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS24.hpp:194
virtual void scale(const Real alpha)=0
Compute where .
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Definition: ROL_HS24.hpp:177
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Definition: ROL_HS24.hpp:92
Vector< Real > V
Definition: ROL_HS24.hpp:63
StdVector< Real > SV
Definition: ROL_HS24.hpp:64
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Definition: ROL_HS24.hpp:73
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Definition: ROL_HS24.hpp:123
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:167
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Definition: ROL_HS24.hpp:210
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:159
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Definition: ROL_HS24.hpp:80
Contains definitions of test 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_HS24.hpp:134
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition: ROL_HS24.hpp:181
std::vector< Real > vector
Definition: ROL_HS24.hpp:113
std::vector< Real > vector
Definition: ROL_HS24.hpp:62
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS24.hpp:173
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS24.hpp:202
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:147
Defines the general constraint operator interface.
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Definition: ROL_HS24.hpp:215
StdVector< Real > SV
Definition: ROL_HS24.hpp:115