ROL
ROL_FletcherObjectiveBase_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_FLETCHEROBJECTVEBASEDEF_H
11#define ROL_FLETCHEROBJECTVEBASEDEF_H
12
13namespace ROL {
14
15template<typename Real>
17 const Ptr<Constraint<Real>> &con,
18 const Vector<Real> &xprim,
19 const Vector<Real> &xdual,
20 const Vector<Real> &cprim,
21 const Vector<Real> &cdual,
22 ParameterList &parlist)
23 : obj_(obj), con_(con), nfval_(0), ngval_(0), ncval_(0),
24 fPhi_(makePtr<ScalarController<Real,int>>()),
25 gPhi_(makePtr<VectorController<Real,int>>()),
26 y_ (makePtr<VectorController<Real,int>>()),
27 fval_(makePtr<ScalarController<Real,int>>()),
28 g_ (makePtr<VectorController<Real,int>>()),
29 c_ (makePtr<VectorController<Real,int>>()),
30 multSolverError_(0), gradSolveError_(0),
31 iterKrylov_(0), flagKrylov_(0) {
32 gL_ = xdual.clone();
33 gLdual_ = xprim.clone();
34 scaledc_ = cprim.clone();
35 xprim_ = xprim.clone();
36 xdual_ = xdual.clone();
37 cprim_ = cprim.clone();
38 cdual_ = cdual.clone();
39
40 v1_ = xprim.clone();
41 v2_ = cdual.clone();
42 vv_ = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({v1_, v2_}));
43
44 w1_ = xprim.clone();
45 w2_ = cdual.clone();
46 ww_ = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({w1_, w2_}));
47
48 b1_ = xdual.clone();
49 b2_ = cprim.clone();
50 bb_ = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({b1_, b2_}));
51
52 ParameterList& sublist = parlist.sublist("Step").sublist("Fletcher");
53 HessianApprox_ = sublist.get("Level of Hessian Approximation", 0);
54 quadPenaltyParameter_ = sublist.get("Quadratic Penalty Parameter", Real(0));
55 useInexact_ = sublist.get("Inexact Solves", false);
56
57 ROL::ParameterList krylovList;
58 Real atol = static_cast<Real>(1e-12);
59 Real rtol = static_cast<Real>(1e-2);
60 krylovList.sublist("General").sublist("Krylov").set("Type", "GMRES");
61 krylovList.sublist("General").sublist("Krylov").set("Absolute Tolerance", atol);
62 krylovList.sublist("General").sublist("Krylov").set("Relative Tolerance", rtol);
63 krylovList.sublist("General").sublist("Krylov").set("Iteration Limit", 200);
64 krylov_ = KrylovFactory<Real>(krylovList);
65}
66
67template<typename Real>
69 obj_->update(x,type,iter);
70 con_->update(x,type,iter);
71 fPhi_->objectiveUpdate(type);
72 gPhi_->objectiveUpdate(type);
73 y_->objectiveUpdate(type);
74 fval_->objectiveUpdate(type);
75 g_->objectiveUpdate(type);
76 c_->objectiveUpdate(type);
77}
78
79// Accessors
80template<typename Real>
82 // TODO: Figure out reasonable tolerance
83 Real tol = static_cast<Real>(1e-12);
84 computeMultipliers(*cdual_, *gLdual_, x, *xdual_, *cprim_, tol);
85 gL_->set(gLdual_->dual());
86 return gL_;
87}
88
89template<typename Real>
91 Real tol = std::sqrt(ROL_EPSILON<Real>());
92 conValue(*cprim_, x, tol);
93 return cprim_;
94}
95
96template<typename Real>
98 // TODO: Figure out reasonable tolerance
99 Real tol = static_cast<Real>(1e-12);
100 computeMultipliers(*cdual_, *gLdual_, x, *xdual_, *cprim_, tol);
101 return cdual_;
102}
103
104template<typename Real>
106 // TODO: Figure out reasonable tolerance
107 Real tol = static_cast<Real>(1e-12);
108 this->gradient(*xdual_, x, tol);
109 return xdual_;
110}
111
112template<typename Real>
114 Real tol = std::sqrt(ROL_EPSILON<Real>());
115 return objValue(x, tol);
116}
117
118template<typename Real>
122
123template<typename Real>
127
128template<typename Real>
132
133template<typename Real>
134void FletcherObjectiveBase<Real>::reset(Real sigma, Real delta) {
135 sigma_ = sigma;
136 delta_ = delta;
137 fPhi_->reset(true);
138 gPhi_->reset(true);
139}
140
141template<typename Real>
143 Real val(0);
144 int key(0);
145 bool isComputed = fval_->get(val,key);
146 if( !isComputed ) {
147 val = obj_->value(x,tol); nfval_++;
148 fval_->set(val,key);
149 }
150 return val;
151}
152
153template<typename Real>
155 int key(0);
156 bool isComputed = g_->get(g,key);
157 if( !isComputed ) {
158 obj_->gradient(g, x, tol); ngval_++;
159 g_->set(g,key);
160 }
161}
162
163template<typename Real>
165 int key(0);
166 bool isComputed = c_->get(c,key);
167 if( !isComputed ) {
168 con_->value(c, x, tol); ncval_++;
169 c_->set(c,key);
170 }
171}
172
173template<typename Real>
175 int key(0);
176 bool isComputed = y_->get(y,key);
177 if (isComputed && multSolverError_ <= tol) return;
178 if (!isComputed) {
179 Real tol2 = tol;
180 objGrad(g, x, tol2); tol2 = tol;
181 conValue(c, x, tol2);
182 scaledc_->set(c); scaledc_->scale(sigma_);
183 cnorm_ = c.norm();
184 }
185
186 bool refine = isComputed;
187 multSolverError_ = tol;
188 solveAugmentedSystem(gL,y,g,*scaledc_,x,multSolverError_,refine);
189
190 y_->set(y,key);
191}
192
193} // namespace ROL
194
195#endif
const Ptr< Obj > obj_
Defines the general constraint operator interface.
Ptr< const Vector< Real > > getLagrangianGradient(const Vector< Real > &x)
Ptr< const Vector< Real > > getConstraintVec(const Vector< Real > &x)
void objGrad(Vector< Real > &g, const Vector< Real > &x, Real &tol)
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1) override
Update objective function.
Real objValue(const Vector< Real > &x, Real &tol)
Real getObjectiveValue(const Vector< Real > &x)
void conValue(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Ptr< PartitionedVector< Real > > bb_
Ptr< PartitionedVector< Real > > ww_
Ptr< PartitionedVector< Real > > vv_
Ptr< const Vector< Real > > getGradient(const Vector< Real > &x)
FletcherObjectiveBase(const Ptr< Objective< Real > > &obj, const Ptr< Constraint< Real > > &con, const Vector< Real > &xprim, const Vector< Real > &xdual, const Vector< Real > &cprim, const Vector< Real > &cdual, ParameterList &parlist)
void computeMultipliers(Vector< Real > &y, Vector< Real > &gL, const Vector< Real > &x, Vector< Real > &g, Vector< Real > &c, Real tol)
Ptr< const Vector< Real > > getMultiplierVec(const Vector< Real > &x)
Provides the interface to evaluate objective functions.
Defines the linear algebra or vector space interface.
virtual Real norm() const =0
Returns where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.