ROL
ROL_FletcherObjectiveBase_Def.hpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Rapid Optimization Library (ROL) Package
5// Copyright (2014) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact lead developers:
38// Drew Kouri (dpkouri@sandia.gov) and
39// Denis Ridzal (dridzal@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
44
45#ifndef ROL_FLETCHEROBJECTVEBASEDEF_H
46#define ROL_FLETCHEROBJECTVEBASEDEF_H
47
48namespace ROL {
49
50template<typename Real>
52 const Ptr<Constraint<Real>> &con,
53 const Vector<Real> &xprim,
54 const Vector<Real> &xdual,
55 const Vector<Real> &cprim,
56 const Vector<Real> &cdual,
57 ParameterList &parlist)
58 : obj_(obj), con_(con), nfval_(0), ngval_(0), ncval_(0),
59 fPhi_(makePtr<ScalarController<Real,int>>()),
60 gPhi_(makePtr<VectorController<Real,int>>()),
61 y_ (makePtr<VectorController<Real,int>>()),
62 fval_(makePtr<ScalarController<Real,int>>()),
63 g_ (makePtr<VectorController<Real,int>>()),
64 c_ (makePtr<VectorController<Real,int>>()),
65 multSolverError_(0), gradSolveError_(0),
66 iterKrylov_(0), flagKrylov_(0) {
67 gL_ = xdual.clone();
68 gLdual_ = xprim.clone();
69 scaledc_ = cprim.clone();
70 xprim_ = xprim.clone();
71 xdual_ = xdual.clone();
72 cprim_ = cprim.clone();
73 cdual_ = cdual.clone();
74
75 v1_ = xprim.clone();
76 v2_ = cdual.clone();
77 vv_ = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({v1_, v2_}));
78
79 w1_ = xprim.clone();
80 w2_ = cdual.clone();
81 ww_ = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({w1_, w2_}));
82
83 b1_ = xdual.clone();
84 b2_ = cprim.clone();
85 bb_ = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({b1_, b2_}));
86
87 ParameterList& sublist = parlist.sublist("Step").sublist("Fletcher");
88 HessianApprox_ = sublist.get("Level of Hessian Approximation", 0);
89 quadPenaltyParameter_ = sublist.get("Quadratic Penalty Parameter", Real(0));
90 useInexact_ = sublist.get("Inexact Solves", false);
91
92 ROL::ParameterList krylovList;
93 Real atol = static_cast<Real>(1e-12);
94 Real rtol = static_cast<Real>(1e-2);
95 krylovList.sublist("General").sublist("Krylov").set("Type", "GMRES");
96 krylovList.sublist("General").sublist("Krylov").set("Absolute Tolerance", atol);
97 krylovList.sublist("General").sublist("Krylov").set("Relative Tolerance", rtol);
98 krylovList.sublist("General").sublist("Krylov").set("Iteration Limit", 200);
99 krylov_ = KrylovFactory<Real>(krylovList);
100}
101
102template<typename Real>
104 obj_->update(x,type,iter);
105 con_->update(x,type,iter);
106 fPhi_->objectiveUpdate(type);
107 gPhi_->objectiveUpdate(type);
108 y_->objectiveUpdate(type);
109 fval_->objectiveUpdate(type);
110 g_->objectiveUpdate(type);
111 c_->objectiveUpdate(type);
112}
113
114// Accessors
115template<typename Real>
117 // TODO: Figure out reasonable tolerance
118 Real tol = static_cast<Real>(1e-12);
119 computeMultipliers(*cdual_, *gLdual_, x, *xdual_, *cprim_, tol);
120 gL_->set(gLdual_->dual());
121 return gL_;
122}
123
124template<typename Real>
126 Real tol = std::sqrt(ROL_EPSILON<Real>());
127 conValue(*cprim_, x, tol);
128 return cprim_;
129}
130
131template<typename Real>
133 // TODO: Figure out reasonable tolerance
134 Real tol = static_cast<Real>(1e-12);
135 computeMultipliers(*cdual_, *gLdual_, x, *xdual_, *cprim_, tol);
136 return cdual_;
137}
138
139template<typename Real>
141 // TODO: Figure out reasonable tolerance
142 Real tol = static_cast<Real>(1e-12);
143 gradient(*xdual_, x, tol);
144 return xdual_;
145}
146
147template<typename Real>
149 Real tol = std::sqrt(ROL_EPSILON<Real>());
150 return objValue(x, tol);
151}
152
153template<typename Real>
155 return nfval_;
156}
157
158template<typename Real>
160 return ngval_;
161}
162
163template<typename Real>
165 return ncval_;
166}
167
168template<typename Real>
169void FletcherObjectiveBase<Real>::reset(Real sigma, Real delta) {
170 sigma_ = sigma;
171 delta_ = delta;
172 fPhi_->reset(true);
173 gPhi_->reset(true);
174}
175
176template<typename Real>
178 Real val(0);
179 int key(0);
180 bool isComputed = fval_->get(val,key);
181 if( !isComputed ) {
182 val = obj_->value(x,tol); nfval_++;
183 fval_->set(val,key);
184 }
185 return val;
186}
187
188template<typename Real>
190 int key(0);
191 bool isComputed = g_->get(g,key);
192 if( !isComputed ) {
193 obj_->gradient(g, x, tol); ngval_++;
194 g_->set(g,key);
195 }
196}
197
198template<typename Real>
200 int key(0);
201 bool isComputed = c_->get(c,key);
202 if( !isComputed ) {
203 con_->value(c, x, tol); ncval_++;
204 c_->set(c,key);
205 }
206}
207
208template<typename Real>
210 int key(0);
211 bool isComputed = y_->get(y,key);
212 if (isComputed && multSolverError_ <= tol) return;
213 if (!isComputed) {
214 Real tol2 = tol;
215 objGrad(g, x, tol2); tol2 = tol;
216 conValue(c, x, tol2);
217 scaledc_->set(c); scaledc_->scale(sigma_);
218 cnorm_ = c.norm();
219 }
220
221 bool refine = isComputed;
222 multSolverError_ = tol;
223 solveAugmentedSystem(gL,y,g,*scaledc_,x,multSolverError_,refine);
224
225 y_->set(y,key);
226}
227
228} // namespace ROL
229
230#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.
Definition: ROL_Vector.hpp:84
virtual Real norm() const =0
Returns where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.