ROL
ROL_AugmentedLagrangianStep.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_AUGMENTEDLAGRANGIANSTEP_H
45 #define ROL_AUGMENTEDLAGRANGIANSTEP_H
46 
48 #include "ROL_Vector.hpp"
49 #include "ROL_Objective.hpp"
50 #include "ROL_BoundConstraint.hpp"
52 #include "ROL_Types.hpp"
53 #include "ROL_Algorithm.hpp"
54 #include "ROL_StatusTest.hpp"
55 #include "ROL_Step.hpp"
56 #include "ROL_LineSearchStep.hpp"
57 #include "ROL_TrustRegionStep.hpp"
58 #include "Teuchos_ParameterList.hpp"
59 
66 namespace ROL {
67 
68 template <class Real>
69 class AugmentedLagrangianStep : public Step<Real> {
70 private:
71  Teuchos::RCP<AugmentedLagrangian<Real> > augLag_;
72  Teuchos::RCP<Algorithm<Real> > algo_;
73  Teuchos::RCP<Vector<Real> > x_;
74 
75  Teuchos::ParameterList parlist_;
76  // Lagrange multiplier update
80  // Optimality tolerance update
85  // Feasibility tolerance update
90  // Subproblem information
91  bool print_;
92  int maxit_;
94  std::string subStep_;
97 
99  const Real mu, BoundConstraint<Real> &bnd) {
100  Real zerotol = std::sqrt(ROL_EPSILON);
101  Real gnorm = 0.;
102  augLag_->gradient(g,x,zerotol);
103  if ( scaleLagrangian_ ) {
104  g.scale(mu);
105  }
106  // Compute norm of projected gradient
107  if (bnd.isActivated()) {
108  x_->set(x);
109  x_->axpy(-1.,g.dual());
110  bnd.project(*x_);
111  x_->axpy(-1.,x);
112  gnorm = x_->norm();
113  }
114  else {
115  gnorm = g.norm();
116  }
117  return gnorm;
118  }
119 
120 public:
122 
123  AugmentedLagrangianStep(Teuchos::ParameterList &parlist)
124  : Step<Real>(), augLag_(Teuchos::null), algo_(Teuchos::null),
125  x_(Teuchos::null), parlist_(parlist), subproblemIter_(0) {
126  Teuchos::ParameterList& sublist = parlist.sublist("Step").sublist("Augmented Lagrangian");
127  Step<Real>::getState()->searchSize = sublist.get("Initial Penalty Parameter",1.e1);
128  // Multiplier update parameters
129  scaleLagrangian_ = sublist.get("Use Scaled Augmented Lagrangian", false);
130  minPenaltyLowerBound_ = sublist.get("Penalty Parameter Reciprocal Lower Bound", 0.1);
131  minPenaltyReciprocal_ = 0.1;
132  // Optimality tolerance update
133  optIncreaseExponent_ = sublist.get("Optimality Tolerance Update Exponent", 1.0);
134  optDecreaseExponent_ = sublist.get("Optimality Tolerance Decrease Exponent", 1.0);
135  optToleranceInitial_ = sublist.get("Initial Optimality Tolerance", 1.0);
136  // Feasibility tolerance update
137  feasIncreaseExponent_ = sublist.get("Feasibility Tolerance Update Exponent", 0.1);
138  feasDecreaseExponent_ = sublist.get("Feasibility Tolerance Decrease Exponent", 0.9);
139  feasToleranceInitial_ = sublist.get("Initial Feasibility Tolerance", 1.0);
140  // Subproblem information
141  print_ = sublist.get("Print Intermediate Optimization History", false);
142  maxit_ = sublist.get("Subproblem Iteration Limit", 1000);
143  subStep_ = sublist.get("Subproblem Step Type", "Trust Region");
144  parlist_.sublist("Status Test").set("Iteration Limit",maxit_);
145  // Outer iteration tolerances
146  outerFeasTolerance_ = parlist.sublist("Status Test").get("Constraint Tolerance", 1.e-8);
147  outerOptTolerance_ = parlist.sublist("Status Test").get("Gradient Tolerance", 1.e-8);
148  }
149 
154  AlgorithmState<Real> &algo_state ) {
155  // Initialize step state
156  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
157  state->descentVec = x.clone();
158  state->gradientVec = g.clone();
159  state->constraintVec = c.clone();
160  // Initialize additional storage
161  x_ = x.clone();
162  // Initialize the algorithm state
163  algo_state.nfval = 0;
164  algo_state.ncval = 0;
165  algo_state.ngrad = 0;
166  // Initialize intermediate stopping tolerances
167  minPenaltyReciprocal_ = std::min(1./state->searchSize,minPenaltyLowerBound_);
168  optTolerance_ = optToleranceInitial_*std::pow(minPenaltyReciprocal_,optDecreaseExponent_);
169  feasTolerance_ = feasToleranceInitial_*std::pow(minPenaltyReciprocal_,feasDecreaseExponent_);
170  // Initialize the Augmented Lagrangian
171  augLag_ = Teuchos::rcp(new AugmentedLagrangian<Real>(obj,con,x,c,l,state->searchSize,parlist_));
172  // Project x onto the feasible set
173  if ( bnd.isActivated() ) {
174  bnd.project(x);
175  }
176  bnd.update(x,true,algo_state.iter);
177  // Update objective and constraint.
178  augLag_->update(x,true,algo_state.iter);
179  algo_state.value = augLag_->getObjectiveValue();
180  algo_state.gnorm = computeGradient(*(state->gradientVec),x,state->searchSize,bnd);
181  augLag_->getConstraintVec(*(state->constraintVec));
182  algo_state.cnorm = (state->constraintVec)->norm();
183  // Update evaluation counters
184  algo_state.ncval += augLag_->getNumberConstraintEvaluations();
185  algo_state.nfval += augLag_->getNumberFunctionEvaluations();
186  algo_state.ngrad += augLag_->getNumberGradientEvaluations();
187  }
188 
191  void compute( Vector<Real> &s, const Vector<Real> &x, const Vector<Real> &l,
193  BoundConstraint<Real> &bnd, AlgorithmState<Real> &algo_state ) {
194  parlist_.sublist("Status Test").set("Gradient Tolerance",optTolerance_);
195  parlist_.sublist("Status Test").set("Step Tolerance",1.e-6*optTolerance_);
196  algo_ = Teuchos::rcp(new Algorithm<Real>(subStep_,parlist_,false));
197  x_->set(x);
198  if ( bnd.isActivated() ) {
199  algo_->run(*x_,*augLag_,bnd,print_);
200  }
201  else {
202  algo_->run(*x_,*augLag_,print_);
203  }
204  s.set(*x_); s.axpy(-1.,x);
205  subproblemIter_ = (algo_->getState())->iter;
206  }
207 
213  AlgorithmState<Real> &algo_state ) {
214  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
215  // Update the step and store in state
216  x.plus(s);
217  algo_state.iterateVec->set(x);
218  state->descentVec->set(s);
219  algo_state.snorm = s.norm();
220  algo_state.iter++;
221  // Update objective function value
222  augLag_->update(x,true,algo_state.iter);
223  bnd.update(x,true,algo_state.iter);
224  algo_state.value = augLag_->getObjectiveValue();
225  // Update constraint value
226  augLag_->getConstraintVec(*(state->constraintVec));
227  algo_state.cnorm = (state->constraintVec)->norm();
228  // Compute gradient of the augmented Lagrangian
229  algo_state.gnorm = computeGradient(*(state->gradientVec),x,state->searchSize,bnd);
230  // Update multipliers
231  bool updated = augLag_->updateMultipliers(l,state->searchSize,x,feasTolerance_);
232  algo_state.snorm += (updated ? l.norm() + 1. : 0.);
233  algo_state.lagmultVec->set(l);
234  minPenaltyReciprocal_ = std::min(1./state->searchSize,minPenaltyLowerBound_);
235  if ( algo_state.cnorm < feasTolerance_ ) {
236  optTolerance_ *= std::pow(minPenaltyReciprocal_,optIncreaseExponent_);
237  feasTolerance_ *= std::pow(minPenaltyReciprocal_,feasIncreaseExponent_);
238  }
239  else {
240  optTolerance_ = optToleranceInitial_*std::pow(minPenaltyReciprocal_,optDecreaseExponent_);
241  feasTolerance_ = feasToleranceInitial_*std::pow(minPenaltyReciprocal_,feasDecreaseExponent_);
242  }
243  // Update evaluation counters
244  algo_state.nfval += augLag_->getNumberFunctionEvaluations();
245  algo_state.ngrad += augLag_->getNumberGradientEvaluations();
246  algo_state.ncval += augLag_->getNumberConstraintEvaluations();
247  augLag_->reset();
248  }
249 
252  std::string printHeader( void ) const {
253  std::stringstream hist;
254  hist << " ";
255  hist << std::setw(6) << std::left << "iter";
256  hist << std::setw(15) << std::left << "fval";
257  hist << std::setw(15) << std::left << "cnorm";
258  hist << std::setw(15) << std::left << "gLnorm";
259  hist << std::setw(15) << std::left << "snorm";
260  hist << std::setw(10) << std::left << "penalty";
261  hist << std::setw(10) << std::left << "feasTol";
262  hist << std::setw(10) << std::left << "optTol";
263  hist << std::setw(8) << std::left << "#fval";
264  hist << std::setw(8) << std::left << "#grad";
265  hist << std::setw(8) << std::left << "#cval";
266  hist << std::setw(8) << std::left << "subIter";
267  hist << "\n";
268  return hist.str();
269  }
270 
273  std::string printName( void ) const {
274  std::stringstream hist;
275  hist << "\n" << " Augmented Lagrangian solver";
276  hist << "\n";
277  return hist.str();
278  }
279 
282  std::string print( AlgorithmState<Real> &algo_state, bool pHeader = false ) const {
283  std::stringstream hist;
284  hist << std::scientific << std::setprecision(6);
285  if ( algo_state.iter == 0 ) {
286  hist << printName();
287  }
288  if ( pHeader ) {
289  hist << printHeader();
290  }
291  if ( algo_state.iter == 0 ) {
292  hist << " ";
293  hist << std::setw(6) << std::left << algo_state.iter;
294  hist << std::setw(15) << std::left << algo_state.value;
295  hist << std::setw(15) << std::left << algo_state.cnorm;
296  hist << std::setw(15) << std::left << algo_state.gnorm;
297  hist << std::setw(15) << std::left << " ";
298  hist << std::scientific << std::setprecision(2);
299  hist << std::setw(10) << std::left << Step<Real>::getStepState()->searchSize;
300  hist << std::setw(10) << std::left << std::max(feasTolerance_,outerFeasTolerance_);
301  hist << std::setw(10) << std::left << std::max(optTolerance_,outerOptTolerance_);
302  hist << "\n";
303  }
304  else {
305  hist << " ";
306  hist << std::setw(6) << std::left << algo_state.iter;
307  hist << std::setw(15) << std::left << algo_state.value;
308  hist << std::setw(15) << std::left << algo_state.cnorm;
309  hist << std::setw(15) << std::left << algo_state.gnorm;
310  hist << std::setw(15) << std::left << algo_state.snorm;
311  hist << std::scientific << std::setprecision(2);
312  hist << std::setw(10) << std::left << Step<Real>::getStepState()->searchSize;
313  hist << std::setw(10) << std::left << feasTolerance_;
314  hist << std::setw(10) << std::left << optTolerance_;
315  hist << std::scientific << std::setprecision(6);
316  hist << std::setw(8) << std::left << algo_state.nfval;
317  hist << std::setw(8) << std::left << algo_state.ngrad;
318  hist << std::setw(8) << std::left << algo_state.ncval;
319  hist << std::setw(8) << std::left << subproblemIter_;
320  hist << "\n";
321  }
322  return hist.str();
323  }
324 
330  AlgorithmState<Real> &algo_state ) {}
331 
337  AlgorithmState<Real> &algo_state ) {}
338 
339 }; // class AugmentedLagrangianStep
340 
341 } // namespace ROL
342 
343 #endif
void initialize(Vector< Real > &x, const Vector< Real > &g, Vector< Real > &l, const Vector< Real > &c, Objective< Real > &obj, EqualityConstraint< Real > &con, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Initialize step with equality constraint.
Provides the interface to evaluate objective functions.
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 .
std::string printHeader(void) const
Print iterate header.
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
Provides the interface to compute optimization steps.
Definition: ROL_Step.hpp:67
Teuchos::RCP< StepState< Real > > getState(void)
Definition: ROL_Step.hpp:72
Contains definitions of custom data types in ROL.
Teuchos::RCP< Algorithm< Real > > algo_
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update bounds.
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
Provides the interface to compute augmented Lagrangian steps.
std::string printName(void) const
Print step name.
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:77
Teuchos::RCP< Vector< Real > > x_
bool isActivated(void)
Check if bounds are on.
Defines the equality constraint operator interface.
Provides an interface to run optimization algorithms.
AugmentedLagrangianStep(Teuchos::ParameterList &parlist)
Teuchos::RCP< AugmentedLagrangian< Real > > augLag_
void compute(Vector< Real > &s, const Vector< Real > &x, const Vector< Real > &l, Objective< Real > &obj, EqualityConstraint< Real > &con, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Compute step (equality and bound constraints).
Provides the interface to apply upper and lower bound constraints.
std::string print(AlgorithmState< Real > &algo_state, bool pHeader=false) const
Print iterate status.
Teuchos::RCP< Vector< Real > > lagmultVec
Definition: ROL_Types.hpp:92
Teuchos::RCP< Vector< Real > > iterateVec
Definition: ROL_Types.hpp:91
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:196
virtual Real norm() const =0
Returns where .
void update(Vector< Real > &x, Vector< Real > &l, const Vector< Real > &s, Objective< Real > &obj, EqualityConstraint< Real > &con, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Update step, if successful (equality and bound constraints).
void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Update step, for bound constraints; here only to satisfy the interface requirements, does nothing, needs refactoring.
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
Real computeGradient(Vector< Real > &g, const Vector< Real > &x, const Real mu, BoundConstraint< Real > &bnd)
static const double ROL_EPSILON
Platform-dependent machine epsilon.
Definition: ROL_Types.hpp:118
void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Compute step for bound constraints; here only to satisfy the interface requirements, does nothing, needs refactoring.