44 #ifndef ROL_TYPEB_MOREAUYOSIDAALGORITHM_DEF_HPP
45 #define ROL_TYPEB_MOREAUYOSIDAALGORITHM_DEF_HPP
52 template<
typename Real>
55 tau_(10), print_(false), list_(list), subproblemIter_(0) {
61 Real ten(10), oem6(1.e-6), oem8(1.e-8), oe8(1e8);
62 ParameterList& steplist = list.sublist(
"Step").sublist(
"Moreau-Yosida Penalty");
63 state_->searchSize = steplist.get(
"Initial Penalty Parameter", ten);
64 maxPenalty_ = steplist.get(
"Maximum Penalty Parameter", oe8);
65 tau_ = steplist.get(
"Penalty Parameter Growth Factor", ten);
68 print_ = steplist.sublist(
"Subproblem").get(
"Print History",
false);
70 Real gtol = steplist.sublist(
"Subproblem").get(
"Optimality Tolerance", oem8);
71 Real ctol = steplist.sublist(
"Subproblem").get(
"Feasibility Tolerance", oem8);
72 int maxit = steplist.sublist(
"Subproblem").get(
"Iteration Limit", 1000);
73 bool reltol = steplist.sublist(
"Subproblem").get(
"Use Relative Tolerances",
true);
74 Real stol = oem6*std::min(gtol,ctol);
75 list_.sublist(
"Status Test").set(
"Gradient Tolerance", gtol);
76 list_.sublist(
"Status Test").set(
"Constraint Tolerance", ctol);
77 list_.sublist(
"Status Test").set(
"Step Tolerance", stol);
78 list_.sublist(
"Status Test").set(
"Iteration Limit", maxit);
79 list_.sublist(
"Status Test").set(
"Use Relative Tolerances", reltol);
81 stepname_ = steplist.sublist(
"Subproblem").get(
"Step Type",
"Trust Region");
85 verbosity_ = list.sublist(
"General").get(
"Output Level", 0);
91 template<
typename Real>
97 std::ostream &outStream) {
99 if (proj_ == nullPtr) {
100 proj_ = makePtr<PolyhedralProjection<Real>>(makePtrFromRef(bnd));
108 updateState(x,myobj,bnd,pwa,outStream);
112 template<
typename Real>
117 std::ostream &outStream) {
119 Real zerotol = std::sqrt(ROL_EPSILON<Real>());
121 if (state_->iter == 0) {
133 pwa.
axpy(-one,state_->gradientVec->dual());
134 proj_->project(pwa,outStream);
139 state_->gnorm = std::max(gnorm_,compViolation_);
145 template<
typename Real>
150 std::ostream &outStream ) {
152 Ptr<Vector<Real>> pwa = x.
clone();
155 x,g,state_->searchSize,updateMultiplier_,
157 initialize(x,g,myobj,bnd,*pwa,outStream);
158 Ptr<TypeU::Algorithm<Real>> algo;
161 if (verbosity_ > 0) writeOutput(outStream,
true);
163 while (status_->check(*state_)) {
165 algo = TypeU::AlgorithmFactory<Real>(list_,secant_);
166 if (hasEcon_) algo->run(x,g,myobj,*proj_->getLinearConstraint(),
167 *proj_->getMultiplier(),*proj_->getResidual(),
169 else algo->run(x,g,myobj,outStream);
170 subproblemIter_ = algo->getState()->iter;
173 state_->stepVec->set(x);
174 state_->stepVec->axpy(-one,*state_->iterateVec);
175 state_->snorm = state_->stepVec->norm();
178 state_->iterateVec->set(x);
184 updateState(x,myobj,bnd,*pwa,outStream);
187 if (updatePenalty_) {
188 state_->searchSize *= tau_;
189 state_->searchSize = std::min(state_->searchSize,maxPenalty_);
197 if (verbosity_ > 0) writeOutput(outStream,writeHeader_);
202 template<
typename Real>
204 std::ios_base::fmtflags osFlags(os.flags());
205 if (verbosity_ > 1) {
206 os << std::string(109,
'-') << std::endl;
207 os <<
"Moreau-Yosida Penalty Solver";
208 os <<
" status output definitions" << std::endl << std::endl;
209 os <<
" iter - Number of iterates (steps taken)" << std::endl;
210 os <<
" fval - Objective function value" << std::endl;
211 os <<
" gnorm - Norm of the gradient" << std::endl;
212 os <<
" ifeas - Infeasibility metric" << std::endl;
213 os <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
214 os <<
" penalty - Penalty parameter for bound constraints" << std::endl;
215 os <<
" #fval - Cumulative number of times the objective function was evaluated" << std::endl;
216 os <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
217 os <<
" subiter - Number of subproblem iterations" << std::endl;
218 os << std::string(109,
'-') << std::endl;
222 os << std::setw(6) << std::left <<
"iter";
223 os << std::setw(15) << std::left <<
"fval";
224 os << std::setw(15) << std::left <<
"gnorm";
225 os << std::setw(15) << std::left <<
"ifeas";
226 os << std::setw(15) << std::left <<
"snorm";
227 os << std::setw(10) << std::left <<
"penalty";
228 os << std::setw(8) << std::left <<
"#fval";
229 os << std::setw(8) << std::left <<
"#grad";
230 os << std::setw(8) << std::left <<
"subIter";
235 template<
typename Real>
237 std::ios_base::fmtflags osFlags(os.flags());
238 os << std::endl <<
" Moreau-Yosida Penalty Solver";
243 template<
typename Real>
245 std::ios_base::fmtflags osFlags(os.flags());
246 os << std::scientific << std::setprecision(6);
247 if ( state_->iter == 0 ) writeName(os);
248 if ( write_header ) writeHeader(os);
249 if ( state_->iter == 0 ) {
251 os << std::setw(6) << std::left << state_->iter;
252 os << std::setw(15) << std::left << state_->value;
253 os << std::setw(15) << std::left << gnorm_;
254 os << std::setw(15) << std::left << compViolation_;
255 os << std::setw(15) << std::left <<
"---";
256 os << std::scientific << std::setprecision(2);
257 os << std::setw(10) << std::left << state_->searchSize;
258 os << std::scientific << std::setprecision(6);
259 os << std::setw(8) << std::left << state_->nfval;
260 os << std::setw(8) << std::left << state_->ngrad;
261 os << std::setw(8) << std::left <<
"---";
266 os << std::setw(6) << std::left << state_->iter;
267 os << std::setw(15) << std::left << state_->value;
268 os << std::setw(15) << std::left << gnorm_;
269 os << std::setw(15) << std::left << compViolation_;
270 os << std::setw(15) << std::left << state_->snorm;
271 os << std::scientific << std::setprecision(2);
272 os << std::setw(10) << std::left << state_->searchSize;
273 os << std::scientific << std::setprecision(6);
274 os << std::setw(8) << std::left << state_->nfval;
275 os << std::setw(8) << std::left << state_->ngrad;
276 os << std::setw(8) << std::left << subproblemIter_;
Provides the interface to evaluate objective functions.
void writeHeader(std::ostream &os) const override
Print iterate header.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void initialize(Vector< Real > &x, const Vector< Real > &g, MoreauYosidaObjective< Real > &myobj, BoundConstraint< Real > &bnd, Vector< Real > &pwa, std::ostream &outStream=std::cout)
void writeOutput(std::ostream &os, const bool write_header=false) const override
Print iterate status.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Real getObjectiveValue(const Vector< Real > &x, Real &tol)
virtual void writeExitStatus(std::ostream &os) const
int getNumberGradientEvaluations(void)
void writeName(std::ostream &os) const override
Print step name.
Defines the linear algebra or vector space interface.
int getNumberFunctionEvaluations(void)
MoreauYosidaAlgorithm(ParameterList &list, const Ptr< Secant< Real >> &secant=nullPtr)
void updateMultipliers(Real mu, const Vector< Real > &x)
void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update Moreau-Yosida penalty function.
Provides an interface to run bound constrained optimization algorithms.
Provides the interface to evaluate the Moreau-Yosida penalty function.
const Ptr< AlgorithmState< Real > > state_
Provides interface for and implements limited-memory secant operators.
Provides an interface to check status of optimization algorithms.
Provides the interface to apply upper and lower bound constraints.
void updateState(const Vector< Real > &x, MoreauYosidaObjective< Real > &myobj, BoundConstraint< Real > &bnd, Vector< Real > &pwa, std::ostream &outStream=std::cout)
void initialize(const Vector< Real > &x, const Vector< Real > &g)
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout) override
Run algorithm on bound constrained problems (Type-B). This general interface supports the use of dual...
virtual void set(const Vector &x)
Set where .
void getObjectiveGradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
virtual Real norm() const =0
Returns where .
Real testComplementarity(const Vector< Real > &x)
const Ptr< CombinedStatusTest< Real > > status_