ROL
ROL_HS52.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_HS52_HPP
17#define ROL_HS52_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_HS52 : public StdObjective<Real> {
36public:
37 Real value( const std::vector<Real> &x, Real &tol ) {
38 const Real c1(1), c2(2), c4(4);
39 return std::pow(c4*x[0]-x[1],c2) + std::pow(x[1]+x[2]-c2,c2)
40 + std::pow(x[3]-c1,c2) + std::pow(x[4]-c1,c2);
41 }
42
43 void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
44 const Real c1(1), c2(2), c4(4);
45 g[0] = c2*c4*(c4*x[0]-x[1]);
46 g[1] = c2*(x[1]-c4*x[0]) + c2*(x[1]+x[2]-c2);
47 g[2] = c2*(x[1]+x[2]-c2);
48 g[3] = c2*(x[3]-c1);
49 g[4] = c2*(x[4]-c1);
50 }
51
52 void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
53 const Real c2(2), c4(4);
54 hv[0] = c2*c4*c4*v[0] - c2*c4*v[1];
55 hv[1] = (c2+c2)*v[1] - c2*c4*v[0] + c2*v[2];
56 hv[2] = c2*v[2] + c2*v[1];
57 hv[3] = c2*v[3];
58 hv[4] = c2*v[4];
59 }
60};
61
62template<class Real>
63class Constraint_HS52 : public StdConstraint<Real> {
64public:
66
67 void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
68 const Real c2(2), c3(3);
69 c[0] = x[0]+c3*x[1];
70 c[1] = x[2]+x[3]-c2*x[4];
71 c[2] = x[1]-x[4];
72 }
73
74 void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
75 const std::vector<Real> &x, Real &tol) {
76 const Real c2(2), c3(3);
77 jv[0] = v[0]+c3*v[1];
78 jv[1] = v[2]+v[3]-c2*v[4];
79 jv[2] = v[1]-v[4];
80 }
81
82 void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
83 const std::vector<Real> &x, Real &tol ) {
84 const Real c2(2), c3(3);
85 ajv[0] = v[0];
86 ajv[1] = c3*v[0] + v[2];
87 ajv[2] = v[1];
88 ajv[3] = v[1];
89 ajv[4] = -c2*v[1] - v[2];
90 }
91
92 void applyAdjointHessian(std::vector<Real> &ahuv, const std::vector<Real> &u,
93 const std::vector<Real> &v, const std::vector<Real> &x,
94 Real &tol) {
95 ahuv.assign(ahuv.size(),static_cast<Real>(0));
96 }
97
98
99};
100
101template<class Real>
102class getHS52 : public TestProblem<Real> {
103public:
104 getHS52(void) {}
105
106 Ptr<Objective<Real>> getObjective(void) const {
107 return ROL::makePtr<Objective_HS52<Real>>();
108 }
109
110 Ptr<Vector<Real>> getInitialGuess(void) const {
111 int n = 5;
112 return ROL::makePtr<StdVector<Real>>(n,2.0);
113 }
114
115 Ptr<Vector<Real>> getSolution(const int i = 0) const {
116 int n = 5;
117 ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n,0.0);
118 (*xp)[0] = static_cast<Real>(-33.0/349.0);
119 (*xp)[1] = static_cast<Real>(11.0/349.0);
120 (*xp)[2] = static_cast<Real>(180.0/349.0);
121 (*xp)[3] = static_cast<Real>(-158.0/349.0);
122 (*xp)[4] = static_cast<Real>(11.0/349.0);
123 return ROL::makePtr<StdVector<Real>>(xp);
124 }
125
126 Ptr<Constraint<Real>> getEqualityConstraint(void) const {
127 return ROL::makePtr<Constraint_HS52<Real>>();
128 }
129
130 Ptr<Vector<Real>> getEqualityMultiplier(void) const {
131 int n = 3;
132 return ROL::makePtr<StdVector<Real>>(n,0.0);
133 }
134};
135
136} // End ZOO Namespace
137} // End ROL Namespace
138
139#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 value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition ROL_HS52.hpp:67
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_HS52.hpp:92
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS52.hpp:82
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS52.hpp:74
W. Hock and K. Schittkowski 52nd test function.
Definition ROL_HS52.hpp:35
Real value(const std::vector< Real > &x, Real &tol)
Definition ROL_HS52.hpp:37
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS52.hpp:52
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition ROL_HS52.hpp:43
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition ROL_HS52.hpp:115
Ptr< Vector< Real > > getInitialGuess(void) const
Definition ROL_HS52.hpp:110
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition ROL_HS52.hpp:130
Ptr< Objective< Real > > getObjective(void) const
Definition ROL_HS52.hpp:106
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition ROL_HS52.hpp:126