ROL
ROL_TypeB_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_TYPEB_PRIMALINTERIORPOINTALGORITHM_DEF_HPP
11#define ROL_TYPEB_PRIMALINTERIORPOINTALGORITHM_DEF_HPP
12
14
15namespace ROL {
16namespace TypeB {
17
18template<typename Real>
20 : TypeB::Algorithm<Real>::Algorithm(), secant_(secant),
21 list_(list), subproblemIter_(0), print_(false) {
22 // Set status test
23 status_->reset();
24 status_->add(makePtr<StatusTest<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 stol_ = static_cast<Real>(1e-6)*gtol_;
38 int maxit = steplist.sublist("Subproblem").get("Iteration Limit", 1000);
39 list_.sublist("Status Test").set("Iteration Limit", maxit);
40 // Subproblem tolerance update parameters
41 gtolrate_ = steplist.sublist("Subproblem").get("Optimality Tolerance Reduction Factor", 0.1);
42 mingtol_ = static_cast<Real>(1e-2)*list.sublist("Status Test").get("Gradient Tolerance", 1e-8);
43 // Get step name from parameterlist
44 stepname_ = steplist.sublist("Subproblem").get("Step Type","Augmented Lagrangian");
45
46 // Output settings
47 verbosity_ = list.sublist("General").get("Output Level", 0);
49 print_ = (verbosity_ > 2 ? true : print_);
50 list_.sublist("General").set("Output Level",(print_ ? verbosity_ : 0));
51}
52
53template<typename Real>
55 const Vector<Real> &g,
58 Vector<Real> &pwa,
59 std::ostream &outStream) {
60 hasPolyProj_ = true;
61 if (proj_ == nullPtr) {
62 proj_ = makePtr<PolyhedralProjection<Real>>(makePtrFromRef(bnd));
63 hasPolyProj_ = false;
64 }
65 proj_->project(x,outStream);
66 bnd.projectInterior(x);
67 // Initialize data
69 // Initialize the algorithm state
70 state_->nfval = 0;
71 state_->ngrad = 0;
72 updateState(x,ipobj,bnd,pwa);
73}
74
75
76template<typename Real>
80 Vector<Real> &pwa,
81 std::ostream &outStream) {
82 const Real one(1);
83 Real zerotol = std::sqrt(ROL_EPSILON<Real>());
84 // Update objective and constraint
85 if (state_-> iter == 0) {
86 ipobj.update(x,UpdateType::Initial,state_->iter);
87 }
88 //else {
89 // ipobj.update(x,UpdateType::Accept,state_->iter);
90 //}
91 // Compute norm of the gradient of the Lagrangian
92 state_->value = ipobj.getObjectiveValue(x, zerotol);
93 //state_->gradientVec->set(*ipobj.getObjectiveGradient(x, zerotol));
94 ipobj.gradient(*state_->gradientVec, x, zerotol);
95 //state_->gnorm = state_->gradientVec->norm();
96 pwa.set(x);
97 pwa.axpy(-one,state_->gradientVec->dual());
98 proj_->project(pwa,outStream);
99 pwa.axpy(-one,x);
100 state_->gnorm = pwa.norm();
101 // Update state
102 state_->nfval++;
103 state_->ngrad++;
104}
105
106template<typename Real>
108 const Vector<Real> &g,
109 Objective<Real> &obj,
111 std::ostream &outStream ) {
112 const Real one(1);
113 Ptr<Vector<Real>> pwa = x.clone();
114 // Initialize interior point data
115 InteriorPointObjective<Real> ipobj(makePtrFromRef(obj),makePtrFromRef(bnd),
117 state_->searchSize);
118 initialize(x,g,ipobj,bnd,*pwa,outStream);
119 Ptr<TypeU::Algorithm<Real>> algo;
120
121 // Output
122 if (verbosity_ > 0) writeOutput(outStream,true);
123
124 while (status_->check(*state_)) {
125 // Solve interior point subproblem
126 list_.sublist("Status Test").set("Gradient Tolerance", gtol_);
127 list_.sublist("Status Test").set("Step Tolerance", stol_);
129 if (hasPolyProj_) algo->run(x,g,ipobj,
130 *proj_->getLinearConstraint(),
131 *proj_->getMultiplier(),
132 *proj_->getResidual(),outStream);
133 else algo->run(x,g,ipobj,outStream);
134 subproblemIter_ = algo->getState()->iter;
135 state_->nfval += algo->getState()->nfval;
136 state_->ngrad += algo->getState()->ngrad;
137
138 // Compute step
139 state_->stepVec->set(x);
140 state_->stepVec->axpy(-one,*state_->iterateVec);
141 state_->snorm = state_->stepVec->norm();
142
143 // Update iterate
144 state_->iterateVec->set(x);
145
146 // Update objective and constraint
147 state_->iter++;
148
149 // Update barrier parameter and subproblem tolerances
150 if (algo->getState()->statusFlag == EXITSTATUS_CONVERGED) {
151 if( (rho_< one && state_->searchSize > mumin_) || (rho_ > one && state_->searchSize < mumax_) ) {
152 state_->searchSize *= rho_;
153 ipobj.updatePenalty(state_->searchSize);
154 }
155 gtol_ *= gtolrate_; gtol_ = std::max(gtol_,mingtol_);
156 stol_ = static_cast<Real>(1e-6)*gtol_;
157 }
158
159 // Update state
160 updateState(x,ipobj,bnd,*pwa,outStream);
161
162 // Update Output
163 if (verbosity_ > 0) writeOutput(outStream,writeHeader_);
164 }
166}
167
168template<typename Real>
169void InteriorPointAlgorithm<Real>::writeHeader( std::ostream& os ) const {
170 std::ios_base::fmtflags osFlags(os.flags());
171 if (verbosity_ > 1) {
172 os << std::string(109,'-') << std::endl;
173 os << "Interior Point 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 << " snorm - Norm of the step (update to optimization vector)" << std::endl;
179 os << " penalty - Penalty parameter for bound constraints" << std::endl;
180 os << " #fval - Cumulative number of times the objective function was evaluated" << std::endl;
181 os << " #grad - Cumulative number of times the gradient was computed" << std::endl;
182 os << " optTol - Subproblem optimality tolerance" << std::endl;
183 os << " subiter - Number of subproblem iterations" << std::endl;
184 os << std::string(109,'-') << std::endl;
185 }
186
187 os << " ";
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 << "snorm";
192 os << std::setw(10) << std::left << "penalty";
193 os << std::setw(8) << std::left << "#fval";
194 os << std::setw(8) << std::left << "#grad";
195 os << std::setw(10) << std::left << "optTol";
196 os << std::setw(8) << std::left << "subIter";
197 os << std::endl;
198 os.flags(osFlags);
199}
200
201template<typename Real>
202void InteriorPointAlgorithm<Real>::writeName( std::ostream& os ) const {
203 std::ios_base::fmtflags osFlags(os.flags());
204 os << std::endl << "Interior Point Solver (Type B, Bound Constraints)";
205 os << std::endl;
206 os << "Subproblem Solver: " << stepname_ << std::endl;
207 os.flags(osFlags);
208}
209
210template<typename Real>
211void InteriorPointAlgorithm<Real>::writeOutput( std::ostream& os, bool write_header ) const {
212 std::ios_base::fmtflags osFlags(os.flags());
213 os << std::scientific << std::setprecision(6);
214 if ( state_->iter == 0 ) writeName(os);
215 if ( write_header ) writeHeader(os);
216 if ( state_->iter == 0 ) {
217 os << " ";
218 os << std::setw(6) << std::left << state_->iter;
219 os << std::setw(15) << std::left << state_->value;
220 os << std::setw(15) << std::left << state_->gnorm;
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::setw(8) << std::left << state_->nfval;
225 os << std::setw(8) << std::left << state_->ngrad;
226 os << std::setw(10) << std::left << "---";
227 os << std::setw(8) << std::left << "---";
228 os << std::endl;
229 }
230 else {
231 os << " ";
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 << state_->gnorm;
235 os << std::setw(15) << std::left << state_->snorm;
236 os << std::scientific << std::setprecision(2);
237 os << std::setw(10) << std::left << state_->searchSize;
238 os << std::scientific << std::setprecision(6);
239 os << std::setw(8) << std::left << state_->nfval;
240 os << std::setw(8) << std::left << state_->ngrad;
241 os << std::scientific << std::setprecision(2);
242 os << std::setw(10) << std::left << gtol_;
243 os << std::scientific << std::setprecision(6);
244 os << std::setw(8) << std::left << subproblemIter_;
245 os << std::endl;
246 }
247 os.flags(osFlags);
248}
249
250} // namespace TypeB
251} // namespace ROL
252
253#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.
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.
Provides an interface to check status of optimization algorithms.
Ptr< PolyhedralProjection< Real > > proj_
void initialize(const Vector< Real > &x, const Vector< Real > &g)
Algorithm()
Constructor, given a step and a status test.
virtual void writeExitStatus(std::ostream &os) const
const Ptr< AlgorithmState< Real > > state_
const Ptr< CombinedStatusTest< Real > > status_
void writeName(std::ostream &os) const override
Print step name.
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...
void writeOutput(std::ostream &os, const bool write_header=false) const override
Print iterate status.
void updateState(const Vector< Real > &x, InteriorPointObjective< Real > &ipobj, BoundConstraint< Real > &bnd, Vector< Real > &pwa, std::ostream &outStream=std::cout)
void initialize(Vector< Real > &x, const Vector< Real > &g, InteriorPointObjective< Real > &ipobj, BoundConstraint< Real > &bnd, Vector< Real > &pwa, std::ostream &outStream=std::cout)
InteriorPointAlgorithm(ParameterList &list, const Ptr< Secant< Real > > &secant=nullPtr)
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 .
Ptr< 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