ROL
ROL_FletcherBase.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_FLETCHERBASE_H
11#define ROL_FLETCHERBASE_H
12
13#include "ROL_Objective.hpp"
14#include "ROL_Constraint.hpp"
15#include "ROL_Vector.hpp"
16#include "ROL_Types.hpp"
17#include "ROL_Ptr.hpp"
18#include "ROL_KrylovFactory.hpp"
20#include <iostream>
21
22namespace ROL {
23
24template <class Real>
25class FletcherBase : public Objective<Real> {
26
27protected:
28 const Ptr<Objective<Real> > obj_;
29 const Ptr<Constraint<Real> > con_;
30
33
34 // Evaluation counters
35 int nfval_;
36 int ngval_;
37 int ncval_;
38
39 Real fPhi_; // value of penalty function
40 Ptr<Vector<Real> > gPhi_; // gradient of penalty function
41
42 Ptr<Vector<Real> > y_; // multiplier estimate
43
44 Real fval_; // value of objective function
45 Ptr<Vector<Real> > g_; // gradient of objective value
46 Ptr<Vector<Real> > c_; // constraint value
47 Ptr<Vector<Real> > scaledc_; // penaltyParameter_ * c_
48 Ptr<Vector<Real> > gL_; // gradient of Lagrangian (g - A*y)
49
50 Real cnorm_; // norm of constraint violation
51
58
59 Real multSolverError_; // Error from augmented system solve in value()
60 Real gradSolveError_; // Error from augmented system solve in gradient()
61
62 Real delta_; // regularization parameter
63
65
66 // For Augmented system solves
67 Ptr<Krylov<Real> > krylov_;
70 Ptr<Vector<Real> > v1_;
71 Ptr<Vector<Real> > v2_;
72 Ptr<PartitionedVector<Real> > vv_;
73 Ptr<Vector<Real> > b1_;
74 Ptr<Vector<Real> > b2_;
75 Ptr<PartitionedVector<Real> > bb_;
76 Ptr<Vector<Real> > w1_;
77 Ptr<Vector<Real> > w2_;
78 Ptr<PartitionedVector<Real> > ww_;
79
80 void objValue(const Vector<Real>& x, Real &tol) {
81 if( !isObjValueComputed_ ) {
82 fval_ = obj_->value(x,tol); nfval_++;
84 }
85 }
86
87 void objGrad(const Vector<Real>& x, Real &tol) {
88 if( !isObjGradComputed_ ) {
89 obj_->gradient(*g_, x, tol); ngval_++;
90 isObjGradComputed_ = true;
91 }
92 }
93
94 void conValue(const Vector<Real>&x, Real &tol) {
95 if( !isConValueComputed_ ) {
96 con_->value(*c_,x,tol); ncval_++;
97 scaledc_->set(*c_);
100 }
101 }
102
103 virtual void computeMultipliers(const Vector<Real>& x, Real tol) {}
104
105public:
106 FletcherBase(const ROL::Ptr<Objective<Real> > &obj,
107 const ROL::Ptr<Constraint<Real> > &con)
108 : obj_(obj), con_(con), nfval_(0), ngval_(0), ncval_(0), fPhi_(0),
113 iterKrylov_(0), flagKrylov_(0) {}
114
115 // Accessors
116 const Ptr<Vector<Real>> getLagrangianGradient(const Vector<Real>& x) {
117 // TODO: Figure out reasonable tolerance
118 if( !isMultiplierComputed_ ) {
119 Real tol = static_cast<Real>(1e-12);
120 computeMultipliers(x, tol);
121 }
122 return gL_;
123 }
124
125 const Ptr<Vector<Real>> getConstraintVec(const Vector<Real>& x) {
126 Real tol = std::sqrt(ROL_EPSILON<Real>());
127 conValue(x, tol);
128 return c_;
129 }
130
131 const Ptr<Vector<Real>> getMultiplierVec(const Vector<Real>& x) {
132 // TODO: Figure out reasonable tolerance
133 if( !isMultiplierComputed_ ) {
134 Real tol = static_cast<Real>(1e-12);
135 computeMultipliers(x, tol);
136 }
137 return y_;
138 }
139
140 const Ptr<Vector<Real>> getGradient(const Vector<Real>& x) {
141 if( !isGradientComputed_ ) {
142 // TODO: Figure out reasonable tolerance
143 Real tol = static_cast<Real>(1e-12);
144 this->gradient(*gPhi_, x, tol);
145 }
146 return gPhi_;
147 }
148
150 Real tol = std::sqrt(ROL_EPSILON<Real>());
151 objValue(x, tol);
152
153 return fval_;
154 }
155
157 return nfval_;
158 }
159
161 return ngval_;
162 }
163
165 return ncval_;
166 }
167
168 void setDelta(Real delta) {
169 delta_ = delta;
170 isValueComputed_ = false;
171 isGradientComputed_ = false;
172 }
173
174 void setPenaltyParameter( Real sigma ) {
175 penaltyParameter_ = sigma;
176 isValueComputed_ = false;
177 isGradientComputed_ = false;
178 }
179
180}; // class Fletcher
181
182} // namespace ROL
183
184#include "ROL_Fletcher.hpp"
185#include "ROL_BoundFletcher.hpp"
186
187#endif
Contains definitions of custom data types in ROL.
Defines the general constraint operator interface.
Ptr< Vector< Real > > v1_
virtual void computeMultipliers(const Vector< Real > &x, Real tol)
Ptr< Vector< Real > > b2_
Ptr< Vector< Real > > c_
Ptr< Vector< Real > > w1_
const Ptr< Constraint< Real > > con_
void conValue(const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > scaledc_
Ptr< Vector< Real > > v2_
const Ptr< Vector< Real > > getLagrangianGradient(const Vector< Real > &x)
const Ptr< Objective< Real > > obj_
Ptr< Vector< Real > > gPhi_
int getNumberConstraintEvaluations() const
Ptr< Vector< Real > > w2_
int getNumberGradientEvaluations() const
void setDelta(Real delta)
void objGrad(const Vector< Real > &x, Real &tol)
const Ptr< Vector< Real > > getMultiplierVec(const Vector< Real > &x)
void objValue(const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > g_
Ptr< Vector< Real > > y_
Real getObjectiveValue(const Vector< Real > &x)
Ptr< PartitionedVector< Real > > vv_
Ptr< Vector< Real > > gL_
const Ptr< Vector< Real > > getGradient(const Vector< Real > &x)
int getNumberFunctionEvaluations() const
Ptr< PartitionedVector< Real > > ww_
Ptr< PartitionedVector< Real > > bb_
Ptr< Krylov< Real > > krylov_
const Ptr< Vector< Real > > getConstraintVec(const Vector< Real > &x)
Ptr< Vector< Real > > b1_
void setPenaltyParameter(Real sigma)
FletcherBase(const ROL::Ptr< Objective< Real > > &obj, const ROL::Ptr< Constraint< Real > > &con)
Provides the interface to evaluate objective functions.
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Defines the linear algebra or vector space interface.