ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
function
constraint
ROL_ConstraintFromObjective_Def.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
10
#ifndef ROL_CONSTRAINTFROMOBJECTIVE_DEF_H
11
#define ROL_CONSTRAINTFROMOBJECTIVE_DEF_H
12
13
namespace
ROL
{
14
15
template
<
typename
Real>
16
ConstraintFromObjective<Real>::ConstraintFromObjective
(
const
Ptr<
Objective<Real>
> &obj,
const
Real offset ) :
17
obj_
(obj),
dualVector_
(nullPtr),
offset_
(offset),
isDualInitialized_
(false) {}
18
19
template
<
typename
Real>
20
const
Ptr<Objective<Real>>
ConstraintFromObjective<Real>::getObjective
(
void
)
const
{
return
obj_
; }
21
22
template
<
typename
Real>
23
void
ConstraintFromObjective<Real>::setParameter
(
const
std::vector<Real> ¶m ) {
24
obj_
->setParameter(param);
25
Constraint<Real>::setParameter
(param);
26
}
27
28
template
<
typename
Real>
29
void
ConstraintFromObjective<Real>::update
(
const
Vector<Real>
& x,
UpdateType
type,
int
iter ) {
30
obj_
->update(x,type,iter);
31
}
32
33
template
<
typename
Real>
34
void
ConstraintFromObjective<Real>::update
(
const
Vector<Real>
& x,
bool
flag,
int
iter ) {
35
obj_
->update(x,flag,iter);
36
}
37
38
template
<
typename
Real>
39
void
ConstraintFromObjective<Real>::value
(
Vector<Real>
& c,
const
Vector<Real>
& x, Real& tol ) {
40
setValue
(c,
obj_
->value(x,tol) -
offset_
);
41
}
42
43
template
<
typename
Real>
44
void
ConstraintFromObjective<Real>::applyJacobian
(
Vector<Real>
& jv,
const
Vector<Real>
& v,
const
Vector<Real>
& x, Real& tol ) {
45
if
( !
isDualInitialized_
) {
46
dualVector_
= x.
dual
().
clone
();
47
isDualInitialized_
=
true
;
48
}
49
obj_
->gradient(*
dualVector_
,x,tol);
50
//setValue(jv,v.dot(dualVector_->dual()));
51
setValue
(jv,v.
apply
(*
dualVector_
));
52
}
53
54
template
<
typename
Real>
55
void
ConstraintFromObjective<Real>::applyAdjointJacobian
(
Vector<Real>
& ajv,
const
Vector<Real>
& v,
const
Vector<Real>
& x, Real& tol ) {
56
obj_
->gradient(ajv,x,tol);
57
ajv.
scale
(
getValue
(v));
58
}
59
60
template
<
typename
Real>
61
void
ConstraintFromObjective<Real>::applyAdjointHessian
(
Vector<Real>
& ahuv,
const
Vector<Real>
& u,
const
Vector<Real>
& v,
const
Vector<Real>
& x, Real& tol ) {
62
obj_
->hessVec(ahuv,v,x,tol);
63
ahuv.
scale
(
getValue
(u));
64
}
65
66
template
<
typename
Real>
67
Real
ConstraintFromObjective<Real>::getValue
(
const
Vector<Real>
& x ) {
68
return
dynamic_cast<
const
SingletonVector<Real>
&
>
(x).
getValue
();
69
}
70
71
template
<
typename
Real>
72
void
ConstraintFromObjective<Real>::setValue
(
Vector<Real>
& x, Real val ) {
73
dynamic_cast<
SingletonVector<Real>
&
>
(x).
setValue
(val);
74
}
75
76
}
// namespace ROL
77
78
#endif
// ROL_CONSTRAINTFROMOBJECTIVE_H
getValue
virtual Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
Definition
ROL_RandVarFunctional.hpp:320
ROL::ConstraintFromObjective::setValue
void setValue(Vector< Real > &x, Real val)
Definition
ROL_ConstraintFromObjective_Def.hpp:72
ROL::ConstraintFromObjective::update
void update(const Vector< Real > &x, UpdateType type, int iter=-1) override
Definition
ROL_ConstraintFromObjective_Def.hpp:29
ROL::ConstraintFromObjective::value
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol) override
Definition
ROL_ConstraintFromObjective_Def.hpp:39
ROL::ConstraintFromObjective::offset_
const Real offset_
Definition
ROL_ConstraintFromObjective.hpp:34
ROL::ConstraintFromObjective::ConstraintFromObjective
ConstraintFromObjective(const Ptr< Objective< Real > > &obj, const Real offset=0)
Definition
ROL_ConstraintFromObjective_Def.hpp:16
ROL::ConstraintFromObjective::applyAdjointHessian
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Definition
ROL_ConstraintFromObjective_Def.hpp:61
ROL::ConstraintFromObjective::obj_
const Ptr< Objective< Real > > obj_
Definition
ROL_ConstraintFromObjective.hpp:32
ROL::ConstraintFromObjective::setParameter
void setParameter(const std::vector< Real > ¶m) override
Definition
ROL_ConstraintFromObjective_Def.hpp:23
ROL::ConstraintFromObjective::getObjective
const Ptr< Objective< Real > > getObjective(void) const
Definition
ROL_ConstraintFromObjective_Def.hpp:20
ROL::ConstraintFromObjective::applyAdjointJacobian
void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Definition
ROL_ConstraintFromObjective_Def.hpp:55
ROL::ConstraintFromObjective::applyJacobian
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Definition
ROL_ConstraintFromObjective_Def.hpp:44
ROL::ConstraintFromObjective::dualVector_
Ptr< Vector< Real > > dualVector_
Definition
ROL_ConstraintFromObjective.hpp:33
ROL::ConstraintFromObjective::isDualInitialized_
bool isDualInitialized_
Definition
ROL_ConstraintFromObjective.hpp:35
ROL::ConstraintFromObjective::getValue
Real getValue(const Vector< Real > &x)
Definition
ROL_ConstraintFromObjective_Def.hpp:67
ROL::Constraint::setParameter
virtual void setParameter(const std::vector< Real > ¶m)
Definition
ROL_Constraint.hpp:374
ROL::Objective
Provides the interface to evaluate objective functions.
Definition
ROL_Objective.hpp:44
ROL::ROL::Vector::clone
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
ROL::SingletonVector
Definition
ROL_SingletonVector.hpp:25
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL::Vector::apply
virtual Real apply(const Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
Definition
ROL_Vector.hpp:205
ROL::Vector::scale
virtual void scale(const Real alpha)=0
Compute where .
ROL::Vector::dual
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
Definition
ROL_Vector.hpp:193
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::UpdateType
UpdateType
Definition
ROL_UpdateType.hpp:18
Generated by
1.17.0