ROL
Loading...
Searching...
No Matches
ROL_AugmentedLagrangianObjective2.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_AUGMENTEDLAGRANGIANOBJECTIVE2_H
11#define ROL_AUGMENTEDLAGRANGIANOBJECTIVE2_H
12
15
16namespace ROL {
17
18template <class Real>
20
21private:
22
23 // Required for Augmented Lagrangian definition
24 const Ptr<Objective<Real>> obj_;
25 const std::vector<Ptr<AugmentedLagrangianPenalty<Real>>> pvec_;
26
27 // Auxiliary storage
28 Ptr<Vector<Real>> dualOptVector_;
29
30 // Objective evaluations
31 Ptr<ScalarController<Real,int>> fval_;
32 Ptr<VectorController<Real,int>> gradient_;
33
34 // Objective function
35 Real fscale_;
36
37 // Evaluation counters
38 int nfval_;
39 int ngval_;
40
41 // User defined options
43 // int HessianApprox_;
44
45public:
46
48 const std::vector<Ptr<AugmentedLagrangianPenalty<Real>>> &pen,
49 const Vector<Real> &dualOptVec,
50 ParameterList &parlist)
51 : obj_(obj), pvec_(pen), fscale_(1), nfval_(0), ngval_(0) {
52
53 fval_ = makePtr<ScalarController<Real,int>>();
54 gradient_ = makePtr<VectorController<Real,int>>();
55
56 dualOptVector_ = dualOptVec.clone();
57
58 ParameterList& sublist = parlist.sublist("Step").sublist("Augmented Lagrangian");
59 scaleLagrangian_ = sublist.get("Use Scaled Augmented Lagrangian", false);
60 }
61
63 const std::vector<Ptr<AugmentedLagrangianPenalty<Real>>> &pen,
64 const Vector<Real> &dualOptVec,
65 const bool scaleLagrangian)
66 : obj_(obj), pvec_(pen), fscale_(1), nfval_(0), ngval_(0),
67 scaleLagrangian_(scaleLagrangian) {
68
69 fval_ = makePtr<ScalarController<Real,int>>();
70 gradient_ = makePtr<VectorController<Real,int>>();
71
72 dualOptVector_ = dualOptVec.clone();
73 }
74
75 virtual void update( const Vector<Real> &x, UpdateType type, int iter = -1 ) {
76 obj_->update(x,type,iter);
77 for (unsigned i = 0; i < unsigned(getNumberConstraints()); ++i) pvec_[i]->update(x,type,iter);
78 fval_->objectiveUpdate(type);
79 gradient_->objectiveUpdate(type);
80 }
81
82 void setScaling(const Real fscale = 1.0) {
83 fscale_ = fscale;
84 }
85
86 void setScaling(const Real cscale, const int k) {
87 pvec_[k]->setScaling(cscale);
88 }
89
90 Real getScaling(const int k) {
91 return pvec_[k]->getScaling();
92 }
93
94 virtual Real value( const Vector<Real> &x, Real &tol ) {
95 // Compute objective function value
96 Real val = getObjectiveValue(x,tol);
97 val *= fscale_;
98 // Compute penalty term
99 for (unsigned i = 0; i < unsigned(getNumberConstraints()); ++i)
100 val += pvec_[i]->value(x,tol);
101 return val;
102 }
103
104 virtual void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
105 // Compute objective function gradient
106 g.set(*getObjectiveGradient(x,tol));
107 g.scale(fscale_);
108 for (unsigned i = 0; i < unsigned(getNumberConstraints()); ++i) {
109 pvec_[i]->gradient(*dualOptVector_,x,tol);
110 // std::cout << "Gradient penalty term " << i << ": " << std::scientific << std::setprecision(8) << dualOptVector_->norm() << std::endl;
112 }
113 }
114
115 virtual void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
116 // Apply objective Hessian to a vector
117 obj_->hessVec(hv,v,x,tol);
118 hv.scale(fscale_);
119 for (unsigned i = 0; i < unsigned(getNumberConstraints()); ++i) {
120 pvec_[i]->hessVec(*dualOptVector_,v,x,tol);
121 // std::cout << "HV penalty term " << i << ": " << std::scientific << std::setprecision(8) << dualOptVector_->norm() << std::endl;
122 hv.plus(*dualOptVector_);
123 }
124 }
125
126 Real dualNorm( const Vector<Real> &x, Real &tol, const int k ) {
127 return pvec_[k]->dualNorm(x,tol);
128 }
129
130 Real dualResidual( const Vector<Real> &x, Real &tol, const int k ) {
131 return pvec_[k]->dualResidual(x,tol);
132 }
133
134 Real feasibility( const Vector<Real> &x, Real &tol, const int k ) {
135 return pvec_[k]->feasibility(x,tol);
136 }
137
138 void setPenaltyParameter( const Real penaltyParameter, const int k ) {
139 pvec_[k]->setPenaltyParameter(penaltyParameter);
140 }
141
142 Real getPenaltyParameter( const int k ) {
143 return pvec_[k]->getPenaltyParameter();
144 }
145 void setMultiplier( const Vector<Real> &multiplier, const int k ) {
146 pvec_[k]->setMultiplier(multiplier);
147 }
148
149 void updateMultiplier( const Vector<Real> &x, Real &tol, const int k ) {
150 pvec_[k]->updateMultiplier(x,tol);
151 }
152
153 // Return objective function value
154 Real getObjectiveValue (const Vector<Real> &x, Real &tol ) {
155 Real val(0);
156 int key(0);
157 bool isComputed = fval_->get(val,key);
158 if ( !isComputed ) {
159 val = obj_->value(x,tol); nfval_++;
160 fval_->set(val,key);
161 }
162 return val;
163 }
164
165 // Compute objective function gradient
166 const Ptr<const Vector<Real>> getObjectiveGradient( const Vector<Real> &x, Real &tol ) {
167 int key(0);
168 if (!gradient_->isComputed(key)) {
169 if (gradient_->isNull(key)) gradient_->allocate(*dualOptVector_,key);
170 obj_->gradient(*gradient_->set(key),x,tol); ngval_++;
171 }
172 return gradient_->get(key);
173 }
174
175 // Return constraint value
176 const Ptr<const Vector<Real>> getConstraintVec( const Vector<Real> &x, Real &tol, const int k ) {
177 return pvec_[k]->getConstraintVec(x,tol);
178 }
179
180 int getNumberConstraints(void) const {
181 return pvec_.size();
182 }
183
184 // Return total number of constraint evaluations
186 int ncval = 0;
187 for (unsigned i = 0; i < unsigned(getNumberConstraints()); ++i)
189 return ncval;
190 }
191
192 // Return total number of objective evaluations
194 return nfval_;
195 }
196
197 // Return total number of gradient evaluations
199 return ngval_;
200 }
201
202 // Reset counters
203 void reset(void) {
204 nfval_ = 0; ngval_ = 0;
205 for (unsigned i = 0; i < unsigned(getNumberConstraints()); ++i) pvec_[i]->reset();
206 }
207
208}; // class AugmentedLagrangianObjective2
209
210} // namespace ROL
211
212#endif
const Ptr< const Vector< Real > > getObjectiveGradient(const Vector< Real > &x, Real &tol)
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
AugmentedLagrangianObjective2(const Ptr< Objective< Real > > &obj, const std::vector< Ptr< AugmentedLagrangianPenalty< Real > > > &pen, const Vector< Real > &dualOptVec, const bool scaleLagrangian)
AugmentedLagrangianObjective2(const Ptr< Objective< Real > > &obj, const std::vector< Ptr< AugmentedLagrangianPenalty< Real > > > &pen, const Vector< Real > &dualOptVec, ParameterList &parlist)
Ptr< VectorController< Real, int > > gradient_
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Real dualResidual(const Vector< Real > &x, Real &tol, const int k)
void setScaling(const Real cscale, const int k)
Real getObjectiveValue(const Vector< Real > &x, Real &tol)
virtual Real value(const Vector< Real > &x, Real &tol)
Compute value.
void setMultiplier(const Vector< Real > &multiplier, const int k)
void setPenaltyParameter(const Real penaltyParameter, const int k)
void updateMultiplier(const Vector< Real > &x, Real &tol, const int k)
const std::vector< Ptr< AugmentedLagrangianPenalty< Real > > > pvec_
Real dualNorm(const Vector< Real > &x, Real &tol, const int k)
Real feasibility(const Vector< Real > &x, Real &tol, const int k)
const Ptr< const Vector< Real > > getConstraintVec(const Vector< Real > &x, Real &tol, const int k)
Provides the interface to evaluate objective functions.
Defines the linear algebra or vector space interface.
virtual void set(const Vector &x)
Set where .
virtual void scale(const Real alpha)=0
Compute where .
virtual void plus(const Vector &x)=0
Compute , where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.