ROL
ROL_TypeE_FletcherAlgorithm_Def.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_TYPEE_FLETCHERALGORITHM_DEF_H
11 #define ROL_TYPEE_FLETCHERALGORITHM_DEF_H
12 
14 
15 namespace ROL {
16 namespace TypeE {
17 
18 template<typename Real>
19 FletcherAlgorithm<Real>::FletcherAlgorithm( ParameterList &list, const Ptr<Secant<Real>> &secant )
20  : TypeE::Algorithm<Real>::Algorithm(), secant_(secant), list_(list), subproblemIter_(0) {
21  // Set status test
22  status_->reset();
23  status_->add(makePtr<ConstraintStatusTest<Real>>(list));
24 
25  ParameterList& sublist = list.sublist("Step").sublist("Fletcher");
26  sigma_ = sublist.get("Penalty Parameter", 1.0);
27  delta_ = sublist.get("Regularization Parameter", 0.0);
28  minDelta_ = sublist.get("Minimum Regularization Parameter", 1e-8);
29  deltaUpdate_ = sublist.get("Regularization Parameter Decrease Factor", 1e-1);
30  sigmaUpdate_ = sublist.get("Penalty Parameter Growth Factor", 2.0);
31  modifySigma_ = sublist.get("Modify Penalty Parameter", false);
32  maxSigma_ = sublist.get("Maximum Penalty Parameter", 1e8);
33  minSigma_ = sublist.get("Minimum Penalty Parameter", 1e-6);
34  subStep_ = sublist.get("Subproblem Step Type", "Trust Region");
35  int subiter = sublist.get("Subproblem Iteration Limit", 100);
36  // Verbosity setting
37  verbosity_ = list.sublist("General").get("Output Level", 0);
39  bool print = verbosity_ >= 2;
40  // Set parameter list for subproblem solve
41  list_.sublist("General").set("Output Level",(print ? verbosity_-1 : 0));
42  list_.sublist("Step").set("Type", subStep_);
43  list_.sublist("Status Test").set("Iteration Limit", subiter);
44 }
45 
46 template<typename Real>
48  const Vector<Real> &g,
49  const Vector<Real> &l,
50  const Vector<Real> &c,
52  Constraint<Real> &con,
53  std::ostream &outStream ) {
54  Real tol = std::sqrt(ROL_EPSILON<Real>());
56 
57  // Initialize the algorithm state
58  state_->nfval = 0;
59  state_->ncval = 0;
60  state_->ngrad = 0;
61 
62  // Compute objective value
63  fobj.reset(sigma_,delta_);
64  fobj.update(x,UpdateType::Initial,state_->iter);
65  merit_ = fobj.value(x,tol);
66  state_->value = fobj.getObjectiveValue(x);
67  fobj.gradient(*state_->gradientVec,x,tol);
68  gpnorm_ = state_->gradientVec->norm();
69  state_->gradientVec->set(*fobj.getLagrangianGradient(x));
70  state_->gnorm = state_->gradientVec->norm();
71 
72  // Compute constraint violation
73  state_->constraintVec->set(*fobj.getConstraintVec(x));
74  state_->cnorm = state_->constraintVec->norm();
75 
76  // Update evaluation counters
77  state_->ncval += fobj.getNumberConstraintEvaluations();
78  state_->nfval += fobj.getNumberFunctionEvaluations();
79  state_->ngrad += fobj.getNumberGradientEvaluations();
80 }
81 
82 template<typename Real>
84  const Vector<Real> &g,
85  Objective<Real> &obj,
86  Constraint<Real> &econ,
87  Vector<Real> &emul,
88  const Vector<Real> &eres,
89  std::ostream &outStream ) {
90  // Initialize Fletcher penalty data
91  const Real one(1);
92  Real tol(std::sqrt(ROL_EPSILON<Real>()));
93  Ptr<Vector<Real>> dwa_ = g.clone();
94  FletcherObjectiveE<Real> fobj(makePtrFromRef(obj),makePtrFromRef(econ),x,g,eres,emul,list_);
95  initialize(x,g,emul,eres,fobj,econ,outStream);
96  Ptr<TypeU::Algorithm<Real>> algo;
97 
98  if (verbosity_ > 0) writeOutput(outStream,true);
99 
100  while (status_->check(*state_)) {
101  // Minimize Fletcher penalty
102  algo = TypeU::AlgorithmFactory<Real>(list_,secant_);
103  algo->run(x,g,fobj,outStream);
104  subproblemIter_ = algo->getState()->iter;
105 
106  // Compute step
107  state_->stepVec->set(x);
108  state_->stepVec->axpy(-one,*state_->iterateVec);
109  state_->snorm = state_->stepVec->norm();
110 
111  // Update iteration information
112  state_->iter++;
113  state_->iterateVec->set(x);
114  state_->value = fobj.getObjectiveValue(x);
115  state_->constraintVec->set(*fobj.getConstraintVec(x));
116  state_->cnorm = state_->constraintVec->norm();
117  state_->gradientVec->set(*fobj.getLagrangianGradient(x));
118  state_->gnorm = state_->gradientVec->norm();
119  state_->lagmultVec->set(*fobj.getMultiplierVec(x));
120  emul.set(*state_->lagmultVec);
121  merit_ = algo->getState()->value;
122  gpnorm_ = algo->getState()->gnorm;
123 
124  // Update evaluation counters
125  state_->nfval += fobj.getNumberFunctionEvaluations();
126  state_->ngrad += fobj.getNumberGradientEvaluations();
127  state_->ncval += fobj.getNumberConstraintEvaluations();
128 
129  // Update penalty parameters
130  bool too_infeasible = state_->cnorm > static_cast<Real>(100.)*gpnorm_;
131  bool too_feasible = state_->cnorm < static_cast<Real>(1e-2)*gpnorm_;
132  bool modified = false;
133  if( too_infeasible && !modified && modifySigma_
134  && algo->getState()->statusFlag == EXITSTATUS_CONVERGED) {
135  sigma_ = std::min(sigma_*sigmaUpdate_, maxSigma_);
136  modified = true;
137  }
138  if( too_feasible && !modified && modifySigma_
139  && algo->getState()->statusFlag == EXITSTATUS_CONVERGED) {
140  sigma_ = std::max(sigma_/sigmaUpdate_, minSigma_);
141  modified = true;
142  }
143  if( delta_ > minDelta_ && !modified ) {
144  Real deltaNext = delta_ * deltaUpdate_;
145  if( gpnorm_ < deltaNext ) {
146  delta_ = deltaNext;
147  modified = true;
148  }
149  }
150  if( modified ) {
151  fobj.reset(sigma_,delta_);
152  merit_ = fobj.value(x,tol);
153  fobj.gradient(*dwa_,x,tol);
154  gpnorm_ = dwa_->norm();
155 
156  state_->nfval++;
157  state_->ngrad++;
158  state_->ncval++;
159  }
160 
161  // Update Output
162  if (verbosity_ > 0) writeOutput(outStream,printHeader_);
163  }
164 
165  if (verbosity_ > 0) TypeE::Algorithm<Real>::writeExitStatus(outStream);
166 }
167 
168 template<typename Real>
169 void FletcherAlgorithm<Real>::writeHeader( std::ostream& os ) const {
170  std::ios_base::fmtflags osFlags(os.flags());
171  if(verbosity_>1) {
172  os << std::string(114,'-') << std::endl;
173  os << "Fletcher exact penalty status output definitions" << std::endl << std::endl;
174  os << " iter - Number of iterates (steps taken)" << std::endl;
175  os << " fval - Objective function value" << std::endl;
176  os << " cnorm - Norm of the constraint violation" << std::endl;
177  os << " gLnorm - Norm of the gradient of the Lagrangian" << std::endl;
178  os << " snorm - Norm of the step" << std::endl;
179  os << " merit - Penalty function value" << std::endl;
180  os << " gpnorm - Norm of the gradient of the penalty" << std::endl;
181  os << " penalty - Penalty parameter" << std::endl;
182  os << " delta - Feasibility tolerance" << std::endl;
183  os << " #fval - Number of times the objective was computed" << std::endl;
184  os << " #grad - Number of times the gradient was computed" << std::endl;
185  os << " #cval - Number of times the constraint was computed" << std::endl;
186  os << " subIter - Number of iterations to solve subproblem" << std::endl;
187  os << std::string(114,'-') << std::endl;
188  }
189  os << " ";
190  os << std::setw(6) << std::left << "iter";
191  os << std::setw(15) << std::left << "fval";
192  os << std::setw(15) << std::left << "cnorm";
193  os << std::setw(15) << std::left << "gLnorm";
194  os << std::setw(15) << std::left << "snorm";
195  os << std::setw(15) << std::left << "merit";
196  os << std::setw(15) << std::left << "gpnorm";
197  os << std::setw(10) << std::left << "penalty";
198  os << std::setw(10) << std::left << "delta";
199  os << std::setw(8) << std::left << "#fval";
200  os << std::setw(8) << std::left << "#grad";
201  os << std::setw(8) << std::left << "#cval";
202  os << std::setw(8) << std::left << "subIter";
203  os << std::endl;
204  os.flags(osFlags);
205 }
206 
207 template<typename Real>
208 void FletcherAlgorithm<Real>::writeName( std::ostream& os ) const {
209  std::ios_base::fmtflags osFlags(os.flags());
210  os << std::endl << "Fletcher Exact Penalty Solver (Type E, Equality Constraints)";
211  os << std::endl;
212  os << "Subproblem Solver: " << subStep_ << std::endl;
213  os.flags(osFlags);
214 }
215 
216 template<typename Real>
217 void FletcherAlgorithm<Real>::writeOutput( std::ostream& os, const bool print_header ) const {
218  std::ios_base::fmtflags osFlags(os.flags());
219  os << std::scientific << std::setprecision(6);
220  if ( state_->iter == 0 ) writeName(os);
221  if ( print_header ) writeHeader(os);
222  if ( state_->iter == 0 ) {
223  os << " ";
224  os << std::setw(6) << std::left << state_->iter;
225  os << std::setw(15) << std::left << state_->value;
226  os << std::setw(15) << std::left << state_->cnorm;
227  os << std::setw(15) << std::left << state_->gnorm;
228  os << std::setw(15) << std::left << "---";
229  os << std::setw(15) << std::left << merit_;
230  os << std::setw(15) << std::left << gpnorm_;
231  os << std::scientific << std::setprecision(2);
232  os << std::setw(10) << std::left << sigma_;
233  os << std::setw(10) << std::left << delta_;
234  os << std::scientific << std::setprecision(6);
235  os << std::setw(8) << std::left << state_->nfval;
236  os << std::setw(8) << std::left << state_->ngrad;
237  os << std::setw(8) << std::left << state_->ncval;
238  os << std::setw(8) << std::left << "---";
239  os << std::endl;
240  }
241  else {
242  os << " ";
243  os << std::setw(6) << std::left << state_->iter;
244  os << std::setw(15) << std::left << state_->value;
245  os << std::setw(15) << std::left << state_->cnorm;
246  os << std::setw(15) << std::left << state_->gnorm;
247  os << std::setw(15) << std::left << state_->snorm;
248  os << std::setw(15) << std::left << merit_;
249  os << std::setw(15) << std::left << gpnorm_;
250  os << std::scientific << std::setprecision(2);
251  os << std::setw(10) << std::left << sigma_;
252  os << std::setw(10) << std::left << delta_;
253  os << std::scientific << std::setprecision(6);
254  os << std::setw(8) << std::left << state_->nfval;
255  os << std::setw(8) << std::left << state_->ngrad;
256  os << std::setw(8) << std::left << state_->ncval;
257  os << std::setw(8) << std::left << subproblemIter_;
258  os << std::endl;
259  }
260  os.flags(osFlags);
261 }
262 
263 } // namespace TypeE
264 } // namespace ROL
265 
266 #endif
Provides the interface to evaluate objective functions.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol) override
Compute gradient.
Ptr< const Vector< Real > > getMultiplierVec(const Vector< Real > &x)
virtual void writeName(std::ostream &os) const override
Print step name.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
virtual void writeOutput(std::ostream &os, const bool print_header=false) const override
Print iterate status.
virtual void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, Constraint< Real > &econ, Vector< Real > &emul, const Vector< Real > &eres, std::ostream &outStream=std::cout) override
Run algorithm on equality constrained problems (Type-E). This general interface supports the use of d...
Provides an interface to check status of optimization algorithms for problems with equality constrain...
void initialize(Vector< Real > &x, const Vector< Real > &g, const Vector< Real > &l, const Vector< Real > &c, FletcherObjectiveE< Real > &fobj, Constraint< Real > &con, std::ostream &outStream)
FletcherAlgorithm(ParameterList &list, const Ptr< Secant< Real >> &secant=nullPtr)
Real getObjectiveValue(const Vector< Real > &x)
Provides interface for and implements limited-memory secant operators.
Definition: ROL_Secant.hpp:45
virtual void writeHeader(std::ostream &os) const override
Print iterate header.
const Ptr< CombinedStatusTest< Real > > status_
virtual void writeExitStatus(std::ostream &os) const
Real value(const Vector< Real > &x, Real &tol) override
Compute value.
void initialize(const Vector< Real > &x, const Vector< Real > &g, const Vector< Real > &mul, const Vector< Real > &c)
Ptr< const Vector< Real > > getConstraintVec(const Vector< Real > &x)
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:175
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1) override
Update objective function.
Ptr< const Vector< Real > > getLagrangianGradient(const Vector< Real > &x)
Defines the general constraint operator interface.