ROL
ROL_HS55.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_HS55_HPP
51 #define ROL_HS55_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_HS55 : public StdObjective<Real> {
71 public:
72  Real value( const std::vector<Real> &x, Real &tol ) {
73  const Real c2(2), c4(4);
74  return x[0] + c2*x[1] + c4*x[4] + std::exp(x[0]*x[3]);
75  }
76 
77  void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
78  const Real c0(0), c1(1), c2(2), c4(4);
79  Real exp03 = std::exp(x[0]*x[3]);
80  g[0] = c1 + x[3]*exp03;
81  g[1] = c2;
82  g[2] = c0;
83  g[3] = x[0]*exp03;
84  g[4] = c4;
85  g[5] = c0;
86  }
87 
88  void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
89  const Real c0(0), c1(1);
90  Real exp03 = std::exp(x[0]*x[3]);
91  hv[0] = x[3]*x[3]*exp03*v[0] + (c1 + x[3]*x[0])*exp03*v[3];
92  hv[1] = c0;
93  hv[2] = c0;
94  hv[3] = (c1 + x[0]*x[3])*exp03*v[0] + x[0]*x[0]*exp03*v[3];
95  hv[4] = c0;
96  hv[5] = c0;
97  }
98 };
99 
100 template<class Real>
101 class Constraint_HS55 : public StdConstraint<Real> {
102 public:
103  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
104  const Real c1(1), c2(2), c3(3), c5(5), c6(6);
105  c[0] = x[0] + c2*x[1] + c5*x[4] - c6;
106  c[1] = x[0] + x[1] + x[2] - c3;
107  c[2] = x[3] + x[4] + x[5] - c2;
108  c[3] = x[0] + x[3] - c1;
109  c[4] = x[1] + x[4] - c2;
110  c[5] = x[2] + x[5] - c2;
111  }
112 
113  void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
114  const std::vector<Real> &x, Real &tol) {
115  const Real c2(2), c5(5);
116  jv[0] = v[0] + c2*v[1] + c5*v[4];
117  jv[1] = v[0] + v[1] + v[2];
118  jv[2] = v[3] + v[4] + v[5];
119  jv[3] = v[0] + v[3];
120  jv[4] = v[1] + v[4];
121  jv[5] = v[2] + v[5];
122  }
123 
124  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
125  const std::vector<Real> &x, Real &tol ) {
126  const Real c2(2), c5(5);
127  ajv[0] = v[0] + v[1] + v[3];
128  ajv[1] = c2*v[0] + v[1] + v[4];
129  ajv[2] = v[1] + v[5];
130  ajv[3] = v[2] + v[3];
131  ajv[4] = c5*v[0] + v[2] + v[4];
132  ajv[5] = v[2] + v[5];
133  }
134 
135  void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
136  const std::vector<Real> &v, const std::vector<Real> &x,
137  Real &tol) {
138  ahuv.assign(ahuv.size(),static_cast<Real>(0));
139  }
140 };
141 
142 template<class Real>
143 class getHS55 : public TestProblem<Real> {
144 public:
145  getHS55(void) {}
146 
147  Ptr<Objective<Real>> getObjective(void) const {
148  return ROL::makePtr<Objective_HS55<Real>>();
149  }
150 
151  Ptr<Vector<Real>> getInitialGuess(void) const {
152  int n = 6;
153  ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n);
154  (*xp)[0] = static_cast<Real>(1.0);
155  (*xp)[1] = static_cast<Real>(2.0);
156  (*xp)[2] = static_cast<Real>(0.0);
157  (*xp)[3] = static_cast<Real>(0.0);
158  (*xp)[4] = static_cast<Real>(0.0);
159  (*xp)[5] = static_cast<Real>(2.0);
160  return ROL::makePtr<StdVector<Real>>(xp);
161  }
162 
163  Ptr<Vector<Real>> getSolution(const int i = 0) const {
164  int n = 6;
165  ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n);
166  (*xp)[0] = static_cast<Real>(0.0);
167  (*xp)[1] = static_cast<Real>(4.0/3.0);
168  (*xp)[2] = static_cast<Real>(5.0/3.0);
169  (*xp)[3] = static_cast<Real>(1.0);
170  (*xp)[4] = static_cast<Real>(2.0/3.0);
171  (*xp)[5] = static_cast<Real>(1.0/3.0);
172  return ROL::makePtr<StdVector<Real>>(xp);
173  }
174 
175  Ptr<Constraint<Real>> getEqualityConstraint(void) const {
176  return ROL::makePtr<Constraint_HS55<Real>>();
177  }
178 
179  Ptr<Vector<Real>> getEqualityMultiplier(void) const {
180  int n = 6;
181  return ROL::makePtr<StdVector<Real>>(n,0.0);
182  }
183 
184  Ptr<BoundConstraint<Real>> getBoundConstraint(void) const {
185  int n = 6;
186  Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(n,0.0);
187  ROL::Ptr<std::vector<Real>> up = ROL::makePtr<std::vector<Real>>(n,ROL_INF<Real>());
188  (*up)[0] = static_cast<Real>(1);
189  (*up)[3] = static_cast<Real>(1);
190  Ptr<Vector<Real>> u = makePtr<StdVector<Real>>(up);
191  return makePtr<Bounds<Real>>(l,u);
192  }
193 };
194 
195 } // End ZOO Namespace
196 } // End ROL Namespace
197 
198 #endif
Contains definitions of custom data types in ROL.
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_HS55.hpp:72
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS55.hpp:124
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition: ROL_HS55.hpp:184
Defines the equality constraint operator interface for StdVectors.
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS55.hpp:113
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector&#39;s.
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition: ROL_HS55.hpp:179
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS55.hpp:151
Contains definitions of test objective functions.
W. Hock and K. Schittkowski 55th test function.
Definition: ROL_HS55.hpp:70
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS55.hpp:77
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_HS55.hpp:135
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS55.hpp:88
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS55.hpp:103
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS55.hpp:163
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS55.hpp:147
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition: ROL_HS55.hpp:175