ROL
ROL_ElasticObjective_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_ELASTICOBJECTIVEDEF_H
11 #define ROL_ELASTICOBJECTIVEDEF_H
12 
13 
14 namespace ROL {
15 
16 template<typename Real>
18  const Ptr<Constraint<Real>> &con,
19  const Real penaltyParameter,
20  const Real sigma,
21  const Vector<Real> &dualOptVec,
22  const Vector<Real> &primConVec,
23  const Vector<Real> &dualConVec,
24  ParameterList &parlist)
25  : sigma_(sigma), cscale_(1) {
26  alobj_ = makePtr<AugmentedLagrangianObjective<Real>>(obj,con,penaltyParameter,dualOptVec,primConVec,dualConVec,parlist);
27  e_ = primConVec.clone(); e_->setScalar(static_cast<Real>(1));
28  tmp_ = primConVec.clone();
29 }
30 
31 template<typename Real>
33  const Ptr<Constraint<Real>> &con,
34  const Real penaltyParameter,
35  const Real sigma,
36  const Vector<Real> &dualOptVec,
37  const Vector<Real> &primConVec,
38  const Vector<Real> &dualConVec,
39  const bool scaleLagrangian,
40  const int HessianApprox)
41  : sigma_(sigma), cscale_(1) {
42  alobj_ = makePtr<AugmentedLagrangianObjective<Real>>(obj,con,penaltyParameter,dualOptVec,primConVec,dualConVec,scaleLagrangian,HessianApprox);
43  e_ = primConVec.clone(); e_->setScalar(static_cast<Real>(1));
44  tmp_ = primConVec.clone();
45 }
46 
47 template<typename Real>
48 void ElasticObjective<Real>::update( const Vector<Real> &x, UpdateType type, int iter ) {
49  Ptr<const Vector<Real>> xs = dynamic_cast<const PartitionedVector<Real>&>(x).get(0);
50  alobj_->update(*xs,type,iter);
51 }
52 
53 template<typename Real>
54 void ElasticObjective<Real>::setScaling(const Real fscale, const Real cscale) {
55  cscale_ = cscale;
56  alobj_->setScaling(fscale,cscale);
57 }
58 
59 template<typename Real>
60 Real ElasticObjective<Real>::value( const Vector<Real> &x, Real &tol ) {
61  Ptr<const Vector<Real>> xs = dynamic_cast<const PartitionedVector<Real>&>(x).get(0);
62  Ptr<const Vector<Real>> xu = dynamic_cast<const PartitionedVector<Real>&>(x).get(1);
63  Ptr<const Vector<Real>> xv = dynamic_cast<const PartitionedVector<Real>&>(x).get(2);
64  Real val = alobj_->value(*xs,tol);
65  tmp_->set(*xu); tmp_->plus(*xv);
66  Real pen = sigma_ * cscale_ * e_->dot(*tmp_);
67  return val + pen;
68 }
69 
70 template<typename Real>
72  Ptr<Vector<Real>> gs = dynamic_cast<PartitionedVector<Real>&>(g).get(0);
73  Ptr<Vector<Real>> gu = dynamic_cast<PartitionedVector<Real>&>(g).get(1);
74  Ptr<Vector<Real>> gv = dynamic_cast<PartitionedVector<Real>&>(g).get(2);
75  Ptr<const Vector<Real>> xs = dynamic_cast<const PartitionedVector<Real>&>(x).get(0);
76  alobj_->gradient(*gs,*xs,tol);
77  gu->set(*e_); gu->scale(sigma_ * cscale_);
78  gv->set(*e_); gv->scale(sigma_ * cscale_);
79 }
80 
81 template<typename Real>
82 void ElasticObjective<Real>::hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
83  Ptr<Vector<Real>> hvs = dynamic_cast<PartitionedVector<Real>&>(hv).get(0);
84  Ptr<Vector<Real>> hvu = dynamic_cast<PartitionedVector<Real>&>(hv).get(1);
85  Ptr<Vector<Real>> hvv = dynamic_cast<PartitionedVector<Real>&>(hv).get(2);
86  Ptr<const Vector<Real>> vs = dynamic_cast<const PartitionedVector<Real>&>(v).get(0);
87  Ptr<const Vector<Real>> xs = dynamic_cast<const PartitionedVector<Real>&>(x).get(0);
88  alobj_->hessVec(*hvs,*vs,*xs,tol);
89  hvu->zero();
90  hvv->zero();
91 }
92 
93 template<typename Real>
95  return alobj_->getObjectiveValue(x,tol);
96 }
97 
98 template<typename Real>
99 const Ptr<const Vector<Real>> ElasticObjective<Real>::getObjectiveGradient(const Vector<Real> &x, Real &tol) {
100  return alobj_->getObjectiveGradient(x,tol);
101 }
102 
103 template<typename Real>
104 const Ptr<const Vector<Real>> ElasticObjective<Real>::getConstraintVec(const Vector<Real> &x, Real &tol) {
105  return alobj_->getConstraintVec(x,tol);
106 }
107 
108 template<typename Real>
110  return alobj_->getNumberConstraintEvaluations();
111 }
112 
113 template<typename Real>
115  return alobj_->getNumberFunctionEvaluations();
116 }
117 
118 template<typename Real>
120  return alobj_->getNumberGradientEvaluations();
121 }
122 
123 template<typename Real>
124 void ElasticObjective<Real>::reset(const Vector<Real> &multiplier, Real penaltyParameter, Real sigma) {
125  sigma_ = sigma;
126  alobj_->reset(multiplier,penaltyParameter);
127 }
128 
129 template<typename Real>
130 const Ptr<AugmentedLagrangianObjective<Real>> ElasticObjective<Real>::getAugmentedLagrangian(void) const {
131  return alobj_;
132 }
133 
134 } // namespace ROL
135 
136 #endif
Provides the interface to evaluate objective functions.
const Ptr< const Vector< Real > > getConstraintVec(const Vector< Real > &x, Real &tol)
Ptr< AugmentedLagrangianObjective< Real > > alobj_
Defines the linear algebra of vector space on a generic partitioned vector.
int getNumberFunctionEvaluations(void) const
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol) override
Compute gradient.
const Ptr< AugmentedLagrangianObjective< Real > > getAugmentedLagrangian(void) const
Ptr< Vector< Real > > e_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
Real getObjectiveValue(const Vector< Real > &x, Real &tol)
void setScaling(const Real fscale=1.0, const Real cscale=1.0)
const Ptr< const Vector< Real > > getObjectiveGradient(const Vector< Real > &x, Real &tol)
int getNumberConstraintEvaluations(void) const
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply Hessian approximation to vector.
Real value(const Vector< Real > &x, Real &tol) override
Compute value.
void update(const Vector< Real > &x, UpdateType type, int iter=-1) override
Update objective function.
int getNumberGradientEvaluations(void) const
ElasticObjective(const Ptr< Objective< Real >> &obj, const Ptr< Constraint< Real >> &con, const Real penaltyParameter, const Real sigma, const Vector< Real > &dualOptVec, const Vector< Real > &primConVec, const Vector< Real > &dualConVec, ParameterList &parlist)
void reset(const Vector< Real > &multiplier, Real penaltyParameter, Real sigma)
Ptr< Vector< Real > > tmp_
Defines the general constraint operator interface.