ROL
ROL_TypeG_InteriorPointAlgorithm_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_TYPEG_INTERIORPOINTALGORITHM_DEF_H
11#define ROL_TYPEG_INTERIORPOINTALGORITHM_DEF_H
12
14
15namespace ROL {
16namespace TypeG {
17
18template<typename Real>
20 : TypeG::Algorithm<Real>::Algorithm(), secant_(secant),
21 list_(list), subproblemIter_(0), print_(false) {
22 // Set status test
23 status_->reset();
24 status_->add(makePtr<ConstraintStatusTest<Real>>(list));
25
26 // Parse parameters
27 ParameterList& steplist = list.sublist("Step").sublist("Interior Point");
28 state_->searchSize = steplist.get("Initial Barrier Parameter", 1.0);
29 mumin_ = steplist.get("Minimum Barrier Parameter", 1e-4);
30 mumax_ = steplist.get("Maximum Barrier Parameter", 1e8);
31 rho_ = steplist.get("Barrier Penalty Reduction Factor", 0.5);
32 useLinearDamping_ = steplist.get("Use Linear Damping", true);
33 kappaD_ = steplist.get("Linear Damping Coefficient", 1.e-4);
34 print_ = steplist.sublist("Subproblem").get("Print History", false);
35 // Set parameters for step subproblem
36 gtol_ = steplist.sublist("Subproblem").get("Initial Optimality Tolerance", 1e-2);
37 ctol_ = steplist.sublist("Subproblem").get("Initial Feasibility Tolerance", 1e-2);
38 stol_ = static_cast<Real>(1e-6)*std::min(gtol_,ctol_);
39 int maxit = steplist.sublist("Subproblem").get("Iteration Limit", 1000);
40 list_.sublist("Status Test").set("Iteration Limit", maxit);
41 // Subproblem tolerance update parameters
42 gtolrate_ = steplist.sublist("Subproblem").get("Optimality Tolerance Reduction Factor", 0.1);
43 ctolrate_ = steplist.sublist("Subproblem").get("Feasibility Tolerance Reduction Factor", 0.1);
44 mingtol_ = static_cast<Real>(1e-2)*list.sublist("Status Test").get("Gradient Tolerance", 1e-8);
45 minctol_ = static_cast<Real>(1e-2)*list.sublist("Status Test").get("Constraint Tolerance", 1e-8);
46 // Get step name from parameterlist
47 stepname_ = steplist.sublist("Subproblem").get("Step Type","Augmented Lagrangian");
48
49 // Output settings
50 verbosity_ = list.sublist("General").get("Output Level", 0);
52 print_ = (verbosity_ > 2 ? true : print_);
53 list_.sublist("General").set("Output Level",(print_ ? verbosity_ : 0));
54}
55
56template<typename Real>
58 const Vector<Real> &g,
59 const Vector<Real> &l,
60 const Vector<Real> &c,
64 Vector<Real> &pwa,
65 Vector<Real> &dwa,
66 std::ostream &outStream) {
67 hasPolyProj_ = true;
68 if (proj_ == nullPtr) {
69 proj_ = makePtr<PolyhedralProjection<Real>>(makePtrFromRef(bnd));
70 hasPolyProj_ = false;
71 }
72 proj_->project(x,outStream);
73 bnd.projectInterior(x);
74 // Initialize data
76 // Initialize the algorithm state
77 state_->nfval = 0;
78 state_->ngrad = 0;
79 state_->ncval = 0;
80 updateState(x,l,ipobj,bnd,con,pwa,dwa,outStream);
81}
82
83
84template<typename Real>
86 const Vector<Real> &l,
90 Vector<Real> &pwa,
91 Vector<Real> &dwa,
92 std::ostream &outStream) {
93 const Real one(1);
94 Real zerotol = std::sqrt(ROL_EPSILON<Real>());
95 // Update objective and constraint
96 if (state_->iter == 0) {
97 ipobj.update(x,UpdateType::Initial,state_->iter);
99 }
100 //else {
101 // ipobj.update(x,UpdateType::Accept,state_->iter);
102 // con.update(x,UpdateType::Accept,state_->iter);
103 //}
104 // Compute norm of the gradient of the Lagrangian
105 state_->value = ipobj.getObjectiveValue(x, zerotol);
106 //state_->gradientVec->set(*ipobj.getObjectiveGradient(x, zerotol));
107 ipobj.gradient(*state_->gradientVec, x, zerotol);
108 con.applyAdjointJacobian(dwa, l, x, zerotol);
109 state_->gradientVec->plus(dwa);
110 //state_->gnorm = state_->gradientVec->norm();
111 pwa.set(x);
112 pwa.axpy(-one,state_->gradientVec->dual());
113 proj_->project(pwa,outStream);
114 pwa.axpy(-one,x);
115 state_->gnorm = pwa.norm();
116 // Compute constraint violation
117 con.value(*state_->constraintVec, x, zerotol);
118 state_->cnorm = state_->constraintVec->norm();
119 // Update state
120 state_->nfval++;
121 state_->ngrad++;
122 state_->ncval++;
123}
124
125template<typename Real>
127 const Vector<Real> &g,
128 Objective<Real> &obj,
130 Constraint<Real> &econ,
131 Vector<Real> &emul,
132 const Vector<Real> &eres,
133 std::ostream &outStream ) {
134 const Real one(1);
135 Ptr<Vector<Real>> pwa = x.clone(), dwa = g.clone();
136 // Initialize interior point data
137 InteriorPointObjective<Real> ipobj(makePtrFromRef(obj),makePtrFromRef(bnd),
139 state_->searchSize);
140 initialize(x,g,emul,eres,ipobj,bnd,econ,*pwa,*dwa,outStream);
141 Ptr<TypeE::Algorithm<Real>> algo;
142
143 // Output
144 if (verbosity_ > 0) writeOutput(outStream,true);
145
146 while (status_->check(*state_)) {
147 // Solve interior point subproblem
148 list_.sublist("Status Test").set("Gradient Tolerance", gtol_);
149 list_.sublist("Status Test").set("Constraint Tolerance", ctol_);
150 list_.sublist("Status Test").set("Step Tolerance", stol_);
152 if (hasPolyProj_) algo->run(x,g,ipobj,econ,emul,eres,
153 *proj_->getLinearConstraint(),
154 *proj_->getMultiplier(),
155 *proj_->getResidual(),outStream);
156 else algo->run(x,g,ipobj,econ,emul,eres,outStream);
157 subproblemIter_ = algo->getState()->iter;
158 state_->nfval += algo->getState()->nfval;
159 state_->ngrad += algo->getState()->ngrad;
160 state_->ncval += algo->getState()->ncval;
161
162 // Compute step
163 state_->stepVec->set(x);
164 state_->stepVec->axpy(-one,*state_->iterateVec);
165 state_->lagmultVec->axpy(-one,emul);
166 state_->snorm = state_->stepVec->norm();
167 state_->snorm += state_->lagmultVec->norm();
168
169 // Update iterate and Lagrange multiplier
170 state_->iterateVec->set(x);
171 state_->lagmultVec->set(emul);
172
173 // Update objective and constraint
174 state_->iter++;
175
176 // Update barrier parameter and subproblem tolerances
177 if (algo->getState()->statusFlag == EXITSTATUS_CONVERGED) {
178 if( (rho_< one && state_->searchSize > mumin_) || (rho_ > one && state_->searchSize < mumax_) ) {
179 state_->searchSize *= rho_;
180 ipobj.updatePenalty(state_->searchSize);
181 }
182 gtol_ *= gtolrate_; gtol_ = std::max(gtol_,mingtol_);
183 ctol_ *= ctolrate_; ctol_ = std::max(ctol_,minctol_);
184 stol_ = static_cast<Real>(1e-6)*std::min(gtol_,ctol_);
185 }
186
187 // Update state
188 updateState(x,emul,ipobj,bnd,econ,*pwa,*dwa);
189
190 // Update Output
191 if (verbosity_ > 0) writeOutput(outStream,printHeader_);
192 }
194}
195
196template<typename Real>
197void InteriorPointAlgorithm<Real>::writeHeader( std::ostream& os ) const {
198 std::ios_base::fmtflags osFlags(os.flags());
199 if (verbosity_ > 1) {
200 os << std::string(109,'-') << std::endl;
201 os << "Interior Point Solver";
202 os << " status output definitions" << std::endl << std::endl;
203 os << " iter - Number of iterates (steps taken)" << std::endl;
204 os << " fval - Objective function value" << std::endl;
205 os << " cnorm - Norm of the constraint" << std::endl;
206 os << " gLnorm - Norm of the gradient of the Lagrangian" << std::endl;
207 os << " snorm - Norm of the step (update to optimization vector)" << std::endl;
208 os << " penalty - Penalty parameter for bound constraints" << std::endl;
209 os << " #fval - Cumulative number of times the objective function was evaluated" << std::endl;
210 os << " #grad - Cumulative number of times the gradient was computed" << std::endl;
211 os << " #cval - Cumulative number of times the constraint was evaluated" << std::endl;
212 os << " optTol - Subproblem optimality tolerance" << std::endl;
213 os << " feasTol - Subproblem feasibility tolerance" << std::endl;
214 os << " subiter - Number of subproblem iterations" << std::endl;
215 os << std::string(109,'-') << std::endl;
216 }
217
218 os << " ";
219 os << std::setw(6) << std::left << "iter";
220 os << std::setw(15) << std::left << "fval";
221 os << std::setw(15) << std::left << "cnorm";
222 os << std::setw(15) << std::left << "gLnorm";
223 os << std::setw(15) << std::left << "snorm";
224 os << std::setw(10) << std::left << "penalty";
225 os << std::setw(8) << std::left << "#fval";
226 os << std::setw(8) << std::left << "#grad";
227 os << std::setw(8) << std::left << "#cval";
228 os << std::setw(10) << std::left << "optTol";
229 os << std::setw(10) << std::left << "feasTol";
230 os << std::setw(8) << std::left << "subIter";
231 os << std::endl;
232 os.flags(osFlags);
233}
234
235template<typename Real>
236void InteriorPointAlgorithm<Real>::writeName( std::ostream& os ) const {
237 std::ios_base::fmtflags osFlags(os.flags());
238 os << std::endl << "Interior Point Solver (Type G, General Constraints)";
239 os << std::endl;
240 os << "Subproblem Solver: " << stepname_ << std::endl;
241 os.flags(osFlags);
242}
243
244template<typename Real>
245void InteriorPointAlgorithm<Real>::writeOutput( std::ostream& os, const bool print_header ) const {
246 std::ios_base::fmtflags osFlags(os.flags());
247 os << std::scientific << std::setprecision(6);
248 if ( state_->iter == 0 ) writeName(os);
249 if ( print_header ) writeHeader(os);
250 if ( state_->iter == 0 ) {
251 os << " ";
252 os << std::setw(6) << std::left << state_->iter;
253 os << std::setw(15) << std::left << state_->value;
254 os << std::setw(15) << std::left << state_->cnorm;
255 os << std::setw(15) << std::left << state_->gnorm;
256 os << std::setw(15) << std::left << "---";
257 os << std::scientific << std::setprecision(2);
258 os << std::setw(10) << std::left << state_->searchSize;
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 << state_->ncval;
262 os << std::setw(10) << std::left << "---";
263 os << std::setw(10) << std::left << "---";
264 os << std::setw(8) << std::left << "---";
265 os << std::endl;
266 }
267 else {
268 os << " ";
269 os << std::setw(6) << std::left << state_->iter;
270 os << std::setw(15) << std::left << state_->value;
271 os << std::setw(15) << std::left << state_->cnorm;
272 os << std::setw(15) << std::left << state_->gnorm;
273 os << std::setw(15) << std::left << state_->snorm;
274 os << std::scientific << std::setprecision(2);
275 os << std::setw(10) << std::left << state_->searchSize;
276 os << std::scientific << std::setprecision(6);
277 os << std::setw(8) << std::left << state_->nfval;
278 os << std::setw(8) << std::left << state_->ngrad;
279 os << std::setw(8) << std::left << state_->ncval;
280 os << std::scientific << std::setprecision(2);
281 os << std::setw(10) << std::left << gtol_;
282 os << std::setw(10) << std::left << ctol_;
283 os << std::scientific << std::setprecision(6);
284 os << std::setw(8) << std::left << subproblemIter_;
285 os << std::endl;
286 }
287 os.flags(osFlags);
288}
289
290} // namespace TypeG
291} // namespace ROL
292
293#endif
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
Provides the interface to apply upper and lower bound constraints.
virtual void projectInterior(Vector< Real > &x)
Project optimization variables into the interior of the feasible set.
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 update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update constraint function.
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 .
void update(const Vector< Real > &x, UpdateType type, int iter=-1)
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Real getObjectiveValue(const Vector< Real > &x, Real &tol)
Provides the interface to evaluate objective functions.
Provides interface for and implements limited-memory secant operators.
Algorithm()
Constructor, given a step and a status test.
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_
Ptr< PolyhedralProjection< Real > > proj_
const Ptr< AlgorithmState< Real > > state_
InteriorPointAlgorithm(ParameterList &list, const Ptr< Secant< Real > > &secant_=nullPtr)
void updateState(const Vector< Real > &x, const Vector< Real > &l, InteriorPointObjective< Real > &ipobj, BoundConstraint< Real > &bnd, Constraint< Real > &con, Vector< Real > &pwa, Vector< Real > &dwa, std::ostream &outStream=std::cout)
void writeName(std::ostream &os) const override
Print step name.
void writeHeader(std::ostream &os) const override
Print iterate header.
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 initialize(Vector< Real > &x, const Vector< Real > &g, const Vector< Real > &l, const Vector< Real > &c, InteriorPointObjective< Real > &ipobj, BoundConstraint< Real > &bnd, Constraint< Real > &con, Vector< Real > &pwa, Vector< Real > &dwa, std::ostream &outStream=std::cout)
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 .
Ptr< TypeE::Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
Definition ROL_Types.hpp:57
@ EXITSTATUS_CONVERGED
Definition ROL_Types.hpp:84