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<MoreauYosidaPenalty<Real> > myPen_;
124  Teuchos::RCP<Algorithm<Real> > algo_;
125  Teuchos::RCP<Vector<Real> > x_;
126  Teuchos::RCP<Vector<Real> > g_;
127  Teuchos::RCP<Vector<Real> > l_;
128 
129  Real tau_;
130  bool print_;
131 
132  Teuchos::ParameterList parlist_;
134 
135  void updateState(const Vector<Real> &x, const Vector<Real> &l,
136  Objective<Real> &obj,
138  AlgorithmState<Real> &algo_state) {
139  Real zerotol = std::sqrt(ROL_EPSILON);
140  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
141  // Update objective and constraint.
142  obj.update(x,true,algo_state.iter);
143  con.update(x,true,algo_state.iter);
144  myPen_->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(-1.0,(state->gradientVec)->dual());
155  bnd.project(*x_);
156  x_->axpy(-1.0,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:
171 
172  MoreauYosidaPenaltyStep(Teuchos::ParameterList &parlist)
173  : Step<Real>(), myPen_(Teuchos::null), 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  Teuchos::ParameterList& steplist = parlist.sublist("Step").sublist("Moreau-Yosida Penalty");
178  Step<Real>::getState()->searchSize = steplist.get("Initial Penalty Parameter",10.0);
179  tau_ = steplist.get("Penalty Parameter Growth Factor",10.0);
180  print_ = steplist.sublist("Subproblem").get("Print History",false);
181  // Set parameters for step subproblem
182  Real gtol = steplist.sublist("Subproblem").get("Optimality Tolerance",1.e-8);
183  Real ctol = steplist.sublist("Subproblem").get("Feasibility Tolerance",1.e-8);
184  Real stol = 1.e-6*std::min(gtol,ctol);
185  int maxit = steplist.sublist("Subproblem").get("Iteration Limit",1000);
186  parlist_.sublist("Status Test").set("Gradient Tolerance", gtol);
187  parlist_.sublist("Status Test").set("Constraint Tolerance", ctol);
188  parlist_.sublist("Status Test").set("Step Tolerance", stol);
189  parlist_.sublist("Status Test").set("Iteration Limit", maxit);
190  }
191 
196  AlgorithmState<Real> &algo_state ) {
197  // Initialize step state
198  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
199  state->descentVec = x.clone();
200  state->gradientVec = g.clone();
201  state->constraintVec = c.clone();
202  // Initialize additional storage
203  x_ = x.clone();
204  g_ = g.clone();
205  l_ = l.clone();
206  // Project x onto the feasible set
207  if ( bnd.isActivated() ) {
208  bnd.project(x);
209  }
210  // Update the Lagrangian
211  myPen_ = Teuchos::rcp(new MoreauYosidaPenalty<Real>(obj,bnd,x,state->searchSize));
212  myPen_->updateMultipliers(state->searchSize,x);
213  // Initialize the algorithm state
214  algo_state.nfval = 0;
215  algo_state.ncval = 0;
216  algo_state.ngrad = 0;
217  updateState(x,l,obj,con,bnd,algo_state);
218  }
219 
222  void compute( Vector<Real> &s, const Vector<Real> &x, const Vector<Real> &l,
224  BoundConstraint<Real> &bnd,
225  AlgorithmState<Real> &algo_state ) {
226  algo_ = Teuchos::rcp(new Algorithm<Real>("Composite Step",parlist_,false));
227  x_->set(x); l_->set(l);
228  algo_->run(*x_,*l_,*myPen_,con,print_);
229  s.set(*x_); s.axpy(-1.0,x);
230  subproblemIter_ = (algo_->getState())->iter;
231  }
232 
238  AlgorithmState<Real> &algo_state ) {
239  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
240  state->descentVec->set(s);
241  // Update iterate and Lagrange multiplier
242  x.plus(s);
243  l.set(*l_);
244  // Update objective and constraint
245  algo_state.iter++;
246  con.update(x,true,algo_state.iter);
247  myPen_->update(x,true,algo_state.iter);
248  // Update multipliers
249  state->searchSize *= tau_;
250  myPen_->updateMultipliers(state->searchSize,x);
251  // Update state
252  updateState(x,l,obj,con,bnd,algo_state);
253  algo_state.nfval += myPen_->getNumberFunctionEvaluations() + ((algo_->getState())->nfval);
254  algo_state.ngrad += myPen_->getNumberGradientEvaluations() + ((algo_->getState())->ngrad);
255  algo_state.ncval += (algo_->getState())->ncval;
256  algo_state.snorm = s.norm();
257  algo_state.iterateVec->set(x);
258  algo_state.lagmultVec->set(l);
259  }
260 
263  std::string printHeader( void ) const {
264  std::stringstream hist;
265  hist << " ";
266  hist << std::setw(6) << std::left << "iter";
267  hist << std::setw(15) << std::left << "fval";
268  hist << std::setw(15) << std::left << "cnorm";
269  hist << std::setw(15) << std::left << "gnorm";
270  hist << std::setw(15) << std::left << "snorm";
271  hist << std::setw(10) << std::left << "penalty";
272  hist << std::setw(8) << std::left << "#fval";
273  hist << std::setw(8) << std::left << "#grad";
274  hist << std::setw(8) << std::left << "#cval";
275  hist << std::setw(8) << std::left << "subIter";
276  hist << "\n";
277  return hist.str();
278  }
279 
282  std::string printName( void ) const {
283  std::stringstream hist;
284  hist << "\n" << " Moreau-Yosida Penalty solver";
285  hist << "\n";
286  return hist.str();
287  }
288 
291  std::string print( AlgorithmState<Real> &algo_state, bool pHeader = false ) const {
292  std::stringstream hist;
293  hist << std::scientific << std::setprecision(6);
294  if ( algo_state.iter == 0 ) {
295  hist << printName();
296  }
297  if ( pHeader ) {
298  hist << printHeader();
299  }
300  if ( algo_state.iter == 0 ) {
301  hist << " ";
302  hist << std::setw(6) << std::left << algo_state.iter;
303  hist << std::setw(15) << std::left << algo_state.value;
304  hist << std::setw(15) << std::left << algo_state.cnorm;
305  hist << std::setw(15) << std::left << algo_state.gnorm;
306  hist << std::setw(15) << std::left << " ";
307  hist << std::scientific << std::setprecision(2);
308  hist << std::setw(10) << std::left << Step<Real>::getStepState()->searchSize;
309  hist << "\n";
310  }
311  else {
312  hist << " ";
313  hist << std::setw(6) << std::left << algo_state.iter;
314  hist << std::setw(15) << std::left << algo_state.value;
315  hist << std::setw(15) << std::left << algo_state.cnorm;
316  hist << std::setw(15) << std::left << algo_state.gnorm;
317  hist << std::setw(15) << std::left << algo_state.snorm;
318  hist << std::scientific << std::setprecision(2);
319  hist << std::setw(10) << std::left << Step<Real>::getStepState()->searchSize;
320  hist << std::scientific << std::setprecision(6);
321  hist << std::setw(8) << std::left << algo_state.nfval;
322  hist << std::setw(8) << std::left << algo_state.ngrad;
323  hist << std::setw(8) << std::left << algo_state.ncval;
324  hist << std::setw(8) << std::left << subproblemIter_;
325  hist << "\n";
326  }
327  return hist.str();
328  }
329 
335  AlgorithmState<Real> &algo_state ) {}
336 
342  AlgorithmState<Real> &algo_state ) {}
343 
344 }; // class MoreauYosidaPenaltyStep
345 
346 } // namespace ROL
347 
348 #endif
Provides the interface to evaluate objective functions.
Teuchos::RCP< Algorithm< Real > > algo_
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
std::string printHeader(void) const
Print iterate header.
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< Vector< Real > > l_
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Teuchos::RCP< MoreauYosidaPenalty< Real > > myPen_
Implements the computation of optimization steps using Moreau-Yosida regularized bound constraints...
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 is ...
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:77
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.
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).
std::string printName(void) const
Print step name.
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 .
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)=0
Evaluate the constraint operator at .
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
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.
std::string print(AlgorithmState< Real > &algo_state, bool pHeader=false) const
Print iterate status.
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
MoreauYosidaPenaltyStep(Teuchos::ParameterList &parlist)
static const double ROL_EPSILON
Platform-dependent machine epsilon.
Definition: ROL_Types.hpp:118
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.