ROL
ROL_HS9.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_HS9_HPP
17#define ROL_HS9_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
25namespace ROL {
26namespace ZOO {
27
34template<class Real>
35class Objective_HS9 : public StdObjective<Real> {
36public:
37 Real value( const std::vector<Real> &x, Real &tol ) {
38 const Real pi(M_PI), c12(12), c16(16);
39 return std::sin(x[0]*pi/c12)*std::cos(x[1]*pi/c16);
40 }
41
42 void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
43 const Real pi(M_PI), c12(12), c16(16);
44 g[0] = pi/c12*std::cos(x[0]*pi/c12)*std::cos(x[1]*pi/c16);
45 g[1] = -pi/c16*std::sin(x[0]*pi/c12)*std::sin(x[1]*pi/c16);
46 }
47
48 void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
49 const Real pi(M_PI), c12(12), c16(16);
50 Real h11 = -pi/c12*pi/c12*std::sin(x[0]*pi/c12)*std::cos(x[1]*pi/c16);
51 Real h12 = -pi/c12*pi/c16*std::cos(x[0]*pi/c12)*std::sin(x[1]*pi/c16);
52 Real h22 = -pi/c16*pi/c16*std::sin(x[0]*pi/c12)*std::cos(x[1]*pi/c16);
53 hv[0] = h11*v[0] + h12*v[1];
54 hv[1] = h12*v[0] + h22*v[1];
55 }
56};
57
58template<class Real>
59class Constraint_HS9 : public StdConstraint<Real> {
60public:
62
63 void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
64 const Real c3(3), c4(4);
65 c[0] = c4*x[0] - c3*x[1];
66 }
67
68 void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
69 const std::vector<Real> &x, Real &tol) {
70 const Real c3(3), c4(4);
71 jv[0] = c4*v[0] - c3*v[1];
72 }
73
74 void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
75 const std::vector<Real> &x, Real &tol ) {
76 const Real c3(3), c4(4);
77 ajv[0] = c4*v[0];
78 ajv[1] = -c3*v[0];
79 }
80
81 void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
82 const std::vector<Real> &v, const std::vector<Real> &x,
83 Real &tol) {
84 ahuv.assign(ahuv.size(),static_cast<Real>(0));
85 }
86
87
88};
89
90template<class Real>
91class getHS9 : public TestProblem<Real> {
92public:
93 getHS9(void) {}
94
95 Ptr<Objective<Real>> getObjective(void) const {
96 // Instantiate Objective Function
97 return ROL::makePtr<Objective_HS9<Real>>();
98 }
99
100 Ptr<Vector<Real>> getInitialGuess(void) const {
101 // Problem dimension
102 int n = 2;
103 return ROL::makePtr<StdVector<Real>>(n,0.0);
104 }
105
106 Ptr<Vector<Real>> getSolution(const int i = 0) const {
107 // Problem dimension
108 int n = 2;
109 // Get Solution
110 ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n,0.0);
111 (*xp)[0] = static_cast<Real>(-3);
112 (*xp)[1] = static_cast<Real>(-4);
113 return ROL::makePtr<StdVector<Real>>(xp);
114 }
115
116 Ptr<Constraint<Real>> getEqualityConstraint(void) const {
117 return ROL::makePtr<Constraint_HS9<Real>>();
118 }
119
120 Ptr<Vector<Real>> getEqualityMultiplier(void) const {
121 // Problem dimension
122 int n = 1;
123 return ROL::makePtr<StdVector<Real>>(n,0.0);
124 }
125};
126
127
128
129} // End ZOO Namespace
130} // End ROL Namespace
131
132#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 applyAdjointHessian(std::vector< Real > &ahuv, const std::vector< Real > &u, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS9.hpp:81
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition ROL_HS9.hpp:63
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS9.hpp:68
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS9.hpp:74
W. Hock and K. Schittkowski 9th test function.
Definition ROL_HS9.hpp:35
Real value(const std::vector< Real > &x, Real &tol)
Definition ROL_HS9.hpp:37
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS9.hpp:48
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition ROL_HS9.hpp:42
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition ROL_HS9.hpp:116
Ptr< Objective< Real > > getObjective(void) const
Definition ROL_HS9.hpp:95
Ptr< Vector< Real > > getInitialGuess(void) const
Definition ROL_HS9.hpp:100
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition ROL_HS9.hpp:106
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition ROL_HS9.hpp:120