44 #ifndef ROL_BUNDLE_AS_H
45 #define ROL_BUNDLE_AS_H
62 ROL::Ptr<Vector<Real> >
tG_;
63 ROL::Ptr<Vector<Real> >
eG_;
64 ROL::Ptr<Vector<Real> >
yG_;
65 ROL::Ptr<Vector<Real> >
gx_;
66 ROL::Ptr<Vector<Real> >
ge_;
78 const Real coeff = 0.0,
79 const Real omega = 2.0,
80 const unsigned remSize = 2)
95 unsigned solveDual(
const Real t,
const unsigned maxit = 1000,
const Real tol = 1.e-8) {
114 Real sum(0), err(0), tmp(0), y(0),
zero(0);
115 for (
unsigned i = 0; i < Bundle<Real>::size(); ++i) {
120 err = (tmp - sum) - y;
123 for (
unsigned i = 0; i < Bundle<Real>::size(); ++i) {
129 for (
unsigned i = 0; i < Bundle<Real>::size(); ++i) {
139 void computeLagMult(std::vector<Real> &lam,
const Real mu,
const std::vector<Real> &g)
const {
144 typename std::set<unsigned>::iterator it =
workingSet_.begin();
145 for (
unsigned i = 0; i < n; ++i) {
146 lam[i] = g[*it] - mu; it++;
158 Real min = ROL_OVERFLOW<Real>();
159 typename std::set<unsigned>::iterator it =
workingSet_.begin();
160 for (
unsigned i = 0; i < n; ++i) {
167 flag = ((min < -ROL_EPSILON<Real>()) ?
false :
true);
172 Real
computeStepSize(
unsigned &ind,
const std::vector<Real> &x,
const std::vector<Real> &p)
const {
174 typename std::set<unsigned>::iterator it;
176 if ( p[*it] < -ROL_EPSILON<Real>() ) {
177 tmp = -x[*it]/p[*it];
178 if (
alpha >= tmp ) {
188 const std::vector<Real> &g,
const Real tol)
const {
195 std::vector<Real> gk(n,
zero);
196 typename std::set<unsigned>::iterator it =
nworkingSet_.begin();
197 for (
unsigned i = 0; i < n; ++i) {
198 gk[i] = g[*it]; it++;
200 std::vector<Real> sk(n,
zero);
203 for (
unsigned i = 0; i < n; ++i) {
204 s[*it] = sk[i]; it++;
213 std::vector<Real> tmp(Px.size(),
zero);
222 void applyG(std::vector<Real> &Gx,
const std::vector<Real> &x)
const {
233 Real sum(0), err(0), tmp(0), y(0);
234 for (
unsigned i = 0; i < dim; ++i) {
239 err = (tmp - sum) - y;
243 for (
unsigned i = 0; i < dim; ++i) {
249 Gx.assign(x.begin(),x.end());
254 Real eHe(0), sum(0), one(1),
zero(0);
255 Real errX(0), tmpX(0), yX(0), errE(0), tmpE(0), yE(0);
256 std::vector<Real> gg(dim,
zero);
257 typename std::set<unsigned>::iterator it =
nworkingSet_.begin();
258 for (
unsigned i = 0; i < dim; ++i) {
262 yX = x[i]*gg[i] - errX;
264 errX = (tmpX - sum) - yX;
270 errE = (tmpE - eHe) - yE;
274 for (
unsigned i = 0; i < dim; ++i) {
275 Px[i] = (x[i]-sum)*gg[i];
279 void applyG_Jacobi(std::vector<Real> &Gx,
const std::vector<Real> &x)
const {
281 typename std::set<unsigned>::iterator it =
nworkingSet_.begin();
282 for (
unsigned i = 0; i < dim; ++i) {
291 Real eHx(0), eHe(0), one(1);
293 std::vector<Real> x1(dim,0), e1(dim,0),gg(dim,0);
294 typename std::set<unsigned>::iterator it, jt;
296 for (
int i = 0; i < dim; ++i) {
298 for (
int j = 0; j < i; ++j) {
309 for (
int i = 0; i < dim; ++i) {
314 std::vector<Real> Hx(dim,0), He(dim,0); it =
nworkingSet_.end();
315 for (
int i = dim-1; i >= 0; --i) {
318 for (
int j = dim-1; j >= i+1; --j) {
330 for (
int i = 0; i < dim; ++i) {
331 Px[i] = Hx[i] - (eHx/eHe)*He[i];
335 void applyG_SymGS(std::vector<Real> &Gx,
const std::vector<Real> &x)
const {
337 typename std::set<unsigned>::iterator it =
nworkingSet_.begin();
338 for (
unsigned i = 0; i < dim; ++i) {
344 unsigned n = g.size();
345 std::vector<Real> Gg(n,0);
346 Real y(0), ytmp(0), yprt(0), yerr(0);
350 for (
unsigned i = 0; i < n; ++i) {
352 yprt = (r[i] - Gg[i]) - yerr;
354 yerr = (ytmp - y) - yprt;
358 for (
unsigned i = 0; i < n; ++i) {
367 for (
unsigned i = 0; i < Bundle<Real>::size(); ++i) {
375 for (
unsigned i = 0; i < Bundle<Real>::size(); ++i) {
381 void applyMatrix(std::vector<Real> &Hx,
const std::vector<Real> &x)
const {
385 typename std::set<unsigned>::iterator it =
nworkingSet_.begin();
386 for (
unsigned i = 0; i < n; ++i) {
396 for (
unsigned i = 0; i < n; ++i) {
402 unsigned projectedCG(std::vector<Real> &x, Real &mu,
const std::vector<Real> &b,
const Real tol)
const {
403 Real one(1),
zero(0);
405 std::vector<Real> r(n,0), r0(n,0), g(n,0), d(n,0), Ad(n,0);
409 r0.assign(r.begin(),r.end());
412 Real rg =
dot(r,g), rg0(0);
415 Real
alpha(0), kappa(0), beta(0), TOL(1.e-2);
416 Real CGtol = std::min(tol,TOL*rg);
418 while (rg > CGtol && cnt < 2*n+1) {
435 Real err(0), tmp(0), y(0);
436 for (
unsigned i = 0; i < n; ++i) {
440 err = (tmp - mu) - y;
443 mu /= static_cast<Real>(n);
448 Real
dot(
const std::vector<Real> &x,
const std::vector<Real> &y)
const {
450 Real val(0), err(0), tmp(0), y0(0);
451 unsigned n = std::min(x.size(),y.size());
452 for (
unsigned i = 0; i < n; ++i) {
454 y0 = x[i]*y[i] - err;
456 err = (tmp - val) - y0;
462 Real
norm(
const std::vector<Real> &x)
const {
463 return std::sqrt(
dot(x,x));
466 void axpy(
const Real a,
const std::vector<Real> &x, std::vector<Real> &y)
const {
467 unsigned n = std::min(y.size(),x.size());
468 for (
unsigned i = 0; i < n; ++i) {
473 void scale(std::vector<Real> &x,
const Real a)
const {
474 for (
unsigned i = 0; i < x.size(); ++i) {
479 void scale(std::vector<Real> &x,
const Real a,
const std::vector<Real> &y)
const {
480 unsigned n = std::min(x.size(),y.size());
481 for (
unsigned i = 0; i < n; ++i) {
489 unsigned ind = 0, i = 0, CGiter = 0;
490 Real snorm(0),
alpha(0), mu(0), one(1),
zero(0);
494 for (
unsigned j = 0; j < Bundle<Real>::size(); ++j) {
499 for (i = 0; i < maxit; ++i) {
502 if ( snorm < ROL_EPSILON<Real>() ) {
533 for (
unsigned j = 0; j < Bundle<Real>::size(); ++j) {
542 void project(std::vector<Real> &x,
const std::vector<Real> &v)
const {
544 vsort.assign(v.begin(),v.end());
545 std::sort(vsort.begin(),vsort.end());
546 Real sum(-1), lam(0),
zero(0), one(1);
557 for (
unsigned i = 0; i < Bundle<Real>::size(); ++i) {
558 x[i] = std::max(
zero,v[i] - lam);
563 Real
zero(0), one(1);