ROL
ROL_AffineTransformObjective_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_AFFINE_TRANSFORM_OBJECTIVE_DEF_H
11#define ROL_AFFINE_TRANSFORM_OBJECTIVE_DEF_H
12
13namespace ROL {
14
15template<typename Real>
17 const Ptr<Constraint<Real>> &acon,
18 const Vector<Real> &range,
19 const Ptr<VectorController<Real>> &storage)
20 : obj_(obj), acon_(acon), storage_(storage) {
21 primal_ = range.clone();
22 Av_ = range.clone();
23 dual_ = range.dual().clone();
24 if (storage == nullPtr) storage_ = makePtr<VectorController<Real>>();
25}
26
27template<typename Real>
29 const Ptr<LinearConstraint<Real>> &acon,
30 const Ptr<VectorController<Real>> &storage)
31 : obj_(obj), acon_(acon), storage_(storage) {
32 primal_ = acon->createRangeSpaceVector();
33 Av_ = acon->createRangeSpaceVector();
34 dual_ = primal_->dual().clone();
35 if (storage == nullPtr) storage_ = makePtr<VectorController<Real>>();
36}
37
38template<typename Real>
40 const Ptr<const LinearOperator<Real>> &A,
41 const Ptr<const Vector<Real>> &b,
42 const Ptr<VectorController<Real>> &storage)
43 : obj_(obj), acon_(makePtr<LinearConstraint<Real>>(A,b)), storage_(storage) {
44 primal_ = b->clone();
45 Av_ = b->clone();
46 dual_ = b->dual().clone();
47 if (storage == nullPtr) storage_ = makePtr<VectorController<Real>>();
48}
49
50template<typename Real>
52 storage_->objectiveUpdate(type);
53 acon_->update(x,type,iter);
54 obj_->update(*transform(x),type,iter);
55}
56
57template<typename Real>
58void AffineTransformObjective<Real>::update( const Vector<Real> &x, bool flag, int iter ) {
59 storage_->objectiveUpdate(true);
60 acon_->update(x,flag,iter);
61 obj_->update(*transform(x),flag,iter);
62}
63
64template<typename Real>
66 return obj_->value(*transform(x),tol);
67}
68
69template<typename Real>
71 obj_->gradient(*dual_,*transform(x),tol);
72 acon_->applyAdjointJacobian(g,*dual_,x,tol);
73}
74
75template<typename Real>
77 acon_->applyJacobian(*Av_,v,x,tol);
78 obj_->hessVec(*dual_,*Av_,*transform(x),tol);
79 acon_->applyAdjointJacobian(hv,*dual_,x,tol);
80}
81
82template<typename Real>
83void AffineTransformObjective<Real>::setParameter(const std::vector<Real> &param) {
85 obj_->setParameter(param);
86}
87
88template<typename Real>
90 bool isApplied = storage_->get(*primal_,Objective<Real>::getParameter());
91 if (!isApplied) {
92 Real tol = std::sqrt(ROL_EPSILON<Real>());
93 acon_->value(*primal_,x,tol);
94 storage_->set(*primal_,Objective<Real>::getParameter());
95 }
96 return primal_;
97}
98
99} // namespace ROL
100
101#endif // ROL_AFFINE_TRANSFORM_OBJECTIVE_DEF_H
const Ptr< Obj > obj_
Ptr< const Vector< Real > > transform(const Vector< Real > &x)
AffineTransformObjective(const Ptr< Objective< Real > > &obj, const Ptr< Constraint< Real > > &acon, const Vector< Real > &range, const Ptr< VectorController< Real > > &storage=nullPtr)
void update(const Vector< Real > &x, UpdateType type, int iter=-1) override
Update objective function.
void setParameter(const std::vector< Real > &param) override
Ptr< VectorController< Real > > storage_
Real value(const Vector< Real > &x, Real &tol) override
Compute value.
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply Hessian approximation to vector.
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol) override
Compute gradient.
Defines the general constraint operator interface.
Defines the general affine constraint with the form .
Provides the interface to apply a linear operator.
Provides the interface to evaluate objective functions.
virtual void setParameter(const std::vector< Real > &param)
Defines the linear algebra or vector space interface.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.