ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
zoo
testproblems
ROL_HS4.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_HS4_HPP
20
#define ROL_HS4_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_HS4
:
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_HS4
(
void
) {}
53
54
Real
value
(
const
Vector<Real>
&x, Real &tol ) {
55
56
ROL::Ptr<const vector> ex =
getVector
(x);
57
58
return
1.0/3.0 * std::pow((*ex)[0] + 1.0,3.0) + (*ex)[1];
59
}
60
61
void
gradient
(
Vector<Real>
&g,
const
Vector<Real>
&x, Real &tol ) {
62
63
ROL::Ptr<const vector> ex =
getVector
(x);
64
ROL::Ptr<vector> eg =
getVector
(g);
65
66
(*eg)[0] = std::pow((*ex)[0] + 1.0,2.0);
67
(*eg)[1] = 1.0;
68
}
69
#if USE_HESSVEC
70
void
hessVec
(
Vector<Real>
&hv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
71
72
ROL::Ptr<const vector> ex =
getVector
(x);
73
ROL::Ptr<const vector> ev =
getVector
(v);
74
ROL::Ptr<vector> ehv =
getVector
(hv);
75
76
Real alpha = 0.0;
77
(*ehv)[0] = 2.0*((*ex)[0] + 1.0)*(*ev)[0] + alpha*(*ev)[0];
78
(*ehv)[1] = 0.0 + alpha*(*ev)[1];
79
}
80
#endif
81
};
82
83
template
<
class
Real>
84
class
getHS4
:
public
TestProblem
<Real> {
85
public
:
86
getHS4
(
void
) {}
87
88
Ptr<Objective<Real>>
getObjective
(
void
)
const
{
89
// Instantiate Objective Function
90
return
ROL::makePtr<Objective_HS4<Real>>();
91
}
92
93
Ptr<Vector<Real>>
getInitialGuess
(
void
)
const
{
94
// Problem dimension
95
int
n = 2;
96
// Get Initial Guess
97
ROL::Ptr<std::vector<Real> > x0p = ROL::makePtr<std::vector<Real>>(n,0.0);
98
(*x0p)[0] = 1.125; (*x0p)[1] = 0.125;
99
return
ROL::makePtr<StdVector<Real>>(x0p);
100
}
101
102
Ptr<Vector<Real>>
getSolution
(
const
int
i = 0)
const
{
103
// Problem dimension
104
int
n = 2;
105
// Get Solution
106
ROL::Ptr<std::vector<Real> > xp = ROL::makePtr<std::vector<Real>>(n,0.0);
107
(*xp)[0] = 1.0; (*xp)[1] = 0.0;
108
return
ROL::makePtr<StdVector<Real>>(xp);
109
}
110
111
Ptr<BoundConstraint<Real>>
getBoundConstraint
(
void
)
const
{
112
// Problem dimension
113
int
n = 2;
114
// Instantiate BoundConstraint
115
ROL::Ptr<std::vector<Real> > lp = ROL::makePtr<std::vector<Real>>(n,0.0);
116
(*lp)[0] = 1.0; (*lp)[1] = 0.0;
117
ROL::Ptr<Vector<Real> > l = ROL::makePtr<StdVector<Real>>(lp);
118
ROL::Ptr<std::vector<Real> > up = ROL::makePtr<std::vector<Real>>(n,0.0);
119
(*up)[0] =
ROL_INF<Real>
(); (*up)[1] =
ROL_INF<Real>
();
120
ROL::Ptr<Vector<Real> > u = ROL::makePtr<StdVector<Real>>(up);
121
return
ROL::makePtr<Bounds<Real>>(l,u);
122
}
123
};
124
125
}
// End ZOO Namespace
126
}
// End ROL Namespace
127
128
#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_HS4::V
Vector< Real > V
Definition
ROL_HS4.hpp:36
ROL::ZOO::Objective_HS4::Objective_HS4
Objective_HS4(void)
Definition
ROL_HS4.hpp:52
ROL::ZOO::Objective_HS4::vector
std::vector< Real > vector
Definition
ROL_HS4.hpp:35
ROL::ZOO::Objective_HS4::getVector
ROL::Ptr< vector > getVector(V &x)
Definition
ROL_HS4.hpp:46
ROL::ZOO::Objective_HS4::getVector
ROL::Ptr< const vector > getVector(const V &x)
Definition
ROL_HS4.hpp:41
ROL::ZOO::Objective_HS4::SV
StdVector< Real > SV
Definition
ROL_HS4.hpp:37
ROL::ZOO::Objective_HS4::value
Real value(const Vector< Real > &x, Real &tol)
Definition
ROL_HS4.hpp:54
ROL::ZOO::Objective_HS4::gradient
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Definition
ROL_HS4.hpp:61
ROL::ZOO::getHS4::getObjective
Ptr< Objective< Real > > getObjective(void) const
Definition
ROL_HS4.hpp:88
ROL::ZOO::getHS4::getInitialGuess
Ptr< Vector< Real > > getInitialGuess(void) const
Definition
ROL_HS4.hpp:93
ROL::ZOO::getHS4::getHS4
getHS4(void)
Definition
ROL_HS4.hpp:86
ROL::ZOO::getHS4::getSolution
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition
ROL_HS4.hpp:102
ROL::ZOO::getHS4::getBoundConstraint
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition
ROL_HS4.hpp:111
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::ROL_INF
Real ROL_INF(void)
Definition
ROL_Types.hpp:71
Generated by
1.17.0