ROL
ROL_HS63.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_HS63_HPP
51#define ROL_HS63_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
66template<class Real>
67class Objective_HS63 : public StdObjective<Real> {
68public:
69 Real value( const std::vector<Real> &x, Real &tol ) {
70 const Real c1(1000), c2(2);
71 return c1 - x[0]*x[0] - c2*x[1]*x[1] - x[2]*x[2] - x[0]*x[1] - x[0]*x[2];
72 }
73
74 void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
75 const Real c2(2);
76 g[0] = -c2*x[0]-x[1]-x[2];
77 g[1] = -c2*c2*x[1]-x[0];
78 g[2] = -c2*x[2]-x[0];
79 }
80
81 void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
82 const Real c2(2);
83 hv[0] = -c2*v[0]-v[1]-v[2];
84 hv[1] = -c2*c2*v[1]-v[0];
85 hv[2] = -c2*v[2]-v[0];
86 }
87};
88
89template<class Real>
90class Constraint_HS63a : public StdConstraint<Real> {
91public:
92 void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
93 const Real c1(8), c2(14), c3(7), c4(56);
94 c[0] = c1*x[0] + c2*x[1] + c3*x[2] - c4;
95 }
96
97 void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
98 const std::vector<Real> &x, Real &tol) {
99 const Real c1(8), c2(14), c3(7);
100 jv[0] = c1*v[0] + c2*v[1] + c3*v[2];
101 }
102
103 void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
104 const std::vector<Real> &x, Real &tol ) {
105 const Real c1(8), c2(14), c3(7);
106 ajv[0] = c1*v[0];
107 ajv[1] = c2*v[0];
108 ajv[2] = c3*v[0];
109 }
110
111 void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
112 const std::vector<Real> &v, const std::vector<Real> &x,
113 Real &tol) {
114 ahuv.assign(ahuv.size(),static_cast<Real>(0));
115 }
116};
117
118template<class Real>
119class Constraint_HS63b : public StdConstraint<Real> {
120public:
121 void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
122 const Real c1(25);
123 c[0] = x[0]*x[0] + x[1]*x[1] + x[2]*x[2] - c1;
124 }
125
126 void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
127 const std::vector<Real> &x, Real &tol) {
128 const Real c1(2);
129 jv[0] = c1*(x[0]*v[0] + x[1]*v[1] + x[2]*v[2]);
130 }
131
132 void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
133 const std::vector<Real> &x, Real &tol ) {
134 const Real c1(2);
135 ajv[0] = c1*x[0]*v[0];
136 ajv[1] = c1*x[1]*v[0];
137 ajv[2] = c1*x[2]*v[0];
138 }
139
140 void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
141 const std::vector<Real> &v, const std::vector<Real> &x,
142 Real &tol) {
143 const Real c1(2);
144 ahuv[0] = c1*v[0]*u[0];
145 ahuv[1] = c1*v[1]*u[0];
146 ahuv[2] = c1*v[2]*u[0];
147 }
148};
149
150template<class Real>
151class getHS63 : public TestProblem<Real> {
152public:
153 getHS63(void) {}
154
155 Ptr<Objective<Real>> getObjective(void) const {
156 return ROL::makePtr<Objective_HS63<Real>>();
157 }
158
159 Ptr<Vector<Real>> getInitialGuess(void) const {
160 int n = 3;
161 return ROL::makePtr<StdVector<Real>>(n,static_cast<Real>(2));
162 }
163
164 Ptr<Vector<Real>> getSolution(const int i = 0) const {
165 int n = 3;
166 ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n);
167 (*xp)[0] = static_cast<Real>(3.512118414);
168 (*xp)[1] = static_cast<Real>(0.2169881741);
169 (*xp)[2] = static_cast<Real>(3.552174034);
170 return ROL::makePtr<StdVector<Real>>(xp);
171 }
172
173 Ptr<Constraint<Real>> getEqualityConstraint(void) const {
174 std::vector<Ptr<Constraint<Real>>> cvec(2);
175 cvec[0] = makePtr<Constraint_HS63a<Real>>();
176 cvec[1] = makePtr<Constraint_HS63b<Real>>();
177 return ROL::makePtr<Constraint_Partitioned<Real>>(cvec);
178 }
179
180 Ptr<Vector<Real>> getEqualityMultiplier(void) const {
181 std::vector<Ptr<Vector<Real>>> lvec(2);
182 lvec[0] = makePtr<StdVector<Real>>(1,static_cast<Real>(0));
183 lvec[1] = makePtr<StdVector<Real>>(1,static_cast<Real>(0));
184 return ROL::makePtr<PartitionedVector<Real>>(lvec);
185 }
186
187 Ptr<BoundConstraint<Real>> getBoundConstraint(void) const {
188 int n = 3;
189 Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(n,static_cast<Real>(0.0));
190 return makePtr<Bounds<Real>>(*l,true);
191 }
192};
193
194} // End ZOO Namespace
195} // End ROL Namespace
196
197#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_HS63.hpp:103
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS63.hpp:97
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition ROL_HS63.hpp:92
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_HS63.hpp:111
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS63.hpp:132
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_HS63.hpp:140
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS63.hpp:126
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition ROL_HS63.hpp:121
W. Hock and K. Schittkowski 63rd test function.
Definition ROL_HS63.hpp:67
Real value(const std::vector< Real > &x, Real &tol)
Definition ROL_HS63.hpp:69
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition ROL_HS63.hpp:74
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS63.hpp:81
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition ROL_HS63.hpp:164
Ptr< Vector< Real > > getInitialGuess(void) const
Definition ROL_HS63.hpp:159
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition ROL_HS63.hpp:173
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition ROL_HS63.hpp:187
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition ROL_HS63.hpp:180
Ptr< Objective< Real > > getObjective(void) const
Definition ROL_HS63.hpp:155