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_Objective.hpp"
55 #include "ROL_BoundConstraint.hpp"
56 
57 namespace ROL {
58 namespace ZOO {
59 
60 template<class Real>
61 class Objective_HS24 : public Objective<Real> {
62 
63  typedef std::vector<Real> vector;
64  typedef Vector<Real> V;
66 
67 private:
68  const Real rt3_;
69 
70 public:
71 
72  Objective_HS24() : rt3_(std::sqrt(3)) {}
73 
74  Real value( const Vector<Real> &x, Real &tol ) {
75 
76  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
77 
78  return rt3_*(*xp)[0]*std::pow((*xp)[1],3)*((*xp)[0]-6)/81.0;
79  }
80 
81  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
82 
83  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
84 
85  Teuchos::RCP<vector> gp = Teuchos::dyn_cast<SV>(g).getVector();
86 
87  (*gp)[0] = 2*rt3_*std::pow((*xp)[1],3)*((*xp)[0]-3)/81.0;
88  (*gp)[1] = rt3_*(*xp)[0]*std::pow((*xp)[1],2)*((*xp)[0]-6)/27.0;
89 
90  }
91 
92 
93  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
94 
95  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
96  Teuchos::RCP<const vector> vp = Teuchos::dyn_cast<const SV>(v).getVector();
97  Teuchos::RCP<vector> hvp = Teuchos::dyn_cast<SV>(hv).getVector();
98 
99  Real a00 = pow((*xp)[1],3)/81.0;
100  Real a01 = pow((*xp)[1],2)*((*xp)[0]-3)/27.0;
101  Real a11 = (*xp)[1]*(std::pow((*xp)[0]-3,2)-9)/27.0;
102 
103  (*hvp)[0] = a00*(*vp)[0] + a01*(*vp)[1];
104  (*hvp)[1] = a01*(*vp)[0] + a11*(*vp)[1];
105  hv.scale(2*rt3_);
106 
107  }
108 }; // class Objective_HS24
109 
110 
111 template<class Real>
113 
114  typedef std::vector<Real> vector;
115  typedef Vector<Real> V;
117 
118 private:
119  const Real rt3_;
120 
121 public:
122  InequalityConstraint_HS24() : rt3_(std::sqrt(3)) {}
123 
124  void value( Vector<Real> &c, const Vector<Real> &x, Real &tol ) {
125 
126  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
127  Teuchos::RCP<vector> cp = Teuchos::dyn_cast<SV>(c).getVector();
128 
129  (*cp)[0] = (*xp)[0]/rt3_ - (*xp)[1];
130  (*cp)[1] = (*xp)[0] + rt3_*(*xp)[1];
131  (*cp)[2] = -(*xp)[0] - rt3_*(*xp)[1] + 6;
132 
133  }
134 
136  const Vector<Real> &x, Real &tol ) {
137 
138  Teuchos::RCP<const vector> vp = Teuchos::dyn_cast<const SV>(v).getVector();
139  Teuchos::RCP<vector> jvp = Teuchos::dyn_cast<SV>(jv).getVector();
140 
141  (*jvp)[0] = (*vp)[0]/rt3_ - (*vp)[1];
142  (*jvp)[1] = (*vp)[0] + rt3_*(*vp)[1];
143  (*jvp)[2] = -(*vp)[0] - rt3_*(*vp)[1];
144 
145 
146  }
147 
149  const Vector<Real> &x, Real &tol ) {
150 
151  Teuchos::RCP<const vector> vp = Teuchos::dyn_cast<const SV>(v).getVector();
152  Teuchos::RCP<vector> ajvp = Teuchos::dyn_cast<SV>(ajv).getVector();
153 
154  (*ajvp)[0] = rt3_*(*vp)[0]/3 + (*vp)[1] - (*vp)[2];
155  (*ajvp)[1] = -(*vp)[0] + rt3_*(*vp)[1] - rt3_*(*vp)[2];
156 
157  }
158 
159 
161  const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
162  ahuv.zero();
163  }
164 
165 }; // class InequalityConstraint_HS32
166 
167 
168 template<class Real>
169 Teuchos::RCP<Objective<Real> > getObjective_HS24( void ) {
170  return Teuchos::rcp( new Objective_HS24<Real>() );
171 }
172 
173 template<class Real>
174 Teuchos::RCP<InequalityConstraint<Real> > getInequalityConstraint_HS24( void ) {
175  return Teuchos::rcp( new InequalityConstraint_HS24<Real>() );
176 }
177 
178 
179 template<class Real>
180 Teuchos::RCP<BoundConstraint<Real> > getBoundConstraint_HS24( void ) {
181 
182  // Lower bound is zero
183  Teuchos::RCP<std::vector<Real> > lp = Teuchos::rcp( new std::vector<Real>(2,0.0) );
184 
185  // No upper bound
186  Teuchos::RCP<std::vector<Real> > up = Teuchos::rcp( new std::vector<Real>(2,ROL_INF) );
187 
188  Teuchos::RCP<Vector<Real> > l = Teuchos::rcp( new StdVector<Real>(lp) );
189  Teuchos::RCP<Vector<Real> > u = Teuchos::rcp( new StdVector<Real>(up) );
190 
191  return Teuchos::rcp( new BoundConstraint<Real>(l,u) );
192 
193 }
194 
195 template<class Real>
196 Teuchos::RCP<Vector<Real> > getInitialGuess_HS24( void ) {
197 
198  Teuchos::RCP<std::vector<Real> > x0p = Teuchos::rcp( new std::vector<Real>(2) );
199  (*x0p)[0] = 1.0;
200  (*x0p)[1] = 0.5;
201 
202  return Teuchos::rcp( new StdVector<Real>(x0p) );
203 }
204 
205 template<class Real>
206 Teuchos::RCP<Vector<Real> > getSolution_HS24( void ) {
207 
208  Teuchos::RCP<std::vector<Real> > xp = Teuchos::rcp( new std::vector<Real>(2) );
209  (*xp)[0] = 3.0;
210  (*xp)[1] = std::sqrt(3.0);
211 
212  return Teuchos::rcp( new StdVector<Real>(xp) );
213 }
214 
215 template<class Real>
216 Teuchos::RCP<Vector<Real> > getInequalityMultiplier_HS24( void ) {
217 
218  Teuchos::RCP<std::vector<Real> > lp = Teuchos::rcp( new std::vector<Real>(3,0.0) );
219  return Teuchos::rcp( new StdVector<Real>(lp) );
220 
221 }
222 
223 
224 
225 
226 } // namespace ZOO
227 } // namespace ROL
228 
229 #endif // ROL_HS24_HPP
230 
Provides the interface to evaluate objective functions.
virtual void scale(const Real alpha)=0
Compute where .
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Definition: ROL_HS24.hpp:93
Vector< Real > V
Definition: ROL_HS24.hpp:64
StdVector< Real > SV
Definition: ROL_HS24.hpp:65
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Definition: ROL_HS24.hpp:74
Teuchos::RCP< BoundConstraint< Real > > getBoundConstraint_HS24(void)
Definition: ROL_HS24.hpp:180
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:157
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
Teuchos::RCP< Vector< Real > > getSolution_HS24(void)
Definition: ROL_HS24.hpp:206
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:160
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:148
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:135
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Definition: ROL_HS24.hpp:81
Teuchos::RCP< Vector< Real > > getInitialGuess_HS24(void)
Definition: ROL_HS24.hpp:196
Provides the interface to apply upper and lower bound constraints.
static const double ROL_INF
Definition: ROL_Types.hpp:128
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Definition: ROL_HS24.hpp:124
Teuchos::RCP< Objective< Real > > getObjective_HS24(void)
Definition: ROL_HS24.hpp:169
std::vector< Real > vector
Definition: ROL_HS24.hpp:63
Provides a unique argument for inequality constraints, which otherwise behave exactly as equality con...
Teuchos::RCP< Vector< Real > > getInequalityMultiplier_HS24(void)
Definition: ROL_HS24.hpp:216
Teuchos::RCP< InequalityConstraint< Real > > getInequalityConstraint_HS24(void)
Definition: ROL_HS24.hpp:174