ROL
ROL_HS53.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_HS53_HPP
51#define ROL_HS53_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
60namespace ROL {
61namespace ZOO {
62
69template<class Real>
70class Objective_HS53 : public StdObjective<Real> {
71public:
72 Real value( const std::vector<Real> &x, Real &tol ) {
73 const Real c1(1), c2(2);
74 return std::pow(x[0]-x[1],c2) + std::pow(x[1]+x[2]-c2,c2)
75 + std::pow(x[3]-c1,c2) + std::pow(x[4]-c1,c2);
76 }
77
78 void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
79 const Real c1(1), c2(2);
80 g[0] = c2*(x[0]-x[1]);
81 g[1] = c2*(x[1]-x[0]) + c2*(x[1]+x[2]-c2);
82 g[2] = c2*(x[1]+x[2]-c2);
83 g[3] = c2*(x[3]-c1);
84 g[4] = c2*(x[4]-c1);
85 }
86
87 void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
88 const Real c2(2);
89 hv[0] = c2*(v[0]-v[1]);
90 hv[1] = c2*(v[1]-v[0]) + c2*(v[1]+v[2]);
91 hv[2] = c2*(v[1]+v[2]);
92 hv[3] = c2*v[3];
93 hv[4] = c2*v[4];
94 }
95};
96
97template<class Real>
98class Constraint_HS53 : public StdConstraint<Real> {
99public:
100 void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
101 const Real c2(2), c3(3);
102 c[0] = x[0] + c3*x[1];
103 c[1] = x[2] + x[3] - c2*x[4];
104 c[2] = x[1] - x[4];
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 c2(2), c3(3);
110 jv[0] = v[0] + c3*v[1];
111 jv[1] = v[2] + v[3] - c2*v[4];
112 jv[2] = v[1] - v[4];
113 }
114
115 void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
116 const std::vector<Real> &x, Real &tol ) {
117 const Real c2(2), c3(3);
118 ajv[0] = v[0];
119 ajv[1] = c3*v[0] + v[2];
120 ajv[2] = v[1];
121 ajv[3] = v[1];
122 ajv[4] = -c2*v[1] - v[2];
123 }
124
125 void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
126 const std::vector<Real> &v, const std::vector<Real> &x,
127 Real &tol) {
128 ahuv.assign(ahuv.size(),static_cast<Real>(0));
129 }
130};
131
132template<class Real>
133class getHS53 : public TestProblem<Real> {
134public:
135 getHS53(void) {}
136
137 Ptr<Objective<Real>> getObjective(void) const {
138 return ROL::makePtr<Objective_HS53<Real>>();
139 }
140
141 Ptr<Vector<Real>> getInitialGuess(void) const {
142 int n = 5;
143 return ROL::makePtr<StdVector<Real>>(n,2.0);
144 }
145
146 Ptr<Vector<Real>> getSolution(const int i = 0) const {
147 int n = 5;
148 ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n);
149 (*xp)[0] = static_cast<Real>(-33.0/43.0);
150 (*xp)[1] = static_cast<Real>( 11.0/43.0);
151 (*xp)[2] = static_cast<Real>( 27.0/43.0);
152 (*xp)[3] = static_cast<Real>( -5.0/43.0);
153 (*xp)[4] = static_cast<Real>( 11.0/43.0);
154 return ROL::makePtr<StdVector<Real>>(xp);
155 }
156
157 Ptr<Constraint<Real>> getEqualityConstraint(void) const {
158 return ROL::makePtr<Constraint_HS53<Real>>();
159 }
160
161 Ptr<Vector<Real>> getEqualityMultiplier(void) const {
162 int n = 3;
163 return ROL::makePtr<StdVector<Real>>(n,0.0);
164 }
165
166 Ptr<BoundConstraint<Real>> getBoundConstraint(void) const {
167 int n = 5;
168 Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(n,-10.0);
169 Ptr<Vector<Real>> u = makePtr<StdVector<Real>>(n, 10.0);
170 return makePtr<Bounds<Real>>(l,u);
171 }
172};
173
174} // End ZOO Namespace
175} // End ROL Namespace
176
177#endif
Contains definitions of test objective functions.
Contains definitions of custom data types in ROL.
Defines the equality constraint operator interface for StdVectors.
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector's.
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS53.hpp:115
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition ROL_HS53.hpp:100
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS53.hpp:107
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_HS53.hpp:125
W. Hock and K. Schittkowski 53th test function.
Definition ROL_HS53.hpp:70
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS53.hpp:87
Real value(const std::vector< Real > &x, Real &tol)
Definition ROL_HS53.hpp:72
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition ROL_HS53.hpp:78
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition ROL_HS53.hpp:166
Ptr< Objective< Real > > getObjective(void) const
Definition ROL_HS53.hpp:137
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition ROL_HS53.hpp:157
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition ROL_HS53.hpp:146
Ptr< Vector< Real > > getInitialGuess(void) const
Definition ROL_HS53.hpp:141
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition ROL_HS53.hpp:161