ROL
ROL_SlacklessObjective_Def.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_SLACKLESSOBJECTIVE_DEF_HPP
11 #define ROL_SLACKLESSOBJECTIVE_DEF_HPP
12 
13 namespace ROL {
14 
15 template<typename Real>
17 
18 template<typename Real>
19 Ptr<Objective<Real>> SlacklessObjective<Real>::getObjective(void) const {
20  return obj_;
21 }
22 
23 template<typename Real>
24 void SlacklessObjective<Real>::update( const Vector<Real> &x, UpdateType type, int iter ) {
25  obj_->update( *getOpt(x), type, iter );
26 }
27 
28 template<typename Real>
29 void SlacklessObjective<Real>::update( const Vector<Real> &x, bool flag, int iter ) {
30  obj_->update( *getOpt(x), flag, iter );
31 }
32 
33 template<typename Real>
34 Real SlacklessObjective<Real>::value( const Vector<Real> &x, Real &tol ) {
35  return obj_->value( *getOpt(x), tol );
36 }
37 
38 template<typename Real>
39 Real SlacklessObjective<Real>::dirDeriv( const Vector<Real> &x, const Vector<Real> &d, Real &tol ) {
40  return obj_->dirDeriv(*getOpt(x),*getOpt(d),tol);
41 }
42 
43 template<typename Real>
45  zeroSlack(g);
46  obj_->gradient(*getOpt(g),*getOpt(x),tol);
47 }
48 
49 template<typename Real>
50 void SlacklessObjective<Real>::hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
51  zeroSlack(hv);
52  obj_->hessVec(*getOpt(hv),*getOpt(v),*getOpt(x),tol);
53 }
54 
55 template<typename Real>
56 void SlacklessObjective<Real>::invHessVec( Vector<Real> &ihv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
57  obj_->invHessVec( *getOpt(ihv), *getOpt(v), *getOpt(x), tol );
58  PartitionedVector<Real> &Pvp = dynamic_cast<PartitionedVector<Real>&>(ihv);
59  const PartitionedVector<Real> &vp = dynamic_cast<const PartitionedVector<Real>&>(v);
60  const int nvec = static_cast<int>(vp.numVectors());
61  for (int i = 1; i < nvec; ++i) {
62  Pvp.get(i)->set(vp.get(i)->dual());
63  }
64 }
65 
66 template<typename Real>
67 void SlacklessObjective<Real>::precond( Vector<Real> &Pv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
68  obj_->precond( *getOpt(Pv), *getOpt(v), *getOpt(x), tol );
69  PartitionedVector<Real> &Pvp = dynamic_cast<PartitionedVector<Real>&>(Pv);
70  const PartitionedVector<Real> &vp = dynamic_cast<const PartitionedVector<Real>&>(v);
71  const int nvec = static_cast<int>(vp.numVectors());
72  for (int i = 1; i < nvec; ++i) {
73  Pvp.get(i)->set(vp.get(i)->dual());
74  }
75 }
76 
77 template<typename Real>
78 void SlacklessObjective<Real>::setParameter(const std::vector<Real> &param) {
80  obj_->setParameter(param);
81 }
82 
83 template<typename Real>
84 Ptr<Vector<Real>> SlacklessObjective<Real>::getOpt( Vector<Real> &xs ) const {
85  return dynamic_cast<PartitionedVector<Real>&>(xs).get(0);
86 }
87 
88 template<typename Real>
89 Ptr<const Vector<Real>> SlacklessObjective<Real>::getOpt( const Vector<Real> &xs ) const {
90  return dynamic_cast<const PartitionedVector<Real>&>(xs).get(0);
91 }
92 
93 template<typename Real>
96  = dynamic_cast<PartitionedVector<Real>&>(x);
97  const int nvec = static_cast<int>(xpv.numVectors());
98  for (int i = 1; i < nvec; ++i) {
99  xpv.get(i)->zero();
100  }
101 }
102 
103 } // namespace ROL
104 
105 #endif // ROL__SLACKLESSOBJECTIVE_HPP
106 
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol) override
Compute gradient.
Real dirDeriv(const Vector< Real > &x, const Vector< Real > &d, Real &tol) override
Compute directional derivative.
Provides the interface to evaluate objective functions.
void setParameter(const std::vector< Real > &param) override
ROL::Ptr< const Vector< Real > > get(size_type i) const
Defines the linear algebra of vector space on a generic partitioned vector.
void update(const Vector< Real > &x, UpdateType type, int iter=-1) override
Update objective function.
void zeroSlack(Vector< Real > &x) const
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply Hessian approximation to vector.
void precond(Vector< Real > &Pv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply preconditioner to vector.
Real value(const Vector< Real > &x, Real &tol) override
Compute value.
Ptr< Vector< Real > > getOpt(Vector< Real > &xs) const
virtual void setParameter(const std::vector< Real > &param)
SlacklessObjective(const Ptr< Objective< Real >> &obj)
Ptr< Objective< Real > > getObjective(void) const
const Ptr< Obj > obj_
void invHessVec(Vector< Real > &ihv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply inverse Hessian approximation to vector.