ROL
ROL_MeritFunction.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef ROL_MERITFUNCTION_H
11 #define ROL_MERITFUNCTION_H
12 
13 #include "ROL_Objective.hpp"
14 #include "ROL_InequalityConstraint.hpp"
16 
17 /* Nonsmooth merit function as depicted in Eq. 19.36 of Nocedal and Wright Second Edition
18 
19  \f[
20  \phi_\nu(x,s) = f(x) - \mu\sum\limits_{i=1}^m \ln(s_i)
21  + \nu \| c_E(x)\| + \nu + \| c_I(x)-s\|
22  \f]
23 
24  using the Euclidean norm without squares
25  */
26 
27 
28 namespace ROL {
29 namespace InteriorPoint {
30 
31 template<class Real>
32 class MeritFunction : public Objective<Real> {
33 
34  typedef Vector<Real> V;
38  typedef InequalityConstraint<Real> INCON;
39 
40  typedef ROL::ParameterList PLIST;
41 
42 
43  typedef typename PV::size_type uint;
44 
45  const static uint OPT = 0;
46  const static uint SLACK = 1;
47 
48 
49 private:
50 
51  ROL::Ptr<OBJ> obj_; // Raw objective function
52  ROL::Ptr<EQCON> eqcon_; // constraint
53  ROL::Ptr<INCON> incon_; // Inequality constraint
54  ROL::Ptr<BND> bnd_; // Bound constraint
55 
56  Real mu_; // Penalty parameter for log barrier on slack
57  Real nu_; // Penalty parameter for constraint norms
58 
59  ROL::Ptr<OBJ> obj_;
60  ROL::Ptr<EQCON> eqcon_;
61  ROL::Ptr<INCON> incon_;
62 
63  ROL::Ptr<V> xopt_;
64  ROL::Ptr<V> slack_;
65 
66  ROL::Ptr<V> gopt_; // Gradient of the objective function
67 
68  ROL::Ptr<V> sfun_; // store elementwise function of slack variable
69 
70 
71  ROL::Ptr<V> eqmult_; // constraint Lagrange multiplier
72  ROL::Ptr<V> inmult_; // Inequality constraint Lagrange multiplier
73 
74  ROL::Ptr<V> ce_; // constraint vector
75  ROL::Ptr<V> ci_; // Inequation constraint vector
76 
77  ROL::Ptr<V> jced_; // Jacobian applied to d
78  ROL::Ptr<V> jcid_; // Inequality Jacobian applied to d
79 
80  Real cenorm_;
81  Real cinorm_;
82 
83 
84  static const Elementwise::Logarithm<Real> LOG_;
85  static const Elementwise::Reciprocal<Real> RECIP_;
86  static const Elementwise::ReductionSum<Real> SUM_;
87 
88 
89 public:
90 
91  MeritFunction( ROL::Ptr<OBJ> &obj,
92  ROL::Ptr<EQCON> &eqcon,
93  ROL::Ptr<INCON> &incon,
94  const V& x,
95  const V& eqmult,
96  const V& inmult,
97  PLIST &parlist ) :
98  obj_(obj), eqcon_(eqcon), incon_(incon) {
99 
100  const PV &xpv = dynamic_cast<const PV&>(x);
101  xopt_ = xpv.get(OPT);
102  slack_ = xpv.get(SLACK);
103  sfun_ = slack_->clone();
104 
105  gopt_ = xopt_->dual().clone();
106 
107  PLIST &iplist = parlist.sublist("Step").sublist("Primal-Dual Interior Point");
108  mu_ = iplist.get("Initial Slack Penalty");
109  nu_ = iplist.get("Initial Constraint Norm Penalty");
110 
111  }
112 
113 
114  Real value( const V &x, Real &tol ) {
115 
116  const PV &xpv = dynamic_cast<const PV&>(x);
117  xopt_ = xpv.get(OPT);
118  slack_ = xpv.get(SLACK);
119 
120  sfun_->set(*slack_);
121 
122  sfun_->applyUnary(LOG_);
123 
124  Real val = obj_->value(*xopt_,tol);
125 
126  val += mu_*logs_->reduce(SUM_);
127 
128  eqcon_->value(*ce_,*xopt_,tol);
129  incon_->value(*ci_,*xopt_,tol);
130 
131  cenorm_ = ce_->norm();
132  cinorm_ = ci_->norm();
133 
134  val += nu_*(cenorm_ + cinorm_);
135 
136  return val;
137  }
138 
139 
140  Real dirDeriv( const V &x, const V &d, Real tol ) {
141 
142  const PV &xpv = dynamic_cast<const PV&>(x);
143  xopt_ = xpv.get(OPT);
144  slack_ = xpv.get(SLACK);
145 
146  const PV &dpv = dynamic_cast<const PV&>(d);
147  ROL::Ptr<V> dopt = dpv.get(OPT);
148  ROL::Ptr<V> dslack = dpv.get(SLACK);
149 
150  sfun_->set(*slack);
151  sfun_->applyUnary(RECIP_);
152 
153  ce_->applyJacobian(*jced_,*dopt,*xopt,tol);
154  ci_->applyJacobian(*jcid_,*dopt,*xopt,tol);
155 
156  obj_->gradient(*gopt_,*xopt,tol);
157 
158 
159  // Contributions to directional derivatives
160  Real ddopt = gopt_->dot(*dopt);
161 
162  Real ddslack = sfun_->dot(*dslack);
163 
164  Real ddce = ce_->dot(*jced_)/cenorm_;
165 
166  Real ddci = ci_->dot(*jcid_)/cinorm_;
167 
168  Real ddsn = slack_->dot(*dslack)/slack->norm();
169 
170  return ddopt - mu_*ddslack + nu_*(ddce + ddci + ddsn);
171 
172  }
173 
174 
175  void updateBarrier( Real mu ) {
176  mu_ = mu;
177  }
178 
179 
180 
181 }; // class MeritFunction
182 
183 } // namespace InteriorPoint
184 } // namespace ROL
185 
186 
187 #endif // ROL_MERITFUNCTION_H
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
Provides the interface to evaluate objective functions.
ROL::Ptr< const Vector< Real > > get(size_type i) const
Defines the linear algebra of vector space on a generic partitioned vector.
static const Elementwise::Reciprocal< Real > RECIP_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
static const Elementwise::Logarithm< Real > LOG_
static const Elementwise::ReductionSum< Real > SUM_
std::vector< PV >::size_type size_type
Real dirDeriv(const V &x, const V &d, Real tol)
MeritFunction(ROL::Ptr< OBJ > &obj, ROL::Ptr< EQCON > &eqcon, ROL::Ptr< INCON > &incon, const V &x, const V &eqmult, const V &inmult, PLIST &parlist)
Real value(const V &x, Real &tol)
Compute value.
Defines the general constraint operator interface.
InequalityConstraint< Real > INCON