ocra-recipes
Doxygen documentation for the ocra-recipes repository
ObjQLD.cpp
Go to the documentation of this file.
1 #include "ocra/optim/ObjQLD.h"
2 
3 
4 namespace ocra
5 {
6 
8  :_lwar(1), _liwar(1), _mnn(1), _sizeFactor(1.), _eps(1.e-8)
9  {
10  _iwarCapacity = 0;
11  _iwar = 0;
12  resize();
13  }
14 
15  int ObjQLD::solve(Map<MatrixXd>& C, const Map<VectorXd>& d, const Map<MatrixXd>& A, const Map<VectorXd>& b, int me,
16  Map<VectorXd>& x, const Map<VectorXd>& xl, const Map<VectorXd>& xu, bool factorizedC)
17  {
18  int m = static_cast<int>(A.rows());
19  int me_ = (int)me;
20  int mmax = static_cast<int>(A.stride());
21  int n = static_cast<int>(x.size());
22  int nmax = static_cast<int>(C.stride());
23  _mnn = m + 2*n;
24  int ifail;
25  _lwar = (int)(_sizeFactor*(1.5*nmax*nmax + 10*nmax + 2*mmax) + 1.99999999);
26  _liwar = (int) (_sizeFactor*n + 0.9999999);
27  if (resize())
28  return 3; //not enough memory
29 
30 
31  //there is a contradiction in the QLD documentation
32  //_iwar[0] is 0 when C is given as an upper triangular choleski factor
33  if (factorizedC)
34  _iwar[0] = 0;
35  else
36  _iwar[0] = 1;
37 
38  double* cd = const_cast<double*>(C.data());
39  double* dd = const_cast<double*>(d.data());
40  double* ad = const_cast<double*>(A.data());
41  double* bd = const_cast<double*>(b.data());
42  double* xld = const_cast<double*>(xl.data());
43  double* xud = const_cast<double*>(xu.data());
44  double* xd = const_cast<double*>(x.data());
45 
46  ql0001_(&m, &me_, &mmax, &n, &nmax, &_mnn, cd, dd, ad, bd,
47  xld, xud, xd, _u.data(), 0, &ifail, 0, _war.data(),
48  &_lwar, _iwar, &_liwar, &_eps);
49 
50  return ifail;
51  }
52 
53 
54  const VectorXd& ObjQLD::getLagrangeMultipliers(void) const
55  {
56  return _u;
57  }
58 
59 
60  double ObjQLD::getSizeFactor(void) const
61  {
62  return _sizeFactor;
63  }
64 
65 
66  void ObjQLD::setSizeFactor(double f)
67  {
68  if (f>=1.)
69  _sizeFactor = f;
70  }
71 
72 
73  int ObjQLD::ql0001_(int *m,int *me,int *mmax,int *n,int *nmax,int *mnn,
74  double *c,double *d,double *a,double *b,double *xl,
75  double *xu,double *x,double *u,int *iout,int *ifail,
76  int *iprint,double *war,int *lwar,int *iwar,int *liwar,
77  double *eps1)
78  {
79  /* Format strings */
80  static char fmt_1000[] = "(/8x,\002***QL: MATRIX G WAS ENLARGED\002,i3\
81  ,\002-TIMES BY UNITMATRIX\002)";
82  static char fmt_1100[] = "(/8x,\002***QL: CONSTRAINT \002,i5,\002 NOT CO\
83  NSISTENT TO \002,/,(10x,10i5))";
84  static char fmt_1200[] = "(/8x,\002***QL: LWAR TOO SMALL\002)";
85  static char fmt_1210[] = "(/8x,\002***QL: LIWAR TOO SMALL\002)";
86  static char fmt_1220[] = "(/8x,\002***QL: MNN TOO SMALL\002)";
87  static char fmt_1300[] = "(/8x,\002***QL: TOO MANY ITERATIONS (MORE THA\
88  N\002,i6,\002)\002)";
89  static char fmt_1400[] = "(/8x,\002***QL: ACCURACY INSUFFICIENT TO ATTAI\
90  N CONVERGENCE\002)";
91 
92  /* System generated locals */
93  int c_dim1, c_offset, a_dim1, a_offset, i__1/*, i__2*/;
94 
95  /* Builtin functions */
96  /* int s_wsfe(), do_fio(), e_wsfe(); */
97 
98  /* Local variables */
99  double diag;
100  /* extern int ql0002_(); */
101  int nact, info;
102  double zero;
103  int i, j, idiag, maxit;
104  double qpeps;
105  int in, mn, lw;
106  double ten;
107  long int lql;
108  int inw1, inw2;
109 
110  struct {
111  double eps;
112  } cmache_1;
113 
114 
115  /* INTRINSIC FUNCTIONS: DSQRT */
116 
117  /* Parameter adjustments */
118  --iwar;
119  --war;
120  --u;
121  --x;
122  --xu;
123  --xl;
124  --b;
125  a_dim1 = *mmax;
126  a_offset = a_dim1 + 1;
127  a -= a_offset;
128  --d;
129  c_dim1 = *nmax;
130  c_offset = c_dim1 + 1;
131  c -= c_offset;
132 
133  /* Function Body */
134  cmache_1.eps = *eps1;
135 
136  /* CONSTANT DATA */
137 
138  /* ################################################################# */
139 
140  if (fabs(c[*nmax + *nmax * c_dim1]) == 0.e0) {
141  c[*nmax + *nmax * c_dim1] = cmache_1.eps;
142  }
143 
144  /* umd */
145  /* This prevents a subsequent more major modification of the Hessian */
146  /* matrix in the important case when a minmax problem (yielding a */
147  /* singular Hessian matrix) is being solved. */
148  /* ----UMCP, April 1991, Jian L. Zhou */
149  /* ################################################################# */
150 
151  lql = FALSE_;
152  if (iwar[1] == 1) {
153  lql = TRUE_;
154  }
155  zero = 0.;
156  ten = 10.;
157  maxit = (*m + *n) * 40;
158  qpeps = cmache_1.eps;
159  inw1 = 1;
160  inw2 = inw1 + *mmax;
161 
162  /* PREPARE PROBLEM DATA FOR EXECUTION */
163 
164  if (*m <= 0) {
165  goto L20;
166  }
167  in = inw1;
168  i__1 = *m;
169  for (j = 1; j <= i__1; ++j) {
170  war[in] = -b[j];
171  /* L10: */
172  ++in;
173  }
174 L20:
175  lw = *nmax * 3 * *nmax / 2 + *nmax * 10 + *m;
176  if (inw2 + lw > *lwar) {
177  goto L80;
178  }
179  if (*liwar < *n) {
180  goto L81;
181  }
182  if (*mnn < *m + *n + *n) {
183  goto L82;
184  }
185  mn = *m + *n;
186 
187  /* CALL OF QL0002 */
188 
189  ql0002_(n, m, me, mmax, &mn, mnn, nmax, &lql, &a[a_offset], &war[inw1], &
190  d[1], &c[c_offset], &xl[1], &xu[1], &x[1], &nact, &iwar[1], &
191  maxit, &qpeps, &info, &diag, &war[inw2], &lw);
192 
193  /* TEST OF MATRIX CORRECTIONS */
194 
195  *ifail = 0;
196  if (info == 1) {
197  goto L40;
198  }
199  if (info == 2) {
200  goto L90;
201  }
202  idiag = 0;
203  if (diag > zero && diag < 1e3) {
204  idiag = (int) diag;
205  }
206 
207  if (info < 0) {
208  goto L70;
209  }
210 
211  /* REORDER MULTIPLIER */
212 
213  i__1 = *mnn;
214  for (j = 1; j <= i__1; ++j) {
215  /* L50: */
216  u[j] = zero;
217  }
218  in = inw2 - 1;
219  if (nact == 0) {
220  goto L30;
221  }
222  i__1 = nact;
223  for (i = 1; i <= i__1; ++i) {
224  j = iwar[i];
225  u[j] = war[in + i];
226  /* L60: */
227  }
228 L30:
229  return 0;
230 
231  /* ERROR MESSAGES */
232 
233 L70:
234  *ifail = -info + 10;
235  return 0;
236 L80:
237  *ifail = 5;
238  return 0;
239 L81:
240  *ifail = 5;
241  return 0;
242 L82:
243  *ifail = 5;
244  return 0;
245 L40:
246  *ifail = 1;
247  return 0;
248 L90:
249  *ifail = 2;
250  return 0;
251 
252  /* FORMAT-INSTRUCTIONS */
253 
254  } /* ql0001_ */
255 
256 
257 
258 
259 
260 
261 
262 
263 
264 
265 
266  int ObjQLD::ql0002_(int *n,int *m,int *meq,int *mmax,
267  int *mn,int *mnn,int *nmax,
268  long int *lql,
269  double *a,double *b,double *grad,
270  double *g,double *xl,double *xu,double *x,
271  int *nact,int *iact,int *maxit,
272  double *vsmall,
273  int *info,
274  double *diag, double *w,
275  int *lw)
276 
277  {
278  /* System generated locals */
279  int a_dim1, a_offset, g_dim1, g_offset, i__1, i__2, i__3, i__4;
280  double d__1, d__2, d__3, d__4;
281 
282  /* Builtin functions */
283  /* umd */
284  /* double sqrt(); */
285 
286  /* Local variables */
287  double onha, xmag, suma, sumb, sumc, temp, step, zero;
288  int iwwn;
289  double sumx, sumy;
290  int i, j, k;
291  double fdiff;
292  int iflag, jflag, kflag, lflag;
293  double diagr;
294  int ifinc, kfinc, jfinc, mflag, nflag;
295  double vfact, tempa;
296  int iterc, itref;
297  double cvmax, ratio, xmagr;
298  int kdrop;
299  long int lower;
300  int knext, k1;
301  double ga, gb;
302  int ia, id;
303  double fdiffa;
304  int ii, il, kk, jl, ip, ir, nm, is, iu, iw, ju, ix, iz, nu, iy;
305 
306  double parinc, parnew;
307  int ira, irb, iwa;
308  double one;
309  int iwd, iza;
310  double res;
311  int ipp, iwr, iws;
312  double sum;
313  int iww, iwx, iwy;
314  double two;
315  int iwz;
316 
317 
318  /* WHETHER THE CONSTRAINT IS ACTIVE. */
319 
320 
321  /* AUTHOR: K. SCHITTKOWSKI, */
322  /* MATHEMATISCHES INSTITUT, */
323  /* UNIVERSITAET BAYREUTH, */
324  /* 8580 BAYREUTH, */
325  /* GERMANY, F.R. */
326 
327  /* AUTHOR OF ORIGINAL VERSION: */
328  /* M.J.D. POWELL, DAMTP, */
329  /* UNIVERSITY OF CAMBRIDGE, SILVER STREET */
330  /* CAMBRIDGE, */
331  /* ENGLAND */
332 
333 
334  /* REFERENCE: M.J.D. POWELL: ZQPCVX, A FORTRAN SUBROUTINE FOR CONVEX */
335  /* PROGRAMMING, REPORT DAMTP/1983/NA17, UNIVERSITY OF */
336  /* CAMBRIDGE, ENGLAND, 1983. */
337 
338 
339  /* VERSION : 2.0 (MARCH, 1987) */
340 
341 
342  /************************************************************************
343  ***/
344 
345 
346  /* INTRINSIC FUNCTIONS: DMAX1,DSQRT,DABS,DMIN1 */
347 
348 
349  /* INITIAL ADDRESSES */
350 
351  /* Parameter adjustments */
352  --w;
353  --iact;
354  --x;
355  --xu;
356  --xl;
357  g_dim1 = *nmax;
358  g_offset = g_dim1 + 1;
359  g -= g_offset;
360  --grad;
361  --b;
362  a_dim1 = *mmax;
363  a_offset = a_dim1 + 1;
364  a -= a_offset;
365 
366  /* Function Body */
367  iwz = *nmax;
368  iwr = iwz + *nmax * *nmax;
369  iww = iwr + *nmax * (*nmax + 3) / 2;
370  iwd = iww + *nmax;
371  iwx = iwd + *nmax;
372  iwa = iwx + *nmax;
373 
374  /* SET SOME CONSTANTS. */
375 
376  zero = 0.;
377  one = 1.;
378  two = 2.;
379  onha = 1.5;
380  vfact = 1.;
381 
382  /* SET SOME PARAMETERS. */
383  /* NUMBER LESS THAN VSMALL ARE ASSUMED TO BE NEGLIGIBLE. */
384  /* THE MULTIPLE OF I THAT IS ADDED TO G IS AT MOST DIAGR TIMES */
385  /* THE LEAST MULTIPLE OF I THAT GIVES POSITIVE DEFINITENESS. */
386  /* X IS RE-INITIALISED IF ITS MAGNITUDE IS REDUCED BY THE */
387  /* FACTOR XMAGR. */
388  /* A CHECK IS MADE FOR AN INCREASE IN F EVERY IFINC ITERATIONS, */
389  /* AFTER KFINC ITERATIONS ARE COMPLETED. */
390 
391  diagr = two;
392  xmagr = .01;
393  ifinc = 3;
394  kfinc = max(10,*n);
395 
396  /* FIND THE RECIPROCALS OF THE LENGTHS OF THE CONSTRAINT NORMALS. */
397  /* RETURN IF A CONSTRAINT IS INFEASIBLE DUE TO A ZERO NORMAL. */
398 
399  *nact = 0;
400  if (*m <= 0) {
401  goto L45;
402  }
403  i__1 = *m;
404  for (k = 1; k <= i__1; ++k) {
405  sum = zero;
406  i__2 = *n;
407  for (i = 1; i <= i__2; ++i) {
408  /* L10: */
409  /* Computing 2nd power */
410  d__1 = a[k + i * a_dim1];
411  sum += d__1 * d__1;
412  }
413  if (sum > zero) {
414  goto L20;
415  }
416  if (b[k] == zero) {
417  goto L30;
418  }
419  *info = -k;
420  if (k <= *meq) {
421  goto L730;
422  }
423  if (b[k] <= 0.) {
424  goto L30;
425  } else {
426  goto L730;
427  }
428 L20:
429  sum = one / sqrt(sum);
430 L30:
431  ia = iwa + k;
432  /* L40: */
433  w[ia] = sum;
434  }
435 L45:
436  i__1 = *n;
437  for (k = 1; k <= i__1; ++k) {
438  ia = iwa + *m + k;
439  /* L50: */
440  w[ia] = one;
441  }
442 
443  /* IF NECESSARY INCREASE THE DIAGONAL ELEMENTS OF G. */
444 
445  if (! (*lql)) {
446  goto L165;
447  }
448  *diag = zero;
449  i__1 = *n;
450  for (i = 1; i <= i__1; ++i) {
451  id = iwd + i;
452  w[id] = g[i + i * g_dim1];
453  /* Computing MAX */
454  d__1 = *diag, d__2 = *vsmall - w[id];
455  *diag = max(d__1,d__2);
456  if (i == *n) {
457  goto L60;
458  }
459  ii = i + 1;
460  i__2 = *n;
461  for (j = ii; j <= i__2; ++j) {
462  /* Computing MIN */
463  d__1 = w[id], d__2 = g[j + j * g_dim1];
464  ga = -min(d__1,d__2);
465  gb = (d__1 = w[id] - g[j + j * g_dim1], abs(d__1)) + (d__2 = g[i
466  + j * g_dim1], abs(d__2));
467  if (gb > zero) {
468  /* Computing 2nd power */
469  d__1 = g[i + j * g_dim1];
470  ga += d__1 * d__1 / gb;
471  }
472  /* L55: */
473  *diag = max(*diag,ga);
474  }
475 L60:
476  ;
477  }
478  if (*diag <= zero) {
479  goto L90;
480  }
481 L70:
482  *diag = diagr * *diag;
483  i__1 = *n;
484  for (i = 1; i <= i__1; ++i) {
485  id = iwd + i;
486  /* L80: */
487  g[i + i * g_dim1] = *diag + w[id];
488  }
489 
490  /* FORM THE CHOLESKY FACTORISATION OF G. THE TRANSPOSE */
491  /* OF THE FACTOR WILL BE PLACED IN THE R-PARTITION OF W. */
492 
493 L90:
494  ir = iwr;
495  i__1 = *n;
496  for (j = 1; j <= i__1; ++j) {
497  ira = iwr;
498  irb = ir + 1;
499  i__2 = j;
500  for (i = 1; i <= i__2; ++i) {
501  temp = g[i + j * g_dim1];
502  if (i == 1) {
503  goto L110;
504  }
505  i__3 = ir;
506  for (k = irb; k <= i__3; ++k) {
507  ++ira;
508  /* L100: */
509  temp -= w[k] * w[ira];
510  }
511 L110:
512  ++ir;
513  ++ira;
514  if (i < j) {
515  w[ir] = temp / w[ira];
516  }
517  /* L120: */
518  }
519  if (temp < *vsmall) {
520  goto L140;
521  }
522  /* L130: */
523  w[ir] = sqrt(temp);
524  }
525  goto L170;
526 
527  /* INCREASE FURTHER THE DIAGONAL ELEMENT OF G. */
528 
529 L140:
530  w[j] = one;
531  sumx = one;
532  k = j;
533 L150:
534  sum = zero;
535  ira = ir - 1;
536  i__1 = j;
537  for (i = k; i <= i__1; ++i) {
538  sum -= w[ira] * w[i];
539  /* L160: */
540  ira += i;
541  }
542  ir -= k;
543  --k;
544  w[k] = sum / w[ir];
545  /* Computing 2nd power */
546  d__1 = w[k];
547  sumx += d__1 * d__1;
548  if (k >= 2) {
549  goto L150;
550  }
551  *diag = *diag + *vsmall - temp / sumx;
552  goto L70;
553 
554  /* STORE THE CHOLESKY FACTORISATION IN THE R-PARTITION */
555  /* OF W. */
556 
557 L165:
558  ir = iwr;
559  i__1 = *n;
560  for (i = 1; i <= i__1; ++i) {
561  i__2 = i;
562  for (j = 1; j <= i__2; ++j) {
563  ++ir;
564  /* L166: */
565  w[ir] = g[j + i * g_dim1];
566  }
567  }
568 
569  /* SET Z THE INVERSE OF THE MATRIX IN R. */
570 
571 L170:
572  nm = *n - 1;
573  i__2 = *n;
574  for (i = 1; i <= i__2; ++i) {
575  iz = iwz + i;
576  if (i == 1) {
577  goto L190;
578  }
579  i__1 = i;
580  for (j = 2; j <= i__1; ++j) {
581  w[iz] = zero;
582  /* L180: */
583  iz += *n;
584  }
585 L190:
586  ir = iwr + (i + i * i) / 2;
587  w[iz] = one / w[ir];
588  if (i == *n) {
589  goto L220;
590  }
591  iza = iz;
592  i__1 = nm;
593  for (j = i; j <= i__1; ++j) {
594  ir += i;
595  sum = zero;
596  i__3 = iz;
597  i__4 = *n;
598  for (k = iza; i__4 < 0 ? k >= i__3 : k <= i__3; k += i__4) {
599  sum += w[k] * w[ir];
600  /* L200: */
601  ++ir;
602  }
603  iz += *n;
604  /* L210: */
605  w[iz] = -sum / w[ir];
606  }
607 L220:
608  ;
609  }
610 
611  /* SET THE INITIAL VALUES OF SOME VARIABLES. */
612  /* ITERC COUNTS THE NUMBER OF ITERATIONS. */
613  /* ITREF IS SET TO ONE WHEN ITERATIVE REFINEMENT IS REQUIRED. */
614  /* JFINC INDICATES WHEN TO TEST FOR AN INCREASE IN F. */
615 
616  iterc = 1;
617  itref = 0;
618  jfinc = -kfinc;
619 
620  /* SET X TO ZERO AND SET THE CORRESPONDING RESIDUALS OF THE */
621  /* KUHN-TUCKER CONDITIONS. */
622 
623 L230:
624  iflag = 1;
625  iws = iww - *n;
626  i__2 = *n;
627  for (i = 1; i <= i__2; ++i) {
628  x[i] = zero;
629  iw = iww + i;
630  w[iw] = grad[i];
631  if (i > *nact) {
632  goto L240;
633  }
634  w[i] = zero;
635  is = iws + i;
636  k = iact[i];
637  if (k <= *m) {
638  goto L235;
639  }
640  if (k > *mn) {
641  goto L234;
642  }
643  k1 = k - *m;
644  w[is] = xl[k1];
645  goto L240;
646 L234:
647  k1 = k - *mn;
648  w[is] = -xu[k1];
649  goto L240;
650 L235:
651  w[is] = b[k];
652 L240:
653  ;
654  }
655  xmag = zero;
656  vfact = 1.;
657  if (*nact <= 0) {
658  goto L340;
659  } else {
660  goto L280;
661  }
662 
663  /* SET THE RESIDUALS OF THE KUHN-TUCKER CONDITIONS FOR GENERAL X. */
664 
665 L250:
666  iflag = 2;
667  iws = iww - *n;
668  i__2 = *n;
669  for (i = 1; i <= i__2; ++i) {
670  iw = iww + i;
671  w[iw] = grad[i];
672  if (*lql) {
673  goto L259;
674  }
675  id = iwd + i;
676  w[id] = zero;
677  i__1 = *n;
678  for (j = i; j <= i__1; ++j) {
679  /* L251: */
680  w[id] += g[i + j * g_dim1] * x[j];
681  }
682  i__1 = i;
683  for (j = 1; j <= i__1; ++j) {
684  id = iwd + j;
685  /* L252: */
686  w[iw] += g[j + i * g_dim1] * w[id];
687  }
688  goto L260;
689 L259:
690  i__1 = *n;
691  for (j = 1; j <= i__1; ++j) {
692  /* L261: */
693  w[iw] += g[i + j * g_dim1] * x[j];
694  }
695 L260:
696  ;
697  }
698  if (*nact == 0) {
699  goto L340;
700  }
701  i__2 = *nact;
702  for (k = 1; k <= i__2; ++k) {
703  kk = iact[k];
704  is = iws + k;
705  if (kk > *m) {
706  goto L265;
707  }
708  w[is] = b[kk];
709  i__1 = *n;
710  for (i = 1; i <= i__1; ++i) {
711  iw = iww + i;
712  w[iw] -= w[k] * a[kk + i * a_dim1];
713  /* L264: */
714  w[is] -= x[i] * a[kk + i * a_dim1];
715  }
716  goto L270;
717 L265:
718  if (kk > *mn) {
719  goto L266;
720  }
721  k1 = kk - *m;
722  iw = iww + k1;
723  w[iw] -= w[k];
724  w[is] = xl[k1] - x[k1];
725  goto L270;
726 L266:
727  k1 = kk - *mn;
728  iw = iww + k1;
729  w[iw] += w[k];
730  w[is] = -xu[k1] + x[k1];
731 L270:
732  ;
733  }
734 
735  /* PRE-MULTIPLY THE VECTOR IN THE S-PARTITION OF W BY THE */
736  /* INVERS OF R TRANSPOSE. */
737 
738 L280:
739  ir = iwr;
740  ip = iww + 1;
741  ipp = iww + *n;
742  il = iws + 1;
743  iu = iws + *nact;
744  i__2 = iu;
745  for (i = il; i <= i__2; ++i) {
746  sum = zero;
747  if (i == il) {
748  goto L300;
749  }
750  ju = i - 1;
751  i__1 = ju;
752  for (j = il; j <= i__1; ++j) {
753  ++ir;
754  /* L290: */
755  sum += w[ir] * w[j];
756  }
757 L300:
758  ++ir;
759  /* L310: */
760  w[i] = (w[i] - sum) / w[ir];
761  }
762 
763  /* SHIFT X TO SATISFY THE ACTIVE CONSTRAINTS AND MAKE THE */
764  /* CORRESPONDING CHANGE TO THE GRADIENT RESIDUALS. */
765 
766  i__2 = *n;
767  for (i = 1; i <= i__2; ++i) {
768  iz = iwz + i;
769  sum = zero;
770  i__1 = iu;
771  for (j = il; j <= i__1; ++j) {
772  sum += w[j] * w[iz];
773  /* L320: */
774  iz += *n;
775  }
776  x[i] += sum;
777  if (*lql) {
778  goto L329;
779  }
780  id = iwd + i;
781  w[id] = zero;
782  i__1 = *n;
783  for (j = i; j <= i__1; ++j) {
784  /* L321: */
785  w[id] += g[i + j * g_dim1] * sum;
786  }
787  iw = iww + i;
788  i__1 = i;
789  for (j = 1; j <= i__1; ++j) {
790  id = iwd + j;
791  /* L322: */
792  w[iw] += g[j + i * g_dim1] * w[id];
793  }
794  goto L330;
795 L329:
796  i__1 = *n;
797  for (j = 1; j <= i__1; ++j) {
798  iw = iww + j;
799  /* L331: */
800  w[iw] += sum * g[i + j * g_dim1];
801  }
802 L330:
803  ;
804  }
805 
806  /* FORM THE SCALAR PRODUCT OF THE CURRENT GRADIENT RESIDUALS */
807  /* WITH EACH COLUMN OF Z. */
808 
809 L340:
810  kflag = 1;
811  goto L930;
812 L350:
813  if (*nact == *n) {
814  goto L380;
815  }
816 
817  /* SHIFT X SO THAT IT SATISFIES THE REMAINING KUHN-TUCKER */
818  /* CONDITIONS. */
819 
820  il = iws + *nact + 1;
821  iza = iwz + *nact * *n;
822  i__2 = *n;
823  for (i = 1; i <= i__2; ++i) {
824  sum = zero;
825  iz = iza + i;
826  i__1 = iww;
827  for (j = il; j <= i__1; ++j) {
828  sum += w[iz] * w[j];
829  /* L360: */
830  iz += *n;
831  }
832  /* L370: */
833  x[i] -= sum;
834  }
835  *info = 0;
836  if (*nact == 0) {
837  goto L410;
838  }
839 
840  /* UPDATE THE LAGRANGE MULTIPLIERS. */
841 
842 L380:
843  lflag = 3;
844  goto L740;
845 L390:
846  i__2 = *nact;
847  for (k = 1; k <= i__2; ++k) {
848  iw = iww + k;
849  /* L400: */
850  w[k] += w[iw];
851  }
852 
853  /* REVISE THE VALUES OF XMAG. */
854  /* BRANCH IF ITERATIVE REFINEMENT IS REQUIRED. */
855 
856 L410:
857  jflag = 1;
858  goto L910;
859 L420:
860  if (iflag == itref) {
861  goto L250;
862  }
863 
864  /* DELETE A CONSTRAINT IF A LAGRANGE MULTIPLIER OF AN */
865  /* INEQUALITY CONSTRAINT IS NEGATIVE. */
866 
867  kdrop = 0;
868  goto L440;
869 L430:
870  ++kdrop;
871  if (w[kdrop] >= zero) {
872  goto L440;
873  }
874  if (iact[kdrop] <= *meq) {
875  goto L440;
876  }
877  nu = *nact;
878  mflag = 1;
879  goto L800;
880 L440:
881  if (kdrop < *nact) {
882  goto L430;
883  }
884 
885  /* SEEK THE GREATEAST NORMALISED CONSTRAINT VIOLATION, DISREGARDING */
886 
887  /* ANY THAT MAY BE DUE TO COMPUTER ROUNDING ERRORS. */
888 
889 L450:
890  cvmax = zero;
891  if (*m <= 0) {
892  goto L481;
893  }
894  i__2 = *m;
895  for (k = 1; k <= i__2; ++k) {
896  ia = iwa + k;
897  if (w[ia] <= zero) {
898  goto L480;
899  }
900  sum = -b[k];
901  i__1 = *n;
902  for (i = 1; i <= i__1; ++i) {
903  /* L460: */
904  sum += x[i] * a[k + i * a_dim1];
905  }
906  sumx = -sum * w[ia];
907  if (k <= *meq) {
908  sumx = abs(sumx);
909  }
910  if (sumx <= cvmax) {
911  goto L480;
912  }
913  temp = (d__1 = b[k], abs(d__1));
914  i__1 = *n;
915  for (i = 1; i <= i__1; ++i) {
916  /* L470: */
917  temp += (d__1 = x[i] * a[k + i * a_dim1], abs(d__1));
918  }
919  tempa = temp + abs(sum);
920  if (tempa <= temp) {
921  goto L480;
922  }
923  temp += onha * abs(sum);
924  if (temp <= tempa) {
925  goto L480;
926  }
927  cvmax = sumx;
928  res = sum;
929  knext = k;
930 L480:
931  ;
932  }
933 L481:
934  i__2 = *n;
935  for (k = 1; k <= i__2; ++k) {
936  lower = TRUE_;
937  ia = iwa + *m + k;
938  if (w[ia] <= zero) {
939  goto L485;
940  }
941  sum = xl[k] - x[k];
942  if (sum < 0.) {
943  goto L482;
944  } else if (sum == 0) {
945  goto L485;
946  } else {
947  goto L483;
948  }
949 L482:
950  sum = x[k] - xu[k];
951  lower = FALSE_;
952 L483:
953  if (sum <= cvmax) {
954  goto L485;
955  }
956  cvmax = sum;
957  res = -sum;
958  knext = k + *m;
959  if (lower) {
960  goto L485;
961  }
962  knext = k + *mn;
963 L485:
964  ;
965  }
966 
967  /* TEST FOR CONVERGENCE */
968 
969  *info = 0;
970  if (cvmax <= *vsmall) {
971  goto L700;
972  }
973 
974  /* RETURN IF, DUE TO ROUNDING ERRORS, THE ACTUAL CHANGE IN */
975  /* X MAY NOT INCREASE THE OBJECTIVE FUNCTION */
976 
977  ++jfinc;
978  if (jfinc == 0) {
979  goto L510;
980  }
981  if (jfinc != ifinc) {
982  goto L530;
983  }
984  fdiff = zero;
985  fdiffa = zero;
986  i__2 = *n;
987  for (i = 1; i <= i__2; ++i) {
988  sum = two * grad[i];
989  sumx = abs(sum);
990  if (*lql) {
991  goto L489;
992  }
993  id = iwd + i;
994  w[id] = zero;
995  i__1 = *n;
996  for (j = i; j <= i__1; ++j) {
997  ix = iwx + j;
998  /* L486: */
999  w[id] += g[i + j * g_dim1] * (w[ix] + x[j]);
1000  }
1001  i__1 = i;
1002  for (j = 1; j <= i__1; ++j) {
1003  id = iwd + j;
1004  temp = g[j + i * g_dim1] * w[id];
1005  sum += temp;
1006  /* L487: */
1007  sumx += abs(temp);
1008  }
1009  goto L495;
1010 L489:
1011  i__1 = *n;
1012  for (j = 1; j <= i__1; ++j) {
1013  ix = iwx + j;
1014  temp = g[i + j * g_dim1] * (w[ix] + x[j]);
1015  sum += temp;
1016  /* L490: */
1017  sumx += abs(temp);
1018  }
1019 L495:
1020  ix = iwx + i;
1021  fdiff += sum * (x[i] - w[ix]);
1022  /* L500: */
1023  fdiffa += sumx * (d__1 = x[i] - w[ix], abs(d__1));
1024  }
1025  *info = 2;
1026  sum = fdiffa + fdiff;
1027  if (sum <= fdiffa) {
1028  goto L700;
1029  }
1030  temp = fdiffa + onha * fdiff;
1031  if (temp <= sum) {
1032  goto L700;
1033  }
1034  jfinc = 0;
1035  *info = 0;
1036 L510:
1037  i__2 = *n;
1038  for (i = 1; i <= i__2; ++i) {
1039  ix = iwx + i;
1040  /* L520: */
1041  w[ix] = x[i];
1042  }
1043 
1044  /* FORM THE SCALAR PRODUCT OF THE NEW CONSTRAINT NORMAL WITH EACH */
1045  /* COLUMN OF Z. PARNEW WILL BECOME THE LAGRANGE MULTIPLIER OF */
1046  /* THE NEW CONSTRAINT. */
1047 
1048 L530:
1049  ++iterc;
1050  if (iterc <= *maxit) {
1051  goto L531;
1052  }
1053  *info = 1;
1054  goto L710;
1055 L531:
1056  iws = iwr + (*nact + *nact * *nact) / 2;
1057  if (knext > *m) {
1058  goto L541;
1059  }
1060  i__2 = *n;
1061  for (i = 1; i <= i__2; ++i) {
1062  iw = iww + i;
1063  /* L540: */
1064  w[iw] = a[knext + i * a_dim1];
1065  }
1066  goto L549;
1067 L541:
1068  i__2 = *n;
1069  for (i = 1; i <= i__2; ++i) {
1070  iw = iww + i;
1071  /* L542: */
1072  w[iw] = zero;
1073  }
1074  k1 = knext - *m;
1075  if (k1 > *n) {
1076  goto L545;
1077  }
1078  iw = iww + k1;
1079  w[iw] = one;
1080  iz = iwz + k1;
1081  i__2 = *n;
1082  for (i = 1; i <= i__2; ++i) {
1083  is = iws + i;
1084  w[is] = w[iz];
1085  /* L543: */
1086  iz += *n;
1087  }
1088  goto L550;
1089 L545:
1090  k1 = knext - *mn;
1091  iw = iww + k1;
1092  w[iw] = -one;
1093  iz = iwz + k1;
1094  i__2 = *n;
1095  for (i = 1; i <= i__2; ++i) {
1096  is = iws + i;
1097  w[is] = -w[iz];
1098  /* L546: */
1099  iz += *n;
1100  }
1101  goto L550;
1102 L549:
1103  kflag = 2;
1104  goto L930;
1105 L550:
1106  parnew = zero;
1107 
1108  /* APPLY GIVENS ROTATIONS TO MAKE THE LAST (N-NACT-2) SCALAR */
1109  /* PRODUCTS EQUAL TO ZERO. */
1110 
1111  if (*nact == *n) {
1112  goto L570;
1113  }
1114  nu = *n;
1115  nflag = 1;
1116  goto L860;
1117 
1118  /* BRANCH IF THERE IS NO NEED TO DELETE A CONSTRAINT. */
1119 
1120 L560:
1121  is = iws + *nact;
1122  if (*nact == 0) {
1123  goto L640;
1124  }
1125  suma = zero;
1126  sumb = zero;
1127  sumc = zero;
1128  iz = iwz + *nact * *n;
1129  i__2 = *n;
1130  for (i = 1; i <= i__2; ++i) {
1131  ++iz;
1132  iw = iww + i;
1133  suma += w[iw] * w[iz];
1134  sumb += (d__1 = w[iw] * w[iz], abs(d__1));
1135  /* L563: */
1136  /* Computing 2nd power */
1137  d__1 = w[iz];
1138  sumc += d__1 * d__1;
1139  }
1140  temp = sumb + abs(suma) * .1;
1141  tempa = sumb + abs(suma) * .2;
1142  if (temp <= sumb) {
1143  goto L570;
1144  }
1145  if (tempa <= temp) {
1146  goto L570;
1147  }
1148  if (sumb > *vsmall) {
1149  goto L5;
1150  }
1151  goto L570;
1152 L5:
1153  sumc = sqrt(sumc);
1154  ia = iwa + knext;
1155  if (knext <= *m) {
1156  sumc /= w[ia];
1157  }
1158  temp = sumc + abs(suma) * .1;
1159  tempa = sumc + abs(suma) * .2;
1160  if (temp <= sumc) {
1161  goto L567;
1162  }
1163  if (tempa <= temp) {
1164  goto L567;
1165  }
1166  goto L640;
1167 
1168  /* CALCULATE THE MULTIPLIERS FOR THE NEW CONSTRAINT NORMAL */
1169  /* EXPRESSED IN TERMS OF THE ACTIVE CONSTRAINT NORMALS. */
1170  /* THEN WORK OUT WHICH CONTRAINT TO DROP. */
1171 
1172 L567:
1173  lflag = 4;
1174  goto L740;
1175 L570:
1176  lflag = 1;
1177  goto L740;
1178 
1179  /* COMPLETE THE TEST FOR LINEARLY DEPENDENT CONSTRAINTS. */
1180 
1181 L571:
1182  if (knext > *m) {
1183  goto L574;
1184  }
1185  i__2 = *n;
1186  for (i = 1; i <= i__2; ++i) {
1187  suma = a[knext + i * a_dim1];
1188  sumb = abs(suma);
1189  if (*nact == 0) {
1190  goto L581;
1191  }
1192  i__1 = *nact;
1193  for (k = 1; k <= i__1; ++k) {
1194  kk = iact[k];
1195  if (kk <= *m) {
1196  goto L568;
1197  }
1198  kk -= *m;
1199  temp = zero;
1200  if (kk == i) {
1201  temp = w[iww + kk];
1202  }
1203  kk -= *n;
1204  if (kk == i) {
1205  temp = -w[iww + kk];
1206  }
1207  goto L569;
1208 L568:
1209  iw = iww + k;
1210  temp = w[iw] * a[kk + i * a_dim1];
1211 L569:
1212  suma -= temp;
1213  /* L572: */
1214  sumb += abs(temp);
1215  }
1216 L581:
1217  if (suma <= *vsmall) {
1218  goto L573;
1219  }
1220  temp = sumb + abs(suma) * .1;
1221  tempa = sumb + abs(suma) * .2;
1222  if (temp <= sumb) {
1223  goto L573;
1224  }
1225  if (tempa <= temp) {
1226  goto L573;
1227  }
1228  goto L630;
1229 L573:
1230  ;
1231  }
1232  lflag = 1;
1233  goto L775;
1234 L574:
1235  k1 = knext - *m;
1236  if (k1 > *n) {
1237  k1 -= *n;
1238  }
1239  i__2 = *n;
1240  for (i = 1; i <= i__2; ++i) {
1241  suma = zero;
1242  if (i != k1) {
1243  goto L575;
1244  }
1245  suma = one;
1246  if (knext > *mn) {
1247  suma = -one;
1248  }
1249 L575:
1250  sumb = abs(suma);
1251  if (*nact == 0) {
1252  goto L582;
1253  }
1254  i__1 = *nact;
1255  for (k = 1; k <= i__1; ++k) {
1256  kk = iact[k];
1257  if (kk <= *m) {
1258  goto L579;
1259  }
1260  kk -= *m;
1261  temp = zero;
1262  if (kk == i) {
1263  temp = w[iww + kk];
1264  }
1265  kk -= *n;
1266  if (kk == i) {
1267  temp = -w[iww + kk];
1268  }
1269  goto L576;
1270 L579:
1271  iw = iww + k;
1272  temp = w[iw] * a[kk + i * a_dim1];
1273 L576:
1274  suma -= temp;
1275  /* L577: */
1276  sumb += abs(temp);
1277  }
1278 L582:
1279  temp = sumb + abs(suma) * .1;
1280  tempa = sumb + abs(suma) * .2;
1281  if (temp <= sumb) {
1282  goto L578;
1283  }
1284  if (tempa <= temp) {
1285  goto L578;
1286  }
1287  goto L630;
1288 L578:
1289  ;
1290  }
1291  lflag = 1;
1292  goto L775;
1293 
1294  /* BRANCH IF THE CONTRAINTS ARE INCONSISTENT. */
1295 
1296 L580:
1297  *info = -knext;
1298  if (kdrop == 0) {
1299  goto L700;
1300  }
1301  parinc = ratio;
1302  parnew = parinc;
1303 
1304  /* REVISE THE LAGRANGE MULTIPLIERS OF THE ACTIVE CONSTRAINTS. */
1305 
1306 L590:
1307  if (*nact == 0) {
1308  goto L601;
1309  }
1310  i__2 = *nact;
1311  for (k = 1; k <= i__2; ++k) {
1312  iw = iww + k;
1313  w[k] -= parinc * w[iw];
1314  if (iact[k] > *meq) {
1315  /* Computing MAX */
1316  d__1 = zero, d__2 = w[k];
1317  w[k] = max(d__1,d__2);
1318  }
1319  /* L600: */
1320  }
1321 L601:
1322  if (kdrop == 0) {
1323  goto L680;
1324  }
1325 
1326  /* DELETE THE CONSTRAINT TO BE DROPPED. */
1327  /* SHIFT THE VECTOR OF SCALAR PRODUCTS. */
1328  /* THEN, IF APPROPRIATE, MAKE ONE MORE SCALAR PRODUCT ZERO. */
1329 
1330  nu = *nact + 1;
1331  mflag = 2;
1332  goto L800;
1333 L610:
1334  iws = iws - *nact - 1;
1335  nu = min(*n,nu);
1336  i__2 = nu;
1337  for (i = 1; i <= i__2; ++i) {
1338  is = iws + i;
1339  j = is + *nact;
1340  /* L620: */
1341  w[is] = w[j + 1];
1342  }
1343  nflag = 2;
1344  goto L860;
1345 
1346  /* CALCULATE THE STEP TO THE VIOLATED CONSTRAINT. */
1347 
1348 L630:
1349  is = iws + *nact;
1350 L640:
1351  sumy = w[is + 1];
1352  step = -res / sumy;
1353  parinc = step / sumy;
1354  if (*nact == 0) {
1355  goto L660;
1356  }
1357 
1358  /* CALCULATE THE CHANGES TO THE LAGRANGE MULTIPLIERS, AND REDUCE */
1359  /* THE STEP ALONG THE NEW SEARCH DIRECTION IF NECESSARY. */
1360 
1361  lflag = 2;
1362  goto L740;
1363 L650:
1364  if (kdrop == 0) {
1365  goto L660;
1366  }
1367  temp = one - ratio / parinc;
1368  if (temp <= zero) {
1369  kdrop = 0;
1370  }
1371  if (kdrop == 0) {
1372  goto L660;
1373  }
1374  step = ratio * sumy;
1375  parinc = ratio;
1376  res = temp * res;
1377 
1378  /* UPDATE X AND THE LAGRANGE MULTIPIERS. */
1379  /* DROP A CONSTRAINT IF THE FULL STEP IS NOT TAKEN. */
1380 
1381 L660:
1382  iwy = iwz + *nact * *n;
1383  i__2 = *n;
1384  for (i = 1; i <= i__2; ++i) {
1385  iy = iwy + i;
1386  /* L670: */
1387  x[i] += step * w[iy];
1388  }
1389  parnew += parinc;
1390  if (*nact >= 1) {
1391  goto L590;
1392  }
1393 
1394  /* ADD THE NEW CONSTRAINT TO THE ACTIVE SET. */
1395 
1396 L680:
1397  ++(*nact);
1398  w[*nact] = parnew;
1399  iact[*nact] = knext;
1400  ia = iwa + knext;
1401  if (knext > *mn) {
1402  ia -= *n;
1403  }
1404  w[ia] = -w[ia];
1405 
1406  /* ESTIMATE THE MAGNITUDE OF X. THEN BEGIN A NEW ITERATION, */
1407  /* RE-INITILISING X IF THIS MAGNITUDE IS SMALL. */
1408 
1409  jflag = 2;
1410  goto L910;
1411 L690:
1412  if (sum < xmagr * xmag) {
1413  goto L230;
1414  }
1415  if (itref <= 0) {
1416  goto L450;
1417  } else {
1418  goto L250;
1419  }
1420 
1421  /* INITIATE ITERATIVE REFINEMENT IF IT HAS NOT YET BEEN USED, */
1422  /* OR RETURN AFTER RESTORING THE DIAGONAL ELEMENTS OF G. */
1423 
1424 L700:
1425  if (iterc == 0) {
1426  goto L710;
1427  }
1428  ++itref;
1429  jfinc = -1;
1430  if (itref == 1) {
1431  goto L250;
1432  }
1433 L710:
1434  if (! (*lql)) {
1435  return 0;
1436  }
1437  i__2 = *n;
1438  for (i = 1; i <= i__2; ++i) {
1439  id = iwd + i;
1440  /* L720: */
1441  g[i + i * g_dim1] = w[id];
1442  }
1443 L730:
1444  return 0;
1445 
1446 
1447  /* THE REMAINIG INSTRUCTIONS ARE USED AS SUBROUTINES. */
1448 
1449 
1450  /* ******************************************************************** */
1451 
1452 
1453 
1454  /* CALCULATE THE LAGRANGE MULTIPLIERS BY PRE-MULTIPLYING THE */
1455  /* VECTOR IN THE S-PARTITION OF W BY THE INVERSE OF R. */
1456 
1457 L740:
1458  ir = iwr + (*nact + *nact * *nact) / 2;
1459  i = *nact;
1460  sum = zero;
1461  goto L770;
1462 L750:
1463  ira = ir - 1;
1464  sum = zero;
1465  if (*nact == 0) {
1466  goto L761;
1467  }
1468  i__2 = *nact;
1469  for (j = i; j <= i__2; ++j) {
1470  iw = iww + j;
1471  sum += w[ira] * w[iw];
1472  /* L760: */
1473  ira += j;
1474  }
1475 L761:
1476  ir -= i;
1477  --i;
1478 L770:
1479  iw = iww + i;
1480  is = iws + i;
1481  w[iw] = (w[is] - sum) / w[ir];
1482  if (i > 1) {
1483  goto L750;
1484  }
1485  if (lflag == 3) {
1486  goto L390;
1487  }
1488  if (lflag == 4) {
1489  goto L571;
1490  }
1491 
1492  /* CALCULATE THE NEXT CONSTRAINT TO DROP. */
1493 
1494 L775:
1495  ip = iww + 1;
1496  ipp = iww + *nact;
1497  kdrop = 0;
1498  if (*nact == 0) {
1499  goto L791;
1500  }
1501  i__2 = *nact;
1502  for (k = 1; k <= i__2; ++k) {
1503  if (iact[k] <= *meq) {
1504  goto L790;
1505  }
1506  iw = iww + k;
1507  if (res * w[iw] >= zero) {
1508  goto L790;
1509  }
1510  temp = w[k] / w[iw];
1511  if (kdrop == 0) {
1512  goto L780;
1513  }
1514  if (abs(temp) >= abs(ratio)) {
1515  goto L790;
1516  }
1517 L780:
1518  kdrop = k;
1519  ratio = temp;
1520 L790:
1521  ;
1522  }
1523 L791:
1524  switch ((int)lflag) {
1525  case 1: goto L580;
1526  case 2: goto L650;
1527  }
1528 
1529 
1530  /* ******************************************************************** */
1531 
1532 
1533 
1534  /* DROP THE CONSTRAINT IN POSITION KDROP IN THE ACTIVE SET. */
1535 
1536 L800:
1537  ia = iwa + iact[kdrop];
1538  if (iact[kdrop] > *mn) {
1539  ia -= *n;
1540  }
1541  w[ia] = -w[ia];
1542  if (kdrop == *nact) {
1543  goto L850;
1544  }
1545 
1546  /* SET SOME INDICES AND CALCULATE THE ELEMENTS OF THE NEXT */
1547  /* GIVENS ROTATION. */
1548 
1549  iz = iwz + kdrop * *n;
1550  ir = iwr + (kdrop + kdrop * kdrop) / 2;
1551 L810:
1552  ira = ir;
1553  ir = ir + kdrop + 1;
1554  /* Computing MAX */
1555  d__3 = (d__1 = w[ir - 1], abs(d__1)), d__4 = (d__2 = w[ir], abs(d__2));
1556  temp = max(d__3,d__4);
1557  /* Computing 2nd power */
1558  d__1 = w[ir - 1] / temp;
1559  /* Computing 2nd power */
1560  d__2 = w[ir] / temp;
1561  sum = temp * sqrt(d__1 * d__1 + d__2 * d__2);
1562  ga = w[ir - 1] / sum;
1563  gb = w[ir] / sum;
1564 
1565  /* EXCHANGE THE COLUMNS OF R. */
1566 
1567  i__2 = kdrop;
1568  for (i = 1; i <= i__2; ++i) {
1569  ++ira;
1570  j = ira - kdrop;
1571  temp = w[ira];
1572  w[ira] = w[j];
1573  /* L820: */
1574  w[j] = temp;
1575  }
1576  w[ir] = zero;
1577 
1578  /* APPLY THE ROTATION TO THE ROWS OF R. */
1579 
1580  w[j] = sum;
1581  ++kdrop;
1582  i__2 = nu;
1583  for (i = kdrop; i <= i__2; ++i) {
1584  temp = ga * w[ira] + gb * w[ira + 1];
1585  w[ira + 1] = ga * w[ira + 1] - gb * w[ira];
1586  w[ira] = temp;
1587  /* L830: */
1588  ira += i;
1589  }
1590 
1591  /* APPLY THE ROTATION TO THE COLUMNS OF Z. */
1592 
1593  i__2 = *n;
1594  for (i = 1; i <= i__2; ++i) {
1595  ++iz;
1596  j = iz - *n;
1597  temp = ga * w[j] + gb * w[iz];
1598  w[iz] = ga * w[iz] - gb * w[j];
1599  /* L840: */
1600  w[j] = temp;
1601  }
1602 
1603  /* REVISE IACT AND THE LAGRANGE MULTIPLIERS. */
1604 
1605  iact[kdrop - 1] = iact[kdrop];
1606  w[kdrop - 1] = w[kdrop];
1607  if (kdrop < *nact) {
1608  goto L810;
1609  }
1610 L850:
1611  --(*nact);
1612  switch ((int)mflag) {
1613  case 1: goto L250;
1614  case 2: goto L610;
1615  }
1616 
1617 
1618  /* ******************************************************************** */
1619 
1620 
1621 
1622  /* APPLY GIVENS ROTATION TO REDUCE SOME OF THE SCALAR */
1623  /* PRODUCTS IN THE S-PARTITION OF W TO ZERO. */
1624 
1625 L860:
1626  iz = iwz + nu * *n;
1627 L870:
1628  iz -= *n;
1629 L880:
1630  is = iws + nu;
1631  --nu;
1632  if (nu == *nact) {
1633  goto L900;
1634  }
1635  if (w[is] == zero) {
1636  goto L870;
1637  }
1638  /* Computing MAX */
1639  d__3 = (d__1 = w[is - 1], abs(d__1)), d__4 = (d__2 = w[is], abs(d__2));
1640  temp = max(d__3,d__4);
1641  /* Computing 2nd power */
1642  d__1 = w[is - 1] / temp;
1643  /* Computing 2nd power */
1644  d__2 = w[is] / temp;
1645  sum = temp * sqrt(d__1 * d__1 + d__2 * d__2);
1646  ga = w[is - 1] / sum;
1647  gb = w[is] / sum;
1648  w[is - 1] = sum;
1649  i__2 = *n;
1650  for (i = 1; i <= i__2; ++i) {
1651  k = iz + *n;
1652  temp = ga * w[iz] + gb * w[k];
1653  w[k] = ga * w[k] - gb * w[iz];
1654  w[iz] = temp;
1655  /* L890: */
1656  --iz;
1657  }
1658  goto L880;
1659 L900:
1660  switch ((int)nflag) {
1661  case 1: goto L560;
1662  case 2: goto L630;
1663  }
1664 
1665 
1666  /* ******************************************************************** */
1667 
1668 
1669 
1670  /* CALCULATE THE MAGNITUDE OF X AN REVISE XMAG. */
1671 
1672 L910:
1673  sum = zero;
1674  i__2 = *n;
1675  for (i = 1; i <= i__2; ++i) {
1676  sum += (d__1 = x[i], abs(d__1)) * vfact * ((d__2 = grad[i], abs(d__2))
1677  + (d__3 = g[i + i * g_dim1] * x[i], abs(d__3)));
1678  if (*lql) {
1679  goto L920;
1680  }
1681  if (sum < 1e-30) {
1682  goto L920;
1683  }
1684  vfact *= 1e-10;
1685  sum *= 1e-10;
1686  xmag *= 1e-10;
1687 L920:
1688  ;
1689  }
1690  /* L925: */
1691  xmag = max(xmag,sum);
1692  switch ((int)jflag) {
1693  case 1: goto L420;
1694  case 2: goto L690;
1695  }
1696 
1697 
1698  /* ******************************************************************** */
1699 
1700 
1701 
1702  /* PRE-MULTIPLY THE VECTOR IN THE W-PARTITION OF W BY Z TRANSPOSE. */
1703 
1704 L930:
1705  jl = iww + 1;
1706  iz = iwz;
1707  i__2 = *n;
1708  for (i = 1; i <= i__2; ++i) {
1709  is = iws + i;
1710  w[is] = zero;
1711  iwwn = iww + *n;
1712  i__1 = iwwn;
1713  for (j = jl; j <= i__1; ++j) {
1714  ++iz;
1715  /* L940: */
1716  w[is] += w[iz] * w[j];
1717  }
1718  }
1719  switch ((int)kflag) {
1720  case 1: goto L350;
1721  case 2: goto L550;
1722  }
1723  return 0;
1724  } /* ql0002_ */
1725 
1726 
1727  int ObjQLD::resize(void)
1728  {
1729  if(_war.size() <_lwar)
1730  _war.resize(_lwar);
1731  if (_liwar>_iwarCapacity)
1732  {
1733  if (_iwar != 0)
1734  delete[] _iwar;
1735  _iwar = new int[_liwar];
1736  _iwarCapacity = _liwar;
1737  if (!_iwar)
1738  return 1;
1739  }
1740  if (_u.size() <_mnn)
1741  _u.resize(_mnn);
1742 
1743  return 0;
1744  }
1745 }
1746 
1747 // cmake:sourcegroup=Solvers
#define FALSE_
Definition: ObjQLD.h:33
int solve(Map< MatrixXd > &C, const Map< VectorXd > &d, const Map< MatrixXd > &A, const Map< VectorXd > &b, int me, Map< VectorXd > &x, const Map< VectorXd > &xl, const Map< VectorXd > &xu, bool factorizedC=false)
Definition: ObjQLD.cpp:15
const VectorXd & getLagrangeMultipliers(void) const
Definition: ObjQLD.cpp:54
double getSizeFactor(void) const
Definition: ObjQLD.cpp:60
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
#define TRUE_
Definition: ObjQLD.h:32
void setSizeFactor(double f)
Definition: ObjQLD.cpp:66
Declaration file of the ObjQLD class. This class should be merged with ocra::ObjQLD. It has been created to have a cml-free solver.