ROL
ROL_QuadraticPenalty.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 #ifndef ROL_QUADRATICPENALTY_H
45 #define ROL_QUADRATICPENALTY_H
46 
47 #include "ROL_Objective.hpp"
49 #include "ROL_Vector.hpp"
50 #include "ROL_Types.hpp"
51 #include "Teuchos_RCP.hpp"
52 #include <iostream>
53 
81 namespace ROL {
82 
83 template <class Real>
84 class QuadraticPenalty : public Objective<Real> {
85 private:
86  // Required for quadratic penalty definition
87  const Teuchos::RCP<EqualityConstraint<Real> > con_;
88  Teuchos::RCP<Vector<Real> > multiplier_;
90 
91  // Auxiliary storage
92  Teuchos::RCP<Vector<Real> > primalMultiplierVector_;
93  Teuchos::RCP<Vector<Real> > dualOptVector_;
94  Teuchos::RCP<Vector<Real> > primalConVector_;
95 
96  // Constraint evaluations
97  Teuchos::RCP<Vector<Real> > conValue_;
98 
99  // Evaluation counters
100  int ncval_;
101 
102  // User defined options
103  const bool useScaling_;
104  const int HessianApprox_;
105 
106  // Flags to recompute quantities
108 
109  void evaluateConstraint(const Vector<Real> &x, Real &tol) {
110  if ( !isConstraintComputed_ ) {
111  // Evaluate constraint
112  con_->value(*conValue_,x,tol); ncval_++;
113  isConstraintComputed_ = true;
114  }
115  }
116 
117 public:
118  QuadraticPenalty(const Teuchos::RCP<EqualityConstraint<Real> > &con,
119  const Vector<Real> &multiplier,
120  const Real penaltyParameter,
121  const Vector<Real> &optVec,
122  const Vector<Real> &conVec,
123  const bool useScaling = false,
124  const int HessianApprox = 0 )
125  : con_(con), penaltyParameter_(penaltyParameter), ncval_(0),
126  useScaling_(useScaling), HessianApprox_(HessianApprox), isConstraintComputed_(false) {
127 
128  dualOptVector_ = optVec.dual().clone();
129  primalConVector_ = conVec.clone();
130  conValue_ = conVec.clone();
131  multiplier_ = multiplier.clone();
132  primalMultiplierVector_ = multiplier.clone();
133  }
134 
135  virtual void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
136  con_->update(x,flag,iter);
137  isConstraintComputed_ = ( flag ? false : isConstraintComputed_ );
138  }
139 
140  virtual Real value( const Vector<Real> &x, Real &tol ) {
141  // Evaluate constraint
142  evaluateConstraint(x,tol);
143  // Apply Lagrange multiplier to constraint
144  Real cval = multiplier_->dot(conValue_->dual());
145  // Compute penalty term
146  Real pval = conValue_->dot(*conValue_);
147  // Compute quadratic penalty value
148  const Real half(0.5);
149  Real val(0);
150  if (useScaling_) {
151  val = cval/penaltyParameter_ + half*pval;
152  }
153  else {
154  val = cval + half*penaltyParameter_*pval;
155  }
156  return val;
157  }
158 
159  virtual void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
160  // Evaluate constraint
161  evaluateConstraint(x,tol);
162  // Compute gradient of Augmented Lagrangian
163  const Real one(1);
164  primalMultiplierVector_->set(conValue_->dual());
165  if ( useScaling_ ) {
167  }
168  else {
171  }
172  con_->applyAdjointJacobian(g,*primalMultiplierVector_,x,tol);
173  }
174 
175  virtual void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
176  // Apply objective Hessian to a vector
177  if (HessianApprox_ < 3) {
178  con_->applyJacobian(*primalConVector_,v,x,tol);
179  con_->applyAdjointJacobian(hv,primalConVector_->dual(),x,tol);
180  if (!useScaling_) {
182  }
183 
184  if (HessianApprox_ == 1) {
185  // Apply Augmented Lagrangian Hessian to a vector
186  const Real one(1);
188  if ( useScaling_ ) {
190  }
191  con_->applyAdjointHessian(*dualOptVector_,*primalMultiplierVector_,v,x,tol);
192  hv.plus(*dualOptVector_);
193  }
194 
195  if (HessianApprox_ == 0) {
196  // Evaluate constraint
197  evaluateConstraint(x,tol);
198  // Apply Augmented Lagrangian Hessian to a vector
199  const Real one(1);
200  primalMultiplierVector_->set(conValue_->dual());
201  if ( useScaling_ ) {
203  }
204  else {
207  }
208  con_->applyAdjointHessian(*dualOptVector_,*primalMultiplierVector_,v,x,tol);
209  hv.plus(*dualOptVector_);
210  }
211  }
212  else {
213  hv.zero();
214  }
215  }
216 
217  // Return constraint value
218  virtual void getConstraintVec(Vector<Real> &c, const Vector<Real> &x) {
219  Real tol = std::sqrt(ROL_EPSILON<Real>());
220  // Evaluate constraint
221  evaluateConstraint(x,tol);
222  c.set(*conValue_);
223  }
224 
225  // Return total number of constraint evaluations
226  virtual int getNumberConstraintEvaluations(void) const {
227  return ncval_;
228  }
229 
230  // Reset with upated penalty parameter
231  virtual void reset(const Vector<Real> &multiplier, const Real penaltyParameter) {
232  ncval_ = 0;
233  multiplier_->set(multiplier);
234  penaltyParameter_ = penaltyParameter;
235  }
236 }; // class AugmentedLagrangian
237 
238 } // namespace ROL
239 
240 #endif
Teuchos::RCP< Vector< Real > > primalMultiplierVector_
Provides the interface to evaluate objective functions.
virtual void scale(const Real alpha)=0
Compute where .
virtual void reset(const Vector< Real > &multiplier, const Real penaltyParameter)
Teuchos::RCP< Vector< Real > > conValue_
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
const Teuchos::RCP< EqualityConstraint< Real > > con_
virtual void plus(const Vector &x)=0
Compute , where .
QuadraticPenalty(const Teuchos::RCP< EqualityConstraint< Real > > &con, const Vector< Real > &multiplier, const Real penaltyParameter, const Vector< Real > &optVec, const Vector< Real > &conVec, const bool useScaling=false, const int HessianApprox=0)
Provides the interface to evaluate the quadratic constraint penalty.
Contains definitions of custom data types in ROL.
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:157
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
void evaluateConstraint(const Vector< Real > &x, Real &tol)
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Teuchos::RCP< Vector< Real > > multiplier_
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Definition: ROL_Vector.hpp:213
Defines the equality constraint operator interface.
Teuchos::RCP< Vector< Real > > primalConVector_
virtual int getNumberConstraintEvaluations(void) const
virtual Real value(const Vector< Real > &x, Real &tol)
Compute value.
Teuchos::RCP< Vector< Real > > dualOptVector_
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:196
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
virtual void getConstraintVec(Vector< Real > &c, const Vector< Real > &x)