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_Krylov.hpp"
55 #include <iostream>
56 
57 namespace ROL {
58 
59 template <class Real>
60 class FletcherBase : public Objective<Real> {
61 
62 protected:
63  const Ptr<Objective<Real> > obj_;
64  const Ptr<Constraint<Real> > con_;
65 
67 
68  // Evaluation counters
69  int nfval_;
70  int ngval_;
71  int ncval_;
72 
73  Real fPhi_; // value of penalty function
74  Ptr<Vector<Real> > gPhi_; // gradient of penalty function
75 
76  Ptr<Vector<Real> > y_; // multiplier estimate
77 
78  Real fval_; // value of objective function
79  Ptr<Vector<Real> > g_; // gradient of objective value
80  Ptr<Vector<Real> > c_; // constraint value
81  Ptr<Vector<Real> > scaledc_; // penaltyParameter_ * c_
82  Ptr<Vector<Real> > gL_; // gradient of Lagrangian (g - A*y)
83 
90 
91  Real multSolverError_; // Error from augmented system solve in value()
92  Real gradSolveError_; // Error from augmented system solve in gradient()
93 
94  Real delta_; // regularization parameter
95 
97 
98  // For Augmented system solves
99  Ptr<Krylov<Real> > krylov_;
102  Ptr<Vector<Real> > v1_;
103  Ptr<Vector<Real> > v2_;
104  Ptr<PartitionedVector<Real> > vv_;
105  Ptr<Vector<Real> > b1_;
106  Ptr<Vector<Real> > b2_;
107  Ptr<PartitionedVector<Real> > bb_;
108 
109  void objValue(const Vector<Real>& x, Real &tol) {
110  if( !isObjValueComputed_ ) {
111  fval_ = obj_->value(x,tol); nfval_++;
112  isObjValueComputed_ = true;
113  }
114  }
115 
116  void objGrad(const Vector<Real>& x, Real &tol) {
117  if( !isObjGradComputed_ ) {
118  obj_->gradient(*g_, x, tol); ngval_++;
119  isObjGradComputed_ = true;
120  }
121  }
122 
123  void conValue(const Vector<Real>&x, Real &tol) {
124  if( !isConValueComputed_ ) {
125  con_->value(*c_,x,tol); ncval_++;
126  scaledc_->set(*c_);
127  scaledc_->scale(penaltyParameter_);
128  isConValueComputed_ = true;
129  }
130  }
131 
132  virtual void computeMultipliers(const Vector<Real>& x, Real tol) {}
133 
134 public:
135  FletcherBase(const ROL::Ptr<Objective<Real> > &obj,
136  const ROL::Ptr<Constraint<Real> > &con)
137  : obj_(obj), con_(con), nfval_(0), ngval_(0), ncval_(0), fPhi_(0),
138  isValueComputed_(false), isGradientComputed_(false),
142  iterKrylov_(0), flagKrylov_(0) {}
143 
144  // Accessors
145  const Ptr<Vector<Real>> getLagrangianGradient(const Vector<Real>& x) {
146  // TODO: Figure out reasonable tolerance
147  if( !isMultiplierComputed_ ) {
148  Real tol = static_cast<Real>(1e-12);
149  computeMultipliers(x, tol);
150  }
151  return gL_;
152  }
153 
154  const Ptr<Vector<Real>> getConstraintVec(const Vector<Real>& x) {
155  Real tol = std::sqrt(ROL_EPSILON<Real>());
156  conValue(x, tol);
157  return c_;
158  }
159 
160  const Ptr<Vector<Real>> getMultiplierVec(const Vector<Real>& x) {
161  // TODO: Figure out reasonable tolerance
162  Real tol = static_cast<Real>(1e-12);
163  computeMultipliers(x, tol);
164  return y_;
165  }
166 
167  const Ptr<Vector<Real>> getGradient(const Vector<Real>& x) {
168  if( !isGradientComputed_ ) {
169  // TODO: Figure out reasonable tolerance
170  Real tol = static_cast<Real>(1e-12);
171  this->gradient(*gPhi_, x, tol);
172  }
173  return gPhi_;
174  }
175 
177  Real tol = std::sqrt(ROL_EPSILON<Real>());
178  objValue(x, tol);
179 
180  return fval_;
181  }
182 
184  return nfval_;
185  }
186 
188  return ngval_;
189  }
190 
192  return ncval_;
193  }
194 
195  void setDelta(Real delta) {
196  delta_ = delta;
197  isValueComputed_ = false;
198  isGradientComputed_ = false;
199  }
200 
201  void setPenaltyParameter( Real sigma ) {
202  penaltyParameter_ = sigma;
203  isValueComputed_ = false;
204  isGradientComputed_ = false;
205  }
206 
207 }; // class Fletcher
208 
209 } // namespace ROL
210 
211 #include "ROL_Fletcher.hpp"
212 #include "ROL_BoundFletcher.hpp"
213 
214 #endif
Provides the interface to evaluate objective functions.
virtual void computeMultipliers(const Vector< Real > &x, Real tol)
Ptr< Vector< Real > > c_
int getNumberGradientEvaluations() const
Ptr< Vector< Real > > gPhi_
void setDelta(Real delta)
const Ptr< Constraint< Real > > con_
Real getObjectiveValue(const Vector< Real > &x)
void objValue(const Vector< Real > &x, Real &tol)
FletcherBase(const ROL::Ptr< Objective< Real > > &obj, const ROL::Ptr< Constraint< Real > > &con)
const Ptr< Objective< Real > > obj_
Contains definitions of custom data types in ROL.
const Ptr< Vector< Real > > getMultiplierVec(const Vector< Real > &x)
int getNumberFunctionEvaluations() const
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
Ptr< Krylov< Real > > krylov_
const Ptr< Vector< Real > > getGradient(const Vector< Real > &x)
Ptr< Vector< Real > > gL_
Ptr< Vector< Real > > v1_
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Ptr< Vector< Real > > b1_
void setPenaltyParameter(Real sigma)
Ptr< Vector< Real > > scaledc_
const Ptr< Vector< Real > > getConstraintVec(const Vector< Real > &x)
Ptr< Vector< Real > > g_
void conValue(const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > y_
int getNumberConstraintEvaluations() const
Ptr< PartitionedVector< Real > > vv_
const Ptr< Vector< Real > > getLagrangianGradient(const Vector< Real > &x)
Ptr< Vector< Real > > v2_
Ptr< Vector< Real > > b2_
Ptr< PartitionedVector< Real > > bb_
void objGrad(const Vector< Real > &x, Real &tol)
Defines the general constraint operator interface.