/usr/include/trilinos/ROL_QuadraticPenalty_SimOpt.hpp is in libtrilinos-rol-dev 12.12.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | // @HEADER
// ************************************************************************
//
// Rapid Optimization Library (ROL) Package
// Copyright (2014) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact lead developers:
// Drew Kouri (dpkouri@sandia.gov) and
// Denis Ridzal (dridzal@sandia.gov)
//
// ************************************************************************
// @HEADER
#ifndef ROL_QUADRATICPENALTY_SIMOPT_H
#define ROL_QUADRATICPENALTY_SIMOPT_H
#include "ROL_Objective_SimOpt.hpp"
#include "ROL_EqualityConstraint_SimOpt.hpp"
#include "ROL_Vector.hpp"
#include "ROL_Types.hpp"
#include "Teuchos_RCP.hpp"
#include <iostream>
/** @ingroup func_group
\class ROL::QuadraticPenalty_SimOpt
\brief Provides the interface to evaluate the quadratic SimOpt constraint penalty.
This class implements the quadratic SimOpt constraint penalty functional.
Given an equality constraint \f$c:\mathcal{U}\times\mathcal{Z}\to\mathcal{C}\f$, the
quadratic penalty functional is
\f[
Q(u,z,\lambda,\mu) =
\langle \lambda, c(u,z)\rangle_{\mathcal{C}^*,\mathcal{C}} +
\frac{\mu}{2} \langle \mathfrak{R}c(u,z),c(u,z)\rangle_{\mathcal{C}^*,\mathcal{C}}
\f]
where \f$\lambda\in\mathcal{C}^*\f$ denotes a multiplier,
\f$\mu > 0\f$ is the penalty parameter and
\f$\mathfrak{R}\in\mathcal{L}(\mathcal{C},\mathcal{C}^*)\f$ is the Riesz operator
on the constraint space.
This implementation permits the scaling of \f$Q\f$ by \f$\mu^{-1}\f$ and also
permits the Hessian approximation
\f[
\nabla^2_{uu} Q(u,z,\lambda,\mu)v \approx \mu c_u(u,z)^*\mathfrak{R} c_u(u,z)v,
\quad
\nabla^2_{uz} Q(u,z,\lambda,\mu)v \approx \mu c_u(u,z)^*\mathfrak{R} c_z(u,z)v,
\f]
\f[
\nabla^2_{zu} Q(u,z,\lambda,\mu)v \approx \mu c_z(u,z)^*\mathfrak{R} c_u(u,z)v,
\quad\text{and}\quad
\nabla^2_{zz} Q(u,z,\lambda,\mu)v \approx \mu c_z(u,z)^*\mathfrak{R} c_z(u,z)v.
\f]
---
*/
namespace ROL {
template <class Real>
class QuadraticPenalty_SimOpt : public Objective_SimOpt<Real> {
private:
// Required for quadratic penalty definition
const Teuchos::RCP<EqualityConstraint_SimOpt<Real> > con_;
Teuchos::RCP<Vector<Real> > multiplier_;
Real penaltyParameter_;
// Auxiliary storage
Teuchos::RCP<Vector<Real> > primalMultiplierVector_;
Teuchos::RCP<Vector<Real> > dualSimVector_;
Teuchos::RCP<Vector<Real> > dualOptVector_;
Teuchos::RCP<Vector<Real> > primalConVector_;
// Constraint evaluations
Teuchos::RCP<Vector<Real> > conValue_;
// Evaluation counters
int ncval_;
// User defined options
const bool useScaling_;
const int HessianApprox_;
// Flags to recompute quantities
bool isConstraintComputed_;
void evaluateConstraint(const Vector<Real> &u, const Vector<Real> &z, Real &tol) {
if ( !isConstraintComputed_ ) {
// Evaluate constraint
con_->value(*conValue_,u,z,tol); ncval_++;
isConstraintComputed_ = true;
}
}
public:
QuadraticPenalty_SimOpt(const Teuchos::RCP<EqualityConstraint_SimOpt<Real> > &con,
const Vector<Real> &multiplier,
const Real penaltyParameter,
const Vector<Real> &simVec,
const Vector<Real> &optVec,
const Vector<Real> &conVec,
const bool useScaling = false,
const int HessianApprox = 0 )
: con_(con), penaltyParameter_(penaltyParameter), ncval_(0),
useScaling_(useScaling), HessianApprox_(HessianApprox), isConstraintComputed_(false) {
dualSimVector_ = simVec.dual().clone();
dualOptVector_ = optVec.dual().clone();
primalConVector_ = conVec.clone();
conValue_ = conVec.clone();
multiplier_ = multiplier.clone();
primalMultiplierVector_ = multiplier.clone();
}
virtual void update( const Vector<Real> &u, const Vector<Real> &z, bool flag = true, int iter = -1 ) {
con_->update(u,z,flag,iter);
isConstraintComputed_ = ( flag ? false : isConstraintComputed_ );
}
virtual Real value( const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
// Evaluate constraint
evaluateConstraint(u,z,tol);
// Apply Lagrange multiplier to constraint
Real cval = multiplier_->dot(conValue_->dual());
// Compute penalty term
Real pval = conValue_->dot(*conValue_);
// Compute quadratic penalty value
const Real half(0.5);
Real val(0);
if (useScaling_) {
val = cval/penaltyParameter_ + half*pval;
}
else {
val = cval + half*penaltyParameter_*pval;
}
return val;
}
virtual void gradient_1( Vector<Real> &g, const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
// Evaluate constraint
evaluateConstraint(u,z,tol);
// Compute gradient of Augmented Lagrangian
primalMultiplierVector_->set(conValue_->dual());
if ( useScaling_ ) {
primalMultiplierVector_->axpy(static_cast<Real>(1)/penaltyParameter_,*multiplier_);
}
else {
primalMultiplierVector_->scale(penaltyParameter_);
primalMultiplierVector_->plus(*multiplier_);
}
con_->applyAdjointJacobian_1(g,*primalMultiplierVector_,u,z,tol);
}
virtual void gradient_2( Vector<Real> &g, const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
// Evaluate constraint
evaluateConstraint(u,z,tol);
// Compute gradient of Augmented Lagrangian
primalMultiplierVector_->set(conValue_->dual());
if ( useScaling_ ) {
primalMultiplierVector_->axpy(static_cast<Real>(1)/penaltyParameter_,*multiplier_);
}
else {
primalMultiplierVector_->scale(penaltyParameter_);
primalMultiplierVector_->plus(*multiplier_);
}
con_->applyAdjointJacobian_2(g,*primalMultiplierVector_,u,z,tol);
}
virtual void hessVec_11( Vector<Real> &hv, const Vector<Real> &v,
const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
// Apply objective Hessian to a vector
if (HessianApprox_ < 2) {
con_->applyJacobian_1(*primalConVector_,v,u,z,tol);
con_->applyAdjointJacobian_1(hv,primalConVector_->dual(),u,z,tol);
if (!useScaling_) {
hv.scale(penaltyParameter_);
}
if (HessianApprox_ == 0) {
// Evaluate constraint
evaluateConstraint(u,z,tol);
// Apply Augmented Lagrangian Hessian to a vector
primalMultiplierVector_->set(conValue_->dual());
if ( useScaling_ ) {
primalMultiplierVector_->axpy(static_cast<Real>(1)/penaltyParameter_,*multiplier_);
}
else {
primalMultiplierVector_->scale(penaltyParameter_);
primalMultiplierVector_->plus(*multiplier_);
}
con_->applyAdjointHessian_11(*dualSimVector_,*primalMultiplierVector_,v,u,z,tol);
hv.plus(*dualSimVector_);
}
}
else {
hv.zero();
}
}
virtual void hessVec_12( Vector<Real> &hv, const Vector<Real> &v,
const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
// Apply objective Hessian to a vector
if (HessianApprox_ < 2) {
con_->applyJacobian_2(*primalConVector_,v,u,z,tol);
con_->applyAdjointJacobian_1(hv,primalConVector_->dual(),u,z,tol);
if (!useScaling_) {
hv.scale(penaltyParameter_);
}
if (HessianApprox_ == 0) {
// Evaluate constraint
evaluateConstraint(u,z,tol);
// Apply Augmented Lagrangian Hessian to a vector
primalMultiplierVector_->set(conValue_->dual());
if ( useScaling_ ) {
primalMultiplierVector_->axpy(static_cast<Real>(1)/penaltyParameter_,*multiplier_);
}
else {
primalMultiplierVector_->scale(penaltyParameter_);
primalMultiplierVector_->plus(*multiplier_);
}
con_->applyAdjointHessian_21(*dualSimVector_,*primalMultiplierVector_,v,u,z,tol);
hv.plus(*dualSimVector_);
}
}
else {
hv.zero();
}
}
virtual void hessVec_21( Vector<Real> &hv, const Vector<Real> &v,
const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
// Apply objective Hessian to a vector
if (HessianApprox_ < 2) {
con_->applyJacobian_1(*primalConVector_,v,u,z,tol);
con_->applyAdjointJacobian_2(hv,primalConVector_->dual(),u,z,tol);
if (!useScaling_) {
hv.scale(penaltyParameter_);
}
if (HessianApprox_ == 0) {
// Evaluate constraint
evaluateConstraint(u,z,tol);
// Apply Augmented Lagrangian Hessian to a vector
primalMultiplierVector_->set(conValue_->dual());
if ( useScaling_ ) {
primalMultiplierVector_->axpy(static_cast<Real>(1)/penaltyParameter_,*multiplier_);
}
else {
primalMultiplierVector_->scale(penaltyParameter_);
primalMultiplierVector_->plus(*multiplier_);
}
con_->applyAdjointHessian_12(*dualOptVector_,*primalMultiplierVector_,v,u,z,tol);
hv.plus(*dualOptVector_);
}
}
else {
hv.zero();
}
}
virtual void hessVec_22( Vector<Real> &hv, const Vector<Real> &v,
const Vector<Real> &u, const Vector<Real> &z, Real &tol ) {
// Apply objective Hessian to a vector
if (HessianApprox_ < 2) {
con_->applyJacobian_2(*primalConVector_,v,u,z,tol);
con_->applyAdjointJacobian_2(hv,primalConVector_->dual(),u,z,tol);
if (!useScaling_) {
hv.scale(penaltyParameter_);
}
if (HessianApprox_ == 0) {
// Evaluate constraint
evaluateConstraint(u,z,tol);
// Apply Augmented Lagrangian Hessian to a vector
primalMultiplierVector_->set(conValue_->dual());
if ( useScaling_ ) {
primalMultiplierVector_->axpy(static_cast<Real>(1)/penaltyParameter_,*multiplier_);
}
else {
primalMultiplierVector_->scale(penaltyParameter_);
primalMultiplierVector_->plus(*multiplier_);
}
con_->applyAdjointHessian_22(*dualOptVector_,*primalMultiplierVector_,v,u,z,tol);
hv.plus(*dualOptVector_);
}
}
else {
hv.zero();
}
}
// Return constraint value
virtual void getConstraintVec(Vector<Real> &c, const Vector<Real> &u, const Vector<Real> &z) {
Real tol = std::sqrt(ROL_EPSILON<Real>());
// Evaluate constraint
evaluateConstraint(u,z,tol);
c.set(*conValue_);
}
// Return total number of constraint evaluations
virtual int getNumberConstraintEvaluations(void) const {
return ncval_;
}
// Reset with upated penalty parameter
virtual void reset(const Vector<Real> &multiplier, const Real penaltyParameter) {
ncval_ = 0;
multiplier_->set(multiplier);
penaltyParameter_ = penaltyParameter;
}
}; // class AugmentedLagrangian
} // namespace ROL
#endif
|