ROL
ROL_HS42.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2042) 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_HS42_HPP
51 #define ROL_HS42_HPP
52 
53 #include "ROL_StdVector.hpp"
54 #include "ROL_StdObjective.hpp"
55 #include "ROL_StdConstraint.hpp"
56 #include "ROL_TestProblem.hpp"
57 #include "ROL_Bounds.hpp"
59 #include "ROL_Types.hpp"
60 
61 namespace ROL {
62 namespace ZOO {
63 
70 template<class Real>
71 class Objective_HS42 : public StdObjective<Real> {
72 public:
73 
74  Real value( const std::vector<Real> &x, Real &tol ) {
75  const Real c1(1), c2(2), c3(3), c4(4);
76  return std::pow(x[0]-c1,c2) + std::pow(x[1]-c2,c2)
77  + std::pow(x[2]-c3,c2) + std::pow(x[3]-c4,c2);
78  }
79 
80  void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
81  const Real c1(1), c2(2), c3(3), c4(4);
82  g[0] = c2*(x[0]-c1);
83  g[1] = c2*(x[1]-c2);
84  g[2] = c2*(x[2]-c3);
85  g[3] = c2*(x[3]-c4);
86  }
87 
88  void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
89  const Real c2(2);
90  hv[0] = c2*v[0];
91  hv[1] = c2*v[1];
92  hv[2] = c2*v[2];
93  hv[3] = c2*v[3];
94  }
95 };
96 
97 template<class Real>
98 class Constraint_HS42a : public StdConstraint<Real> {
99 public:
101 
102  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
103  const Real c2(2);
104  c[0] = x[0] - c2;
105  }
106 
107  void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
108  const std::vector<Real> &x, Real &tol) {
109  jv[0] = v[0];
110  }
111 
112  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
113  const std::vector<Real> &x, Real &tol ) {
114  ajv[0] = v[0];
115  ajv[1] = static_cast<Real>(0);
116  ajv[2] = static_cast<Real>(0);
117  ajv[3] = static_cast<Real>(0);
118  }
119 
120  void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
121  const std::vector<Real> &v, const std::vector<Real> &x,
122  Real &tol) {
123  ahuv.assign(ahuv.size(),static_cast<Real>(0));
124  }
125 };
126 
127 template<class Real>
128 class Constraint_HS42b : public StdConstraint<Real> {
129 public:
131 
132  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
133  const Real c2(2);
134  c[0] = std::pow(x[2],c2) + std::pow(x[3],c2) - c2;
135  }
136 
137  void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
138  const std::vector<Real> &x, Real &tol) {
139  const Real c2(2);
140  jv[0] = c2*x[2]*v[2] + c2*x[3]*v[3];
141  }
142 
143  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
144  const std::vector<Real> &x, Real &tol ) {
145  const Real c2(2);
146  ajv[0] = static_cast<Real>(0);
147  ajv[1] = static_cast<Real>(0);
148  ajv[2] = c2*x[2]*v[0];
149  ajv[3] = c2*x[3]*v[0];
150  }
151 
152  void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
153  const std::vector<Real> &v, const std::vector<Real> &x,
154  Real &tol) {
155  const Real c2(2);
156  ahuv[0] = static_cast<Real>(0);
157  ahuv[1] = static_cast<Real>(0);
158  ahuv[2] = c2*v[2]*u[0];
159  ahuv[3] = c2*v[3]*u[0];
160  }
161 };
162 
163 template<class Real>
164 class getHS42 : public TestProblem<Real> {
165 public:
166  getHS42(void) {}
167 
168  Ptr<Objective<Real>> getObjective(void) const {
169  return ROL::makePtr<Objective_HS42<Real>>();
170  }
171 
172  Ptr<Vector<Real>> getInitialGuess(void) const {
173  int n = 4;
174  return ROL::makePtr<StdVector<Real>>(n,1.0);
175  }
176 
177  Ptr<Vector<Real>> getSolution(const int i = 0) const {
178  int n = 4;
179  ROL::Ptr<std::vector<Real> > xp = ROL::makePtr<std::vector<Real>>(n,0.0);
180  (*xp)[0] = static_cast<Real>(2);
181  (*xp)[1] = static_cast<Real>(2);
182  (*xp)[2] = static_cast<Real>(0.6*std::sqrt(2));
183  (*xp)[3] = static_cast<Real>(0.8*std::sqrt(2));
184  return ROL::makePtr<StdVector<Real>>(xp);
185  }
186 
187  Ptr<Constraint<Real>> getEqualityConstraint(void) const {
188  std::vector<Ptr<Constraint<Real>>> cvec(2);
189  cvec[0] = makePtr<Constraint_HS42a<Real>>();
190  cvec[1] = makePtr<Constraint_HS42b<Real>>();
191  return ROL::makePtr<Constraint_Partitioned<Real>>(cvec);
192  }
193 
194  Ptr<Vector<Real>> getEqualityMultiplier(void) const {
195  std::vector<Ptr<Vector<Real>>> lvec(2);
196  lvec[0] = makePtr<StdVector<Real>>(makePtr<std::vector<Real>>(1,0.0));
197  lvec[1] = makePtr<StdVector<Real>>(makePtr<std::vector<Real>>(1,0.0));
198  return ROL::makePtr<PartitionedVector<Real>>(lvec);
199  }
200 };
201 
202 } // End ZOO Namespace
203 } // End ROL Namespace
204 
205 #endif
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_HS42.hpp:74
W. Hock and K. Schittkowski 42th test function.
Definition: ROL_HS42.hpp:71
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS42.hpp:177
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS42.hpp:137
Contains definitions of custom data types in ROL.
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS42.hpp:107
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition: ROL_HS42.hpp:187
Defines the equality constraint operator interface for StdVectors.
void applyAdjointHessian(std::vector< Real > &ahuv, const std::vector< Real > &u, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS42.hpp:120
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS42.hpp:112
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector&#39;s.
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS42.hpp:102
Contains definitions of test objective functions.
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition: ROL_HS42.hpp:194
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS42.hpp:88
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS42.hpp:172
void applyAdjointHessian(std::vector< Real > &ahuv, const std::vector< Real > &u, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS42.hpp:152
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS42.hpp:132
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS42.hpp:143
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS42.hpp:168
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS42.hpp:80