79 Teuchos::RCP<const std::vector<Real> > xp =
81 return 0.5*((*xp)[0]*(*xp)[0] + 2*(*xp)[1]*(*xp)[1]);
85 Teuchos::RCP<std::vector<Real> > gp =
87 Teuchos::RCP<const std::vector<Real> > xp =
88 Teuchos::dyn_cast<
const ROL::StdVector<Real> >(x).getVector();
90 (*gp)[1] = 2*(*xp)[1];
97 Teuchos::RCP<std::vector<Real> > hvp =
99 Teuchos::RCP<const std::vector<Real> > vp =
100 Teuchos::dyn_cast<
const ROL::StdVector<Real> >(v).getVector();
101 (*hvp)[0] = (*vp)[0];
102 (*hvp)[1] = 2*(*vp)[1];
110 Teuchos::RCP<std::vector<Real> >
x_;
111 const Teuchos::RCP<const std::vector<Real> >
l_;
112 const Teuchos::RCP<const std::vector<Real> >
u_;
113 Teuchos::RCP<std::vector<Real> >
g_;
114 Teuchos::RCP<std::vector<Real> >
di_;
115 Teuchos::RCP<std::vector<Real> >
j_;
116 Teuchos::RCP<ROL::Objective<Real> >
obj_;
121 const Teuchos::RCP<
const std::vector<Real> > &lp,
122 const Teuchos::RCP<
const std::vector<Real> > &up ) :
123 x_(xp), l_(lp), u_(up) {
124 g_ = Teuchos::rcp(
new std::vector<double>(x_->size()) );
125 di_ = Teuchos::rcp(
new std::vector<double>(x_->size()) );
126 j_ = Teuchos::rcp(
new std::vector<double>(x_->size()) );
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 Teuchos::RCP<const std::vector<Real> > xc =
177 std::vector<Real> v(2);
178 ROL::StdVector<Real> g(g_);
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 Teuchos::RCP<const std::vector<Real> > sp =
217 Teuchos::RCP<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 Teuchos::RCP<std::vector<Real> > gp =
230 (*gp)[0] += (*di_)[0]*(*g_)[0];
231 (*gp)[1] += (*di_)[1]*(*g_)[1];
239 Teuchos::RCP<std::vector<Real> > hvp =
241 Teuchos::RCP<const std::vector<Real> > vp =
242 Teuchos::dyn_cast<
const ROL::StdVector<Real> >(v).getVector();
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.
Teuchos::RCP< std::vector< Real > > g_
void gradient(ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real &tol)
Compute gradient.
Teuchos::RCP< std::vector< Real > > j_
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Real value(const ROL::Vector< Real > &s, Real &tol)
Compute value.
Defines the linear algebra or vector space interface.
void hessVec(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &s, Real &tol)
Apply Hessian approximation to vector.
CLExactModel(Teuchos::RCP< std::vector< Real > > &xp, const Teuchos::RCP< const std::vector< Real > > &lp, const Teuchos::RCP< const std::vector< Real > > &up)
Teuchos::RCP< std::vector< Real > > x_
Teuchos::RCP< ROL::Objective< Real > > obj_
const Teuchos::RCP< const std::vector< Real > > l_
Teuchos::RCP< std::vector< Real > > di_
const Teuchos::RCP< const std::vector< Real > > u_
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.
void hessVec(ROL::Vector< Real > &hv, const ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.