79 ROL::Ptr<const std::vector<Real> > xp =
81 return 0.5*((*xp)[0]*(*xp)[0] + 2*(*xp)[1]*(*xp)[1]);
85 ROL::Ptr<std::vector<Real> > gp =
87 ROL::Ptr<const std::vector<Real> > xp =
90 (*gp)[1] = 2*(*xp)[1];
97 ROL::Ptr<std::vector<Real> > hvp =
99 ROL::Ptr<const std::vector<Real> > vp =
101 (*hvp)[0] = (*vp)[0];
102 (*hvp)[1] = 2*(*vp)[1];
110 ROL::Ptr<std::vector<Real> >
x_;
111 const ROL::Ptr<const std::vector<Real> >
l_;
112 const ROL::Ptr<const std::vector<Real> >
u_;
113 ROL::Ptr<std::vector<Real> >
g_;
114 ROL::Ptr<std::vector<Real> >
di_;
115 ROL::Ptr<std::vector<Real> >
j_;
116 ROL::Ptr<ROL::Objective<Real> >
obj_;
121 const ROL::Ptr<
const std::vector<Real> > &lp,
122 const ROL::Ptr<
const std::vector<Real> > &up ) :
124 g_ = ROL::makePtr<std::vector<double>(
x_->size>());
125 di_ = ROL::makePtr<std::vector<double>(
x_->size>());
126 j_ = ROL::makePtr<std::vector<double>(
x_->size>());
129 obj_ = ROL::makePtr<CLTestObjective<Real>>();
133 Real tol = std::sqrt(ROL::ROL_EPSILON<Real>());
134 obj_->gradient(g,x,tol);
136 std::vector<Real> v(2);
138 for(
int i=0; i<2;++i) {
141 if( (*
g_)[i]<0 && (*
u_)[i] < ROL::ROL_INF<Real>() ) {
142 v[i] = (*u_)[i]-(*x_)[i];
146 else if( (*
g_)[i]>=0 && (*
l_)[i] > ROL::ROL_NINF<Real>() ) {
147 v[i] = (*x_)[i] - (*l_)[i];
151 else if( (*
g_)[i]<=0 && (*
u_)[i] == ROL::ROL_INF<Real>() ) {
158 (*di_)[i] = std::sqrt(std::abs(v[i]));
162 std::cout <<
"x[0] = " << (*x_)[0] << std::endl;
163 std::cout <<
"x[1] = " << (*x_)[1] << std::endl;
164 std::cout <<
"g[0] = " << (*g_)[0] << std::endl;
165 std::cout <<
"g[0] = " << (*g_)[1] << std::endl;
166 std::cout <<
"di[0] = " << (*di_)[0] << std::endl;
167 std::cout <<
"di[1] = " << (*di_)[1] << std::endl;
172 ROL::Ptr<const std::vector<Real> > xc =
177 std::vector<Real> v(2);
179 Real tol = std::sqrt(ROL::ROL_EPSILON<Real>());
180 obj_->gradient(g,x,tol);
182 for(
int i=0; i<2;++i) {
185 if( (*
g_)[i]<0 && (*
u_)[i] < ROL::ROL_INF<Real>() ) {
186 v[i] = (*u_)[i]-(*x_)[i];
190 else if( (*
g_)[i]>=0 && (*
l_)[i] > ROL::ROL_NINF<Real>() ) {
191 v[i] = (*x_)[i] - (*l_)[i];
195 else if( (*
g_)[i]<=0 && (*
u_)[i] == ROL::ROL_INF<Real>() ) {
202 (*di_)[i] = std::sqrt(std::abs(v[i]));
205 std::cout <<
"x[0] = " << (*x_)[0] << std::endl;
206 std::cout <<
"x[1] = " << (*x_)[1] << std::endl;
207 std::cout <<
"g[0] = " << (*g_)[0] << std::endl;
208 std::cout <<
"g[0] = " << (*g_)[1] << std::endl;
209 std::cout <<
"di[0] = " << (*di_)[0] << std::endl;
210 std::cout <<
"di[1] = " << (*di_)[1] << std::endl;
214 ROL::Ptr<const std::vector<Real> > sp =
217 ROL::Ptr<ROL::Vector<Real> > y = s.
clone();
219 Real result = 0.5*y->dot(s);
220 result += (*di_)[0]*(*g_)[0]*(*sp)[0];
221 result += (*di_)[1]*(*g_)[1]*(*sp)[1];
226 ROL::Ptr<std::vector<Real> > gp =
230 (*gp)[0] += (*di_)[0]*(*g_)[0];
231 (*gp)[1] += (*di_)[1]*(*g_)[1];
239 ROL::Ptr<std::vector<Real> > hvp =
241 ROL::Ptr<const std::vector<Real> > vp =
244 obj_->hessVec(hv,v,s,tol);
246 for(
int i=0; i<2; ++i) {
247 (*hvp)[i] *= (*di_)[i]*(*di_)[i];
248 (*hvp)[i] += (*g_)[i]*(*j_)[i]*(*vp)[i];
Real value(const ROL::Vector< Real > &x, Real &tol)
Compute value.
Provides the interface to evaluate objective functions.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
ROL::Ptr< std::vector< Real > > x_
void gradient(ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real &tol)
Compute gradient.
const ROL::Ptr< const std::vector< Real > > l_
Real value(const ROL::Vector< Real > &s, Real &tol)
Compute value.
Defines the linear algebra or vector space interface.
ROL::Ptr< std::vector< Real > > di_
void hessVec(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &s, Real &tol)
Apply Hessian approximation to vector.
ROL::Ptr< ROL::Objective< Real > > obj_
const ROL::Ptr< const std::vector< Real > > u_
ROL::Ptr< std::vector< Real > > j_
void gradient(ROL::Vector< Real > &g, const ROL::Vector< Real > &s, Real &tol)
Compute gradient.
void update(const ROL::Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
CLExactModel(ROL::Ptr< std::vector< Real > > &xp, const ROL::Ptr< const std::vector< Real > > &lp, const ROL::Ptr< const std::vector< Real > > &up)
void hessVec(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
ROL::Ptr< std::vector< Real > > g_