ROL
ROL_HS28.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_HS28_HPP
17#define ROL_HS28_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_HS28 : public StdObjective<Real> {
36public:
37 Real value( const std::vector<Real> &x, Real &tol ) {
38 const Real two(2);
39 return std::pow(x[0]+x[1],two) + std::pow(x[1]+x[2],two);
40 }
41
42 void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
43 const Real two(2);
44 g[0] = two*(x[0]+x[1]);
45 g[1] = two*(x[0]+x[1]) + two*(x[1]+x[2]);
46 g[2] = two*(x[1]+x[2]);
47 }
48
49 void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
50 const Real two(2);
51 hv[0] = two*v[0] + two*v[1];
52 hv[1] = two*v[0] + two*two*v[1] + two*v[2];
53 hv[2] = two*v[1] + two*v[2];
54 }
55};
56
57template<class Real>
58class Constraint_HS28 : public StdConstraint<Real> {
59public:
61
62 void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
63 const Real c1(1), c2(2), c3(3);
64 c[0] = c1*x[0]+c2*x[1]+c3*x[2]-c1;
65 }
66
67 void applyJacobian(std::vector<Real> &jv, const std::vector<Real> &v,
68 const std::vector<Real> &x, Real &tol) {
69 const Real c1(1), c2(2), c3(3);
70 jv[0] = c1*v[0]+c2*v[1]+c3*v[2];
71 }
72
73 void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
74 const std::vector<Real> &x, Real &tol ) {
75 const Real c1(1), c2(2), c3(3);
76 ajv[0] = c1*v[0];
77 ajv[1] = c2*v[0];
78 ajv[2] = 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 getHS28 : public TestProblem<Real> {
92public:
93 getHS28(void) {}
94
95 Ptr<Objective<Real>> getObjective(void) const {
96 return ROL::makePtr<Objective_HS28<Real>>();
97 }
98
99 Ptr<Vector<Real>> getInitialGuess(void) const {
100 int n = 3;
101 ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n,0.0);
102 (*xp)[0] = static_cast<Real>(-4);
103 (*xp)[1] = static_cast<Real>(1);
104 (*xp)[2] = static_cast<Real>(1);
105 return ROL::makePtr<StdVector<Real>>(xp);
106 }
107
108 Ptr<Vector<Real>> getSolution(const int i = 0) const {
109 int n = 3;
110 ROL::Ptr<std::vector<Real>> xp = ROL::makePtr<std::vector<Real>>(n,0.0);
111 (*xp)[0] = static_cast<Real>(0.5);
112 (*xp)[1] = static_cast<Real>(-0.5);
113 (*xp)[2] = static_cast<Real>(0.5);
114 return ROL::makePtr<StdVector<Real>>(xp);
115 }
116
117 Ptr<Constraint<Real>> getEqualityConstraint(void) const {
118 return ROL::makePtr<Constraint_HS28<Real>>();
119 }
120
121 Ptr<Vector<Real>> getEqualityMultiplier(void) const {
122 int n = 1;
123 return ROL::makePtr<StdVector<Real>>(n,0.0);
124 }
125};
126
127} // End ZOO Namespace
128} // End ROL Namespace
129
130#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 applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS28.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_HS28.hpp:81
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS28.hpp:73
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition ROL_HS28.hpp:62
W. Hock and K. Schittkowski 28th test function.
Definition ROL_HS28.hpp:35
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition ROL_HS28.hpp:42
Real value(const std::vector< Real > &x, Real &tol)
Definition ROL_HS28.hpp:37
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition ROL_HS28.hpp:49
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition ROL_HS28.hpp:108
Ptr< Objective< Real > > getObjective(void) const
Definition ROL_HS28.hpp:95
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Definition ROL_HS28.hpp:117
Ptr< Vector< Real > > getInitialGuess(void) const
Definition ROL_HS28.hpp:99
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Definition ROL_HS28.hpp:121