ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
zoo
testproblems
ROL_HS45.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_HS45_HPP
20
#define ROL_HS45_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_HS45
:
public
Objective
<Real> {
34
35
typedef
std::vector<Real>
vector
;
36
typedef
Vector<Real>
V
;
37
typedef
StdVector<Real>
SV
;
38
39
typedef
typename
vector::size_type
uint
;
40
41
private
:
42
uint
dim_
;
43
Real
fact_
;
44
45
ROL::Ptr<const vector>
getVector
(
const
V
& x ) {
46
47
return
dynamic_cast<
const
SV
&
>
(x).
getVector
();
48
}
49
50
ROL::Ptr<vector>
getVector
(
V
& x ) {
51
52
return
dynamic_cast<
SV
&
>
(x).
getVector
();
53
}
54
55
public
:
56
Objective_HS45
(
int
dim
= 5) :
dim_
((
uint
)
dim
) {
57
fact_
= 1.0;
58
for
(
uint
i = 0; i <
dim_
; i++ ) {
59
fact_
*= (Real)(i+1);
60
}
61
}
62
63
Real
value
(
const
Vector<Real>
&x, Real &tol ) {
64
65
ROL::Ptr<const vector> ex =
getVector
(x);
66
Real prod = 1.0;
67
for
(
uint
i = 0; i <
dim_
; i++ ) {
68
prod *= (*ex)[i];
69
}
70
return
2.0 - prod/
fact_
;
71
}
72
73
void
gradient
(
Vector<Real>
&g,
const
Vector<Real>
&x, Real &tol ) {
74
75
ROL::Ptr<const vector> ex =
getVector
(x);
76
ROL::Ptr<vector> eg =
getVector
(g);
77
78
Real prod = 1.0;
79
for
(
uint
j = 0; j <
dim_
; j++ ) {
80
for
(
uint
i = 0; i <
dim_
; i++ ) {
81
if
( j != i ) {
82
prod *= (*ex)[i];
83
}
84
}
85
(*eg)[j] = -prod/
fact_
;
86
prod = 1.0;
87
}
88
}
89
#if USE_HESSVEC
90
void
hessVec
(
Vector<Real>
&hv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
91
92
93
ROL::Ptr<const vector> ex =
getVector
(x);
94
ROL::Ptr<const vector> ev =
getVector
(v);
95
ROL::Ptr<vector> ehv =
getVector
(hv);
96
97
hv.
zero
();
98
Real prod = 1.0;
99
for
(
uint
l = 0; l <
dim_
; l++ ) {
100
for
(
uint
j = 0; j <
dim_
; j++ ) {
101
if
( l != j ) {
102
for
(
uint
i = 0; i <
dim_
; i++ ) {
103
if
( j != i && l != i ) {
104
prod *= (*ex)[i];
105
}
106
}
107
(*ehv)[l] += -prod/
fact_
*(*ev)[j];
108
}
109
prod = 1.0;
110
}
111
}
112
}
113
#endif
114
};
115
116
template
<
class
Real>
117
class
getHS45
:
public
TestProblem
<Real> {
118
public
:
119
getHS45
(
void
) {}
120
121
Ptr<Objective<Real>>
getObjective
(
void
)
const
{
122
// Problem dimension
123
int
n = 10;
124
// Instantiate Objective Function
125
return
ROL::makePtr<Objective_HS45<Real>>(n);
126
}
127
128
Ptr<Vector<Real>>
getInitialGuess
(
void
)
const
{
129
// Problem dimension
130
int
n = 10;
131
// Get Initial Guess
132
ROL::Ptr<std::vector<Real> > x0p = ROL::makePtr<std::vector<Real>>(n,0.0);
133
for
(
int
i = 0; i < n; i++ ) {
134
(*x0p)[i] = 2.0;
135
}
136
return
ROL::makePtr<StdVector<Real>>(x0p);
137
}
138
139
Ptr<Vector<Real>>
getSolution
(
const
int
i = 0)
const
{
140
// Problem dimension
141
int
n = 10;
142
// Get Solution
143
ROL::Ptr<std::vector<Real> > xp = ROL::makePtr<std::vector<Real>>(n,0.0);
144
for
(
int
li = 0; li < n; li++ ) {
145
(*xp)[li] = (Real)(li+1);
146
}
147
return
ROL::makePtr<StdVector<Real>>(xp);
148
}
149
150
Ptr<BoundConstraint<Real>>
getBoundConstraint
(
void
)
const
{
151
// Problem dimension
152
int
n = 10;
153
// Instantiate BoundConstraint
154
ROL::Ptr<std::vector<Real> > lp = ROL::makePtr<std::vector<Real>>(n,0.0);
155
ROL::Ptr<std::vector<Real> > up = ROL::makePtr<std::vector<Real>>(n,0.0);
156
for
(
int
i = 0; i < n; i++ ) {
157
(*lp)[i] = 0.0;
158
(*up)[i] =
static_cast<
Real
>
(i+1);
159
}
160
ROL::Ptr<Vector<Real> > l = ROL::makePtr<StdVector<Real>>(lp);
161
ROL::Ptr<Vector<Real> > u = ROL::makePtr<StdVector<Real>>(up);
162
return
ROL::makePtr<Bounds<Real>>(l,u);
163
}
164
};
165
166
167
}
// End ZOO Namespace
168
}
// End ROL Namespace
169
170
#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::Vector::zero
virtual void zero()
Set to zero vector.
Definition
ROL_Vector.hpp:134
ROL::ZOO::Objective_HS45::Objective_HS45
Objective_HS45(int dim=5)
Definition
ROL_HS45.hpp:56
ROL::ZOO::Objective_HS45::gradient
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Definition
ROL_HS45.hpp:73
ROL::ZOO::Objective_HS45::fact_
Real fact_
Definition
ROL_HS45.hpp:43
ROL::ZOO::Objective_HS45::getVector
ROL::Ptr< const vector > getVector(const V &x)
Definition
ROL_HS45.hpp:45
ROL::ZOO::Objective_HS45::value
Real value(const Vector< Real > &x, Real &tol)
Definition
ROL_HS45.hpp:63
ROL::ZOO::Objective_HS45::vector
std::vector< Real > vector
Definition
ROL_HS45.hpp:35
ROL::ZOO::Objective_HS45::getVector
ROL::Ptr< vector > getVector(V &x)
Definition
ROL_HS45.hpp:50
ROL::ZOO::Objective_HS45::SV
StdVector< Real > SV
Definition
ROL_HS45.hpp:37
ROL::ZOO::Objective_HS45::dim_
uint dim_
Definition
ROL_HS45.hpp:42
ROL::ZOO::Objective_HS45::uint
vector::size_type uint
Definition
ROL_HS45.hpp:39
ROL::ZOO::Objective_HS45::V
Vector< Real > V
Definition
ROL_HS45.hpp:36
ROL::ZOO::getHS45::getHS45
getHS45(void)
Definition
ROL_HS45.hpp:119
ROL::ZOO::getHS45::getSolution
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition
ROL_HS45.hpp:139
ROL::ZOO::getHS45::getBoundConstraint
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition
ROL_HS45.hpp:150
ROL::ZOO::getHS45::getObjective
Ptr< Objective< Real > > getObjective(void) const
Definition
ROL_HS45.hpp:121
ROL::ZOO::getHS45::getInitialGuess
Ptr< Vector< Real > > getInitialGuess(void) const
Definition
ROL_HS45.hpp:128
ROL
Definition
ROL_ElementwiseVector.hpp:27
dim
constexpr auto dim
Definition
vector/test_11.cpp:23
Generated by
1.17.0