ROL
ROL_HS41.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_HS41_HPP
51 #define ROL_HS41_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 #include "ROL_Bounds.hpp"
59 
60 namespace ROL {
61 namespace ZOO {
62 
69 template<class Real>
70 class Objective_HS41 : public StdObjective<Real> {
71 public:
72  Real value( const std::vector<Real> &x, Real &tol ) {
73  const Real c2(2);
74  return c2 - x[0]*x[1]*x[2];
75  }
76 
77  void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
78  g[0] = -x[1]*x[2];
79  g[1] = -x[0]*x[2];
80  g[2] = -x[0]*x[1];
81  g[3] = static_cast<Real>(0);
82  }
83 
84  void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
85  hv[0] = -x[2]*v[1] - x[1]*v[2];
86  hv[1] = -x[2]*v[0] - x[0]*v[2];
87  hv[2] = -x[1]*v[0] - x[0]*v[1];
88  hv[3] = static_cast<Real>(0);
89  }
90 };
91 
92 template<class Real>
93 class Constraint_HS41 : public StdConstraint<Real> {
94 public:
95  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
96  const Real c2(2);
97  c[0] = x[0] + c2*x[1] + c2*x[2] - x[3];
98  }
99 
100  void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
101  const std::vector<Real> &x, Real &tol) {
102  const Real c2(2);
103  jv[0] = v[0] + c2*v[1] + c2*v[2] - v[3];
104  }
105 
106  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
107  const std::vector<Real> &x, Real &tol ) {
108  const Real c2(2);
109  ajv[0] = v[0];
110  ajv[1] = c2*v[0];
111  ajv[2] = c2*v[0];
112  ajv[3] = -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 template<class Real>
123 class getHS41 : public TestProblem<Real> {
124 public:
125  getHS41(void) {}
126 
127  Ptr<Objective<Real>> getObjective(void) const {
128  return ROL::makePtr<Objective_HS41<Real>>();
129  }
130 
131  Ptr<Vector<Real>> getInitialGuess(void) const {
132  int n = 4;
133  return ROL::makePtr<StdVector<Real>>(n,2.0);
134  }
135 
136  Ptr<Vector<Real>> getSolution(const int i = 0) const {
137  int n = 4;
138  ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n,1.0/3.0);
139  (*xp)[0] = static_cast<Real>(2.0/3.0);
140  (*xp)[3] = static_cast<Real>(2.0);
141  return ROL::makePtr<StdVector<Real>>(xp);
142  }
143 
144  Ptr<Constraint<Real>> getEqualityConstraint(void) const {
145  return ROL::makePtr<Constraint_HS41<Real>>();
146  }
147 
148  Ptr<Vector<Real>> getEqualityMultiplier(void) const {
149  int n = 1;
150  return ROL::makePtr<StdVector<Real>>(n,0.0);
151  }
152 
153  Ptr<BoundConstraint<Real>> getBoundConstraint(void) const {
154  int n = 4;
155  Ptr<std::vector<Real>> up = makePtr<std::vector<Real>>(n,1.0);
156  (*up)[3] = static_cast<Real>(2.0);
157  Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(n,0.0);
158  Ptr<Vector<Real>> u = makePtr<StdVector<Real>>(up);
159  return makePtr<Bounds<Real>>(l,u);
160  }
161 };
162 
163 } // End ZOO Namespace
164 } // End ROL Namespace
165 
166 #endif
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS41.hpp:136
Contains definitions of custom data types in ROL.
Defines the equality constraint operator interface for StdVectors.
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition: ROL_HS41.hpp:144
W. Hock and K. Schittkowski 41th test function.
Definition: ROL_HS41.hpp:70
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_HS41.hpp:72
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition: ROL_HS41.hpp:153
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_HS41.hpp:106
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS41.hpp:84
Contains definitions of test objective functions.
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS41.hpp:95
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS41.hpp:77
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS41.hpp:127
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS41.hpp:100
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS41.hpp:131
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_HS41.hpp:115
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition: ROL_HS41.hpp:148