ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
zoo
testproblems
ROL_Quartic.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_QUARTIC_HPP
20
#define ROL_QUARTIC_HPP
21
22
#include "
ROL_ScaledStdVector.hpp
"
23
#include "
ROL_StdObjective.hpp
"
24
#include "
ROL_StdConstraint.hpp
"
25
#include "
ROL_TestProblem.hpp
"
26
27
namespace
ROL
{
28
namespace
ZOO {
29
30
template
<
class
Real>
31
class
Objective_Quartic
:
public
StdObjective
<Real> {
32
public
:
33
Objective_Quartic
() {}
34
35
Real
value
(
const
std::vector<Real> &x, Real &tol ) {
36
const
Real one(1);
37
return
std::pow(x[0]-one, 4) + std::pow(x[1]-one, 4);
38
}
39
40
void
gradient
( std::vector<Real> &g,
const
std::vector<Real> &x, Real &tol ) {
41
const
Real one(1), four(4);
42
g[0] = four * std::pow(x[0]-one, 3);
43
g[1] = four * std::pow(x[1]-one, 3);
44
}
45
#if USE_HESSVEC
46
void
hessVec
( std::vector<Real> &hv,
const
std::vector<Real> &v,
const
std::vector<Real> &x, Real &tol ) {
47
const
Real one(1), twelve(12);
48
hv[0] = twelve * std::pow(x[0]-one, 2) * v[0];
49
hv[1] = twelve * std::pow(x[1]-one, 2) * v[1];
50
}
51
#endif
52
};
53
54
template
<
class
Real>
55
class
Constraint_Quartic
:
public
StdConstraint
<Real> {
56
public
:
57
Constraint_Quartic
() {}
58
59
void
value
( std::vector<Real> &c,
const
std::vector<Real> &x, Real &tol ) {
60
const
Real half(0.5);
61
c[0] = std::pow(x[0], 2) - half*x[1];
62
c[1] = std::pow(x[1], 2) - half*x[0];
63
}
64
65
void
applyJacobian
( std::vector<Real> &jv,
const
std::vector<Real> &v,
const
std::vector<Real> &x, Real &tol ) {
66
const
Real half(0.5), two(2);
67
jv[0] = two*x[0]*v[0] - half*v[1];
68
jv[1] = two*x[1]*v[1] - half*v[0];
69
}
70
71
void
applyAdjointJacobian
( std::vector<Real> &ajv,
const
std::vector<Real> &v,
const
std::vector<Real> &x, Real &tol ) {
72
const
Real half(0.5), two(2);
73
ajv[0] = two*x[0]*v[0] - half*v[1];
74
ajv[1] = two*x[1]*v[1] - half*v[0];
75
}
76
#if USE_HESSVEC
77
void
applyAdjointHessian
( std::vector<Real> &ahuv,
const
std::vector<Real> &u,
const
std::vector<Real> &v,
const
std::vector<Real> &x, Real &tol ) {
78
const
Real two(2);
79
ahuv[0] = two*u[0]*v[0];
80
ahuv[1] = two*u[1]*v[1];
81
}
82
#endif
83
};
84
85
template
<
class
Real>
86
class
getQuartic
:
public
TestProblem
<Real> {
87
public
:
88
getQuartic
() {}
89
90
Ptr<Objective<Real>>
getObjective
(
void
)
const
{
91
return
makePtr<Objective_Quartic<Real>>();
92
}
93
94
Ptr<Vector<Real>>
getInitialGuess
(
void
)
const
{
95
int
n = 2;
96
Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(n,
static_cast<
Real
>
(1.0));
97
Ptr<std::vector<Real>> xp = makePtr<std::vector<Real>>(n,
static_cast<
Real
>
(1.0));
98
return
makePtr<PrimalScaledStdVector<Real>>(xp,scale);
99
}
100
101
Ptr<Vector<Real>>
getSolution
(
const
int
i = 0)
const
{
102
int
n = 2;
103
Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(n,
static_cast<
Real
>
(1.0));
104
Ptr<std::vector<Real>> xp = makePtr<std::vector<Real>>(n,
static_cast<
Real
>
(0.5));
105
return
makePtr<PrimalScaledStdVector<Real>>(xp,scale);
106
}
107
108
Ptr<BoundConstraint<Real>>
getBoundConstraint
(
void
)
const
{
109
int
n = 2;
110
Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(n,
static_cast<
Real
>
(1.0));
111
Ptr<std::vector<Real>> lp = makePtr<std::vector<Real>>(n,
static_cast<
Real
>
(0.0));
112
Ptr<std::vector<Real>> up = makePtr<std::vector<Real>>(n,
static_cast<
Real
>
(0.0));
113
(*lp)[0] =
static_cast<
Real
>
( 0.5);
114
(*lp)[1] =
static_cast<
Real
>
(-2.9);
115
(*up)[0] =
static_cast<
Real
>
( 5.8);
116
(*up)[1] =
static_cast<
Real
>
( 2.9);
117
Ptr<Vector<Real>> l = makePtr<PrimalScaledStdVector<Real>>(lp,scale);
118
Ptr<Vector<Real>> u = makePtr<PrimalScaledStdVector<Real>>(up,scale);
119
return
makePtr<Bounds<Real>>(l,u);
120
}
121
122
Ptr<Constraint<Real>>
getInequalityConstraint
(
void
)
const
{
123
return
makePtr<Constraint_Quartic<Real>>();
124
}
125
126
Ptr<Vector<Real>>
getInequalityMultiplier
(
void
)
const
{
127
Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(2,
static_cast<
Real
>
(1.0));
128
Ptr<std::vector<Real>> lp = makePtr<std::vector<Real>>(2,
static_cast<
Real
>
(0.0));
129
return
makePtr<DualScaledStdVector<Real>>(lp,scale);
130
}
131
132
Ptr<BoundConstraint<Real>>
getSlackBoundConstraint
(
void
)
const
{
133
Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(2,
static_cast<
Real
>
(1.0));
134
Ptr<std::vector<Real>> up = makePtr<std::vector<Real>>(2,
static_cast<
Real
>
(0.0));
135
Ptr<Vector<Real>> u = makePtr<DualScaledStdVector<Real>>(up,scale);
136
return
makePtr<Bounds<Real>>(*u,
false
);
137
}
138
};
139
140
}
// End ZOO Namespace
141
}
// End ROL Namespace
142
143
#endif
ROL_ScaledStdVector.hpp
ROL_StdConstraint.hpp
ROL_StdObjective.hpp
ROL_TestProblem.hpp
Contains definitions of test objective functions.
ROL::StdConstraint
Defines the equality constraint operator interface for StdVectors.
Definition
ROL_StdConstraint.hpp:25
ROL::StdConstraint::applyAdjointHessian
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Definition
ROL_StdConstraint_Def.hpp:81
ROL::StdObjective
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector's.
Definition
ROL_StdObjective.hpp:26
ROL::StdObjective::hessVec
virtual void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition
ROL_StdObjective_Def.hpp:78
ROL::TestProblem::TestProblem
TestProblem(void)
Definition
ROL_TestProblem.hpp:28
ROL::ZOO::Constraint_Quartic::applyAdjointJacobian
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition
ROL_Quartic.hpp:71
ROL::ZOO::Constraint_Quartic::value
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition
ROL_Quartic.hpp:59
ROL::ZOO::Constraint_Quartic::Constraint_Quartic
Constraint_Quartic()
Definition
ROL_Quartic.hpp:57
ROL::ZOO::Constraint_Quartic::applyJacobian
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition
ROL_Quartic.hpp:65
ROL::ZOO::Objective_Quartic::Objective_Quartic
Objective_Quartic()
Definition
ROL_Quartic.hpp:33
ROL::ZOO::Objective_Quartic::value
Real value(const std::vector< Real > &x, Real &tol)
Definition
ROL_Quartic.hpp:35
ROL::ZOO::Objective_Quartic::gradient
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition
ROL_Quartic.hpp:40
ROL::ZOO::getQuartic::getObjective
Ptr< Objective< Real > > getObjective(void) const
Definition
ROL_Quartic.hpp:90
ROL::ZOO::getQuartic::getSlackBoundConstraint
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Definition
ROL_Quartic.hpp:132
ROL::ZOO::getQuartic::getInequalityConstraint
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Definition
ROL_Quartic.hpp:122
ROL::ZOO::getQuartic::getSolution
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition
ROL_Quartic.hpp:101
ROL::ZOO::getQuartic::getInequalityMultiplier
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Definition
ROL_Quartic.hpp:126
ROL::ZOO::getQuartic::getQuartic
getQuartic()
Definition
ROL_Quartic.hpp:88
ROL::ZOO::getQuartic::getBoundConstraint
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition
ROL_Quartic.hpp:108
ROL::ZOO::getQuartic::getInitialGuess
Ptr< Vector< Real > > getInitialGuess(void) const
Definition
ROL_Quartic.hpp:94
ROL
Definition
ROL_ElementwiseVector.hpp:27
Generated by
1.17.0