ROL
ROL_FletcherBase.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_FLETCHERBASE_H
46#define ROL_FLETCHERBASE_H
47
48#include "ROL_Objective.hpp"
49#include "ROL_Constraint.hpp"
50#include "ROL_Vector.hpp"
51#include "ROL_Types.hpp"
52#include "ROL_Ptr.hpp"
53#include "ROL_KrylovFactory.hpp"
55#include <iostream>
56
57namespace ROL {
58
59template <class Real>
60class FletcherBase : public Objective<Real> {
61
62protected:
63 const Ptr<Objective<Real> > obj_;
64 const Ptr<Constraint<Real> > con_;
65
68
69 // Evaluation counters
70 int nfval_;
71 int ngval_;
72 int ncval_;
73
74 Real fPhi_; // value of penalty function
75 Ptr<Vector<Real> > gPhi_; // gradient of penalty function
76
77 Ptr<Vector<Real> > y_; // multiplier estimate
78
79 Real fval_; // value of objective function
80 Ptr<Vector<Real> > g_; // gradient of objective value
81 Ptr<Vector<Real> > c_; // constraint value
82 Ptr<Vector<Real> > scaledc_; // penaltyParameter_ * c_
83 Ptr<Vector<Real> > gL_; // gradient of Lagrangian (g - A*y)
84
85 Real cnorm_; // norm of constraint violation
86
93
94 Real multSolverError_; // Error from augmented system solve in value()
95 Real gradSolveError_; // Error from augmented system solve in gradient()
96
97 Real delta_; // regularization parameter
98
100
101 // For Augmented system solves
102 Ptr<Krylov<Real> > krylov_;
105 Ptr<Vector<Real> > v1_;
106 Ptr<Vector<Real> > v2_;
107 Ptr<PartitionedVector<Real> > vv_;
108 Ptr<Vector<Real> > b1_;
109 Ptr<Vector<Real> > b2_;
110 Ptr<PartitionedVector<Real> > bb_;
111 Ptr<Vector<Real> > w1_;
112 Ptr<Vector<Real> > w2_;
113 Ptr<PartitionedVector<Real> > ww_;
114
115 void objValue(const Vector<Real>& x, Real &tol) {
116 if( !isObjValueComputed_ ) {
117 fval_ = obj_->value(x,tol); nfval_++;
118 isObjValueComputed_ = true;
119 }
120 }
121
122 void objGrad(const Vector<Real>& x, Real &tol) {
123 if( !isObjGradComputed_ ) {
124 obj_->gradient(*g_, x, tol); ngval_++;
125 isObjGradComputed_ = true;
126 }
127 }
128
129 void conValue(const Vector<Real>&x, Real &tol) {
130 if( !isConValueComputed_ ) {
131 con_->value(*c_,x,tol); ncval_++;
132 scaledc_->set(*c_);
134 isConValueComputed_ = true;
135 }
136 }
137
138 virtual void computeMultipliers(const Vector<Real>& x, Real tol) {}
139
140public:
141 FletcherBase(const ROL::Ptr<Objective<Real> > &obj,
142 const ROL::Ptr<Constraint<Real> > &con)
143 : obj_(obj), con_(con), nfval_(0), ngval_(0), ncval_(0), fPhi_(0),
148 iterKrylov_(0), flagKrylov_(0) {}
149
150 // Accessors
151 const Ptr<Vector<Real>> getLagrangianGradient(const Vector<Real>& x) {
152 // TODO: Figure out reasonable tolerance
153 if( !isMultiplierComputed_ ) {
154 Real tol = static_cast<Real>(1e-12);
155 computeMultipliers(x, tol);
156 }
157 return gL_;
158 }
159
160 const Ptr<Vector<Real>> getConstraintVec(const Vector<Real>& x) {
161 Real tol = std::sqrt(ROL_EPSILON<Real>());
162 conValue(x, tol);
163 return c_;
164 }
165
166 const Ptr<Vector<Real>> getMultiplierVec(const Vector<Real>& x) {
167 // TODO: Figure out reasonable tolerance
168 if( !isMultiplierComputed_ ) {
169 Real tol = static_cast<Real>(1e-12);
170 computeMultipliers(x, tol);
171 }
172 return y_;
173 }
174
175 const Ptr<Vector<Real>> getGradient(const Vector<Real>& x) {
176 if( !isGradientComputed_ ) {
177 // TODO: Figure out reasonable tolerance
178 Real tol = static_cast<Real>(1e-12);
179 this->gradient(*gPhi_, x, tol);
180 }
181 return gPhi_;
182 }
183
185 Real tol = std::sqrt(ROL_EPSILON<Real>());
186 objValue(x, tol);
187
188 return fval_;
189 }
190
192 return nfval_;
193 }
194
196 return ngval_;
197 }
198
200 return ncval_;
201 }
202
203 void setDelta(Real delta) {
204 delta_ = delta;
205 isValueComputed_ = false;
206 isGradientComputed_ = false;
207 }
208
209 void setPenaltyParameter( Real sigma ) {
210 penaltyParameter_ = sigma;
211 isValueComputed_ = false;
212 isGradientComputed_ = false;
213 }
214
215}; // class Fletcher
216
217} // namespace ROL
218
219#include "ROL_Fletcher.hpp"
220#include "ROL_BoundFletcher.hpp"
221
222#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.