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];
76 ROL::Ptr<std::vector<Real> >
x_;
77 const ROL::Ptr<const std::vector<Real> >
l_;
78 const ROL::Ptr<const std::vector<Real> >
u_;
79 ROL::Ptr<std::vector<Real> >
g_;
80 ROL::Ptr<std::vector<Real> >
di_;
81 ROL::Ptr<std::vector<Real> >
j_;
82 ROL::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>>();
99 Real tol = std::sqrt(ROL::ROL_EPSILON<Real>());
100 obj_->gradient(g,x,tol);
102 std::vector<Real> v(2);
104 for(
int i=0; i<2;++i) {
107 if( (*
g_)[i]<0 && (*
u_)[i] < ROL::ROL_INF<Real>() ) {
108 v[i] = (*u_)[i]-(*x_)[i];
112 else if( (*
g_)[i]>=0 && (*
l_)[i] > ROL::ROL_NINF<Real>() ) {
113 v[i] = (*x_)[i] - (*l_)[i];
117 else if( (*
g_)[i]<=0 && (*
u_)[i] == ROL::ROL_INF<Real>() ) {
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);
145 Real tol = std::sqrt(ROL::ROL_EPSILON<Real>());
146 obj_->gradient(g,x,tol);
148 for(
int i=0; i<2;++i) {
151 if( (*
g_)[i]<0 && (*
u_)[i] < ROL::ROL_INF<Real>() ) {
152 v[i] = (*u_)[i]-(*x_)[i];
156 else if( (*
g_)[i]>=0 && (*
l_)[i] > ROL::ROL_NINF<Real>() ) {
157 v[i] = (*x_)[i] - (*l_)[i];
161 else if( (*
g_)[i]<=0 && (*
u_)[i] == ROL::ROL_INF<Real>() ) {
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];
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_