ROL
ROL_InteriorPoint.hpp
Go to the documentation of this file.
1 // Rapid Optimization Library (ROL) Package
2 // Copyright (2014) Sandia Corporation
3 //
4 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
5 // license for use of this work by or on behalf of the U.S. Government.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are
9 // met:
10 //
11 // 1. Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 //
18 // 3. Neither the name of the Corporation nor the names of the
19 // contributors may be used to endorse or promote products derived from
20 // this software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
23 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
26 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34 // Questions? Contact lead developers:
35 // Drew Kouri (dpkouri@sandia.gov) and
36 // Denis Ridzal (dridzal@sandia.gov)
37 //
38 // ************************************************************************
39 // @HEADER
40 
41 #ifndef ROL_INTERIORPOINT_H
42 #define ROL_INTERIORPOINT_H
43 
45 #include "ROL_Objective.hpp"
47 #include "ROL_BoundConstraint.hpp"
48 
49 namespace ROL {
50 
51 
56 template <class Real>
57 class InteriorPointObjective : public Objective<Real> {
58 private:
59 
60  typedef Vector<Real> V;
62  typedef typename PV::size_type size_type;
63 
64  const static size_type OPT = 0;
65  const static size_type SLACK = 1;
66 
67  Teuchos::RCP<Objective<Real> > obj_;
68  Teuchos::RCP<Objective<Real> > barrier_;
69 
70  Real mu_;
71  int nfval_;
72  int ngval_;
73 
74  // Downcast const ROL::Vector to const ROL::PartitionedVector
75  const PV& partition(const V& x) {
76  using Teuchos::dyn_cast;
77  return dyn_cast<const PV>(x);
78  }
79 
80  // Downcast ROL::Vector to ROL::PartitionedVector
81  PV& partition(V &x) {
82  using Teuchos::dyn_cast;
83  return dyn_cast<PV>(x);
84  }
85 
86 
87 public:
88  InteriorPointObjective( const Teuchos::RCP<Objective<Real> > &obj,
89  const Teuchos::RCP<Objective<Real> > &barrier, Real mu ) :
90  obj_(obj),barrier_(barrier),mu_(mu),nfval_(0),ngval_(0) {
91  }
92 
93  void updatePenalty( Real mu ) {
94  mu_ = mu;
95  }
96 
98  return nfval_;
99  }
100 
102  return ngval_;
103  }
104 
105  Real value( const Vector<Real> &x, Real &tol ) {
106  const PV &xpv = partition(x);
107 
108  Teuchos::RCP<const V> xopt = xpv.get(OPT);
109  Teuchos::RCP<const V> s = xpv.get(SLACK);
110 
111  ++nfval_;
112  return obj_->value(*xopt,tol) + mu_*barrier_->value(*s,tol);
113 
114  }
115 
116  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
117 
118  const PV &xpv = partition(x);
119  PV &gpv = partition(g);
120 
121  Teuchos::RCP<const V> xopt = xpv.get(OPT);
122  Teuchos::RCP<const V> s = xpv.get(SLACK);
123 
124  Teuchos::RCP<V> gopt = gpv.get(OPT);
125  Teuchos::RCP<V> gs = gpv.get(SLACK);
126 
127  obj_->gradient(*gopt, *xopt, tol);
128  barrier_->gradient(*gs, *s, tol);
129  gs->scale(mu_);
130 
131  ++ngval_;
132  }
133 
134  void hessVec( Vector<Real> &hv, const Vector<Real> &v,
135  const Vector<Real> &x, Real &tol ) {
136 
137  const PV &xpv = partition(x);
138  const PV &vpv = partition(v);
139  PV &hvpv = partition(hv);
140 
141  Teuchos::RCP<const V> xopt = xpv.get(OPT);
142  Teuchos::RCP<const V> s = xpv.get(SLACK);
143 
144  Teuchos::RCP<const V> vopt = vpv.get(OPT);
145  Teuchos::RCP<const V> vs = vpv.get(SLACK);
146 
147  Teuchos::RCP<V> hvopt = hvpv.get(OPT);
148  Teuchos::RCP<V> hvs = hvpv.get(SLACK);
149 
150  obj_->hessVec(*hvopt, *vopt, *xopt, tol);
151  barrier_->hessVec(*hvs, *vs, *s, tol);
152  hvs->scale(mu_);
153 
154  }
155 
156 }; // class InteriorPointObjective
157 
158 
159 
166 template<class Real>
168 private:
169  typedef Vector<Real> V;
171  typedef typename PV::size_type size_type;
172 
173  const static size_type OPT = 0;
174  const static size_type SLACK = 1;
175 
176  const static size_type INEQ = 0;
177  const static size_type EQUAL = 1;
178 
179  Teuchos::RCP<EqualityConstraint<Real> > incon_;
180  Teuchos::RCP<EqualityConstraint<Real> > eqcon_;
181 
182  bool hasEquality_; // True if an equality constraint is present
183  int ncval_; // Number of constraint evaluations
184 
185  // Downcast const ROL::Vector to const ROL::PartitionedVector
186  const PV& partition(const V& x) {
187  using Teuchos::dyn_cast;
188  return dyn_cast<const PV>(x);
189  }
190 
191  // Downcast ROL::Vector to ROL::PartitionedVector
192  PV& partition(V &x) {
193  using Teuchos::dyn_cast;
194  return dyn_cast<PV>(x);
195  }
196 
197 public:
198 
199  // Constructor with inequality and equality constraints
201  const Teuchos::RCP<EqualityConstraint<Real> > &eqcon ) :
202  incon_(incon), eqcon_(eqcon),hasEquality_(true), ncval_(0) {}
203 
204  // Constructor with inequality constraint only
206  incon_(incon), hasEquality_(false), ncval_(0) {}
207 
208 
210  return ncval_;
211  }
212 
213 
214  void value( Vector<Real> &c, const Vector<Real> &x, Real &tol ) {
215 
216  using Teuchos::RCP;
217 
218  // Partition vectors and extract subvectors
219  const PV &xpv = partition(x);
220 
221  RCP<const V> xopt = xpv.get(OPT);
222  RCP<const V> s = xpv.get(SLACK);
223 
224  PV &cpv = partition(c);
225 
226  RCP<V> ci = cpv.get(INEQ);
227  incon_->value(*ci, *xopt, tol);
228  ci->axpy(-1.0,*s);
229 
230  if(hasEquality_) {
231  RCP<V> ce = cpv.get(EQUAL);
232  eqcon_->value(*ce, *xopt, tol);
233  }
234 
235  ++ncval_;
236  }
237 
239  const Vector<Real> &v,
240  const Vector<Real> &x,
241  Real &tol ) {
242 
243  using Teuchos::RCP;
244 
245  // Partition vectors and extract subvectors
246  const PV &xpv = partition(x);
247  const PV &vpv = partition(v);
248 
249  RCP<const V> xopt = xpv.get(OPT);
250  RCP<const V> s = xpv.get(SLACK);
251 
252  RCP<const V> vopt = vpv.get(OPT);
253  RCP<const V> vs = vpv.get(SLACK);
254 
255  PV &jvpv = partition(jv);
256 
257  RCP<V> jvi = jvpv.get(INEQ);
258  incon_->applyJacobian(*jvi, *vopt, *xopt, tol);
259  jvi->axpy(-1.0,*vs);
260 
261  if(hasEquality_) {
262  RCP<V> jve = jvpv.get(EQUAL);
263  eqcon_->applyJacobian(*jve, *vopt, *xopt, tol);
264  }
265 
266  }
267 
269  const Vector<Real> &v,
270  const Vector<Real> &x,
271  Real &tol ) {
272 
273  using Teuchos::RCP;
274 
275  // Partition vectors and extract subvectors
276  const PV &xpv = partition(x);
277  PV &ajvpv = partition(ajv);
278 
279  RCP<const V> xopt = xpv.get(OPT);
280  RCP<const V> s = xpv.get(SLACK);
281 
282  RCP<V> ajvopt = ajvpv.get(OPT);
283  RCP<V> ajvs = ajvpv.get(SLACK);
284 
285  const PV &vpv = partition(v);
286 
287  RCP<const V> vi = vpv.get(INEQ);
288 
289  incon_->applyAdjointJacobian(*ajvopt,*vi,*xopt,tol);
290 
291 
292  ajvs->set(*vi);
293  ajvs->scale(-1.0);
294 
295  if(hasEquality_) {
296 
297  RCP<const V> ve = vpv.get(EQUAL);
298  RCP<V> temp = ajvopt->clone();
299  eqcon_->applyAdjointJacobian(*temp,*ve,*xopt,tol);
300  ajvopt->plus(*temp);
301 
302  }
303 
304  }
305 
307  const Vector<Real> &u,
308  const Vector<Real> &v,
309  const Vector<Real> &x,
310  Real &tol ) {
311 
312  using Teuchos::RCP;
313 
314  const PV &xpv = partition(x);
315  const PV &vpv = partition(v);
316  PV &ahuvpv = partition(ahuv);
317 
318  RCP<const V> xopt = xpv.get(OPT);
319  RCP<const V> s = xpv.get(SLACK);
320 
321  RCP<const V> vopt = vpv.get(OPT);
322 
323  RCP<V> ahuvopt = ahuvpv.get(OPT);
324  RCP<V> ahuvs = ahuvpv.get(SLACK);
325 
326  RCP<V> temp = ahuvopt->clone();
327 
328  const PV &upv = partition(u);
329 
330  RCP<const V> ui = upv.get(INEQ);
331 
332  incon_->applyAdjointHessian(*ahuvopt,*ui,*vopt,*xopt,tol);
333  ahuvs->zero();
334 
335  if(hasEquality_) {
336  RCP<const V> ue = upv.get(EQUAL);
337  eqcon_->applyAdjointHessian(*temp,*ue,*vopt,*xopt,tol);
338  ahuvopt->plus(*temp);
339  }
340 
341  }
342 
343 }; // class InteriorPointEqualityConstraint
344 
345 
351 template<class Real>
353 private:
354  typedef Vector<Real> V;
356  typedef typename PV::size_type size_type;
357 
358  const static size_type OPT = 0;
359  const static size_type SLACK = 1;
360 
361  Teuchos::RCP<BoundConstraint<Real> > bc_;
362 
363  Teuchos::RCP<Vector<Real> > lower_;
364  Teuchos::RCP<Vector<Real> > upper_;
365 
366 public:
367 
369 
370  lower_ = x.clone();
371  upper_ = x.clone();
372 
373  PV lowerpv = Teuchos::dyn_cast<PV>(lower_);
374  PV upperpv = Teuchos::dyn_cast<PV>(upper_);
375 
376  Teuchos::RCP<V> lower_opt = lowerpv.get(OPT);
377  Teuchos::RCP<V> lower_slack = lowerpv.get(SLACK);
378 
379  Teuchos::RCP<V> upper_opt = upperpv.get(OPT);
380  Teuchos::RCP<V> upper_slack = upperpv.get(SLACK);
381 
382  Elementwise::Fill<Real> setToMax(std::numeric_limits<Real>::max());
383  Elementwise::Fill<Real> setToMin(std::numeric_limits<Real>::lowest());
384 
385  lower_opt->applyUnary( setToMin );
386  lower_slack->zero();
387 
388  upper_opt->applyUnary( setToMax );
389  upper_slack->applyUnary( setToMax );
390 
391  bc_ = Teuchos::rcp( new BoundConstraint<Real>( lower_, upper_ ) );
392 
393  }
394 
395  void project( Vector<Real> &x ) {
396  bc_->project(x);
397  }
398 
399  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &x, Real eps ) {
400  bc_->pruneUpperActive( v, x, eps );
401  }
402 
404  const Vector<Real> &x, Real eps ) {
405  bc_->pruneUpperActive( v, g, x, eps );
406  }
407 
408  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &x, Real eps ) {
409  bc_->pruneLowerActive( v, x, eps );
410  }
411 
413  const Vector<Real> &x, Real eps ) {
414  bc_->pruneLowerActive( v, g, x, eps );
415  }
416 
418  u.set(*upper_);
419  }
420 
422  l.set(*lower_);
423  }
424 
425  bool isFeasible( const Vector<Real> &v ) {
426  return bc_->isFeasible(v);
427  }
428 
429 }; // class InteriorPointBoundConstraint
430 
431 
432 }
433 
434 #endif
void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the adjoint of the the constraint Jacobian at , , to vector .
Provides the interface to evaluate objective functions.
Teuchos::RCP< EqualityConstraint< Real > > eqcon_
Has both inequality and equality constraints. Treat inequality constraint as equality with slack vari...
Defines the linear algebra of vector space on a generic partitioned vector.
Teuchos::RCP< BoundConstraint< Real > > bc_
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void pruneUpperActive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the upper -binding set.
InteriorPointEqualityConstraint(const Teuchos::RCP< EqualityConstraint< Real > > &incon)
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Teuchos::RCP< Vector< Real > > upper_
InteriorPointEqualityConstraint(const Teuchos::RCP< EqualityConstraint< Real > > &incon, const Teuchos::RCP< EqualityConstraint< Real > > &eqcon)
Require positivity of slack variables.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
const PV & partition(const V &x)
void pruneLowerActive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the lower -binding set.
Teuchos::RCP< EqualityConstraint< Real > > incon_
InteriorPointBoundConstraint(const Vector< Real > &x)
static const size_type SLACK
Defines the equality constraint operator interface.
void pruneUpperActive(Vector< Real > &v, const Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the upper -active set.
Teuchos::RCP< Vector< Real > > lower_
Teuchos::RCP< const Vector< Real > > get(size_type i) const
void pruneLowerActive(Vector< Real > &v, const Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the lower -active set.
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ...
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
void project(Vector< Real > &x)
Project optimization variables onto the bounds.
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
Adds barrier term to generic objective.
Teuchos::RCP< Objective< Real > > barrier_
Provides the interface to apply upper and lower bound constraints.
bool isFeasible(const Vector< Real > &v)
Check if the vector, v, is feasible.
Teuchos::RCP< Objective< Real > > obj_
Real value(const Vector< Real > &x, Real &tol)
Compute value.
std::vector< PV >::size_type size_type
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:196
void setVectorToUpperBound(Vector< Real > &u)
Set the input vector to the upper bound.
PartitionedVector< Real > PV
InteriorPointObjective(const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< Objective< Real > > &barrier, Real mu)
void setVectorToLowerBound(Vector< Real > &l)
Set the input vector to the lower bound.
static const size_type OPT