ROL
ROL_HS14.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_HS14_HPP
51 #define ROL_HS14_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_HS14 : public StdObjective<Real> {
72 public:
73 
74  Real value( const std::vector<Real> &x, Real &tol ) {
75  const Real c1(1), c2(2);
76  return std::pow(x[0]-c2,c2) + std::pow(x[1]-c1,c2);
77  }
78 
79  void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
80  const Real c1(1), c2(2);
81  g[0] = c2*(x[0]-c2);
82  g[1] = c2*(x[1]-c1);
83  }
84 
85  void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
86  const Real c2(2);
87  hv[0] = c2*v[0];
88  hv[1] = c2*v[1];
89  }
90 };
91 
92 template<class Real>
93 class Constraint_HS14a : public StdConstraint<Real> {
94 public:
96 
97  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
98  const Real c1(1), c2(2);
99  c[0] = x[0] - c2*x[1] + c1;
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 c2(2);
105  jv[0] = v[0] - c2*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 c2(2);
111  ajv[0] = v[0];
112  ajv[1] = -c2*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 Constraint_HS14b : public StdConstraint<Real> {
124 public:
126 
127  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
128  const Real c0(0.25), c1(1), c2(2);
129  c[0] = -c0*std::pow(x[0],c2) - std::pow(x[1],c2) + c1;
130  }
131 
132  void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
133  const std::vector<Real> &x, Real &tol) {
134  const Real c0(0.25), c2(2);
135  jv[0] = -c0*c2*x[0]*v[0] - c2*x[1]*v[1];
136  }
137 
138  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
139  const std::vector<Real> &x, Real &tol ) {
140  const Real c0(0.25), c2(2);
141  ajv[0] = -c0*c2*x[0]*v[0];
142  ajv[1] = -c2*x[1]*v[0];
143  }
144 
145  void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
146  const std::vector<Real> &v, const std::vector<Real> &x,
147  Real &tol) {
148  const Real c0(0.25), c2(2);
149  ahuv[0] = -c0*c2*v[0]*u[0];
150  ahuv[1] = -c2*v[1]*u[0];
151  }
152 };
153 
154 template<class Real>
155 class getHS14 : public TestProblem<Real> {
156 public:
157  getHS14(void) {}
158 
159  Ptr<Objective<Real>> getObjective(void) const {
160  return ROL::makePtr<Objective_HS14<Real>>();
161  }
162 
163  Ptr<Vector<Real>> getInitialGuess(void) const {
164  int n = 2;
165  return ROL::makePtr<StdVector<Real>>(n,2.0);
166  }
167 
168  Ptr<Vector<Real>> getSolution(const int i = 0) const {
169  int n = 2;
170  ROL::Ptr<std::vector<Real> > xp = ROL::makePtr<std::vector<Real>>(n,0.0);
171  (*xp)[0] = static_cast<Real>(0.5 *(std::sqrt(7)-1));
172  (*xp)[1] = static_cast<Real>(0.25*(std::sqrt(7)+1));
173  return ROL::makePtr<StdVector<Real>>(xp);
174  }
175 
176  Ptr<Constraint<Real>> getEqualityConstraint(void) const {
177  return makePtr<Constraint_HS14a<Real>>();
178  }
179 
180  Ptr<Vector<Real>> getEqualityMultiplier(void) const {
181  return makePtr<StdVector<Real>>(1,0.0);
182  }
183 
184  Ptr<Constraint<Real>> getInequalityConstraint(void) const {
185  return makePtr<Constraint_HS14b<Real>>();
186  }
187 
188  Ptr<Vector<Real>> getInequalityMultiplier(void) const {
189  return makePtr<StdVector<Real>>(1,0.0);
190  }
191 
192  Ptr<BoundConstraint<Real>> getSlackBoundConstraint(void) const {
193  Ptr<Vector<Real>> lb = makePtr<StdVector<Real>>(1,0.0);
194  return makePtr<Bounds<Real>>(*lb,true);
195  }
196 };
197 
198 } // End ZOO Namespace
199 } // End ROL Namespace
200 
201 #endif
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_HS14.hpp:115
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:74
Contains definitions of custom data types in ROL.
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS14.hpp:159
Defines the equality constraint operator interface for StdVectors.
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:108
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:127
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:79
W. Hock and K. Schittkowski 14th test function.
Definition: ROL_HS14.hpp:71
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition: ROL_HS14.hpp:180
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector&#39;s.
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:85
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:132
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:102
Contains definitions of test objective functions.
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:138
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_HS14.hpp:145
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Definition: ROL_HS14.hpp:192
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition: ROL_HS14.hpp:176
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Definition: ROL_HS14.hpp:188
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS14.hpp:163
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS14.hpp:168
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Definition: ROL_HS14.hpp:184
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS14.hpp:97