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