ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
zoo
testproblems
ROL_HS38.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_HS38_HPP
20
#define ROL_HS38_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_HS38
:
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_HS38
(
void
) {}
53
54
Real
value
(
const
Vector<Real>
&x, Real &tol ) {
55
56
57
ROL::Ptr<const vector> ex =
getVector
(x);
58
return
100.0 * std::pow((*ex)[1] - std::pow((*ex)[0],2.0),2.0) + std::pow(1.0-(*ex)[0],2.0) +
59
90.0 * std::pow((*ex)[3] - std::pow((*ex)[2],2.0),2.0) + std::pow(1.0-(*ex)[2],2.0) +
60
10.1 * (std::pow((*ex)[1] - 1.0,2.0) + std::pow((*ex)[3]-1.0,2.0)) +
61
19.8 * ((*ex)[1] - 1.0) * ((*ex)[3] - 1.0);
62
}
63
64
void
gradient
(
Vector<Real>
&g,
const
Vector<Real>
&x, Real &tol ) {
65
66
67
ROL::Ptr<const vector> ex =
getVector
(x);
68
ROL::Ptr<vector> eg =
getVector
(g);
69
70
(*eg)[0] = -4.0 * 100.0 * ((*ex)[1] - std::pow((*ex)[0],2.0)) * (*ex)[0] - 2.0 * (1.0-(*ex)[0]);
71
(*eg)[1] = 2.0 * 100.0 * ((*ex)[1] - std::pow((*ex)[0],2.0)) +
72
2.0 * 10.1 * ((*ex)[1] - 1.0) + 19.8*((*ex)[3] - 1.0);
73
(*eg)[2] = -4.0 * 90.0 * ((*ex)[3] - std::pow((*ex)[2],2.0)) * (*ex)[2] - 2.0 * (1.0-(*ex)[2]);
74
(*eg)[3] = 2.0 * 90.0 * ((*ex)[3] - std::pow((*ex)[2],2.0)) +
75
2.0 * 10.1 * ((*ex)[3] - 1.0) + 19.8*((*ex)[1] - 1.0);
76
}
77
#if USE_HESSVEC
78
void
hessVec
(
Vector<Real>
&hv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
79
80
81
ROL::Ptr<const vector> ex =
getVector
(x);
82
ROL::Ptr<const vector> ev =
getVector
(v);
83
ROL::Ptr<vector> ehv =
getVector
(hv);
84
85
Real h11 = -4.0 * 100.0 * (*ex)[1] + 12.0 * 100.0 * std::pow((*ex)[0],2.0) + 2.0;
86
Real h12 = -4.0 * 100.0 * (*ex)[0];
87
Real h13 = 0.0;
88
Real h14 = 0.0;
89
Real h21 = -4.0 * 100.0 * (*ex)[0];
90
Real h22 = 2.0 * 100.0 + 2.0 * 10.1;
91
Real h23 = 0.0;
92
Real h24 = 19.8;
93
Real h31 = 0.0;
94
Real h32 = 0.0;
95
Real h33 = -4.0 * 90.0 * (*ex)[3] + 12.0 * 90.0 * std::pow((*ex)[2],2.0) + 2.0;
96
Real h34 = -4.0 * 90.0 * (*ex)[2];
97
Real h41 = 0.0;
98
Real h42 = 19.8;
99
Real h43 = -4.0 * 90.0 * (*ex)[2];
100
Real h44 = 2.0 * 90.0 + 2.0 * 10.1;
101
102
(*ehv)[0] = h11 * (*ev)[0] + h12 * (*ev)[1] + h13 * (*ev)[2] + h14 * (*ev)[3];
103
(*ehv)[1] = h21 * (*ev)[0] + h22 * (*ev)[1] + h23 * (*ev)[2] + h24 * (*ev)[3];
104
(*ehv)[2] = h31 * (*ev)[0] + h32 * (*ev)[1] + h33 * (*ev)[2] + h34 * (*ev)[3];
105
(*ehv)[3] = h41 * (*ev)[0] + h42 * (*ev)[1] + h43 * (*ev)[2] + h44 * (*ev)[3];
106
}
107
#endif
108
};
109
110
template
<
class
Real>
111
class
getHS38
:
public
TestProblem
<Real> {
112
public
:
113
getHS38
(
void
) {}
114
115
Ptr<Objective<Real>>
getObjective
(
void
)
const
{
116
// Instantiate Objective Function
117
return
ROL::makePtr<Objective_HS38<Real>>();
118
}
119
120
Ptr<Vector<Real>>
getInitialGuess
(
void
)
const
{
121
// Problem dimension
122
int
n = 4;
123
// Get Initial Guess
124
ROL::Ptr<std::vector<Real> > x0p = ROL::makePtr<std::vector<Real>>(n,0.0);
125
(*x0p)[0] = -3.0; (*x0p)[1] = -1.0;
126
(*x0p)[2] = -3.0; (*x0p)[3] = -1.0;
127
return
ROL::makePtr<StdVector<Real>>(x0p);
128
}
129
130
Ptr<Vector<Real>>
getSolution
(
const
int
i = 0)
const
{
131
// Problem dimension
132
int
n = 4;
133
// Get Solution
134
ROL::Ptr<std::vector<Real> > xp = ROL::makePtr<std::vector<Real>>(n,0.0);
135
(*xp)[0] = 1.0; (*xp)[1] = 1.0;
136
(*xp)[2] = 1.0; (*xp)[3] = 1.0;
137
return
ROL::makePtr<StdVector<Real>>(xp);
138
}
139
140
Ptr<BoundConstraint<Real>>
getBoundConstraint
(
void
)
const
{
141
// Problem dimension
142
int
n = 4;
143
// Instantiate BoundConstraint
144
ROL::Ptr<std::vector<Real> > lp = ROL::makePtr<std::vector<Real>>(n,-10.0);
145
ROL::Ptr<Vector<Real> > l = ROL::makePtr<StdVector<Real>>(lp);
146
ROL::Ptr<std::vector<Real> > up = ROL::makePtr<std::vector<Real>>(n, 10.0);
147
ROL::Ptr<Vector<Real> > u = ROL::makePtr<StdVector<Real>>(up);
148
return
ROL::makePtr<Bounds<Real>>(l,u);
149
}
150
};
151
152
153
}
// End ZOO Namespace
154
}
// End ROL Namespace
155
156
#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_HS38::value
Real value(const Vector< Real > &x, Real &tol)
Definition
ROL_HS38.hpp:54
ROL::ZOO::Objective_HS38::Objective_HS38
Objective_HS38(void)
Definition
ROL_HS38.hpp:52
ROL::ZOO::Objective_HS38::getVector
ROL::Ptr< const vector > getVector(const V &x)
Definition
ROL_HS38.hpp:41
ROL::ZOO::Objective_HS38::SV
StdVector< Real > SV
Definition
ROL_HS38.hpp:37
ROL::ZOO::Objective_HS38::vector
std::vector< Real > vector
Definition
ROL_HS38.hpp:35
ROL::ZOO::Objective_HS38::V
Vector< Real > V
Definition
ROL_HS38.hpp:36
ROL::ZOO::Objective_HS38::gradient
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Definition
ROL_HS38.hpp:64
ROL::ZOO::Objective_HS38::getVector
ROL::Ptr< vector > getVector(V &x)
Definition
ROL_HS38.hpp:46
ROL::ZOO::getHS38::getInitialGuess
Ptr< Vector< Real > > getInitialGuess(void) const
Definition
ROL_HS38.hpp:120
ROL::ZOO::getHS38::getSolution
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition
ROL_HS38.hpp:130
ROL::ZOO::getHS38::getObjective
Ptr< Objective< Real > > getObjective(void) const
Definition
ROL_HS38.hpp:115
ROL::ZOO::getHS38::getBoundConstraint
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition
ROL_HS38.hpp:140
ROL::ZOO::getHS38::getHS38
getHS38(void)
Definition
ROL_HS38.hpp:113
ROL
Definition
ROL_ElementwiseVector.hpp:27
Generated by
1.17.0