ROL
ROL_TypeB_PrimalDualActiveSetAlgorithm.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_PRIMALDUALACTIVESETALGORITHM_HPP
11#define ROL_TYPEB_PRIMALDUALACTIVESETALGORITHM_HPP
12
14#include "ROL_KrylovFactory.hpp"
15#include "ROL_SecantFactory.hpp"
16
21namespace ROL {
22namespace TypeB {
23
24template<typename Real>
26private:
27 Ptr<Secant<Real>> secant_;
29 std::string secantName_;
30
31 Ptr<Krylov<Real>> krylov_;
33 std::string krylovName_;
34
38
41
42 int maxit_;
43 int iter_;
44 int flag_;
45 Real stol_;
46 Real gtol_;
47 Real scale_;
48 Real neps_;
49 Real itol_;
53 bool feasible_;
54
58
59 class HessianPDAS : public LinearOperator<Real> {
60 private:
61 const Ptr<Objective<Real>> obj_;
62 const Ptr<BoundConstraint<Real>> bnd_;
63 const Ptr<const Vector<Real>> x_;
64 const Ptr<const Vector<Real>> xlam_;
65 const Real eps_;
66 const Ptr<Secant<Real>> secant_;
67 const bool useSecant_;
68 const Ptr<Vector<Real>> pwa_;
69 public:
71 const Ptr<BoundConstraint<Real>> &bnd,
72 const Ptr<const Vector<Real>> &x,
73 const Ptr<const Vector<Real>> &xlam,
74 Real eps,
75 const Ptr<Secant<Real>> &secant,
76 bool useSecant,
77 const Ptr<Vector<Real>> &pwa)
78 : obj_(obj), bnd_(bnd), x_(x), xlam_(xlam), eps_(eps),
79 secant_(secant), useSecant_(useSecant), pwa_(pwa) {}
80 void apply(Vector<Real> &Hv, const Vector<Real> &v, Real &tol) const {
81 pwa_->set(v);
82 bnd_->pruneActive(*pwa_,*xlam_,eps_);
83 if (!useSecant_) obj_->hessVec(Hv,*pwa_,*x_,tol);
84 else secant_->applyB(Hv,*pwa_);
85 bnd_->pruneActive(Hv,*xlam_,eps_);
86 }
87 };
88
89 class PrecondPDAS : public LinearOperator<Real> {
90 private:
91 const Ptr<Objective<Real>> obj_;
92 const Ptr<BoundConstraint<Real>> bnd_;
93 const Ptr<const Vector<Real>> x_;
94 const Ptr<const Vector<Real>> xlam_;
95 const Real eps_;
96 const Ptr<Secant<Real>> secant_;
97 const bool useSecant_;
98 const Ptr<Vector<Real>> dwa_;
99 public:
101 const Ptr<BoundConstraint<Real>> &bnd,
102 const Ptr<const Vector<Real>> &x,
103 const Ptr<const Vector<Real>> &xlam,
104 Real eps,
105 const Ptr<Secant<Real>> &secant,
106 bool useSecant,
107 const Ptr<Vector<Real>> &dwa)
108 : obj_(obj), bnd_(bnd), x_(x), xlam_(xlam), eps_(eps),
109 secant_(secant), useSecant_(useSecant), dwa_(dwa) {}
110 void apply(Vector<Real> &Hv, const Vector<Real> &v, Real &tol) const {
111 Hv.set(v.dual());
112 }
113 void applyInverse(Vector<Real> &Hv, const Vector<Real> &v, Real &tol) const {
114 dwa_->set(v);
115 bnd_->pruneActive(*dwa_,*xlam_,eps_);
116 if ( useSecant_ ) secant_->applyH(Hv,*dwa_);
117 else obj_->precond(Hv,*dwa_,*x_,tol);
118 bnd_->pruneActive(Hv,*xlam_,eps_);
119 dwa_->set(v);
120 bnd_->pruneInactive(*dwa_,*xlam_,eps_);
121 Hv.plus(dwa_->dual());
122 }
123 };
124
125 class HessianPDAS_Poly : public LinearOperator<Real> {
126 private:
127 const Ptr<Objective<Real>> obj_;
128 const Ptr<BoundConstraint<Real>> bnd_;
129 const Ptr<Constraint<Real>> con_;
130 const Ptr<const Vector<Real>> x_;
131 const Ptr<const Vector<Real>> xlam_;
132 const Real eps_;
133 const Ptr<Secant<Real>> secant_;
134 const bool useSecant_;
135 const Ptr<Vector<Real>> pwa_, dwa_;
136 public:
138 const Ptr<BoundConstraint<Real>> &bnd,
139 const Ptr<Constraint<Real>> &con,
140 const Ptr<const Vector<Real>> &x,
141 const Ptr<const Vector<Real>> &xlam,
142 Real eps,
143 const Ptr<Secant<Real>> &secant,
144 bool useSecant,
145 const Ptr<Vector<Real>> &pwa,
146 const Ptr<Vector<Real>> &dwa)
147 : obj_(obj), bnd_(bnd), con_(con), x_(x), xlam_(xlam), eps_(eps),
148 secant_(secant), useSecant_(useSecant), pwa_(pwa), dwa_(dwa) {}
149 void apply(Vector<Real> &Hv, const Vector<Real> &v, Real &tol) const {
150 PartitionedVector<Real> &Hvp = dynamic_cast<PartitionedVector<Real>&>(Hv);
151 const PartitionedVector<Real> &vp = dynamic_cast<const PartitionedVector<Real>&>(v);
152 pwa_->set(*vp.get(0));
153 bnd_->pruneActive(*pwa_,*xlam_,eps_);
154 if (!useSecant_) obj_->hessVec(*Hvp.get(0),*pwa_,*x_,tol);
155 else secant_->applyB(*Hvp.get(0),*pwa_);
156 con_->applyAdjointJacobian(*dwa_,*vp.get(1),*x_,tol);
157 Hvp.get(0)->plus(*dwa_);
158 bnd_->pruneActive(*Hvp.get(0),*xlam_,eps_);
159 con_->applyJacobian(*Hvp.get(1),*pwa_,*x_,tol);
160 }
161 };
162
163 class PrecondPDAS_Poly : public LinearOperator<Real> {
164 private:
165 const Ptr<Objective<Real>> obj_;
166 const Ptr<BoundConstraint<Real>> bnd_;
167 const Ptr<const Vector<Real>> x_;
168 const Ptr<const Vector<Real>> xlam_;
169 const Real eps_;
170 const Ptr<Secant<Real>> secant_;
171 const bool useSecant_;
172 const Ptr<Vector<Real>> dwa_;
173 public:
175 const Ptr<BoundConstraint<Real>> &bnd,
176 const Ptr<const Vector<Real>> &x,
177 const Ptr<const Vector<Real>> &xlam,
178 Real eps,
179 const Ptr<Secant<Real>> &secant,
180 bool useSecant,
181 const Ptr<Vector<Real>> &dwa)
182 : obj_(obj), bnd_(bnd), x_(x), xlam_(xlam), eps_(eps),
183 secant_(secant), useSecant_(useSecant), dwa_(dwa) {}
184 void apply(Vector<Real> &Hv, const Vector<Real> &v, Real &tol) const {
185 Hv.set(v.dual());
186 }
187 void applyInverse(Vector<Real> &Hv, const Vector<Real> &v, Real &tol) const {
188 PartitionedVector<Real> &Hvp = dynamic_cast<PartitionedVector<Real>&>(Hv);
189 const PartitionedVector<Real> &vp = dynamic_cast<const PartitionedVector<Real>&>(v);
190 dwa_->set(*vp.get(0));
191 bnd_->pruneActive(*dwa_,*xlam_,eps_);
192 if ( useSecant_ ) secant_->applyH(*Hvp.get(0),*dwa_);
193 else obj_->precond(*Hvp.get(0),*dwa_,*x_,tol);
194 bnd_->pruneActive(*Hvp.get(0),*xlam_,eps_);
195 dwa_->set(*vp.get(0));
196 bnd_->pruneInactive(*dwa_,*xlam_,eps_);
197 Hvp.get(0)->plus(dwa_->dual());
198 Hvp.get(1)->set(vp.get(1)->dual());
199 }
200 };
201
202 using TypeB::Algorithm<Real>::status_;
203 using TypeB::Algorithm<Real>::state_;
204 using TypeB::Algorithm<Real>::proj_;
205
206 void initialize(Vector<Real> &x,
207 const Vector<Real> &g,
208 Objective<Real> &obj,
210 std::ostream &outStream = std::cout);
211
212public:
213
214 PrimalDualActiveSetAlgorithm(ParameterList &list, const Ptr<Secant<Real>> &secant = nullPtr);
215
216 using TypeB::Algorithm<Real>::run;
217 void run( Vector<Real> &x,
218 const Vector<Real> &g,
219 Objective<Real> &obj,
221 std::ostream &outStream = std::cout) override;
222
223 void writeHeader( std::ostream& os ) const override;
224
225 void writeName( std::ostream& os ) const override;
226
227 void writeOutput( std::ostream& os, const bool write_header = false ) const override;
228
229}; // class ROL::TypeB::PrimalDualActiveSetAlgorithm
230
231} // namespace TypeB
232} // namespace ROL
233
235
236#endif
Provides the interface to apply upper and lower bound constraints.
Defines the general constraint operator interface.
Provides the interface to apply a linear operator.
Provides the interface to evaluate objective functions.
Defines the linear algebra of vector space on a generic partitioned vector.
ROL::Ptr< const Vector< Real > > get(size_type i) const
void set(const V &x)
Set where .
Provides interface for and implements limited-memory secant operators.
Provides an interface to run bound constrained optimization algorithms.
Ptr< PolyhedralProjection< Real > > proj_
const Ptr< AlgorithmState< Real > > state_
const Ptr< CombinedStatusTest< Real > > status_
HessianPDAS_Poly(const Ptr< Objective< Real > > &obj, const Ptr< BoundConstraint< Real > > &bnd, const Ptr< Constraint< Real > > &con, const Ptr< const Vector< Real > > &x, const Ptr< const Vector< Real > > &xlam, Real eps, const Ptr< Secant< Real > > &secant, bool useSecant, const Ptr< Vector< Real > > &pwa, const Ptr< Vector< Real > > &dwa)
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
HessianPDAS(const Ptr< Objective< Real > > &obj, const Ptr< BoundConstraint< Real > > &bnd, const Ptr< const Vector< Real > > &x, const Ptr< const Vector< Real > > &xlam, Real eps, const Ptr< Secant< Real > > &secant, bool useSecant, const Ptr< Vector< Real > > &pwa)
PrecondPDAS_Poly(const Ptr< Objective< Real > > &obj, const Ptr< BoundConstraint< Real > > &bnd, const Ptr< const Vector< Real > > &x, const Ptr< const Vector< Real > > &xlam, Real eps, const Ptr< Secant< Real > > &secant, bool useSecant, const Ptr< Vector< Real > > &dwa)
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply inverse of linear operator.
PrecondPDAS(const Ptr< Objective< Real > > &obj, const Ptr< BoundConstraint< Real > > &bnd, const Ptr< const Vector< Real > > &x, const Ptr< const Vector< Real > > &xlam, Real eps, const Ptr< Secant< Real > > &secant, bool useSecant, const Ptr< Vector< Real > > &dwa)
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply inverse of linear operator.
Provides an interface to run the projected secant algorithm.
int flagKrylov_
Termination flag for Krylov method (used for inexact Newton)
int iterKrylov_
Number of Krylov iterations (used for inexact Newton)
Real stol_
PDAS minimum step size stopping tolerance (default: 1e-8)
void writeName(std::ostream &os) const override
Print step name.
Real scale_
Scale for dual variables in the active set, (default: 1)
bool feasible_
Flag whether the current iterate is feasible or not.
Ptr< Secant< Real > > secant_
Secant object (used for quasi-Newton)
Real atolKrylov_
Absolute tolerance for Krylov solve (default: 1e-4)
int totalKrylov_
Total number of Krylov iterations per PDAS iteration.
Real gtol_
PDAS gradient stopping tolerance (default: 1e-6)
void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, 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...
int maxit_
Maximum number of PDAS steps (default: 10)
Ptr< Krylov< Real > > krylov_
Krylov solver object (used for inexact Newton)
void writeHeader(std::ostream &os) const override
Print iterate header.
int maxitKrylov_
Maximum number of Krylov iterations (default: 100)
bool useSecantHessVec_
Whether or not to use to a secant approximation as the Hessian.
void writeOutput(std::ostream &os, const bool write_header=false) const override
Print iterate status.
Real rtolKrylov_
Relative tolerance for Krylov solve (default: 1e-2)
bool useSecantPrecond_
Whether or not to use a secant approximation to precondition inexact Newton.
Defines the linear algebra or vector space interface.
virtual void set(const Vector &x)
Set where .
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
virtual void plus(const Vector &x)=0
Compute , where .