ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
zoo
testproblems
ROL_HS3.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 USE_HESSVEC
16
#define USE_HESSVEC 1
17
#endif
18
19
#ifndef ROL_HS3_HPP
20
#define ROL_HS3_HPP
21
22
#include "
ROL_StdVector.hpp
"
23
#include "
ROL_TestProblem.hpp
"
24
#include "
ROL_Bounds.hpp
"
25
#include "
ROL_Types.hpp
"
26
27
namespace
ROL
{
28
namespace
ZOO {
29
32
template
<
class
Real>
33
class
Objective_HS3
:
public
Objective
<Real> {
34
35
typedef
std::vector<Real>
vector
;
36
typedef
Vector<Real>
V
;
37
typedef
StdVector<Real>
SV
;
38
39
private
:
40
41
ROL::Ptr<const vector>
getVector
(
const
V
& x ) {
42
43
return
dynamic_cast<
const
SV
&
>
(x).
getVector
();
44
}
45
46
ROL::Ptr<vector>
getVector
(
V
& x ) {
47
48
return
dynamic_cast<
SV
&
>
(x).
getVector
();
49
}
50
51
public
:
52
Objective_HS3
(
void
) {}
53
54
Real
value
(
const
Vector<Real>
&x, Real &tol ) {
55
56
57
ROL::Ptr<const vector> ex =
getVector
(x);
58
return
(*ex)[1] + 1.e-5 * std::pow((*ex)[1] - (*ex)[0],2.0);
59
}
60
61
void
gradient
(
Vector<Real>
&g,
const
Vector<Real>
&x, Real &tol ) {
62
63
64
ROL::Ptr<const vector> ex =
getVector
(x);
65
ROL::Ptr<vector> eg =
getVector
(g);
66
(*eg)[0] = -1.e-5 * 2.0 * ((*ex)[1] - (*ex)[0]);
67
(*eg)[1] = 1.0 + 1.e-5 * 2.0 * ((*ex)[1] - (*ex)[0]);
68
}
69
#if USE_HESSVEC
70
void
hessVec
(
Vector<Real>
&hv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
71
72
73
ROL::Ptr<const vector> ex =
getVector
(x);
74
ROL::Ptr<const vector> ev =
getVector
(v);
75
ROL::Ptr<vector> ehv =
getVector
(hv);
76
Real h11 = 1.e-5 * 2.0;
77
Real h22 = 1.e-5 * 2.0;
78
Real h12 = -1.e-5 * 2.0;
79
Real h21 = -1.e-5 * 2.0;
80
81
(*ehv)[0] = h11 * (*ev)[0] + h12 * (*ev)[1];
82
(*ehv)[1] = h21 * (*ev)[0] + h22 * (*ev)[1];
83
}
84
#endif
85
void
invHessVec
(
Vector<Real>
&hv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
86
87
88
ROL::Ptr<const vector> ex =
getVector
(x);
89
ROL::Ptr<const vector> ev =
getVector
(v);
90
ROL::Ptr<vector> ehv =
getVector
(hv);
91
92
Real h11 = 1.e-5 * 2.0;
93
Real h22 = 1.e-5 * 2.0;
94
Real h12 = -1.e-5 * 2.0;
95
Real h21 = -1.e-5 * 2.0;
96
97
(*ehv)[0] = 1.0/(h11*h22 - h12*h21) * (h22 * (*ev)[0] - h12 * (*ev)[1]);
98
(*ehv)[1] = 1.0/(h11*h22 - h12*h21) * (-h21 * (*ev)[0] + h11 * (*ev)[1]);
99
}
100
};
101
102
template
<
class
Real>
103
class
getHS3
:
public
TestProblem
<Real> {
104
public
:
105
getHS3
(
void
) {}
106
107
Ptr<Objective<Real>>
getObjective
(
void
)
const
{
108
// Instantiate Objective Function
109
return
ROL::makePtr<Objective_HS3<Real>>();
110
}
111
112
Ptr<Vector<Real>>
getInitialGuess
(
void
)
const
{
113
// Problem dimension
114
int
n = 2;
115
// Get Initial Guess
116
ROL::Ptr<std::vector<Real> > x0p = ROL::makePtr<std::vector<Real>>(n,0.0);
117
(*x0p)[0] = 10.0; (*x0p)[1] = 1.0;
118
return
ROL::makePtr<StdVector<Real>>(x0p);
119
}
120
121
Ptr<Vector<Real>>
getSolution
(
const
int
i = 0)
const
{
122
// Problem dimension
123
int
n = 2;
124
// Get Solution
125
ROL::Ptr<std::vector<Real> > xp = ROL::makePtr<std::vector<Real>>(n,0.0);
126
(*xp)[0] = 0.0; (*xp)[1] = 0.0;
127
return
ROL::makePtr<StdVector<Real>>(xp);
128
}
129
130
Ptr<BoundConstraint<Real>>
getBoundConstraint
(
void
)
const
{
131
// Problem dimension
132
int
n = 2;
133
// Instantiate BoundConstraint
134
ROL::Ptr<std::vector<Real> > lp = ROL::makePtr<std::vector<Real>>(n,0.0);
135
(*lp)[0] =
ROL_NINF<Real>
(); (*lp)[1] = 0.0;
136
ROL::Ptr<Vector<Real> > l = ROL::makePtr<StdVector<Real>>(lp);
137
ROL::Ptr<std::vector<Real> > up = ROL::makePtr<std::vector<Real>>(n,0.0);
138
(*up)[0] =
ROL_INF<Real>
(); (*up)[1] =
ROL_INF<Real>
();
139
ROL::Ptr<Vector<Real> > u = ROL::makePtr<StdVector<Real>>(up);
140
return
ROL::makePtr<Bounds<Real>>(l,u);
141
}
142
};
143
144
}
// End ZOO Namespace
145
}
// End ROL Namespace
146
147
#endif
ROL_Bounds.hpp
ROL_StdVector.hpp
ROL_TestProblem.hpp
Contains definitions of test objective functions.
ROL_Types.hpp
Contains definitions of custom data types in ROL.
ROL::ROL::Objective::hessVec
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Definition
ROL_ObjectiveDef.hpp:61
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::ZOO::Objective_HS3::Objective_HS3
Objective_HS3(void)
Definition
ROL_HS3.hpp:52
ROL::ZOO::Objective_HS3::gradient
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Definition
ROL_HS3.hpp:61
ROL::ZOO::Objective_HS3::V
Vector< Real > V
Definition
ROL_HS3.hpp:36
ROL::ZOO::Objective_HS3::value
Real value(const Vector< Real > &x, Real &tol)
Definition
ROL_HS3.hpp:54
ROL::ZOO::Objective_HS3::getVector
ROL::Ptr< vector > getVector(V &x)
Definition
ROL_HS3.hpp:46
ROL::ZOO::Objective_HS3::SV
StdVector< Real > SV
Definition
ROL_HS3.hpp:37
ROL::ZOO::Objective_HS3::getVector
ROL::Ptr< const vector > getVector(const V &x)
Definition
ROL_HS3.hpp:41
ROL::ZOO::Objective_HS3::vector
std::vector< Real > vector
Definition
ROL_HS3.hpp:35
ROL::ZOO::Objective_HS3::invHessVec
void invHessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition
ROL_HS3.hpp:85
ROL::ZOO::getHS3::getInitialGuess
Ptr< Vector< Real > > getInitialGuess(void) const
Definition
ROL_HS3.hpp:112
ROL::ZOO::getHS3::getSolution
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition
ROL_HS3.hpp:121
ROL::ZOO::getHS3::getHS3
getHS3(void)
Definition
ROL_HS3.hpp:105
ROL::ZOO::getHS3::getBoundConstraint
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition
ROL_HS3.hpp:130
ROL::ZOO::getHS3::getObjective
Ptr< Objective< Real > > getObjective(void) const
Definition
ROL_HS3.hpp:107
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::ROL_NINF
Real ROL_NINF(void)
Definition
ROL_Types.hpp:74
ROL::ROL_INF
Real ROL_INF(void)
Definition
ROL_Types.hpp:71
Generated by
1.17.0