ROL
ROL_MoreauYosidaPenaltyStep.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_MOREAUYOSIDAPENALTYSTEP_H
45 #define ROL_MOREAUYOSIDAPENALTYSTEP_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 "Teuchos_ParameterList.hpp"
55 
118 namespace ROL {
119 
120 template <class Real>
121 class MoreauYosidaPenaltyStep : public Step<Real> {
122 private:
123  Teuchos::RCP<Algorithm<Real> > algo_;
124  Teuchos::RCP<Vector<Real> > x_;
125  Teuchos::RCP<Vector<Real> > g_;
126  Teuchos::RCP<Vector<Real> > l_;
127 
129  Real gLnorm_;
130  Real tau_;
131  bool print_;
132 
133  Teuchos::ParameterList parlist_;
135 
136  void updateState(const Vector<Real> &x, const Vector<Real> &l,
137  Objective<Real> &obj,
139  AlgorithmState<Real> &algo_state) {
141  = Teuchos::dyn_cast<MoreauYosidaPenalty<Real> >(obj);
142  Real zerotol = std::sqrt(ROL_EPSILON<Real>());
143  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
144  // Update objective and constraint.
145  myPen.update(x,true,algo_state.iter);
146  con.update(x,true,algo_state.iter);
147  // Compute norm of the gradient of the Lagrangian
148  algo_state.value = myPen.value(x, zerotol);
149  myPen.gradient(*(state->gradientVec), x, zerotol);
150  con.applyAdjointJacobian(*g_,l,x,zerotol);
151  state->gradientVec->plus(*g_);
152  gLnorm_ = (state->gradientVec)->norm();
153  // Compute constraint violation
154  con.value(*(state->constraintVec),x, zerotol);
155  algo_state.cnorm = (state->constraintVec)->norm();
156  compViolation_ = myPen.testComplementarity(x);
157  algo_state.gnorm = std::max(gLnorm_,compViolation_);
158  // Update state
159  algo_state.nfval++;
160  algo_state.ngrad++;
161  algo_state.ncval++;
162  }
163 
164 public:
165 
167  using Step<Real>::compute;
168  using Step<Real>::update;
169 
171 
172  MoreauYosidaPenaltyStep(Teuchos::ParameterList &parlist)
173  : Step<Real>(), algo_(Teuchos::null),
174  x_(Teuchos::null), g_(Teuchos::null), l_(Teuchos::null),
175  tau_(10), print_(false), parlist_(parlist), subproblemIter_(0) {
176  // Parse parameters
177  Real ten(10), oem6(1.e-6), oem8(1.e-8);
178  Teuchos::ParameterList& steplist = parlist.sublist("Step").sublist("Moreau-Yosida Penalty");
179  Step<Real>::getState()->searchSize = steplist.get("Initial Penalty Parameter",ten);
180  tau_ = steplist.get("Penalty Parameter Growth Factor",ten);
181  print_ = steplist.sublist("Subproblem").get("Print History",false);
182  // Set parameters for step subproblem
183  Real gtol = steplist.sublist("Subproblem").get("Optimality Tolerance",oem8);
184  Real ctol = steplist.sublist("Subproblem").get("Feasibility Tolerance",oem8);
185  Real stol = oem6*std::min(gtol,ctol);
186  int maxit = steplist.sublist("Subproblem").get("Iteration Limit",1000);
187  parlist_.sublist("Status Test").set("Gradient Tolerance", gtol);
188  parlist_.sublist("Status Test").set("Constraint Tolerance", ctol);
189  parlist_.sublist("Status Test").set("Step Tolerance", stol);
190  parlist_.sublist("Status Test").set("Iteration Limit", maxit);
191  }
192 
197  AlgorithmState<Real> &algo_state ) {
198  // MoreauYosidaPenalty<Real> &myPen
199  // = Teuchos::dyn_cast<MoreauYosidaPenalty<Real> >(obj);
200  // Initialize step state
201  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
202  state->descentVec = x.clone();
203  state->gradientVec = g.clone();
204  state->constraintVec = c.clone();
205  // Initialize additional storage
206  x_ = x.clone();
207  g_ = g.clone();
208  l_ = l.clone();
209  // Project x onto the feasible set
210  if ( bnd.isActivated() ) {
211  bnd.project(x);
212  }
213  // Update the Lagrangian
214  //myPen.updateMultipliers(state->searchSize,x);
215  // Initialize the algorithm state
216  algo_state.nfval = 0;
217  algo_state.ncval = 0;
218  algo_state.ngrad = 0;
219  updateState(x,l,obj,con,bnd,algo_state);
220  }
221 
224  void compute( Vector<Real> &s, const Vector<Real> &x, const Vector<Real> &l,
226  BoundConstraint<Real> &bnd,
227  AlgorithmState<Real> &algo_state ) {
228  Real one(1);
230  = Teuchos::dyn_cast<MoreauYosidaPenalty<Real> >(obj);
231  algo_ = Teuchos::rcp(new Algorithm<Real>("Composite Step",parlist_,false));
232  x_->set(x); l_->set(l);
233  algo_->run(*x_,*l_,myPen,con,print_);
234  s.set(*x_); s.axpy(-one,x);
235  subproblemIter_ = (algo_->getState())->iter;
236  }
237 
243  AlgorithmState<Real> &algo_state ) {
245  = Teuchos::dyn_cast<MoreauYosidaPenalty<Real> >(obj);
246  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
247  state->descentVec->set(s);
248  // Update iterate and Lagrange multiplier
249  x.plus(s);
250  l.set(*l_);
251  // Update objective and constraint
252  algo_state.iter++;
253  con.update(x,true,algo_state.iter);
254  myPen.update(x,true,algo_state.iter);
255  // Update state
256  updateState(x,l,obj,con,bnd,algo_state);
257  // Update multipliers
258  state->searchSize *= tau_;
259  myPen.updateMultipliers(state->searchSize,x);
260  algo_state.nfval += myPen.getNumberFunctionEvaluations() + ((algo_->getState())->nfval);
261  algo_state.ngrad += myPen.getNumberGradientEvaluations() + ((algo_->getState())->ngrad);
262  algo_state.ncval += (algo_->getState())->ncval;
263  algo_state.snorm = s.norm();
264  algo_state.iterateVec->set(x);
265  algo_state.lagmultVec->set(l);
266  }
267 
270  std::string printHeader( void ) const {
271  std::stringstream hist;
272  hist << " ";
273  hist << std::setw(6) << std::left << "iter";
274  hist << std::setw(15) << std::left << "fval";
275  hist << std::setw(15) << std::left << "cnorm";
276  hist << std::setw(15) << std::left << "gnorm";
277  hist << std::setw(15) << std::left << "ifeas";
278  hist << std::setw(15) << std::left << "snorm";
279  hist << std::setw(10) << std::left << "penalty";
280  hist << std::setw(8) << std::left << "#fval";
281  hist << std::setw(8) << std::left << "#grad";
282  hist << std::setw(8) << std::left << "#cval";
283  hist << std::setw(8) << std::left << "subIter";
284  hist << "\n";
285  return hist.str();
286  }
287 
290  std::string printName( void ) const {
291  std::stringstream hist;
292  hist << "\n" << " Moreau-Yosida Penalty solver";
293  hist << "\n";
294  return hist.str();
295  }
296 
299  std::string print( AlgorithmState<Real> &algo_state, bool pHeader = false ) const {
300  std::stringstream hist;
301  hist << std::scientific << std::setprecision(6);
302  if ( algo_state.iter == 0 ) {
303  hist << printName();
304  }
305  if ( pHeader ) {
306  hist << printHeader();
307  }
308  if ( algo_state.iter == 0 ) {
309  hist << " ";
310  hist << std::setw(6) << std::left << algo_state.iter;
311  hist << std::setw(15) << std::left << algo_state.value;
312  hist << std::setw(15) << std::left << algo_state.cnorm;
313  hist << std::setw(15) << std::left << gLnorm_;
314  hist << std::setw(15) << std::left << compViolation_;
315  hist << std::setw(15) << std::left << " ";
316  hist << std::scientific << std::setprecision(2);
317  hist << std::setw(10) << std::left << Step<Real>::getStepState()->searchSize;
318  hist << "\n";
319  }
320  else {
321  hist << " ";
322  hist << std::setw(6) << std::left << algo_state.iter;
323  hist << std::setw(15) << std::left << algo_state.value;
324  hist << std::setw(15) << std::left << algo_state.cnorm;
325  hist << std::setw(15) << std::left << gLnorm_;
326  hist << std::setw(15) << std::left << compViolation_;
327  hist << std::setw(15) << std::left << algo_state.snorm;
328  hist << std::scientific << std::setprecision(2);
329  hist << std::setw(10) << std::left << Step<Real>::getStepState()->searchSize;
330  hist << std::scientific << std::setprecision(6);
331  hist << std::setw(8) << std::left << algo_state.nfval;
332  hist << std::setw(8) << std::left << algo_state.ngrad;
333  hist << std::setw(8) << std::left << algo_state.ncval;
334  hist << std::setw(8) << std::left << subproblemIter_;
335  hist << "\n";
336  }
337  return hist.str();
338  }
339 
345  AlgorithmState<Real> &algo_state ) {}
346 
352  AlgorithmState<Real> &algo_state ) {}
353 
354 }; // class MoreauYosidaPenaltyStep
355 
356 } // namespace ROL
357 
358 #endif
Provides the interface to evaluate objective functions.
Teuchos::RCP< Algorithm< Real > > algo_
std::string printName(void) const
Print step name.
Teuchos::RCP< Vector< Real > > x_
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:145
Provides the interface to compute optimization steps.
Definition: ROL_Step.hpp:69
Teuchos::RCP< StepState< Real > > getState(void)
Definition: ROL_Step.hpp:74
Contains definitions of custom data types in ROL.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Teuchos::RCP< Vector< Real > > l_
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
std::string printHeader(void) const
Print iterate header.
Implements the computation of optimization steps using Moreau-Yosida regularized bound constraints...
void updateMultipliers(Real mu, const ROL::Vector< Real > &x)
std::string print(AlgorithmState< Real > &algo_state, bool pHeader=false) const
Print iterate status.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:76
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).
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update constraint functions. x is the optimization variable, flag = true if optimization variable is ...
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:91
void updateState(const Vector< Real > &x, const Vector< Real > &l, Objective< Real > &obj, EqualityConstraint< Real > &con, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
bool isActivated(void)
Check if bounds are on.
Defines the equality constraint operator interface.
Teuchos::RCP< Vector< Real > > g_
Provides an interface to run optimization algorithms.
virtual void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the adjoint of the the constraint Jacobian at , , to vector .
Provides the interface to evaluate the Moreau-Yosida penalty function.
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Provides the interface to apply upper and lower bound constraints.
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.
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).
Teuchos::RCP< Vector< Real > > lagmultVec
Definition: ROL_Types.hpp:106
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update Moreau-Yosida penalty function.
Teuchos::RCP< Vector< Real > > iterateVec
Definition: ROL_Types.hpp:105
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:198
virtual Real norm() const =0
Returns where .
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)=0
Evaluate the constraint operator at .
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.
Real testComplementarity(const ROL::Vector< Real > &x)
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
MoreauYosidaPenaltyStep(Teuchos::ParameterList &parlist)
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.