ROL
ROL_AugmentedLagrangian_SimOpt.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_AUGMENTEDLAGRANGIAN_SIMOPT_H
11 #define ROL_AUGMENTEDLAGRANGIAN_SIMOPT_H
12 
13 #include "ROL_Objective_SimOpt.hpp"
16 #include "ROL_Vector.hpp"
17 #include "ROL_Types.hpp"
18 #include "ROL_Ptr.hpp"
19 #include <iostream>
20 
60 namespace ROL {
61 
62 template <class Real>
64 private:
65  // Required for Augmented Lagrangian definition
66  const ROL::Ptr<Objective_SimOpt<Real> > obj_;
67  ROL::Ptr<QuadraticPenalty_SimOpt<Real> > pen_;
69 
70  // Auxiliary storage
71  ROL::Ptr<Vector<Real> > dualSimVector_;
72  ROL::Ptr<Vector<Real> > dualOptVector_;
73 
74  // Objective and constraint evaluations
75  Real fval_;
76  ROL::Ptr<Vector<Real> > gradient1_;
77  ROL::Ptr<Vector<Real> > gradient2_;
78 
79  // Evaluation counters
80  int nfval_;
81  int ngval_;
82 
83  // User defined options
85 
86  // Flags to recompute quantities
90 
91 public:
93  const ROL::Ptr<Constraint_SimOpt<Real> > &con,
94  const Vector<Real> &multiplier,
95  const Real penaltyParameter,
96  const Vector<Real> &simVec,
97  const Vector<Real> &optVec,
98  const Vector<Real> &conVec,
99  ROL::ParameterList &parlist)
100  : obj_(obj), penaltyParameter_(penaltyParameter),
101  fval_(0), nfval_(0), ngval_(0), isValueComputed_(false),
103 
104  gradient1_ = simVec.dual().clone();
105  gradient2_ = optVec.dual().clone();
106  dualSimVector_ = simVec.dual().clone();
107  dualOptVector_ = optVec.dual().clone();
108 
109  ROL::ParameterList& sublist = parlist.sublist("Step").sublist("Augmented Lagrangian");
110  scaleLagrangian_ = sublist.get("Use Scaled Augmented Lagrangian", false);
111  int HessianApprox = sublist.get("Level of Hessian Approximation", 0);
112 
113  pen_ = ROL::makePtr<QuadraticPenalty_SimOpt<Real>>(con,multiplier,penaltyParameter,simVec,optVec,conVec,scaleLagrangian_,HessianApprox);
114  }
115 
116  virtual void update( const Vector<Real> &u, const Vector<Real> &z, bool flag = true, int iter = -1 ) {
117  obj_->update(u,z,flag,iter);
118  pen_->update(u,z,flag,iter);
119  isValueComputed_ = (flag ? false : isValueComputed_);
120  isGradient1Computed_ = (flag ? false : isGradient1Computed_);
121  isGradient2Computed_ = (flag ? false : isGradient2Computed_);
122  }
123 
124  virtual Real value( const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
125  // Compute objective function value
126  if ( !isValueComputed_ ) {
127  fval_ = obj_->value(u,z,tol); nfval_++;
128  isValueComputed_ = true;
129  }
130  // Compute penalty term
131  Real pval = pen_->value(u,z,tol);
132  // Compute augmented Lagrangian
133  Real val = fval_;
134  if (scaleLagrangian_) {
135  val /= penaltyParameter_;
136  }
137  return val + pval;
138  }
139 
140  virtual void gradient_1( Vector<Real> &g, const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
141  // Compute objective function gradient
142  if ( !isGradient1Computed_ ) {
143  obj_->gradient_1(*gradient1_,u,z,tol); ngval_++;
144  isGradient1Computed_ = true;
145  }
146  g.set(*gradient1_);
147  // Compute gradient of penalty
148  pen_->gradient_1(*dualSimVector_,u,z,tol);
149  // Compute gradient of Augmented Lagrangian
150  if ( scaleLagrangian_ ) {
151  g.scale(static_cast<Real>(1)/penaltyParameter_);
152  }
153  g.plus(*dualSimVector_);
154  }
155 
156  virtual void gradient_2( Vector<Real> &g, const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
157  // Compute objective function gradient
158  if ( !isGradient2Computed_ ) {
159  obj_->gradient_2(*gradient2_,u,z,tol); ngval_++;
160  isGradient2Computed_ = true;
161  }
162  g.set(*gradient2_);
163  // Compute gradient of penalty
164  pen_->gradient_2(*dualOptVector_,u,z,tol);
165  // Compute gradient of Augmented Lagrangian
166  if ( scaleLagrangian_ ) {
167  g.scale(static_cast<Real>(1)/penaltyParameter_);
168  }
169  g.plus(*dualOptVector_);
170  }
171 
172  virtual void hessVec_11( Vector<Real> &hv, const Vector<Real> &v,
173  const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
174  // Apply objective Hessian to a vector
175  obj_->hessVec_11(hv,v,u,z,tol);
176  // Apply penalty Hessian to a vector
177  pen_->hessVec_11(*dualSimVector_,v,u,z,tol);
178  // Build hessVec of Augmented Lagrangian
179  if ( scaleLagrangian_ ) {
180  hv.scale(static_cast<Real>(1)/penaltyParameter_);
181  }
182  hv.plus(*dualSimVector_);
183  }
184 
185  virtual void hessVec_12( Vector<Real> &hv, const Vector<Real> &v,
186  const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
187  // Apply objective Hessian to a vector
188  obj_->hessVec_12(hv,v,u,z,tol);
189  // Apply penalty Hessian to a vector
190  pen_->hessVec_12(*dualSimVector_,v,u,z,tol);
191  // Build hessVec of Augmented Lagrangian
192  if ( scaleLagrangian_ ) {
193  hv.scale(static_cast<Real>(1)/penaltyParameter_);
194  }
195  hv.plus(*dualSimVector_);
196  }
197 
198  virtual void hessVec_21( Vector<Real> &hv, const Vector<Real> &v,
199  const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
200  // Apply objective Hessian to a vector
201  obj_->hessVec_21(hv,v,u,z,tol);
202  // Apply penalty Hessian to a vector
203  pen_->hessVec_21(*dualOptVector_,v,u,z,tol);
204  // Build hessVec of Augmented Lagrangian
205  if ( scaleLagrangian_ ) {
206  hv.scale(static_cast<Real>(1)/penaltyParameter_);
207  }
208  hv.plus(*dualOptVector_);
209  }
210 
211  virtual void hessVec_22( Vector<Real> &hv, const Vector<Real> &v,
212  const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
213  // Apply objective Hessian to a vector
214  obj_->hessVec_22(hv,v,u,z,tol);
215  // Apply penalty Hessian to a vector
216  pen_->hessVec_22(*dualOptVector_,v,u,z,tol);
217  // Build hessVec of Augmented Lagrangian
218  if ( scaleLagrangian_ ) {
219  hv.scale(static_cast<Real>(1)/penaltyParameter_);
220  }
221  hv.plus(*dualOptVector_);
222  }
223 
224  // Return objective function value
225  virtual Real getObjectiveValue(const Vector<Real> &u, const Vector<Real> &z) {
226  Real tol = std::sqrt(ROL_EPSILON<Real>());
227  // Evaluate objective function value
228  if ( !isValueComputed_ ) {
229  fval_ = obj_->value(u,z,tol); nfval_++;
230  isValueComputed_ = true;
231  }
232  return fval_;
233  }
234 
235  // Return constraint value
236  virtual void getConstraintVec(Vector<Real> &c, const Vector<Real> &u, const Vector<Real> &z) {
237  pen_->getConstraintVec(c,u,z);
238  }
239 
240  // Return total number of constraint evaluations
241  virtual int getNumberConstraintEvaluations(void) const {
242  return pen_->getNumberConstraintEvaluations();
243  }
244 
245  // Return total number of objective evaluations
246  virtual int getNumberFunctionEvaluations(void) const {
247  return nfval_;
248  }
249 
250  // Return total number of gradient evaluations
251  virtual int getNumberGradientEvaluations(void) const {
252  return ngval_;
253  }
254 
255  // Reset with upated penalty parameter
256  virtual void reset(const Vector<Real> &multiplier, const Real penaltyParameter) {
257  nfval_ = 0; ngval_ = 0;
258  pen_->reset(multiplier,penaltyParameter);
259  }
260 }; // class AugmentedLagrangian
261 
262 } // namespace ROL
263 
264 #endif
Provides the interface to evaluate simulation-based objective functions.
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:192
virtual void hessVec_22(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
virtual void scale(const Real alpha)=0
Compute where .
virtual void plus(const Vector &x)=0
Compute , where .
AugmentedLagrangian_SimOpt(const ROL::Ptr< Objective_SimOpt< Real > > &obj, const ROL::Ptr< Constraint_SimOpt< Real > > &con, const Vector< Real > &multiplier, const Real penaltyParameter, const Vector< Real > &simVec, const Vector< Real > &optVec, const Vector< Real > &conVec, ROL::ParameterList &parlist)
virtual void hessVec_12(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Contains definitions of custom data types in ROL.
virtual void hessVec_21(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
virtual void update(const Vector< Real > &u, const Vector< Real > &z, bool flag=true, int iter=-1)
Update objective function. u is an iterate, z is an iterate, flag = true if the iterate has changed...
ROL::Ptr< QuadraticPenalty_SimOpt< Real > > pen_
virtual Real value(const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Compute value.
Provides the interface to evaluate the SimOpt augmented Lagrangian.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
const ROL::Ptr< Objective_SimOpt< Real > > obj_
virtual void hessVec_11(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply Hessian approximation to vector.
virtual void gradient_2(Vector< Real > &g, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Compute gradient with respect to second component.
virtual void gradient_1(Vector< Real > &g, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Compute gradient with respect to first component.
virtual void reset(const Vector< Real > &multiplier, const Real penaltyParameter)
virtual Real getObjectiveValue(const Vector< Real > &u, const Vector< Real > &z)
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:175
Defines the constraint operator interface for simulation-based optimization.
virtual void getConstraintVec(Vector< Real > &c, const Vector< Real > &u, const Vector< Real > &z)