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"
49 #include "ROL_Vector.hpp"
50 #include "ROL_Types.hpp"
51 #include "Teuchos_RCP.hpp"
52 #include <iostream>
53 
62 namespace ROL {
63 
64 template <class Real>
65 class AugmentedLagrangian : public Objective<Real> {
66 private:
67  Teuchos::RCP<Objective<Real> > obj_;
68  Teuchos::RCP<EqualityConstraint<Real> > con_;
69  Teuchos::RCP<Vector<Real> > lam_;
70  Teuchos::RCP<Vector<Real> > dlam_;
71  Teuchos::RCP<Vector<Real> > x_;
72  Teuchos::RCP<Vector<Real> > g_;
73  Teuchos::RCP<Vector<Real> > c_;
74  Teuchos::RCP<Vector<Real> > dc1_;
75  Teuchos::RCP<Vector<Real> > dc2_;
76 
77  Real fval_;
78  int ncval_;
79  int nfval_;
80  int ngval_;
81 
89 
90 public:
92 
94  const Vector<Real> &x, const Vector<Real> &c,
95  const Vector<Real> &l, const Real mu,
96  Teuchos::ParameterList &parlist)
97  : fval_(0.0), ncval_(0), nfval_(0), ngval_(0), penaltyParameter_(mu) {
98  obj_ = Teuchos::rcp(&obj, false);
99  con_ = Teuchos::rcp(&con, false);
100 
101  x_ = x.clone();
102  g_ = x.dual().clone();
103  dc1_ = x.dual().clone();
104  dc2_ = c.clone();
105  c_ = c.clone();
106  lam_ = l.clone();
107  dlam_ = l.clone();
108  lam_->set(l);
109 
110  Teuchos::ParameterList& sublist = parlist.sublist("Step").sublist("Augmented Lagrangian");
111  penaltyUpdate_ = sublist.get("Penalty Parameter Growth Factor", 1.e1);
112  multiplierUpdateScale_ = sublist.get("Multiplier Update Scale", 1.e0);
113  multiplierUpdateExponent_ = sublist.get("Multiplier Update Exponent", 1.e0);
114  multiplierUpdateMethod_ = sublist.get("Multiplier Update Method", 1);
115  scaleLagrangian_ = sublist.get("Use Scaled Augmented Lagrangian", false);
116  HessianLevel_ = sublist.get("Level of Hessian Approximation", 0);
117  }
118 
119  bool updateMultipliers(Vector<Real> &l, Real &penaltyParameter,
120  const Vector<Real> &x, const Real feasTolerance) {
121  bool updated = false;
122  if ( multiplierUpdateMethod_ == 0 ) {
123  l.axpy(penaltyParameter,c_->dual());
124  }
125  else if ( multiplierUpdateMethod_ == 1 ) {
126  Real tol = std::sqrt(ROL_EPSILON);
127  dc2_->zero();
128  con_->solveAugmentedSystem(*x_,l,*g_,*dc2_,x,tol);
129  l.scale(-1.);
130  }
131 
132  penaltyParameter *= ((c_->norm() < feasTolerance) ? 1. : penaltyUpdate_);
133  penaltyParameter_ = penaltyParameter;
134 
135  if ( l.norm() < multiplierUpdateScale_*std::pow(penaltyParameter_,multiplierUpdateExponent_) ) {
136  updated = true;
137  lam_->set(l);
138  }
139  else {
140  l.set(*lam_);
141  }
142  return updated;
143  }
144 
145  Real getObjectiveValue(void) const {
146  return fval_;
147  }
148 
150  g.set(*g_);
151  }
152 
154  c.set(*c_);
155  }
156 
158  return ncval_;
159  }
160 
162  return nfval_;
163  }
164 
166  return ngval_;
167  }
168 
169  void reset(void) {
170  ncval_ = 0.; nfval_ = 0.; ngval_ = 0.;
171  }
172 
180  void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
181  Real tol = std::sqrt(ROL_EPSILON);
182  obj_->update(x,flag,iter);
183  con_->update(x,flag,iter);
184  // Evaluate constraint
185  con_->value(*c_,x,tol);
186  ncval_++;
187  // Compute objective function value
188  fval_ = obj_->value(x,tol);
189  nfval_++;
190  // Compute objective function gradient
191  obj_->gradient(*g_,x,tol);
192  ngval_++;
193  }
194 
201  Real value( const Vector<Real> &x, Real &tol ) {
202  // Evaluate constraint
203  con_->value(*c_,x,tol);
204  ncval_++;
205  // Compute objective function value
206  fval_ = obj_->value(x,tol);
207  nfval_++;
208  // Compute objective function gradient
209  obj_->gradient(*g_,x,tol);
210  ngval_++;
211  // Apply Lagrange multiplier to constraint
212  Real cval = lam_->dot(c_->dual());
213  // Compute penalty term
214  Real pval = c_->dot(*c_);
215  // Compute Augmented Lagrangian value
216  Real val = 0.0;
217  if (scaleLagrangian_) {
218  val = (fval_ + cval)/penaltyParameter_ + 0.5*pval;
219  }
220  else {
221  val = fval_ + cval + 0.5*penaltyParameter_*pval;
222  }
223  return val;
224  }
225 
233  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
234  // Evaluate constraint
235  con_->value(*c_,x,tol);
236  ncval_++;
237  // Compute objective function value
238  fval_ = obj_->value(x,tol);
239  nfval_++;
240  // Compute objective function gradient
241  obj_->gradient(*g_,x,tol);
242  ngval_++;
243  g.set(*g_);
244  // Compute gradient of Augmented Lagrangian
245  dlam_->set(c_->dual());
246  if ( scaleLagrangian_ ) {
247  g.scale(1./penaltyParameter_);
248  dlam_->axpy(1./penaltyParameter_,*lam_);
249  }
250  else {
251  dlam_->scale(penaltyParameter_);
252  dlam_->plus(*lam_);
253  }
254  con_->applyAdjointJacobian(*dc1_,*dlam_,x,tol);
255  g.plus(*dc1_);
256  }
257 
266  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
267  // Evaluate constraint
268  con_->value(*c_,x,tol);
269  ncval_++;
270  // Compute objective function value
271  fval_ = obj_->value(x,tol);
272  nfval_++;
273  // Compute objective function gradient
274  obj_->gradient(*g_,x,tol);
275  ngval_++;
276  // Apply objective Hessian to a vector
277  obj_->hessVec(hv,v,x,tol);
278  if (HessianLevel_ < 2) {
279  con_->applyJacobian(*dc2_,v,x,tol);
280  con_->applyAdjointJacobian(*dc1_,dc2_->dual(),x,tol);
281  if (scaleLagrangian_) {
282  hv.scale(1./penaltyParameter_);
283  hv.plus(*dc1_);
284  }
285  else {
286  hv.axpy(penaltyParameter_,*dc1_);
287  }
288 
289  if (HessianLevel_ == 0) {
290  // Apply Augmented Lagrangian Hessian to a vector
291  dlam_->set(c_->dual());
292  if ( scaleLagrangian_ ) {
293  dlam_->axpy(1./penaltyParameter_,*lam_);
294  }
295  else {
296  dlam_->scale(penaltyParameter_);
297  dlam_->plus(*lam_);
298  }
299  con_->applyAdjointHessian(*dc1_,*dlam_,v,x,tol);
300  hv.plus(*dc1_);
301  }
302  }
303  }
304 
305 }; // class AugmentedLagrangian
306 
307 } // namespace ROL
308 
309 #endif
Provides the interface to evaluate objective functions.
void getObjectiveGradient(Vector< Real > &g) const
Provides the interface to evaluate the augmented Lagrangian.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Definition: ROL_Vector.hpp:213
virtual void scale(const Real alpha)=0
Compute where .
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update augmented Lagrangian function.
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:143
bool updateMultipliers(Vector< Real > &l, Real &penaltyParameter, const Vector< Real > &x, const Real feasTolerance)
Teuchos::RCP< Vector< Real > > g_
void getConstraintVec(Vector< Real > &c)
Contains definitions of custom data types in ROL.
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Teuchos::RCP< Objective< Real > > obj_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
Teuchos::RCP< Vector< Real > > c_
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Teuchos::RCP< Vector< Real > > dc2_
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Defines the equality constraint operator interface.
Teuchos::RCP< EqualityConstraint< Real > > con_
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Teuchos::RCP< Vector< Real > > dc1_
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:196
virtual Real norm() const =0
Returns where .
Teuchos::RCP< Vector< Real > > lam_
Teuchos::RCP< Vector< Real > > x_
AugmentedLagrangian(Objective< Real > &obj, EqualityConstraint< Real > &con, const Vector< Real > &x, const Vector< Real > &c, const Vector< Real > &l, const Real mu, Teuchos::ParameterList &parlist)
Teuchos::RCP< Vector< Real > > dlam_
static const double ROL_EPSILON
Platform-dependent machine epsilon.
Definition: ROL_Types.hpp:118