ROL
ROL_HS39.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 
50 #ifndef ROL_HS39_HPP
51 #define ROL_HS39_HPP
52 
53 #include "ROL_StdVector.hpp"
54 #include "ROL_Objective.hpp"
56 #include "ROL_BoundConstraint.hpp"
57 #include "ROL_Types.hpp"
58 
59 namespace ROL {
60 namespace ZOO {
61 
68 template<class Real>
69 class Objective_HS39 : public Objective<Real> {
70 
71  typedef std::vector<Real> vector;
72 
74 
75 
76 
77 public:
78 
79  Real value( const Vector<Real> &x, Real &tol ) {
80  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
81  return -(*xp)[0];
82  }
83 
84  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
85  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
86  Teuchos::RCP<vector> gp = Teuchos::dyn_cast<SV>(g).getVector();
87 
88  (*gp)[0] = -1.0;
89  (*gp)[1] = 0.0;
90  (*gp)[2] = 0.0;
91  (*gp)[3] = 0.0;
92 
93  }
94 
95  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
96  hv.zero();
97  }
98 };
99 
100 // First of two equality constraints
101 template<class Real>
103 
104  typedef std::vector<Real> vector;
106 
107 public:
108 
109  void value( Vector<Real> &c, const Vector<Real> &x, Real &tol ) {
110 
111  Teuchos::RCP<vector> cp = Teuchos::dyn_cast<SV>(c).getVector();
112  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
113 
114  (*cp)[0] = (*xp)[1]-std::pow((*xp)[0],3)-std::pow((*xp)[2],2);
115  }
116 
118  const Vector<Real> &x, Real &tol) {
119 
120  Teuchos::RCP<vector> jvp = Teuchos::dyn_cast<SV>(jv).getVector();
121  Teuchos::RCP<const vector> vp = Teuchos::dyn_cast<const SV>(v).getVector();
122  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
123 
124  (*jvp)[0] = (*vp)[1] - 3.0*(*xp)[0]*(*xp)[0]*(*vp)[0] - 2.0*(*xp)[2]*(*vp)[2];
125 
126  }
127 
129  const Vector<Real> &x, Real &tol ) {
130 
131  Teuchos::RCP<vector> ajvp = Teuchos::dyn_cast<SV>(ajv).getVector();
132  Teuchos::RCP<const vector> vp = Teuchos::dyn_cast<const SV>(v).getVector();
133  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
134 
135  (*ajvp)[0] = -3.0*(*xp)[0]*(*xp)[0]*(*vp)[0];
136  (*ajvp)[1] = (*vp)[0];
137  (*ajvp)[2] = -2.0*(*xp)[2]*(*vp)[0];
138  (*ajvp)[3] = 0.0;
139  }
140 
142  const Vector<Real> &v, const Vector<Real> &x,
143  Real &tol) {
144 
145  Teuchos::RCP<vector> ahuvp = Teuchos::dyn_cast<SV>(ahuv).getVector();
146  Teuchos::RCP<const vector> up = Teuchos::dyn_cast<const SV>(u).getVector();
147  Teuchos::RCP<const vector> vp = Teuchos::dyn_cast<const SV>(v).getVector();
148  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
149 
150  (*ahuvp)[0] = -6.0*(*up)[0]*(*xp)[0]*(*vp)[0];
151  (*ahuvp)[1] = 0.0;
152  (*ahuvp)[2] = -2.0*(*up)[0]*(*vp)[2];
153  (*ahuvp)[3] = 0.0;
154 
155  }
156 
157 
158 };
159 
160 // Second of two equality constraints
161 template<class Real>
163 
164  typedef std::vector<Real> vector;
166 
167 public:
168 
169  void value( Vector<Real> &c, const Vector<Real> &x, Real &tol ) {
170  Teuchos::RCP<vector> cp = Teuchos::dyn_cast<SV>(c).getVector();
171  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
172 
173  (*cp)[0] = std::pow((*xp)[0],2)-(*xp)[1]-std::pow((*xp)[3],2);
174  }
175 
177  const Vector<Real> &x, Real &tol) {
178 
179  Teuchos::RCP<vector> jvp = Teuchos::dyn_cast<SV>(jv).getVector();
180  Teuchos::RCP<const vector> vp = Teuchos::dyn_cast<const SV>(v).getVector();
181  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
182 
183  (*jvp)[0] = 2.0*(*xp)[0]*(*vp)[0] - (*vp)[1] - 2.0*(*xp)[3]*(*vp)[3];
184 
185  }
186 
188  const Vector<Real> &x, Real &tol ) {
189 
190  Teuchos::RCP<vector> ajvp = Teuchos::dyn_cast<SV>(ajv).getVector();
191  Teuchos::RCP<const vector> vp = Teuchos::dyn_cast<const SV>(v).getVector();
192  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
193 
194  (*ajvp)[0] = 2.0*(*xp)[0]*(*vp)[0];
195  (*ajvp)[1] = -(*vp)[0];
196  (*ajvp)[2] = 0.0;
197  (*ajvp)[3] = -2.0*(*vp)[0]*(*xp)[3];
198  }
199 
201  const Vector<Real> &v, const Vector<Real> &x,
202  Real &tol) {
203 
204  Teuchos::RCP<vector> ahuvp = Teuchos::dyn_cast<SV>(ahuv).getVector();
205  Teuchos::RCP<const vector> up = Teuchos::dyn_cast<const SV>(u).getVector();
206  Teuchos::RCP<const vector> vp = Teuchos::dyn_cast<const SV>(v).getVector();
207  Teuchos::RCP<const vector> xp = Teuchos::dyn_cast<const SV>(x).getVector();
208 
209  // (*cp)[0] = std::pow((*xp)[0],2)-(*xp)[1]-std::pow((*xp)[3],2);
210 
211  (*ahuvp)[0] = 2.0*(*up)[0]*(*vp)[0];
212  (*ahuvp)[1] = 0.0;
213  (*ahuvp)[2] = 0.0;
214  (*ahuvp)[3] = -2.0*(*up)[0]*(*vp)[3];
215  }
216 
217 
218 };
219 
220 
221 
222 
223 } // End ZOO Namespace
224 } // End ROL Namespace
225 
226 #endif
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:176
Provides the interface to evaluate objective functions.
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Definition: ROL_HS39.hpp:95
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:200
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:141
Contains definitions of custom data types in ROL.
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
std::vector< Real > vector
Definition: ROL_HS39.hpp:71
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:128
Defines the equality constraint operator interface.
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Definition: ROL_HS39.hpp:109
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:187
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Definition: ROL_HS39.hpp:84
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:117
StdVector< Real > SV
Definition: ROL_HS39.hpp:73
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Definition: ROL_HS39.hpp:79
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Definition: ROL_HS39.hpp:169
W. Hock and K. Schittkowski 39th test function.
Definition: ROL_HS39.hpp:69