ROL
ROL_ChainRuleConstraint.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_CHAIN_RULE_CONSTRAINT_HPP
45 #define ROL_CHAIN_RULE_CONSTRAINT_HPP
46 
47 #include "ROL_Constraint.hpp"
48 
61 namespace ROL {
62 
63 template<typename Real>
64 class ChainRuleConstraint: public Constraint<Real> {
65 public:
66 
67  ChainRuleConstraint( const Ptr<Constraint<Real>>& outer_con,
68  const Ptr<Constraint<Real>>& inner_con,
69  const Vector<Real>& x,
70  const Vector<Real>& lag_inner )
71  : outer_con_(outer_con), inner_con_(inner_con),
72  y_(lag_inner.dual().clone()), // Inner constraint space vector
73  Jiv_(lag_inner.dual().clone()), // Inner Jacobian applied to optimization space vector
74  aJol_(lag_inner.dual().clone()), // Outer adjoint Jacobian applied to outer dual constaint space vector
75  HiaJol_(x.dual().clone()), // Inner Hessian applied to dual optimization space vector
76  HolJiv_(lag_inner.clone()), // Outer Hessian applied to inner constaint space vector
77  tol_(0) {
78  }
79 
80  virtual ~ChainRuleConstraint() = default;
81 
82  virtual void update( const Vector<Real>& x,
83  UpdateType type,
84  int iter = -1 ) {
85  inner_con_->update(x,type,iter);
86  inner_con_->value(*y_,x,tol_);
87  outer_con_->update(*y_,type,iter);
88  }
89 
90  virtual void update( const Vector<Real>& x,
91  bool flag,
92  int iter = -1 ) {
93  inner_con_->update(x,flag,iter);
94  inner_con_->value(*y_,x,tol_);
95  outer_con_->update(*y_,flag,iter);
96  }
97 
98  virtual void value( Vector<Real>& c,
99  const Vector<Real>& x,
100  Real& tol ) override {
101  inner_con_->value(*y_,x,tol);
102  outer_con_->value(c,*y_,tol);
103  }
104 
105  virtual void applyJacobian( Vector<Real>& jv,
106  const Vector<Real>& v,
107  const Vector<Real>& x,
108  Real& tol ) override {
109  inner_con_->value(*y_,x,tol);
110  inner_con_->applyJacobian(*Jiv_,v,x,tol);
111  outer_con_->applyJacobian(jv,*Jiv_,*y_,tol);
112  }
113 
114  virtual void applyAdjointJacobian( Vector<Real>& ajl,
115  const Vector<Real>& l,
116  const Vector<Real>& x,
117  Real& tol ) override {
118  inner_con_->value(*y_,x,tol);
119  outer_con_->applyAdjointJacobian(*aJol_,l,*y_,tol);
120  inner_con_->applyAdjointJacobian(ajl,*aJol_,x,tol);
121  }
122 
123  virtual void applyAdjointHessian( Vector<Real>& ahlv,
124  const Vector<Real>& l,
125  const Vector<Real>& v,
126  const Vector<Real>& x,
127  Real& tol ) override {
128  inner_con_->value(*y_,x,tol);
129  inner_con_->applyJacobian(*Jiv_,v,x,tol);
130  outer_con_->applyAdjointJacobian(*aJol_,l,*y_,tol);
131  inner_con_->applyAdjointHessian(*HiaJol_,*aJol_,v,x,tol);
132  outer_con_->applyAdjointHessian(*HolJiv_,l,*Jiv_,*y_,tol);
133  inner_con_->applyAdjointJacobian(ahlv,*HolJiv_,x,tol);
134  ahlv.plus(*HiaJol_);
135  }
136 
137 private:
138 
139  const Ptr<Constraint<Real>> outer_con_, inner_con_;
140 
141  Ptr<Vector<Real>> y_; // Inner constraint space vector
142  Ptr<Vector<Real>> Jiv_; // Inner Jacobian applied to optimization space vector
143  Ptr<Vector<Real>> aJol_; // Outer adjoint Jacobian applied to outer dual constaint space vector
144  Ptr<Vector<Real>> HiaJol_; // Inner Hessian applied to dual optimization space vector
145  Ptr<Vector<Real>> HolJiv_; // Outer Hessian applied to inner constaint space vector
146  Real tol_;
147 }; // class ChainRuleConstraint
148 
149 } // namespace ROL
150 
151 #endif // ROL_CHAIN_RULE_CONSTRAINT_HPP
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol) override
Evaluate the constraint operator at .
virtual void update(const Vector< Real > &x, bool flag, int iter=-1)
Update constraint functions. x is the optimization variable, flag = true if optimization variable is ...
virtual void plus(const Vector &x)=0
Compute , where .
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
virtual void applyAdjointJacobian(Vector< Real > &ajl, const Vector< Real > &l, const Vector< Real > &x, Real &tol) override
Apply the adjoint of the the constraint Jacobian at , , to vector .
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update constraint function.
virtual void applyAdjointHessian(Vector< Real > &ahlv, const Vector< Real > &l, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ...
const Ptr< Constraint< Real > > outer_con_
Defines a constaint formed through function composition .
virtual void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply the constraint Jacobian at , , to vector .
ChainRuleConstraint(const Ptr< Constraint< Real >> &outer_con, const Ptr< Constraint< Real >> &inner_con, const Vector< Real > &x, const Vector< Real > &lag_inner)
const Ptr< Constraint< Real > > inner_con_
virtual ~ChainRuleConstraint()=default
Defines the general constraint operator interface.