10#ifndef ROL_TYPEB_MOREAUYOSIDAALGORITHM_DEF_HPP
11#define ROL_TYPEB_MOREAUYOSIDAALGORITHM_DEF_HPP
18template<
typename Real>
21 tau_(10), print_(false), list_(list), subproblemIter_(0) {
27 Real ten(10), oem6(1.e-6), oem8(1.e-8), oe8(1e8);
28 ParameterList& steplist = list.sublist(
"Step").sublist(
"Moreau-Yosida Penalty");
29 state_->searchSize = steplist.get(
"Initial Penalty Parameter", ten);
30 maxPenalty_ = steplist.get(
"Maximum Penalty Parameter", oe8);
31 tau_ = steplist.get(
"Penalty Parameter Growth Factor", ten);
34 print_ = steplist.sublist(
"Subproblem").get(
"Print History",
false);
36 Real gtol = steplist.sublist(
"Subproblem").get(
"Optimality Tolerance", oem8);
37 Real ctol = steplist.sublist(
"Subproblem").get(
"Feasibility Tolerance", oem8);
38 int maxit = steplist.sublist(
"Subproblem").get(
"Iteration Limit", 1000);
39 bool reltol = steplist.sublist(
"Subproblem").get(
"Use Relative Tolerances",
true);
40 Real stol = oem6*std::min(gtol,ctol);
41 list_.sublist(
"Status Test").set(
"Gradient Tolerance", gtol);
42 list_.sublist(
"Status Test").set(
"Constraint Tolerance", ctol);
43 list_.sublist(
"Status Test").set(
"Step Tolerance", stol);
44 list_.sublist(
"Status Test").set(
"Iteration Limit", maxit);
45 list_.sublist(
"Status Test").set(
"Use Relative Tolerances", reltol);
47 stepname_ = steplist.sublist(
"Subproblem").get(
"Step Type",
"Trust Region");
51 verbosity_ = list.sublist(
"General").get(
"Output Level", 0);
57template<
typename Real>
63 std::ostream &outStream) {
65 if (proj_ == nullPtr) {
66 proj_ = makePtr<PolyhedralProjection<Real>>(makePtrFromRef(bnd));
74 updateState(x,myobj,bnd,pwa,outStream);
78template<
typename Real>
83 std::ostream &outStream) {
85 Real zerotol = std::sqrt(ROL_EPSILON<Real>());
87 if (state_->iter == 0) {
99 pwa.
axpy(-one,state_->gradientVec->dual());
100 proj_->project(pwa,outStream);
105 state_->gnorm = std::max(gnorm_,compViolation_);
111template<
typename Real>
116 std::ostream &outStream ) {
118 Ptr<Vector<Real>> pwa = x.
clone();
121 x,g,state_->searchSize,updateMultiplier_,
123 initialize(x,g,myobj,bnd,*pwa,outStream);
124 Ptr<TypeU::Algorithm<Real>> algo;
127 if (verbosity_ > 0) writeOutput(outStream,
true);
129 while (status_->check(*state_)) {
131 algo = TypeU::AlgorithmFactory<Real>(list_,secant_);
132 if (hasEcon_) algo->run(x,g,myobj,*proj_->getLinearConstraint(),
133 *proj_->getMultiplier(),*proj_->getResidual(),
135 else algo->run(x,g,myobj,outStream);
136 subproblemIter_ = algo->getState()->iter;
139 state_->stepVec->set(x);
140 state_->stepVec->axpy(-one,*state_->iterateVec);
141 state_->snorm = state_->stepVec->norm();
144 state_->iterateVec->set(x);
150 updateState(x,myobj,bnd,*pwa,outStream);
153 if (updatePenalty_) {
154 state_->searchSize *= tau_;
155 state_->searchSize = std::min(state_->searchSize,maxPenalty_);
163 if (verbosity_ > 0) writeOutput(outStream,writeHeader_);
168template<
typename Real>
170 std::ios_base::fmtflags osFlags(os.flags());
171 if (verbosity_ > 1) {
172 os << std::string(109,
'-') << std::endl;
173 os <<
"Moreau-Yosida Penalty Solver";
174 os <<
" status output definitions" << std::endl << std::endl;
175 os <<
" iter - Number of iterates (steps taken)" << std::endl;
176 os <<
" fval - Objective function value" << std::endl;
177 os <<
" gnorm - Norm of the gradient" << std::endl;
178 os <<
" ifeas - Infeasibility metric" << std::endl;
179 os <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
180 os <<
" penalty - Penalty parameter for bound constraints" << std::endl;
181 os <<
" #fval - Cumulative number of times the objective function was evaluated" << std::endl;
182 os <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
183 os <<
" subiter - Number of subproblem iterations" << std::endl;
184 os << std::string(109,
'-') << std::endl;
188 os << std::setw(6) << std::left <<
"iter";
189 os << std::setw(15) << std::left <<
"fval";
190 os << std::setw(15) << std::left <<
"gnorm";
191 os << std::setw(15) << std::left <<
"ifeas";
192 os << std::setw(15) << std::left <<
"snorm";
193 os << std::setw(10) << std::left <<
"penalty";
194 os << std::setw(8) << std::left <<
"#fval";
195 os << std::setw(8) << std::left <<
"#grad";
196 os << std::setw(8) << std::left <<
"subIter";
201template<
typename Real>
203 std::ios_base::fmtflags osFlags(os.flags());
204 os << std::endl <<
" Moreau-Yosida Penalty Solver";
209template<
typename Real>
211 std::ios_base::fmtflags osFlags(os.flags());
212 os << std::scientific << std::setprecision(6);
213 if ( state_->iter == 0 ) writeName(os);
214 if ( write_header ) writeHeader(os);
215 if ( state_->iter == 0 ) {
217 os << std::setw(6) << std::left << state_->iter;
218 os << std::setw(15) << std::left << state_->value;
219 os << std::setw(15) << std::left << gnorm_;
220 os << std::setw(15) << std::left << compViolation_;
221 os << std::setw(15) << std::left <<
"---";
222 os << std::scientific << std::setprecision(2);
223 os << std::setw(10) << std::left << state_->searchSize;
224 os << std::scientific << std::setprecision(6);
225 os << std::setw(8) << std::left << state_->nfval;
226 os << std::setw(8) << std::left << state_->ngrad;
227 os << std::setw(8) << std::left <<
"---";
232 os << std::setw(6) << std::left << state_->iter;
233 os << std::setw(15) << std::left << state_->value;
234 os << std::setw(15) << std::left << gnorm_;
235 os << std::setw(15) << std::left << compViolation_;
236 os << std::setw(15) << std::left << state_->snorm;
237 os << std::scientific << std::setprecision(2);
238 os << std::setw(10) << std::left << state_->searchSize;
239 os << std::scientific << std::setprecision(6);
240 os << std::setw(8) << std::left << state_->nfval;
241 os << std::setw(8) << std::left << state_->ngrad;
242 os << std::setw(8) << std::left << subproblemIter_;
Provides the interface to apply upper and lower bound constraints.
Provides the interface to evaluate the Moreau-Yosida penalty function.
void getObjectiveGradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Real getObjectiveValue(const Vector< Real > &x, Real &tol)
int getNumberGradientEvaluations(void)
Real testComplementarity(const Vector< Real > &x)
int getNumberFunctionEvaluations(void)
void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update Moreau-Yosida penalty function.
void updateMultipliers(Real mu, const Vector< Real > &x)
Provides the interface to evaluate objective functions.
Provides interface for and implements limited-memory secant operators.
Provides an interface to check status of optimization algorithms.
Provides an interface to run bound constrained optimization algorithms.
void initialize(const Vector< Real > &x, const Vector< Real > &g)
virtual void writeExitStatus(std::ostream &os) const
const Ptr< AlgorithmState< Real > > state_
const Ptr< CombinedStatusTest< Real > > status_
void updateState(const Vector< Real > &x, MoreauYosidaObjective< Real > &myobj, BoundConstraint< Real > &bnd, Vector< Real > &pwa, std::ostream &outStream=std::cout)
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...
MoreauYosidaAlgorithm(ParameterList &list, const Ptr< Secant< Real > > &secant=nullPtr)
void writeName(std::ostream &os) const override
Print step name.
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.
void writeHeader(std::ostream &os) const override
Print iterate header.
Defines the linear algebra or vector space interface.
virtual Real norm() const =0
Returns where .
virtual void set(const Vector &x)
Set where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .