ROL
ROL_HS49.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_HS49_HPP
51 #define ROL_HS49_HPP
52 
53 #include "ROL_StdVector.hpp"
54 #include "ROL_TestProblem.hpp"
55 #include "ROL_Types.hpp"
56 #include "ROL_StdObjective.hpp"
57 #include "ROL_StdConstraint.hpp"
58 
59 namespace ROL {
60 namespace ZOO {
61 
68 template<class Real>
69 class Objective_HS49 : public StdObjective<Real> {
70 public:
71  Real value( const std::vector<Real> &x, Real &tol ) {
72  const Real c1(1), c2(2), c4(4), c6(6);
73  return std::pow(x[0]-x[1],c2) + std::pow(x[2]-c1,c2)
74  + std::pow(x[3]-c1,c4) + std::pow(x[4]-c1,c6);
75  }
76 
77  void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
78  const Real c1(1), c2(2), c3(3), c4(4), c5(5), c6(6);
79  g[0] = c2*(x[0]-x[1]);
80  g[1] = c2*(x[1]-x[0]);
81  g[2] = c2*(x[2]-c1);
82  g[3] = c4*std::pow(x[3]-c1,c3);
83  g[4] = c6*std::pow(x[4]-c1,c5);
84  }
85 
86  void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
87  const Real c1(1), c2(2), c3(3), c4(4), c5(5), c6(6);
88  hv[0] = c2*v[0] - c2*v[1];
89  hv[1] = c2*v[1] - c2*v[0];
90  hv[2] = c2*v[2];
91  hv[3] = c4*c3*std::pow(x[3]-c1,c2)*v[3];
92  hv[4] = c6*c5*std::pow(x[4]-c1,c4)*v[4];
93  }
94 };
95 
96 template<class Real>
97 class Constraint_HS49 : public StdConstraint<Real> {
98 public:
99  Constraint_HS49(void) {}
100 
101  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
102  const Real c4(4), c5(5), c6(6), c7(7);
103  c[0] = x[0]+x[1]+x[2]+c4*x[3]-c7;
104  c[1] = x[2]+c5*x[4]-c6;
105  }
106 
107  void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
108  const std::vector<Real> &x, Real &tol) {
109  const Real c4(4), c5(5);
110  jv[0] = v[0]+v[1]+v[2]+c4*v[3];
111  jv[1] = v[2]+c5*v[4];
112  }
113 
114  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
115  const std::vector<Real> &x, Real &tol ) {
116  const Real c4(4), c5(5);
117  ajv[0] = v[0];
118  ajv[1] = v[0];
119  ajv[2] = v[0] + v[1];
120  ajv[3] = c4*v[0];
121  ajv[4] = c5*v[1];
122  }
123 
124  void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
125  const std::vector<Real> &v, const std::vector<Real> &x,
126  Real &tol) {
127  ahuv.assign(ahuv.size(),static_cast<Real>(0));
128  }
129 
130 
131 };
132 
133 template<class Real>
134 class getHS49 : public TestProblem<Real> {
135 public:
136  getHS49(void) {}
137 
138  Ptr<Objective<Real>> getObjective(void) const {
139  return ROL::makePtr<Objective_HS49<Real>>();
140  }
141 
142  Ptr<Vector<Real>> getInitialGuess(void) const {
143  int n = 5;
144  ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n,0.0);
145  (*xp)[0] = static_cast<Real>(10);
146  (*xp)[1] = static_cast<Real>(7);
147  (*xp)[2] = static_cast<Real>(2);
148  (*xp)[3] = static_cast<Real>(-3);
149  (*xp)[4] = static_cast<Real>(0.8);
150  return ROL::makePtr<StdVector<Real>>(xp);
151  }
152 
153  Ptr<Vector<Real>> getSolution(const int i = 0) const {
154  int n = 5;
155  return ROL::makePtr<StdVector<Real>>(n,1.0);
156  }
157 
158  Ptr<Constraint<Real>> getEqualityConstraint(void) const {
159  return ROL::makePtr<Constraint_HS49<Real>>();
160  }
161 
162  Ptr<Vector<Real>> getEqualityMultiplier(void) const {
163  int n = 2;
164  return ROL::makePtr<StdVector<Real>>(n,0.0);
165  }
166 };
167 
168 } // End ZOO Namespace
169 } // End ROL Namespace
170 
171 #endif
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS49.hpp:77
Contains definitions of custom data types in ROL.
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_HS49.hpp:124
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS49.hpp:86
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS49.hpp:101
Defines the equality constraint operator interface for StdVectors.
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_HS49.hpp:71
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition: ROL_HS49.hpp:162
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector&#39;s.
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS49.hpp:107
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition: ROL_HS49.hpp:158
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS49.hpp:142
Contains definitions of test objective functions.
W. Hock and K. Schittkowski 49th test function.
Definition: ROL_HS49.hpp:69
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS49.hpp:153
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS49.hpp:114
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS49.hpp:138