44#ifndef ROL_TYPEG_MOREAUYOSIDAALGORITHM_DEF_H
45#define ROL_TYPEG_MOREAUYOSIDAALGORITHM_DEF_H
52template<
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 Real stol = oem6*std::min(gtol,ctol);
74 list_.sublist(
"Status Test").set(
"Gradient Tolerance", gtol);
75 list_.sublist(
"Status Test").set(
"Constraint Tolerance", ctol);
76 list_.sublist(
"Status Test").set(
"Step Tolerance", stol);
77 list_.sublist(
"Status Test").set(
"Iteration Limit", maxit);
79 stepname_ = steplist.sublist(
"Subproblem").get(
"Step Type",
"Augmented Lagrangian");
82 verbosity_ = list.sublist(
"General").get(
"Output Level", 0);
88template<
typename Real>
98 std::ostream &outStream) {
100 if (proj_ == nullPtr) {
101 proj_ = makePtr<PolyhedralProjection<Real>>(makePtrFromRef(bnd));
102 hasPolyProj_ =
false;
104 proj_->project(x,outStream);
111 updateState(x,l,myobj,bnd,con,pwa,dwa,outStream);
115template<
typename Real>
123 std::ostream &outStream) {
125 Real zerotol = std::sqrt(ROL_EPSILON<Real>());
127 if (state_->iter == 0) {
140 state_->gradientVec->plus(dwa);
143 pwa.
axpy(-one,state_->gradientVec->dual());
144 proj_->project(pwa,outStream);
148 con.
value(*state_->constraintVec, x, zerotol);
149 state_->cnorm = state_->constraintVec->norm();
151 state_->gnorm = std::max(gnorm_,compViolation_);
158template<
typename Real>
166 std::ostream &outStream ) {
168 Ptr<Vector<Real>> pwa = x.
clone(), dwa = g.
clone();
171 x,g,state_->searchSize,updateMultiplier_,
173 initialize(x,g,emul,eres,myobj,bnd,econ,*pwa,*dwa,outStream);
174 Ptr<TypeE::Algorithm<Real>> algo;
177 if (verbosity_ > 0) writeOutput(outStream,
true);
179 while (status_->check(*state_)) {
181 algo = TypeE::AlgorithmFactory<Real>(list_);
183 if (hasPolyProj_) algo->run(x,g,myobj,econ,emul,eres,
184 *proj_->getLinearConstraint(),
185 *proj_->getMultiplier(),
186 *proj_->getResidual(),outStream);
187 else algo->run(x,g,myobj,econ,emul,eres,outStream);
188 subproblemIter_ = algo->getState()->iter;
189 state_->nfval += algo->getState()->nfval;
190 state_->ngrad += algo->getState()->ngrad;
191 state_->ncval += algo->getState()->ncval;
194 state_->stepVec->set(x);
195 state_->stepVec->axpy(-one,*state_->iterateVec);
196 state_->snorm = state_->stepVec->norm();
197 state_->lagmultVec->axpy(-one,emul);
198 state_->snorm += state_->lagmultVec->norm();
201 state_->iterateVec->set(x);
202 state_->lagmultVec->set(emul);
208 updateState(x,emul,myobj,bnd,econ,*pwa,*dwa);
211 if (updatePenalty_) {
212 state_->searchSize *= tau_;
213 state_->searchSize = std::min(state_->searchSize,maxPenalty_);
218 if (verbosity_ > 0) writeOutput(outStream,printHeader_);
223template<
typename Real>
225 std::stringstream hist;
226 if (verbosity_ > 1) {
227 hist << std::string(109,
'-') << std::endl;
228 hist <<
"Moreau-Yosida Penalty Solver";
229 hist <<
" status output definitions" << std::endl << std::endl;
230 hist <<
" iter - Number of iterates (steps taken)" << std::endl;
231 hist <<
" fval - Objective function value" << std::endl;
232 hist <<
" cnorm - Norm of the constraint" << std::endl;
233 hist <<
" gLnorm - Norm of the gradient of the Lagrangian" << std::endl;
234 hist <<
" ifeas - Infeasibility metric" << std::endl;
235 hist <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
236 hist <<
" penalty - Penalty parameter for bound constraints" << std::endl;
237 hist <<
" #fval - Cumulative number of times the objective function was evaluated" << std::endl;
238 hist <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
239 hist <<
" #cval - Cumulative number of times the constraint was evaluated" << std::endl;
240 hist <<
" subiter - Number of subproblem iterations" << std::endl;
241 hist << std::string(109,
'-') << std::endl;
245 hist << std::setw(6) << std::left <<
"iter";
246 hist << std::setw(15) << std::left <<
"fval";
247 hist << std::setw(15) << std::left <<
"cnorm";
248 hist << std::setw(15) << std::left <<
"gLnorm";
249 hist << std::setw(15) << std::left <<
"ifeas";
250 hist << std::setw(15) << std::left <<
"snorm";
251 hist << std::setw(10) << std::left <<
"penalty";
252 hist << std::setw(8) << std::left <<
"#fval";
253 hist << std::setw(8) << std::left <<
"#grad";
254 hist << std::setw(8) << std::left <<
"#cval";
255 hist << std::setw(8) << std::left <<
"subIter";
260template<
typename Real>
262 std::stringstream hist;
263 hist << std::endl <<
"Moreau-Yosida Penalty Solver (Type G, General Constraints)";
265 hist <<
"Subproblem Solver: " << stepname_ << std::endl;
269template<
typename Real>
271 std::stringstream hist;
272 hist << std::scientific << std::setprecision(6);
273 if ( state_->iter == 0 ) writeName(os);
274 if ( print_header ) writeHeader(os);
275 if ( state_->iter == 0 ) {
277 hist << std::setw(6) << std::left << state_->iter;
278 hist << std::setw(15) << std::left << state_->value;
279 hist << std::setw(15) << std::left << state_->cnorm;
280 hist << std::setw(15) << std::left << gnorm_;
281 hist << std::setw(15) << std::left << compViolation_;
282 hist << std::setw(15) << std::left <<
"---";
283 hist << std::scientific << std::setprecision(2);
284 hist << std::setw(10) << std::left << state_->searchSize;
285 hist << std::setw(8) << std::left << state_->nfval;
286 hist << std::setw(8) << std::left << state_->ngrad;
287 hist << std::setw(8) << std::left << state_->ncval;
288 hist << std::setw(8) << std::left <<
"---";
293 hist << std::setw(6) << std::left << state_->iter;
294 hist << std::setw(15) << std::left << state_->value;
295 hist << std::setw(15) << std::left << state_->cnorm;
296 hist << std::setw(15) << std::left << gnorm_;
297 hist << std::setw(15) << std::left << compViolation_;
298 hist << std::setw(15) << std::left << state_->snorm;
299 hist << std::scientific << std::setprecision(2);
300 hist << std::setw(10) << std::left << state_->searchSize;
301 hist << std::scientific << std::setprecision(6);
302 hist << std::setw(8) << std::left << state_->nfval;
303 hist << std::setw(8) << std::left << state_->ngrad;
304 hist << std::setw(8) << std::left << state_->ncval;
305 hist << std::setw(8) << std::left << subproblemIter_;
Provides the interface to apply upper and lower bound constraints.
Provides an interface to check status of optimization algorithms for problems with equality constrain...
Defines the general constraint operator interface.
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)=0
Evaluate the constraint operator at .
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 .
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update constraint function.
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)
Real testComplementarity(const Vector< Real > &x)
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 an interface to run general constrained optimization algorithms.
void initialize(const Vector< Real > &x, const Vector< Real > &g, const Vector< Real > &mul, const Vector< Real > &c)
virtual void writeExitStatus(std::ostream &os) const
const Ptr< CombinedStatusTest< Real > > status_
const Ptr< AlgorithmState< Real > > state_
void writeName(std::ostream &os) const override
Print step name.
MoreauYosidaAlgorithm(ParameterList &list)
void initialize(Vector< Real > &x, const Vector< Real > &g, const Vector< Real > &l, const Vector< Real > &c, MoreauYosidaObjective< Real > &myobj, BoundConstraint< Real > &bnd, Constraint< Real > &con, Vector< Real > &pwa, Vector< Real > &dwa, std::ostream &outStream=std::cout)
void updateState(const Vector< Real > &x, const Vector< Real > &l, MoreauYosidaObjective< Real > &myobj, BoundConstraint< Real > &bnd, Constraint< Real > &con, Vector< Real > &pwa, Vector< Real > &dwa, std::ostream &outStream=std::cout)
void writeOutput(std::ostream &os, const bool print_header=false) const override
Print iterate status.
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, Constraint< Real > &econ, Vector< Real > &emul, const Vector< Real > &eres, std::ostream &outStream=std::cout) override
Run algorithm on general constrained problems (Type-G). This is the primary Type-G interface.
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 void zero()
Set to zero vector.
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 .