ROL
ROL_HS32.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_HS32_HPP
50 #define ROL_HS32_HPP
51 
52 #include "ROL_StdVector.hpp"
53 #include "ROL_Objective.hpp"
55 
56 
57 namespace ROL {
58 namespace ZOO {
59 
60 template<class Real>
61 class Objective_HS32 : public Objective<Real> {
62 
63  typedef std::vector<Real> vector;
64  typedef Vector<Real> V;
66 
67 private:
68 
69  Teuchos::RCP<const vector> getVector( const V& x ) {
70  using Teuchos::dyn_cast;
71  return dyn_cast<const SV>(x).getVector();
72  }
73 
74  Teuchos::RCP<vector> getVector( V& x ) {
75  using Teuchos::dyn_cast;
76  return dyn_cast<SV>(x).getVector();
77  }
78 
79 public:
80 
81  Real value( const Vector<Real> &x, Real &tol ) {
82 
83  using Teuchos::RCP;
84  RCP<const vector> xp = getVector(x);
85 
86  Real term1 = (*xp)[0]+3*(*xp)[1]+(*xp)[2];
87  Real term2 = (*xp)[0]-(*xp)[1];
88  return term1*term1 + 4*term2*term2;
89  }
90 
91  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
92 
93  using Teuchos::RCP;
94 
95  RCP<vector> gp = getVector(g);
96  RCP<const vector> xp = getVector(x);
97 
98  (*gp)[0] = 10*(*xp)[0] - 2*(*xp)[1] + 2*(*xp)[2];
99  (*gp)[1] = -2*(*xp)[0] + 26*(*xp)[1] + 6*(*xp)[2];
100  (*gp)[2] = 2*(*xp)[0] + 6*(*xp)[1] + 2*(*xp)[2];
101  }
102 
103  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
104 
105  using Teuchos::RCP;
106 
107  RCP<vector> hvp = getVector(hv);
108  RCP<const vector> vp = getVector(v);
109 
110  (*hvp)[0] = 10*(*vp)[0] - 2*(*vp)[1] + 2*(*vp)[2];
111  (*hvp)[1] = -2*(*vp)[0] + 26*(*vp)[1] + 6*(*vp)[2];
112  (*hvp)[2] = 2*(*vp)[0] + 6*(*vp)[1] + 2*(*vp)[2];
113 
114  }
115 
116 }; // class Objective_HS32
117 
118 
119 template<class Real>
121 
122  typedef std::vector<Real> vector;
123  typedef Vector<Real> V;
125 
126 private:
127 
128  Teuchos::RCP<const vector> getVector( const V& x ) {
129  using Teuchos::dyn_cast;
130  return dyn_cast<const SV>(x).getVector();
131  }
132 
133  Teuchos::RCP<vector> getVector( V& x ) {
134  using Teuchos::dyn_cast;
135  return dyn_cast<SV>(x).getVector();
136  }
137 
138 public:
139 
140  void value( Vector<Real> &c, const Vector<Real> &x, Real &tol ) {
141 
142  using Teuchos::RCP;
143  RCP<vector> cp = getVector(c);
144  RCP<const vector> xp = getVector(x);
145 
146  (*cp)[0] = 1.0 - (*xp)[0] - (*xp)[1] - (*xp)[2];
147  }
148 
150  const Vector<Real> &x, Real &tol ) {
151 
152  using Teuchos::RCP;
153  RCP<vector> jvp = getVector(jv);
154  RCP<const vector> vp = getVector(v);
155 
156  (*jvp)[0] = - (*vp)[0] - (*vp)[1] - (*vp)[2];
157 
158  }
159 
161  const Vector<Real> &x, Real &tol ) {
162 
163  using Teuchos::RCP;
164 
165  RCP<vector> ajvp = getVector(ajv);
166  RCP<const vector> vp = getVector(v);
167 
168  (*ajvp)[0] = -(*vp)[0];
169  (*ajvp)[1] = -(*vp)[0];
170  (*ajvp)[2] = -(*vp)[0];
171 
172  }
173 
175  const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
176  ahuv.zero();
177  }
178 
179 }; // class EqualityConstraint_HS32
180 
181 
182 template<class Real>
184 
185  typedef std::vector<Real> vector;
186  typedef Vector<Real> V;
188 
189 private:
190 
191  Teuchos::RCP<const vector> getVector( const V& x ) {
192  using Teuchos::dyn_cast;
193  return dyn_cast<const SV>(x).getVector();
194  }
195 
196  Teuchos::RCP<vector> getVector( V& x ) {
197  using Teuchos::dyn_cast;
198  return dyn_cast<SV>(x).getVector();
199  }
200 
201 public:
202 
203  void value( Vector<Real> &c, const Vector<Real> &x, Real &tol ) {
204 
205  using Teuchos::RCP;
206  RCP<vector> cp = getVector(c);
207  RCP<const vector> xp = getVector(x);
208 
209  (*cp)[0] = 6*(*xp)[1]+4*(*xp)[2]-std::pow((*xp)[0],3)-3.0;
210  (*cp)[1] = (*xp)[0];
211  (*cp)[2] = (*xp)[1];
212  (*cp)[3] = (*xp)[2];
213 
214  }
215 
217  const Vector<Real> &x, Real &tol ) {
218 
219  using Teuchos::RCP;
220  RCP<vector> jvp = getVector(jv);
221  RCP<const vector> vp = getVector(v);
222  RCP<const vector> xp = getVector(x);
223 
224  (*jvp)[0] = -3*(*xp)[0]*(*xp)[0]*(*vp)[0]+6*(*vp)[1]+4*(*vp)[2];
225  (*jvp)[1] = (*vp)[0];
226  (*jvp)[2] = (*vp)[1];
227  (*jvp)[3] = (*vp)[2];
228 
229  }
230 
232  const Vector<Real> &x, Real &tol ) {
233 
234  using Teuchos::RCP;
235  RCP<vector> ajvp = getVector(ajv);
236  RCP<const vector> vp = getVector(v);
237  RCP<const vector> xp = getVector(x);
238 
239  (*ajvp)[0] = -3*(*xp)[0]*(*xp)[0]*(*vp)[0] + (*vp)[1];
240  (*ajvp)[1] = 6*(*vp)[0] + (*vp)[2];
241  (*ajvp)[2] = 4*(*vp)[0] + (*vp)[3];
242 
243  }
244 
246  const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
247 
248  using Teuchos::RCP;
249  RCP<vector> ahuvp = getVector(ahuv);
250  RCP<const vector> up = getVector(u);
251  RCP<const vector> vp = getVector(v);
252  RCP<const vector> xp = getVector(x);
253 
254  (*ahuvp)[0] = -6*(*up)[0]*(*vp)[0]*(*xp)[0];
255  (*ahuvp)[1] = 0.0;
256  (*ahuvp)[2] = 0.0;
257 
258  }
259 
260 }; // class InequalityConstraint_HS32
261 
262 }
263 } // namespace ROL
264 
265 
266 #endif // ROL_HS32_HPP
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Definition: ROL_HS32.hpp:91
Provides the interface to evaluate objective functions.
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_HS32.hpp:231
std::vector< Real > vector
Definition: ROL_HS32.hpp:63
Vector< Real > V
Definition: ROL_HS32.hpp:64
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
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Definition: ROL_HS32.hpp:140
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
Definition: ROL_HS32.hpp:216
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Definition: ROL_HS32.hpp:103
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_HS32.hpp:160
Defines the equality constraint operator interface.
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Definition: ROL_HS32.hpp:203
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
Definition: ROL_HS32.hpp:149
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_HS32.hpp:174
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_HS32.hpp:245
StdVector< Real > SV
Definition: ROL_HS32.hpp:65
Teuchos::RCP< vector > getVector(V &x)
Definition: ROL_HS32.hpp:74
Teuchos::RCP< vector > getVector(V &x)
Definition: ROL_HS32.hpp:133
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Definition: ROL_HS32.hpp:81
Teuchos::RCP< const vector > getVector(const V &x)
Definition: ROL_HS32.hpp:128
Teuchos::RCP< const vector > getVector(const V &x)
Definition: ROL_HS32.hpp:191
Provides a unique argument for inequality constraints, which otherwise behave exactly as equality con...
Teuchos::RCP< vector > getVector(V &x)
Definition: ROL_HS32.hpp:196
std::vector< Real > vector
Definition: ROL_HS32.hpp:122
Teuchos::RCP< const vector > getVector(const V &x)
Definition: ROL_HS32.hpp:69