45 ROL::Ptr<const std::vector<Real> > xp =
47 return 0.5*((*xp)[0]*(*xp)[0] + 2*(*xp)[1]*(*xp)[1]);
51 ROL::Ptr<std::vector<Real> > gp =
53 ROL::Ptr<const std::vector<Real> > xp =
56 (*gp)[1] = 2*(*xp)[1];
63 ROL::Ptr<std::vector<Real> > hvp =
65 ROL::Ptr<const std::vector<Real> > vp =
68 (*hvp)[1] = 2*(*vp)[1];
76ROL::Ptr<std::vector<Real> >
x_;
77const ROL::Ptr<const std::vector<Real> >
l_;
78const ROL::Ptr<const std::vector<Real> >
u_;
79ROL::Ptr<std::vector<Real> >
g_;
80ROL::Ptr<std::vector<Real> >
di_;
81ROL::Ptr<std::vector<Real> >
j_;
82ROL::Ptr<ROL::Objective<Real> >
obj_;
87 const ROL::Ptr<
const std::vector<Real> > &lp,
88 const ROL::Ptr<
const std::vector<Real> > &up ) :
90 g_ = ROL::makePtr<std::vector<double>(
x_->size>());
91 di_ = ROL::makePtr<std::vector<double>(
x_->size>());
92 j_ = ROL::makePtr<std::vector<double>(
x_->size>());
95 obj_ = ROL::makePtr<CLTestObjective<Real>>();
100 obj_->gradient(g,x,tol);
102 std::vector<Real> v(2);
104 for(
int i=0; i<2;++i) {
108 v[i] = (*u_)[i]-(*x_)[i];
113 v[i] = (*x_)[i] - (*l_)[i];
124 (*di_)[i] = std::sqrt(std::abs(v[i]));
128 std::cout <<
"x[0] = " << (*x_)[0] << std::endl;
129 std::cout <<
"x[1] = " << (*x_)[1] << std::endl;
130 std::cout <<
"g[0] = " << (*g_)[0] << std::endl;
131 std::cout <<
"g[0] = " << (*g_)[1] << std::endl;
132 std::cout <<
"di[0] = " << (*di_)[0] << std::endl;
133 std::cout <<
"di[1] = " << (*di_)[1] << std::endl;
138 ROL::Ptr<const std::vector<Real> > xc =
143 std::vector<Real> v(2);
146 obj_->gradient(g,x,tol);
148 for(
int i=0; i<2;++i) {
152 v[i] = (*u_)[i]-(*x_)[i];
157 v[i] = (*x_)[i] - (*l_)[i];
168 (*di_)[i] = std::sqrt(std::abs(v[i]));
171 std::cout <<
"x[0] = " << (*x_)[0] << std::endl;
172 std::cout <<
"x[1] = " << (*x_)[1] << std::endl;
173 std::cout <<
"g[0] = " << (*g_)[0] << std::endl;
174 std::cout <<
"g[0] = " << (*g_)[1] << std::endl;
175 std::cout <<
"di[0] = " << (*di_)[0] << std::endl;
176 std::cout <<
"di[1] = " << (*di_)[1] << std::endl;
180 ROL::Ptr<const std::vector<Real> > sp =
183 ROL::Ptr<ROL::Vector<Real> > y = s.
clone();
185 Real result = 0.5*y->dot(s);
186 result += (*di_)[0]*(*g_)[0]*(*sp)[0];
187 result += (*di_)[1]*(*g_)[1]*(*sp)[1];
192 ROL::Ptr<std::vector<Real> > gp =
196 (*gp)[0] += (*di_)[0]*(*g_)[0];
197 (*gp)[1] += (*di_)[1]*(*g_)[1];
205 ROL::Ptr<std::vector<Real> > hvp =
207 ROL::Ptr<const std::vector<Real> > vp =
210 obj_->hessVec(hv,v,s,tol);
212 for(
int i=0; i<2; ++i) {
213 (*hvp)[i] *= (*di_)[i]*(*di_)[i];
214 (*hvp)[i] += (*g_)[i]*(*j_)[i]*(*vp)[i];
ROL::Ptr< std::vector< Real > > j_
ROL::Ptr< ROL::Objective< Real > > obj_
void update(const ROL::Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
void gradient(ROL::Vector< Real > &g, const ROL::Vector< Real > &s, Real &tol)
Compute gradient.
const ROL::Ptr< const std::vector< Real > > l_
ROL::Ptr< std::vector< Real > > x_
ROL::Ptr< std::vector< Real > > di_
ROL::Ptr< std::vector< Real > > g_
const ROL::Ptr< const std::vector< Real > > u_
void hessVec(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &s, Real &tol)
Apply Hessian approximation to vector.
Real value(const ROL::Vector< Real > &s, Real &tol)
Compute value.
CLExactModel(ROL::Ptr< std::vector< Real > > &xp, const ROL::Ptr< const std::vector< Real > > &lp, const ROL::Ptr< const std::vector< Real > > &up)
void gradient(ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real &tol)
Compute gradient.
void hessVec(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Real value(const ROL::Vector< Real > &x, Real &tol)
Compute value.
Provides the interface to evaluate objective functions.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Defines the linear algebra or vector space interface.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.