ROL
ROL_HS9.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_HS9_HPP
51 #define ROL_HS9_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_HS9 : public StdObjective<Real> {
70 public:
71  Real value( const std::vector<Real> &x, Real &tol ) {
72  const Real pi(M_PI), c12(12), c16(16);
73  return std::sin(x[0]*pi/c12)*std::cos(x[1]*pi/c16);
74  }
75 
76  void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
77  const Real pi(M_PI), c12(12), c16(16);
78  g[0] = pi/c12*std::cos(x[0]*pi/c12)*std::cos(x[1]*pi/c16);
79  g[1] = -pi/c16*std::sin(x[0]*pi/c12)*std::sin(x[1]*pi/c16);
80  }
81 
82  void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
83  const Real pi(M_PI), c12(12), c16(16);
84  Real h11 = -pi/c12*pi/c12*std::sin(x[0]*pi/c12)*std::cos(x[1]*pi/c16);
85  Real h12 = -pi/c12*pi/c16*std::cos(x[0]*pi/c12)*std::sin(x[1]*pi/c16);
86  Real h22 = -pi/c16*pi/c16*std::sin(x[0]*pi/c12)*std::cos(x[1]*pi/c16);
87  hv[0] = h11*v[0] + h12*v[1];
88  hv[1] = h12*v[0] + h22*v[1];
89  }
90 };
91 
92 template<class Real>
93 class Constraint_HS9 : public StdConstraint<Real> {
94 public:
95  Constraint_HS9(void) {}
96 
97  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
98  const Real c3(3), c4(4);
99  c[0] = c4*x[0] - c3*x[1];
100  }
101 
102  void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
103  const std::vector<Real> &x, Real &tol) {
104  const Real c3(3), c4(4);
105  jv[0] = c4*v[0] - c3*v[1];
106  }
107 
108  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
109  const std::vector<Real> &x, Real &tol ) {
110  const Real c3(3), c4(4);
111  ajv[0] = c4*v[0];
112  ajv[1] = -c3*v[0];
113  }
114 
115  void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
116  const std::vector<Real> &v, const std::vector<Real> &x,
117  Real &tol) {
118  ahuv.assign(ahuv.size(),static_cast<Real>(0));
119  }
120 
121 
122 };
123 
124 template<class Real>
125 class getHS9 : public TestProblem<Real> {
126 public:
127  getHS9(void) {}
128 
129  Ptr<Objective<Real>> getObjective(void) const {
130  // Instantiate Objective Function
131  return ROL::makePtr<Objective_HS9<Real>>();
132  }
133 
134  Ptr<Vector<Real>> getInitialGuess(void) const {
135  // Problem dimension
136  int n = 2;
137  return ROL::makePtr<StdVector<Real>>(n,0.0);
138  }
139 
140  Ptr<Vector<Real>> getSolution(const int i = 0) const {
141  // Problem dimension
142  int n = 2;
143  // Get Solution
144  ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n,0.0);
145  (*xp)[0] = static_cast<Real>(-3);
146  (*xp)[1] = static_cast<Real>(-4);
147  return ROL::makePtr<StdVector<Real>>(xp);
148  }
149 
150  Ptr<Constraint<Real>> getEqualityConstraint(void) const {
151  return ROL::makePtr<Constraint_HS9<Real>>();
152  }
153 
154  Ptr<Vector<Real>> getEqualityMultiplier(void) const {
155  // Problem dimension
156  int n = 1;
157  return ROL::makePtr<StdVector<Real>>(n,0.0);
158  }
159 };
160 
161 
162 
163 } // End ZOO Namespace
164 } // End ROL Namespace
165 
166 #endif
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS9.hpp:134
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_HS9.hpp:71
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition: ROL_HS9.hpp:154
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS9.hpp:76
Contains definitions of custom data types in ROL.
Defines the equality constraint operator interface for StdVectors.
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS9.hpp:140
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS9.hpp:102
W. Hock and K. Schittkowski 9th test function.
Definition: ROL_HS9.hpp:69
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector&#39;s.
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS9.hpp:108
Contains definitions of test objective functions.
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS9.hpp:97
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition: ROL_HS9.hpp:150
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS9.hpp:129
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS9.hpp:82
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_HS9.hpp:115