ROL
ROL_HS53.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Rapid Optimization Library (ROL) Package
4//
5// Copyright 2014 NTESS and the ROL contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
16#ifndef ROL_HS53_HPP
17#define ROL_HS53_HPP
18
19#include "ROL_StdVector.hpp"
20#include "ROL_TestProblem.hpp"
21#include "ROL_Types.hpp"
22#include "ROL_StdObjective.hpp"
23#include "ROL_StdConstraint.hpp"
24#include "ROL_Bounds.hpp"
25
26namespace ROL {
27namespace ZOO {
28
35template<class Real>
36class Objective_HS53 : public StdObjective<Real> {
37public:
38 Real value( const std::vector<Real> &x, Real &tol ) {
39 const Real c1(1), c2(2);
40 return std::pow(x[0]-x[1],c2) + std::pow(x[1]+x[2]-c2,c2)
41 + std::pow(x[3]-c1,c2) + std::pow(x[4]-c1,c2);
42 }
43
44 void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
45 const Real c1(1), c2(2);
46 g[0] = c2*(x[0]-x[1]);
47 g[1] = c2*(x[1]-x[0]) + c2*(x[1]+x[2]-c2);
48 g[2] = c2*(x[1]+x[2]-c2);
49 g[3] = c2*(x[3]-c1);
50 g[4] = c2*(x[4]-c1);
51 }
52
53 void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
54 const Real c2(2);
55 hv[0] = c2*(v[0]-v[1]);
56 hv[1] = c2*(v[1]-v[0]) + c2*(v[1]+v[2]);
57 hv[2] = c2*(v[1]+v[2]);
58 hv[3] = c2*v[3];
59 hv[4] = c2*v[4];
60 }
61};
62
63template<class Real>
64class Constraint_HS53 : public StdConstraint<Real> {
65public:
66 void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
67 const Real c2(2), c3(3);
68 c[0] = x[0] + c3*x[1];
69 c[1] = x[2] + x[3] - c2*x[4];
70 c[2] = x[1] - x[4];
71 }
72
73 void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
74 const std::vector<Real> &x, Real &tol) {
75 const Real c2(2), c3(3);
76 jv[0] = v[0] + c3*v[1];
77 jv[1] = v[2] + v[3] - c2*v[4];
78 jv[2] = v[1] - v[4];
79 }
80
81 void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
82 const std::vector<Real> &x, Real &tol ) {
83 const Real c2(2), c3(3);
84 ajv[0] = v[0];
85 ajv[1] = c3*v[0] + v[2];
86 ajv[2] = v[1];
87 ajv[3] = v[1];
88 ajv[4] = -c2*v[1] - v[2];
89 }
90
91 void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
92 const std::vector<Real> &v, const std::vector<Real> &x,
93 Real &tol) {
94 ahuv.assign(ahuv.size(),static_cast<Real>(0));
95 }
96};
97
98template<class Real>
99class getHS53 : public TestProblem<Real> {
100public:
101 getHS53(void) {}
102
103 Ptr<Objective<Real>> getObjective(void) const {
104 return ROL::makePtr<Objective_HS53<Real>>();
105 }
106
107 Ptr<Vector<Real>> getInitialGuess(void) const {
108 int n = 5;
109 return ROL::makePtr<StdVector<Real>>(n,2.0);
110 }
111
112 Ptr<Vector<Real>> getSolution(const int i = 0) const {
113 int n = 5;
114 ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n);
115 (*xp)[0] = static_cast<Real>(-33.0/43.0);
116 (*xp)[1] = static_cast<Real>( 11.0/43.0);
117 (*xp)[2] = static_cast<Real>( 27.0/43.0);
118 (*xp)[3] = static_cast<Real>( -5.0/43.0);
119 (*xp)[4] = static_cast<Real>( 11.0/43.0);
120 return ROL::makePtr<StdVector<Real>>(xp);
121 }
122
123 Ptr<Constraint<Real>> getEqualityConstraint(void) const {
124 return ROL::makePtr<Constraint_HS53<Real>>();
125 }
126
127 Ptr<Vector<Real>> getEqualityMultiplier(void) const {
128 int n = 3;
129 return ROL::makePtr<StdVector<Real>>(n,0.0);
130 }
131
132 Ptr<BoundConstraint<Real>> getBoundConstraint(void) const {
133 int n = 5;
134 Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(n,-10.0);
135 Ptr<Vector<Real>> u = makePtr<StdVector<Real>>(n, 10.0);
136 return makePtr<Bounds<Real>>(l,u);
137 }
138};
139
140} // End ZOO Namespace
141} // End ROL Namespace
142
143#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:81
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition ROL_HS53.hpp:66
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS53.hpp:73
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:91
W. Hock and K. Schittkowski 53th test function.
Definition ROL_HS53.hpp:36
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS53.hpp:53
Real value(const std::vector< Real > &x, Real &tol)
Definition ROL_HS53.hpp:38
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition ROL_HS53.hpp:44
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition ROL_HS53.hpp:132
Ptr< Objective< Real > > getObjective(void) const
Definition ROL_HS53.hpp:103
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition ROL_HS53.hpp:123
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition ROL_HS53.hpp:112
Ptr< Vector< Real > > getInitialGuess(void) const
Definition ROL_HS53.hpp:107
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition ROL_HS53.hpp:127