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_QuadraticPenalty.hpp"
50 #include "ROL_Vector.hpp"
51 #include "ROL_Types.hpp"
52 #include "Teuchos_RCP.hpp"
53 #include <iostream>
54 
83 namespace ROL {
84 
85 template <class Real>
86 class AugmentedLagrangian : public Objective<Real> {
87 private:
88  // Required for Augmented Lagrangian definition
89  const Teuchos::RCP<Objective<Real> > obj_;
90  Teuchos::RCP<QuadraticPenalty<Real> > pen_;
92 
93  // Auxiliary storage
94  Teuchos::RCP<Vector<Real> > dualOptVector_;
95 
96  // Objective and constraint evaluations
97  Real fval_;
98  Teuchos::RCP<Vector<Real> > gradient_;
99 
100  // Evaluation counters
101  int nfval_;
102  int ngval_;
103 
104  // User defined options
106 
107  // Flags to recompute quantities
110 
111 public:
123  AugmentedLagrangian(const Teuchos::RCP<Objective<Real> > &obj,
124  const Teuchos::RCP<EqualityConstraint<Real> > &con,
125  const Vector<Real> &multiplier,
126  const Real penaltyParameter,
127  const Vector<Real> &optVec,
128  const Vector<Real> &conVec,
129  Teuchos::ParameterList &parlist)
130  : obj_(obj), penaltyParameter_(penaltyParameter),
131  fval_(0), nfval_(0), ngval_(0), isValueComputed_(false), isGradientComputed_(false) {
132 
133  gradient_ = optVec.dual().clone();
134  dualOptVector_ = optVec.dual().clone();
135 
136  Teuchos::ParameterList& sublist = parlist.sublist("Step").sublist("Augmented Lagrangian");
137  scaleLagrangian_ = sublist.get("Use Scaled Augmented Lagrangian", false);
138  int HessianApprox = sublist.get("Level of Hessian Approximation", 0);
139 
140  pen_ = Teuchos::rcp(new QuadraticPenalty<Real>(con,multiplier,penaltyParameter,optVec,conVec,scaleLagrangian_,HessianApprox));
141  }
142 
149  : obj_(Teuchos::null), pen_(Teuchos::null), dualOptVector_(Teuchos::null),
150  fval_(0), gradient_(Teuchos::null), nfval_(0), ngval_(0),
151  scaleLagrangian_(false), isValueComputed_(false), isGradientComputed_(false) {}
152 
153  virtual void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
154  obj_->update(x,flag,iter);
155  pen_->update(x,flag,iter);
156  isValueComputed_ = (flag ? false : isValueComputed_);
157  isGradientComputed_ = (flag ? false : isGradientComputed_);
158  }
159 
160  virtual Real value( const Vector<Real> &x, Real &tol ) {
161  // Compute objective function value
162  if ( !isValueComputed_ ) {
163  fval_ = obj_->value(x,tol); nfval_++;
164  isValueComputed_ = true;
165  }
166  // Compute penalty term
167  Real pval = pen_->value(x,tol);
168  // Compute augmented Lagrangian
169  Real val = fval_;
170  if (scaleLagrangian_) {
171  val /= penaltyParameter_;
172  }
173  return val + pval;
174  }
175 
176  virtual void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
177  // Compute objective function gradient
178  if ( !isGradientComputed_ ) {
179  obj_->gradient(*gradient_,x,tol); ngval_++;
180  isGradientComputed_ = true;
181  }
182  g.set(*gradient_);
183  // Compute gradient of penalty
184  pen_->gradient(*dualOptVector_,x,tol);
185  // Compute gradient of Augmented Lagrangian
186  if ( scaleLagrangian_ ) {
187  g.scale(static_cast<Real>(1)/penaltyParameter_);
188  }
189  g.plus(*dualOptVector_);
190  }
191 
192  virtual void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
193  // Apply objective Hessian to a vector
194  obj_->hessVec(hv,v,x,tol);
195  // Apply penalty Hessian to a vector
196  pen_->hessVec(*dualOptVector_,v,x,tol);
197  // Build hessVec of Augmented Lagrangian
198  if ( scaleLagrangian_ ) {
199  hv.scale(static_cast<Real>(1)/penaltyParameter_);
200  }
201  hv.plus(*dualOptVector_);
202  }
203 
204  // Return objective function value
205  virtual Real getObjectiveValue(const Vector<Real> &x) {
206  Real tol = std::sqrt(ROL_EPSILON<Real>());
207  // Evaluate objective function value
208  if ( !isValueComputed_ ) {
209  fval_ = obj_->value(x,tol); nfval_++;
210  isValueComputed_ = true;
211  }
212  return fval_;
213  }
214 
215  // Return constraint value
216  virtual void getConstraintVec(Vector<Real> &c, const Vector<Real> &x) {
217  pen_->getConstraintVec(c,x);
218  }
219 
220  // Return total number of constraint evaluations
221  virtual int getNumberConstraintEvaluations(void) const {
222  return pen_->getNumberConstraintEvaluations();
223  }
224 
225  // Return total number of objective evaluations
226  virtual int getNumberFunctionEvaluations(void) const {
227  return nfval_;
228  }
229 
230  // Return total number of gradient evaluations
231  virtual int getNumberGradientEvaluations(void) const {
232  return ngval_;
233  }
234 
235  // Reset with upated penalty parameter
236  virtual void reset(const Vector<Real> &multiplier, const Real penaltyParameter) {
237  nfval_ = 0; ngval_ = 0;
238  pen_->reset(multiplier,penaltyParameter);
239  }
240 }; // class AugmentedLagrangian
241 
242 } // namespace ROL
243 
244 #endif
Provides the interface to evaluate objective functions.
Provides the interface to evaluate the augmented Lagrangian.
virtual void scale(const Real alpha)=0
Compute where .
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
virtual void plus(const Vector &x)=0
Compute , where .
Provides the interface to evaluate the quadratic constraint penalty.
Contains definitions of custom data types in ROL.
virtual Real getObjectiveValue(const Vector< Real > &x)
Teuchos::RCP< Vector< Real > > gradient_
virtual Real value(const Vector< Real > &x, Real &tol)
Compute value.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
virtual void reset(const Vector< Real > &multiplier, const Real penaltyParameter)
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
Defines the equality constraint operator interface.
AugmentedLagrangian(const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< EqualityConstraint< Real > > &con, const Vector< Real > &multiplier, const Real penaltyParameter, const Vector< Real > &optVec, const Vector< Real > &conVec, Teuchos::ParameterList &parlist)
Constructor.
virtual int getNumberFunctionEvaluations(void) const
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
AugmentedLagrangian()
Null constructor.
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
virtual int getNumberConstraintEvaluations(void) const
Teuchos::RCP< Vector< Real > > dualOptVector_
virtual int getNumberGradientEvaluations(void) const
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:196
Teuchos::RCP< QuadraticPenalty< Real > > pen_
virtual void getConstraintVec(Vector< Real > &c, const Vector< Real > &x)
const Teuchos::RCP< Objective< Real > > obj_