ROL
ROL_ElasticObjective_Def.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_ELASTICOBJECTIVEDEF_H
45 #define ROL_ELASTICOBJECTIVEDEF_H
46 
47 
48 namespace ROL {
49 
50 template<typename Real>
52  const Ptr<Constraint<Real>> &con,
53  const Real penaltyParameter,
54  const Real sigma,
55  const Vector<Real> &dualOptVec,
56  const Vector<Real> &primConVec,
57  const Vector<Real> &dualConVec,
58  ParameterList &parlist)
59  : sigma_(sigma), cscale_(1) {
60  alobj_ = makePtr<AugmentedLagrangianObjective<Real>>(obj,con,penaltyParameter,dualOptVec,primConVec,dualConVec,parlist);
61  e_ = primConVec.clone(); e_->setScalar(static_cast<Real>(1));
62  tmp_ = primConVec.clone();
63 }
64 
65 template<typename Real>
67  const Ptr<Constraint<Real>> &con,
68  const Real penaltyParameter,
69  const Real sigma,
70  const Vector<Real> &dualOptVec,
71  const Vector<Real> &primConVec,
72  const Vector<Real> &dualConVec,
73  const bool scaleLagrangian,
74  const int HessianApprox)
75  : sigma_(sigma), cscale_(1) {
76  alobj_ = makePtr<AugmentedLagrangianObjective<Real>>(obj,con,penaltyParameter,dualOptVec,primConVec,dualConVec,scaleLagrangian,HessianApprox);
77  e_ = primConVec.clone(); e_->setScalar(static_cast<Real>(1));
78  tmp_ = primConVec.clone();
79 }
80 
81 template<typename Real>
82 void ElasticObjective<Real>::update( const Vector<Real> &x, UpdateType type, int iter ) {
83  Ptr<const Vector<Real>> xs = dynamic_cast<const PartitionedVector<Real>&>(x).get(0);
84  alobj_->update(*xs,type,iter);
85 }
86 
87 template<typename Real>
88 void ElasticObjective<Real>::setScaling(const Real fscale, const Real cscale) {
89  cscale_ = cscale;
90  alobj_->setScaling(fscale,cscale);
91 }
92 
93 template<typename Real>
94 Real ElasticObjective<Real>::value( const Vector<Real> &x, Real &tol ) {
95  Ptr<const Vector<Real>> xs = dynamic_cast<const PartitionedVector<Real>&>(x).get(0);
96  Ptr<const Vector<Real>> xu = dynamic_cast<const PartitionedVector<Real>&>(x).get(1);
97  Ptr<const Vector<Real>> xv = dynamic_cast<const PartitionedVector<Real>&>(x).get(2);
98  Real val = alobj_->value(*xs,tol);
99  tmp_->set(*xu); tmp_->plus(*xv);
100  Real pen = sigma_ * cscale_ * e_->dot(*tmp_);
101  return val + pen;
102 }
103 
104 template<typename Real>
106  Ptr<Vector<Real>> gs = dynamic_cast<PartitionedVector<Real>&>(g).get(0);
107  Ptr<Vector<Real>> gu = dynamic_cast<PartitionedVector<Real>&>(g).get(1);
108  Ptr<Vector<Real>> gv = dynamic_cast<PartitionedVector<Real>&>(g).get(2);
109  Ptr<const Vector<Real>> xs = dynamic_cast<const PartitionedVector<Real>&>(x).get(0);
110  alobj_->gradient(*gs,*xs,tol);
111  gu->set(*e_); gu->scale(sigma_ * cscale_);
112  gv->set(*e_); gv->scale(sigma_ * cscale_);
113 }
114 
115 template<typename Real>
116 void ElasticObjective<Real>::hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
117  Ptr<Vector<Real>> hvs = dynamic_cast<PartitionedVector<Real>&>(hv).get(0);
118  Ptr<Vector<Real>> hvu = dynamic_cast<PartitionedVector<Real>&>(hv).get(1);
119  Ptr<Vector<Real>> hvv = dynamic_cast<PartitionedVector<Real>&>(hv).get(2);
120  Ptr<const Vector<Real>> vs = dynamic_cast<const PartitionedVector<Real>&>(v).get(0);
121  Ptr<const Vector<Real>> xs = dynamic_cast<const PartitionedVector<Real>&>(x).get(0);
122  alobj_->hessVec(*hvs,*vs,*xs,tol);
123  hvu->zero();
124  hvv->zero();
125 }
126 
127 template<typename Real>
129  return alobj_->getObjectiveValue(x,tol);
130 }
131 
132 template<typename Real>
133 const Ptr<const Vector<Real>> ElasticObjective<Real>::getObjectiveGradient(const Vector<Real> &x, Real &tol) {
134  return alobj_->getObjectiveGradient(x,tol);
135 }
136 
137 template<typename Real>
138 const Ptr<const Vector<Real>> ElasticObjective<Real>::getConstraintVec(const Vector<Real> &x, Real &tol) {
139  return alobj_->getConstraintVec(x,tol);
140 }
141 
142 template<typename Real>
144  return alobj_->getNumberConstraintEvaluations();
145 }
146 
147 template<typename Real>
149  return alobj_->getNumberFunctionEvaluations();
150 }
151 
152 template<typename Real>
154  return alobj_->getNumberGradientEvaluations();
155 }
156 
157 template<typename Real>
158 void ElasticObjective<Real>::reset(const Vector<Real> &multiplier, Real penaltyParameter, Real sigma) {
159  sigma_ = sigma;
160  alobj_->reset(multiplier,penaltyParameter);
161 }
162 
163 template<typename Real>
164 const Ptr<AugmentedLagrangianObjective<Real>> ElasticObjective<Real>::getAugmentedLagrangian(void) const {
165  return alobj_;
166 }
167 
168 } // namespace ROL
169 
170 #endif
Provides the interface to evaluate objective functions.
const Ptr< const Vector< Real > > getConstraintVec(const Vector< Real > &x, Real &tol)
Ptr< AugmentedLagrangianObjective< Real > > alobj_
Defines the linear algebra of vector space on a generic partitioned vector.
int getNumberFunctionEvaluations(void) const
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol) override
Compute gradient.
const Ptr< AugmentedLagrangianObjective< Real > > getAugmentedLagrangian(void) const
Ptr< Vector< Real > > e_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
Real getObjectiveValue(const Vector< Real > &x, Real &tol)
void setScaling(const Real fscale=1.0, const Real cscale=1.0)
const Ptr< const Vector< Real > > getObjectiveGradient(const Vector< Real > &x, Real &tol)
int getNumberConstraintEvaluations(void) const
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply Hessian approximation to vector.
Real value(const Vector< Real > &x, Real &tol) override
Compute value.
void update(const Vector< Real > &x, UpdateType type, int iter=-1) override
Update objective function.
int getNumberGradientEvaluations(void) const
ElasticObjective(const Ptr< Objective< Real >> &obj, const Ptr< Constraint< Real >> &con, const Real penaltyParameter, const Real sigma, const Vector< Real > &dualOptVec, const Vector< Real > &primConVec, const Vector< Real > &dualConVec, ParameterList &parlist)
void reset(const Vector< Real > &multiplier, Real penaltyParameter, Real sigma)
Ptr< Vector< Real > > tmp_
Defines the general constraint operator interface.