ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
zoo
testproblems
ROL_HS24.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
14
15
#ifndef ROL_HS24_HPP
16
#define ROL_HS24_HPP
17
18
#include "
ROL_StdVector.hpp
"
19
#include "
ROL_TestProblem.hpp
"
20
#include "
ROL_Bounds.hpp
"
21
22
namespace
ROL
{
23
namespace
ZOO
{
24
25
template
<
class
Real>
26
class
Objective_HS24
:
public
Objective
<Real> {
27
28
typedef
std::vector<Real>
vector
;
29
typedef
Vector<Real>
V
;
30
typedef
StdVector<Real>
SV
;
31
32
private
:
33
const
Real
rt3_
;
34
35
public
:
36
37
Objective_HS24
() :
rt3_
(std::sqrt(3)) {}
38
39
Real
value
(
const
Vector<Real>
&x, Real &tol ) {
40
41
Ptr<const vector> xp =
dynamic_cast<
const
SV
&
>
(x).getVector();
42
43
return
rt3_
*(*xp)[0]*std::pow((*xp)[1],3)*((*xp)[0]-6)/81.0;
44
}
45
46
void
gradient
(
Vector<Real>
&g,
const
Vector<Real>
&x, Real &tol ) {
47
48
Ptr<const vector> xp =
dynamic_cast<
const
SV
&
>
(x).getVector();
49
50
Ptr<vector> gp =
dynamic_cast<
SV
&
>
(g).getVector();
51
52
(*gp)[0] = 2*
rt3_
*std::pow((*xp)[1],3)*((*xp)[0]-3)/81.0;
53
(*gp)[1] =
rt3_
*(*xp)[0]*std::pow((*xp)[1],2)*((*xp)[0]-6)/27.0;
54
55
}
56
57
58
void
hessVec
(
Vector<Real>
&hv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
59
60
Ptr<const vector> xp =
dynamic_cast<
const
SV
&
>
(x).getVector();
61
Ptr<const vector> vp =
dynamic_cast<
const
SV
&
>
(v).getVector();
62
Ptr<vector> hvp =
dynamic_cast<
SV
&
>
(hv).getVector();
63
64
Real a00 = pow((*xp)[1],3)/81.0;
65
Real a01 = pow((*xp)[1],2)*((*xp)[0]-3)/27.0;
66
Real a11 = (*xp)[1]*(std::pow((*xp)[0]-3,2)-9)/27.0;
67
68
(*hvp)[0] = a00*(*vp)[0] + a01*(*vp)[1];
69
(*hvp)[1] = a01*(*vp)[0] + a11*(*vp)[1];
70
hv.
scale
(2*
rt3_
);
71
72
}
73
};
// class Objective_HS24
74
75
76
template
<
class
Real>
77
class
Constraint_HS24
:
public
Constraint
<Real> {
78
79
typedef
std::vector<Real>
vector
;
80
typedef
Vector<Real>
V
;
81
typedef
StdVector<Real>
SV
;
82
83
private
:
84
const
Real
rt3_
;
85
86
public
:
87
Constraint_HS24
() :
rt3_
(std::sqrt(3)) {}
88
89
void
value
(
Vector<Real>
&c,
const
Vector<Real>
&x, Real &tol ) {
90
91
Ptr<const vector> xp =
dynamic_cast<
const
SV
&
>
(x).getVector();
92
Ptr<vector> cp =
dynamic_cast<
SV
&
>
(c).getVector();
93
94
(*cp)[0] = (*xp)[0]/
rt3_
- (*xp)[1];
95
(*cp)[1] = (*xp)[0] +
rt3_
*(*xp)[1];
96
(*cp)[2] = -(*xp)[0] -
rt3_
*(*xp)[1] + 6;
97
98
}
99
100
void
applyJacobian
(
Vector<Real>
&jv,
const
Vector<Real>
&v,
101
const
Vector<Real>
&x, Real &tol ) {
102
103
Ptr<const vector> vp =
dynamic_cast<
const
SV
&
>
(v).getVector();
104
Ptr<vector> jvp =
dynamic_cast<
SV
&
>
(jv).getVector();
105
106
(*jvp)[0] = (*vp)[0]/
rt3_
- (*vp)[1];
107
(*jvp)[1] = (*vp)[0] +
rt3_
*(*vp)[1];
108
(*jvp)[2] = -(*vp)[0] -
rt3_
*(*vp)[1];
109
110
111
}
112
113
void
applyAdjointJacobian
(
Vector<Real>
&ajv,
const
Vector<Real>
&v,
114
const
Vector<Real>
&x, Real &tol ) {
115
116
Ptr<const vector> vp =
dynamic_cast<
const
SV
&
>
(v).getVector();
117
Ptr<vector> ajvp =
dynamic_cast<
SV
&
>
(ajv).getVector();
118
119
(*ajvp)[0] =
rt3_
*(*vp)[0]/3 + (*vp)[1] - (*vp)[2];
120
(*ajvp)[1] = -(*vp)[0] +
rt3_
*(*vp)[1] -
rt3_
*(*vp)[2];
121
122
}
123
124
125
void
applyAdjointHessian
(
Vector<Real>
&ahuv,
const
Vector<Real>
&u,
126
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
127
ahuv.
zero
();
128
}
129
130
};
// class Constraint_HS24
131
132
133
134
template
<
class
Real>
135
class
getHS24
:
public
TestProblem
<Real> {
136
public
:
137
getHS24
(
void
) {}
138
139
Ptr<Objective<Real> >
getObjective
(
void
)
const
{
140
return
makePtr<Objective_HS24<Real>>();
141
}
142
143
Ptr<Constraint<Real> >
getInequalityConstraint
(
void
)
const
{
144
return
makePtr<Constraint_HS24<Real>>();
145
}
146
147
Ptr<BoundConstraint<Real>>
getBoundConstraint
(
void
)
const
{
148
// Lower bound is zero
149
Ptr<std::vector<Real>> lp = makePtr<std::vector<Real>>(2,0.0);
150
151
// No upper bound
152
Ptr<std::vector<Real>> up = makePtr<std::vector<Real>>(2,
ROL_INF<Real>
());
153
154
Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(lp);
155
Ptr<Vector<Real>> u = makePtr<StdVector<Real>>(up);
156
157
return
makePtr<Bounds<Real>>(l,u);
158
}
159
160
Ptr<Vector<Real>>
getInitialGuess
(
void
)
const
{
161
Ptr<std::vector<Real> > x0p = makePtr<std::vector<Real>>(2);
162
(*x0p)[0] = 1.0;
163
(*x0p)[1] = 0.5;
164
165
return
makePtr<StdVector<Real>>(x0p);
166
}
167
168
Ptr<Vector<Real>>
getSolution
(
const
int
i = 0 )
const
{
169
Ptr<std::vector<Real> > xp = makePtr<std::vector<Real>>(2);
170
(*xp)[0] = 3.0;
171
(*xp)[1] = std::sqrt(3.0);
172
173
return
makePtr<StdVector<Real>>(xp);
174
}
175
176
Ptr<Vector<Real>>
getInequalityMultiplier
(
void
)
const
{
177
Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(3,0.0);
178
return
makePtr<StdVector<Real>>(lp);
179
}
180
181
Ptr<BoundConstraint<Real>>
getSlackBoundConstraint
(
void
)
const
{
182
// Lower bound is zero
183
Ptr<std::vector<Real> > lp = makePtr<std::vector<Real>>(3,0.0);
184
185
// No upper bound
186
Ptr<std::vector<Real> > up = makePtr<std::vector<Real>>(3,
ROL_INF<Real>
());
187
188
Ptr<Vector<Real> > l = makePtr<StdVector<Real>>(lp);
189
Ptr<Vector<Real> > u = makePtr<StdVector<Real>>(up);
190
191
return
makePtr<Bounds<Real>>(l,u);
192
}
193
};
194
195
196
}
// namespace ZOO
197
}
// namespace ROL
198
199
#endif
// ROL_HS24_HPP
200
ROL_Bounds.hpp
ROL_StdVector.hpp
ROL_TestProblem.hpp
Contains definitions of test objective functions.
ROL::ROL::Constraint::Constraint
Constraint(void)
Definition
ROL_Constraint_SerialSimOpt.hpp:59
ROL::ROL::Objective::Objective
Objective()
Definition
ROL_Constraint_SerialSimOpt.hpp:53
ROL::StdVector
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Definition
ROL_StdVector.hpp:27
ROL::TestProblem::TestProblem
TestProblem(void)
Definition
ROL_TestProblem.hpp:28
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL::Vector::scale
virtual void scale(const Real alpha)=0
Compute where .
ROL::Vector::zero
virtual void zero()
Set to zero vector.
Definition
ROL_Vector.hpp:134
ROL::ZOO::Constraint_HS24::Constraint_HS24
Constraint_HS24()
Definition
ROL_HS24.hpp:87
ROL::ZOO::Constraint_HS24::applyJacobian
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition
ROL_HS24.hpp:100
ROL::ZOO::Constraint_HS24::value
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Definition
ROL_HS24.hpp:89
ROL::ZOO::Constraint_HS24::applyAdjointJacobian
void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition
ROL_HS24.hpp:113
ROL::ZOO::Constraint_HS24::SV
StdVector< Real > SV
Definition
ROL_HS24.hpp:81
ROL::ZOO::Constraint_HS24::vector
std::vector< Real > vector
Definition
ROL_HS24.hpp:79
ROL::ZOO::Constraint_HS24::applyAdjointHessian
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition
ROL_HS24.hpp:125
ROL::ZOO::Constraint_HS24::V
Vector< Real > V
Definition
ROL_HS24.hpp:80
ROL::ZOO::Constraint_HS24::rt3_
const Real rt3_
Definition
ROL_HS24.hpp:84
ROL::ZOO::Objective_HS24::vector
std::vector< Real > vector
Definition
ROL_HS24.hpp:28
ROL::ZOO::Objective_HS24::rt3_
const Real rt3_
Definition
ROL_HS24.hpp:33
ROL::ZOO::Objective_HS24::SV
StdVector< Real > SV
Definition
ROL_HS24.hpp:30
ROL::ZOO::Objective_HS24::gradient
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Definition
ROL_HS24.hpp:46
ROL::ZOO::Objective_HS24::value
Real value(const Vector< Real > &x, Real &tol)
Definition
ROL_HS24.hpp:39
ROL::ZOO::Objective_HS24::V
Vector< Real > V
Definition
ROL_HS24.hpp:29
ROL::ZOO::Objective_HS24::Objective_HS24
Objective_HS24()
Definition
ROL_HS24.hpp:37
ROL::ZOO::Objective_HS24::hessVec
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition
ROL_HS24.hpp:58
ROL::ZOO::getHS24::getSlackBoundConstraint
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Definition
ROL_HS24.hpp:181
ROL::ZOO::getHS24::getHS24
getHS24(void)
Definition
ROL_HS24.hpp:137
ROL::ZOO::getHS24::getInequalityConstraint
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Definition
ROL_HS24.hpp:143
ROL::ZOO::getHS24::getInitialGuess
Ptr< Vector< Real > > getInitialGuess(void) const
Definition
ROL_HS24.hpp:160
ROL::ZOO::getHS24::getInequalityMultiplier
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Definition
ROL_HS24.hpp:176
ROL::ZOO::getHS24::getSolution
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition
ROL_HS24.hpp:168
ROL::ZOO::getHS24::getObjective
Ptr< Objective< Real > > getObjective(void) const
Definition
ROL_HS24.hpp:139
ROL::ZOO::getHS24::getBoundConstraint
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition
ROL_HS24.hpp:147
ROL::ZOO
Definition
ROL_Beale.hpp:26
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::ROL_INF
Real ROL_INF(void)
Definition
ROL_Types.hpp:71
Generated by
1.17.0