ROL
ROL_AugmentedLagrangian.hpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Rapid Optimization Library (ROL) Package
5// Copyright (2014) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact lead developers:
38// Drew Kouri (dpkouri@sandia.gov) and
39// Denis Ridzal (dridzal@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
44#ifndef ROL_AUGMENTEDLAGRANGIAN_H
45#define ROL_AUGMENTEDLAGRANGIAN_H
46
47#include "ROL_Objective.hpp"
48#include "ROL_Constraint.hpp"
50#include "ROL_Vector.hpp"
51#include "ROL_Types.hpp"
52#include "ROL_Ptr.hpp"
53#include <iostream>
54
83namespace ROL {
84
85template <class Real>
86class AugmentedLagrangian : public Objective<Real> {
87private:
88 // Required for Augmented Lagrangian definition
89 const ROL::Ptr<Objective<Real> > obj_;
90 ROL::Ptr<QuadraticPenalty<Real> > pen_;
92
93 // Auxiliary storage
94 ROL::Ptr<Vector<Real> > dualOptVector_;
95
96 // Objective and constraint evaluations
97 Real fval_;
98 ROL::Ptr<Vector<Real> > gradient_;
99
100 // Objective function scaling
102
103 // Evaluation counters
106
107 // User defined options
109
110 // Flags to recompute quantities
113
114public:
127 const ROL::Ptr<Constraint<Real> > &con,
128 const Vector<Real> &multiplier,
129 const Real penaltyParameter,
130 const Vector<Real> &optVec,
131 const Vector<Real> &conVec,
132 ROL::ParameterList &parlist)
133 : obj_(obj), penaltyParameter_(penaltyParameter),
134 fval_(0), fscale_(1),
135 nfval_(0), ngval_(0),
137
138 gradient_ = optVec.dual().clone();
139 dualOptVector_ = optVec.dual().clone();
140
141 ROL::ParameterList& sublist = parlist.sublist("Step").sublist("Augmented Lagrangian");
142 scaleLagrangian_ = sublist.get("Use Scaled Augmented Lagrangian", false);
143 int HessianApprox = sublist.get("Level of Hessian Approximation", 0);
144
145 pen_ = ROL::makePtr<QuadraticPenalty<Real>>(con,multiplier,penaltyParameter,optVec,conVec,scaleLagrangian_,HessianApprox);
146 }
147
160 const ROL::Ptr<Constraint<Real> > &con,
161 const Vector<Real> &multiplier,
162 const Real penaltyParameter,
163 const Vector<Real> &optVec,
164 const Vector<Real> &conVec,
165 const bool scaleLagrangian,
166 const int HessianApprox)
167 : obj_(obj), penaltyParameter_(penaltyParameter),
168 fval_(0), fscale_(1),
169 nfval_(0), ngval_(0),
170 scaleLagrangian_(scaleLagrangian),
172
173 gradient_ = optVec.dual().clone();
174 dualOptVector_ = optVec.dual().clone();
175
176 pen_ = ROL::makePtr<QuadraticPenalty<Real>>(con,multiplier,penaltyParameter,optVec,conVec,scaleLagrangian_,HessianApprox);
177 }
178
185 : obj_(ROL::nullPtr), pen_(ROL::nullPtr), dualOptVector_(ROL::nullPtr),
186 fval_(0), gradient_(ROL::nullPtr), fscale_(1),
187 nfval_(0), ngval_(0),
189
190 virtual void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
191 obj_->update(x,flag,iter);
192 pen_->update(x,flag,iter);
193 isValueComputed_ = ((flag || (!flag && iter < 0)) ? false : isValueComputed_);
194 isGradientComputed_ = ((flag || (!flag && iter < 0)) ? false : isGradientComputed_);
195 }
196
197 void setScaling(const Real fscale, const Real cscale = 1.0) {
198 fscale_ = fscale;
199 pen_->setScaling(cscale);
200 }
201
202 virtual Real value( const Vector<Real> &x, Real &tol ) {
203 // Compute objective function value
204 if ( !isValueComputed_ ) {
205 fval_ = obj_->value(x,tol); nfval_++;
206 isValueComputed_ = true;
207 }
208 // Compute penalty term
209 Real pval = pen_->value(x,tol);
210 // Compute augmented Lagrangian
211 Real val = fscale_*fval_;
212 if (scaleLagrangian_) {
213 val /= penaltyParameter_;
214 }
215 return val + pval;
216 }
217
218 virtual void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
219 // Compute objective function gradient
220 if ( !isGradientComputed_ ) {
221 obj_->gradient(*gradient_,x,tol); ngval_++;
222 isGradientComputed_ = true;
223 }
224 g.set(*gradient_);
225 g.scale(fscale_);
226 // Compute gradient of penalty
227 pen_->gradient(*dualOptVector_,x,tol);
228 // Compute gradient of Augmented Lagrangian
229 if ( scaleLagrangian_ ) {
230 g.scale(static_cast<Real>(1)/penaltyParameter_);
231 }
233 }
234
235 virtual void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
236 // Apply objective Hessian to a vector
237 obj_->hessVec(hv,v,x,tol);
238 hv.scale(fscale_);
239 // Apply penalty Hessian to a vector
240 pen_->hessVec(*dualOptVector_,v,x,tol);
241 // Build hessVec of Augmented Lagrangian
242 if ( scaleLagrangian_ ) {
243 hv.scale(static_cast<Real>(1)/penaltyParameter_);
244 }
245 hv.plus(*dualOptVector_);
246 }
247
248 // Return objective function value
249 virtual Real getObjectiveValue(const Vector<Real> &x) {
250 Real tol = std::sqrt(ROL_EPSILON<Real>());
251 // Evaluate objective function value
252 if ( !isValueComputed_ ) {
253 fval_ = obj_->value(x,tol); nfval_++;
254 isValueComputed_ = true;
255 }
256 return fval_;
257 }
258
259 const Ptr<const Vector<Real>> getObjectiveGradient(const Vector<Real> &x) {
260 Real tol = std::sqrt(ROL_EPSILON<Real>());
261 // Compute objective function gradient
262 if ( !isGradientComputed_ ) {
263 obj_->gradient(*gradient_,x,tol); ngval_++;
264 isGradientComputed_ = true;
265 }
266 return gradient_;
267 }
268
269 // Return constraint value
270 virtual void getConstraintVec(Vector<Real> &c, const Vector<Real> &x) {
271 pen_->getConstraintVec(c,x);
272 }
273
274 // Return total number of constraint evaluations
275 virtual int getNumberConstraintEvaluations(void) const {
276 return pen_->getNumberConstraintEvaluations();
277 }
278
279 // Return total number of objective evaluations
280 virtual int getNumberFunctionEvaluations(void) const {
281 return nfval_;
282 }
283
284 // Return total number of gradient evaluations
285 virtual int getNumberGradientEvaluations(void) const {
286 return ngval_;
287 }
288
289 // Reset with upated penalty parameter
290 virtual void reset(const Vector<Real> &multiplier, const Real penaltyParameter) {
291 nfval_ = 0; ngval_ = 0;
292 pen_->reset(multiplier,penaltyParameter);
293 }
294}; // class AugmentedLagrangian
295
296} // namespace ROL
297
298#endif
Contains definitions of custom data types in ROL.
Provides the interface to evaluate the augmented Lagrangian.
virtual void getConstraintVec(Vector< Real > &c, const Vector< Real > &x)
AugmentedLagrangian(const ROL::Ptr< Objective< Real > > &obj, const ROL::Ptr< Constraint< Real > > &con, const Vector< Real > &multiplier, const Real penaltyParameter, const Vector< Real > &optVec, const Vector< Real > &conVec, const bool scaleLagrangian, const int HessianApprox)
Constructor.
ROL::Ptr< Vector< Real > > dualOptVector_
virtual int getNumberFunctionEvaluations(void) const
void setScaling(const Real fscale, const Real cscale=1.0)
virtual int getNumberConstraintEvaluations(void) const
const Ptr< const Vector< Real > > getObjectiveGradient(const Vector< Real > &x)
virtual void reset(const Vector< Real > &multiplier, const Real penaltyParameter)
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
virtual Real getObjectiveValue(const Vector< Real > &x)
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
virtual Real value(const Vector< Real > &x, Real &tol)
Compute value.
virtual int getNumberGradientEvaluations(void) const
AugmentedLagrangian(const ROL::Ptr< Objective< Real > > &obj, const ROL::Ptr< Constraint< Real > > &con, const Vector< Real > &multiplier, const Real penaltyParameter, const Vector< Real > &optVec, const Vector< Real > &conVec, ROL::ParameterList &parlist)
Constructor.
ROL::Ptr< QuadraticPenalty< Real > > pen_
ROL::Ptr< Vector< Real > > gradient_
const ROL::Ptr< Objective< Real > > obj_
Defines the general constraint operator interface.
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 const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
virtual void plus(const Vector &x)=0
Compute , where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.