ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
function
objective
ROL_LinearCombinationObjective_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_LINEARCOMBINATIONOBJECTIVE_DEF_H
11
#define ROL_LINEARCOMBINATIONOBJECTIVE_DEF_H
12
13
namespace
ROL
{
14
15
template
<
typename
Real>
16
LinearCombinationObjective<Real>::LinearCombinationObjective
(
const
std::vector<Ptr<
Objective<Real>
>> &obj)
17
:
Objective
<Real>(),
obj_
(obj),
18
xdual_
(nullPtr),
initialized_
(false) {
19
size_
=
obj_
.size();
20
weights_
.clear();
weights_
.assign(
size_
,
static_cast<
Real
>
(1));
21
}
22
23
template
<
typename
Real>
24
LinearCombinationObjective<Real>::LinearCombinationObjective
(
const
std::vector<Real> &weights,
25
const
std::vector<Ptr<
Objective<Real>
>> &obj)
26
:
Objective
<Real>(),
obj_
(obj),
weights_
(weights),
size_
(weights.size()),
27
xdual_
(nullPtr),
initialized_
(false) {}
28
29
template
<
typename
Real>
30
void
LinearCombinationObjective<Real>::update
(
const
Vector<Real>
&x,
UpdateType
type,
int
iter) {
31
for
(
size_t
i=0; i<
size_
; ++i) {
32
obj_
[i]->update(x,type,iter);
33
}
34
}
35
36
template
<
typename
Real>
37
void
LinearCombinationObjective<Real>::update
(
const
Vector<Real>
&x,
bool
flag,
int
iter) {
38
for
(
size_t
i=0; i<
size_
; ++i) {
39
obj_
[i]->update(x,flag,iter);
40
}
41
}
42
43
template
<
typename
Real>
44
Real
LinearCombinationObjective<Real>::value
(
const
Vector<Real>
&x, Real &tol ) {
45
Real val(0);
46
for
(
size_t
i = 0; i <
size_
; i++) {
47
val +=
weights_
[i]*
obj_
[i]->value(x,tol);
48
}
49
return
val;
50
}
51
52
template
<
typename
Real>
53
void
LinearCombinationObjective<Real>::gradient
(
Vector<Real>
&g,
const
Vector<Real>
&x, Real &tol ) {
54
if
(!
initialized_
) {
55
xdual_
= g.
clone
();
56
initialized_
=
true
;
57
}
58
g.
zero
();
59
for
(
size_t
i = 0; i <
size_
; i++) {
60
obj_
[i]->gradient(*
xdual_
,x,tol);
61
g.
axpy
(
weights_
[i],*
xdual_
);
62
}
63
}
64
65
template
<
typename
Real>
66
void
LinearCombinationObjective<Real>::hessVec
(
Vector<Real>
&hv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
67
if
(!
initialized_
) {
68
xdual_
= hv.
clone
();
69
initialized_
=
true
;
70
}
71
hv.
zero
();
72
for
(
size_t
i = 0; i <
size_
; i++) {
73
obj_
[i]->hessVec(*
xdual_
,v,x,tol);
74
hv.
axpy
(
weights_
[i],*
xdual_
);
75
}
76
}
77
78
template
<
typename
Real>
79
void
LinearCombinationObjective<Real>::setParameter
(
const
std::vector<Real> ¶m) {
80
Objective<Real>::setParameter
(param);
81
for
(
size_t
i = 0; i <
size_
; ++i) {
82
obj_
[i]->setParameter(param);
83
}
84
}
85
86
}
// namespace ROL
87
88
#endif
ROL::LinearCombinationObjective::setParameter
void setParameter(const std::vector< Real > ¶m) override
Definition
ROL_LinearCombinationObjective_Def.hpp:79
ROL::LinearCombinationObjective::size_
size_t size_
Definition
ROL_LinearCombinationObjective.hpp:23
ROL::LinearCombinationObjective::xdual_
Ptr< Vector< Real > > xdual_
Definition
ROL_LinearCombinationObjective.hpp:25
ROL::LinearCombinationObjective::obj_
const std::vector< Ptr< Objective< Real > > > obj_
Definition
ROL_LinearCombinationObjective.hpp:21
ROL::LinearCombinationObjective::initialized_
bool initialized_
Definition
ROL_LinearCombinationObjective.hpp:26
ROL::LinearCombinationObjective::value
Real value(const Vector< Real > &x, Real &tol) override
Definition
ROL_LinearCombinationObjective_Def.hpp:44
ROL::LinearCombinationObjective::LinearCombinationObjective
LinearCombinationObjective(const std::vector< Ptr< Objective< Real > > > &obj)
Definition
ROL_LinearCombinationObjective_Def.hpp:16
ROL::LinearCombinationObjective::gradient
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol) override
Definition
ROL_LinearCombinationObjective_Def.hpp:53
ROL::LinearCombinationObjective::hessVec
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Definition
ROL_LinearCombinationObjective_Def.hpp:66
ROL::LinearCombinationObjective::weights_
std::vector< Real > weights_
Definition
ROL_LinearCombinationObjective.hpp:22
ROL::LinearCombinationObjective::update
void update(const Vector< Real > &x, UpdateType type, int iter=-1) override
Definition
ROL_LinearCombinationObjective_Def.hpp:30
ROL::Objective::setParameter
virtual void setParameter(const std::vector< Real > ¶m)
Definition
ROL_Objective.hpp:509
ROL::ROL::Objective::Objective
Objective()
Definition
ROL_Constraint_SerialSimOpt.hpp:53
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::Vector::clone
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
ROL::Vector::axpy
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition
ROL_Vector.hpp:120
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::UpdateType
UpdateType
Definition
ROL_UpdateType.hpp:18
Generated by
1.17.0