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 
128  Real tau_;
129  bool print_;
130 
131  Teuchos::ParameterList parlist_;
133 
134  void updateState(const Vector<Real> &x, const Vector<Real> &l,
135  Objective<Real> &obj,
137  AlgorithmState<Real> &algo_state) {
139  = Teuchos::dyn_cast<MoreauYosidaPenalty<Real> >(obj);
140  Real zerotol = std::sqrt(ROL_EPSILON<Real>()), one(1);
141  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
142  // Update objective and constraint.
143  myPen.update(x,true,algo_state.iter);
144  con.update(x,true,algo_state.iter);
145  // Compute objective value, constraint value, & gradient of Lagrangian
146  algo_state.value = myPen.value(x, zerotol);
147  con.value(*(state->constraintVec),x, zerotol);
148  myPen.gradient(*(state->gradientVec), x, zerotol);
149  con.applyAdjointJacobian(*g_,l,x,zerotol);
150  state->gradientVec->plus(*g_);
151  // Compute criticality measure
152  if (bnd.isActivated()) {
153  x_->set(x);
154  x_->axpy(-one,(state->gradientVec)->dual());
155  bnd.project(*x_);
156  x_->axpy(-one,x);
157  algo_state.gnorm = x_->norm();
158  }
159  else {
160  algo_state.gnorm = (state->gradientVec)->norm();
161  }
162  algo_state.cnorm = (state->constraintVec)->norm();
163  // Update state
164  algo_state.nfval++;
165  algo_state.ngrad++;
166  algo_state.ncval++;
167  }
168 
169 public:
170 
172  using Step<Real>::compute;
173  using Step<Real>::update;
174 
176 
177  MoreauYosidaPenaltyStep(Teuchos::ParameterList &parlist)
178  : Step<Real>(), algo_(Teuchos::null),
179  x_(Teuchos::null), g_(Teuchos::null), l_(Teuchos::null),
180  tau_(10), print_(false), parlist_(parlist), subproblemIter_(0) {
181  // Parse parameters
182  Real ten(10), oem6(1.e-6), oem8(1.e-8);
183  Teuchos::ParameterList& steplist = parlist.sublist("Step").sublist("Moreau-Yosida Penalty");
184  Step<Real>::getState()->searchSize = steplist.get("Initial Penalty Parameter",ten);
185  tau_ = steplist.get("Penalty Parameter Growth Factor",ten);
186  print_ = steplist.sublist("Subproblem").get("Print History",false);
187  // Set parameters for step subproblem
188  Real gtol = steplist.sublist("Subproblem").get("Optimality Tolerance",oem8);
189  Real ctol = steplist.sublist("Subproblem").get("Feasibility Tolerance",oem8);
190  Real stol = oem6*std::min(gtol,ctol);
191  int maxit = steplist.sublist("Subproblem").get("Iteration Limit",1000);
192  parlist_.sublist("Status Test").set("Gradient Tolerance", gtol);
193  parlist_.sublist("Status Test").set("Constraint Tolerance", ctol);
194  parlist_.sublist("Status Test").set("Step Tolerance", stol);
195  parlist_.sublist("Status Test").set("Iteration Limit", maxit);
196  }
197 
202  AlgorithmState<Real> &algo_state ) {
204  = Teuchos::dyn_cast<MoreauYosidaPenalty<Real> >(obj);
205  // Initialize step state
206  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
207  state->descentVec = x.clone();
208  state->gradientVec = g.clone();
209  state->constraintVec = c.clone();
210  // Initialize additional storage
211  x_ = x.clone();
212  g_ = g.clone();
213  l_ = l.clone();
214  // Project x onto the feasible set
215  if ( bnd.isActivated() ) {
216  bnd.project(x);
217  }
218  // Update the Lagrangian
219  myPen.updateMultipliers(state->searchSize,x);
220  // Initialize the algorithm state
221  algo_state.nfval = 0;
222  algo_state.ncval = 0;
223  algo_state.ngrad = 0;
224  updateState(x,l,obj,con,bnd,algo_state);
225  }
226 
229  void compute( Vector<Real> &s, const Vector<Real> &x, const Vector<Real> &l,
231  BoundConstraint<Real> &bnd,
232  AlgorithmState<Real> &algo_state ) {
233  Real one(1);
235  = Teuchos::dyn_cast<MoreauYosidaPenalty<Real> >(obj);
236  algo_ = Teuchos::rcp(new Algorithm<Real>("Composite Step",parlist_,false));
237  x_->set(x); l_->set(l);
238  algo_->run(*x_,*l_,myPen,con,print_);
239  s.set(*x_); s.axpy(-one,x);
240  subproblemIter_ = (algo_->getState())->iter;
241  }
242 
248  AlgorithmState<Real> &algo_state ) {
250  = Teuchos::dyn_cast<MoreauYosidaPenalty<Real> >(obj);
251  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
252  state->descentVec->set(s);
253  // Update iterate and Lagrange multiplier
254  x.plus(s);
255  l.set(*l_);
256  // Update objective and constraint
257  algo_state.iter++;
258  con.update(x,true,algo_state.iter);
259  myPen.update(x,true,algo_state.iter);
260  // Update multipliers
261  state->searchSize *= tau_;
262  myPen.updateMultipliers(state->searchSize,x);
263  // Update state
264  updateState(x,l,obj,con,bnd,algo_state);
265  algo_state.nfval += myPen.getNumberFunctionEvaluations() + ((algo_->getState())->nfval);
266  algo_state.ngrad += myPen.getNumberGradientEvaluations() + ((algo_->getState())->ngrad);
267  algo_state.ncval += (algo_->getState())->ncval;
268  algo_state.snorm = s.norm();
269  algo_state.iterateVec->set(x);
270  algo_state.lagmultVec->set(l);
271  }
272 
275  std::string printHeader( void ) const {
276  std::stringstream hist;
277  hist << " ";
278  hist << std::setw(6) << std::left << "iter";
279  hist << std::setw(15) << std::left << "fval";
280  hist << std::setw(15) << std::left << "cnorm";
281  hist << std::setw(15) << std::left << "gnorm";
282  hist << std::setw(15) << std::left << "snorm";
283  hist << std::setw(10) << std::left << "penalty";
284  hist << std::setw(8) << std::left << "#fval";
285  hist << std::setw(8) << std::left << "#grad";
286  hist << std::setw(8) << std::left << "#cval";
287  hist << std::setw(8) << std::left << "subIter";
288  hist << "\n";
289  return hist.str();
290  }
291 
294  std::string printName( void ) const {
295  std::stringstream hist;
296  hist << "\n" << " Moreau-Yosida Penalty solver";
297  hist << "\n";
298  return hist.str();
299  }
300 
303  std::string print( AlgorithmState<Real> &algo_state, bool pHeader = false ) const {
304  std::stringstream hist;
305  hist << std::scientific << std::setprecision(6);
306  if ( algo_state.iter == 0 ) {
307  hist << printName();
308  }
309  if ( pHeader ) {
310  hist << printHeader();
311  }
312  if ( algo_state.iter == 0 ) {
313  hist << " ";
314  hist << std::setw(6) << std::left << algo_state.iter;
315  hist << std::setw(15) << std::left << algo_state.value;
316  hist << std::setw(15) << std::left << algo_state.cnorm;
317  hist << std::setw(15) << std::left << algo_state.gnorm;
318  hist << std::setw(15) << std::left << " ";
319  hist << std::scientific << std::setprecision(2);
320  hist << std::setw(10) << std::left << Step<Real>::getStepState()->searchSize;
321  hist << "\n";
322  }
323  else {
324  hist << " ";
325  hist << std::setw(6) << std::left << algo_state.iter;
326  hist << std::setw(15) << std::left << algo_state.value;
327  hist << std::setw(15) << std::left << algo_state.cnorm;
328  hist << std::setw(15) << std::left << algo_state.gnorm;
329  hist << std::setw(15) << std::left << algo_state.snorm;
330  hist << std::scientific << std::setprecision(2);
331  hist << std::setw(10) << std::left << Step<Real>::getStepState()->searchSize;
332  hist << std::scientific << std::setprecision(6);
333  hist << std::setw(8) << std::left << algo_state.nfval;
334  hist << std::setw(8) << std::left << algo_state.ngrad;
335  hist << std::setw(8) << std::left << algo_state.ncval;
336  hist << std::setw(8) << std::left << subproblemIter_;
337  hist << "\n";
338  }
339  return hist.str();
340  }
341 
347  AlgorithmState<Real> &algo_state ) {}
348 
354  AlgorithmState<Real> &algo_state ) {}
355 
356 }; // class MoreauYosidaPenaltyStep
357 
358 } // namespace ROL
359 
360 #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:143
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:74
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 i...
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:196
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.
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.