8 :_lwar(1), _liwar(1), _mnn(1), _sizeFactor(1.), _eps(1.e-8)
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)
18 int m =
static_cast<int>(A.rows());
20 int mmax =
static_cast<int>(A.stride());
21 int n =
static_cast<int>(x.size());
22 int nmax =
static_cast<int>(C.stride());
25 _lwar = (int)(_sizeFactor*(1.5*nmax*nmax + 10*nmax + 2*mmax) + 1.99999999);
26 _liwar = (int) (_sizeFactor*n + 0.9999999);
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());
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);
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,
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\ 89 static char fmt_1400[] =
"(/8x,\002***QL: ACCURACY INSUFFICIENT TO ATTAI\ 93 int c_dim1, c_offset, a_dim1, a_offset, i__1;
103 int i, j, idiag, maxit;
126 a_offset = a_dim1 + 1;
130 c_offset = c_dim1 + 1;
134 cmache_1.eps = *eps1;
140 if (fabs(c[*nmax + *nmax * c_dim1]) == 0.e0) {
141 c[*nmax + *nmax * c_dim1] = cmache_1.eps;
157 maxit = (*m + *n) * 40;
158 qpeps = cmache_1.eps;
169 for (j = 1; j <= i__1; ++j) {
175 lw = *nmax * 3 * *nmax / 2 + *nmax * 10 + *m;
176 if (inw2 + lw > *lwar) {
182 if (*mnn < *m + *n + *n) {
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);
203 if (diag > zero && diag < 1e3) {
214 for (j = 1; j <= i__1; ++j) {
223 for (i = 1; i <= i__1; ++i) {
266 int ObjQLD::ql0002_(
int *n,
int *m,
int *meq,
int *mmax,
267 int *mn,
int *mnn,
int *nmax,
269 double *a,
double *b,
double *grad,
270 double *g,
double *xl,
double *xu,
double *x,
271 int *nact,
int *iact,
int *maxit,
274 double *diag,
double *w,
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;
287 double onha, xmag, suma, sumb, sumc, temp, step, zero;
292 int iflag, jflag, kflag, lflag;
294 int ifinc, kfinc, jfinc, mflag, nflag;
297 double cvmax, ratio, xmagr;
304 int ii, il, kk, jl, ip, ir, nm, is, iu, iw, ju, ix, iz, nu, iy;
306 double parinc, parnew;
358 g_offset = g_dim1 + 1;
363 a_offset = a_dim1 + 1;
368 iwr = iwz + *nmax * *nmax;
369 iww = iwr + *nmax * (*nmax + 3) / 2;
404 for (k = 1; k <= i__1; ++k) {
407 for (i = 1; i <= i__2; ++i) {
410 d__1 = a[k + i * a_dim1];
429 sum = one / sqrt(sum);
437 for (k = 1; k <= i__1; ++k) {
450 for (i = 1; i <= i__1; ++i) {
452 w[id] = g[i + i * g_dim1];
454 d__1 = *diag, d__2 = *vsmall - w[id];
455 *diag = max(d__1,d__2);
461 for (j = ii; j <= i__2; ++j) {
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));
469 d__1 = g[i + j * g_dim1];
470 ga += d__1 * d__1 / gb;
473 *diag = max(*diag,ga);
482 *diag = diagr * *diag;
484 for (i = 1; i <= i__1; ++i) {
487 g[i + i * g_dim1] = *diag + w[id];
496 for (j = 1; j <= i__1; ++j) {
500 for (i = 1; i <= i__2; ++i) {
501 temp = g[i + j * g_dim1];
506 for (k = irb; k <= i__3; ++k) {
509 temp -= w[k] * w[ira];
515 w[ir] = temp / w[ira];
519 if (temp < *vsmall) {
537 for (i = k; i <= i__1; ++i) {
538 sum -= w[ira] * w[i];
551 *diag = *diag + *vsmall - temp / sumx;
560 for (i = 1; i <= i__1; ++i) {
562 for (j = 1; j <= i__2; ++j) {
565 w[ir] = g[j + i * g_dim1];
574 for (i = 1; i <= i__2; ++i) {
580 for (j = 2; j <= i__1; ++j) {
586 ir = iwr + (i + i * i) / 2;
593 for (j = i; j <= i__1; ++j) {
598 for (k = iza; i__4 < 0 ? k >= i__3 : k <= i__3; k += i__4) {
605 w[iz] = -sum / w[ir];
627 for (i = 1; i <= i__2; ++i) {
669 for (i = 1; i <= i__2; ++i) {
678 for (j = i; j <= i__1; ++j) {
680 w[id] += g[i + j * g_dim1] * x[j];
683 for (j = 1; j <= i__1; ++j) {
686 w[iw] += g[j + i * g_dim1] * w[id];
691 for (j = 1; j <= i__1; ++j) {
693 w[iw] += g[i + j * g_dim1] * x[j];
702 for (k = 1; k <= i__2; ++k) {
710 for (i = 1; i <= i__1; ++i) {
712 w[iw] -= w[k] * a[kk + i * a_dim1];
714 w[is] -= x[i] * a[kk + i * a_dim1];
724 w[is] = xl[k1] - x[k1];
730 w[is] = -xu[k1] + x[k1];
745 for (i = il; i <= i__2; ++i) {
752 for (j = il; j <= i__1; ++j) {
760 w[i] = (w[i] - sum) / w[ir];
767 for (i = 1; i <= i__2; ++i) {
771 for (j = il; j <= i__1; ++j) {
783 for (j = i; j <= i__1; ++j) {
785 w[id] += g[i + j * g_dim1] * sum;
789 for (j = 1; j <= i__1; ++j) {
792 w[iw] += g[j + i * g_dim1] * w[id];
797 for (j = 1; j <= i__1; ++j) {
800 w[iw] += sum * g[i + j * g_dim1];
820 il = iws + *nact + 1;
821 iza = iwz + *nact * *n;
823 for (i = 1; i <= i__2; ++i) {
827 for (j = il; j <= i__1; ++j) {
847 for (k = 1; k <= i__2; ++k) {
860 if (iflag == itref) {
871 if (w[kdrop] >= zero) {
874 if (iact[kdrop] <= *meq) {
895 for (k = 1; k <= i__2; ++k) {
902 for (i = 1; i <= i__1; ++i) {
904 sum += x[i] * a[k + i * a_dim1];
913 temp = (d__1 = b[k], abs(d__1));
915 for (i = 1; i <= i__1; ++i) {
917 temp += (d__1 = x[i] * a[k + i * a_dim1], abs(d__1));
919 tempa = temp + abs(sum);
923 temp += onha * abs(sum);
935 for (k = 1; k <= i__2; ++k) {
944 }
else if (sum == 0) {
970 if (cvmax <= *vsmall) {
981 if (jfinc != ifinc) {
987 for (i = 1; i <= i__2; ++i) {
996 for (j = i; j <= i__1; ++j) {
999 w[id] += g[i + j * g_dim1] * (w[ix] + x[j]);
1002 for (j = 1; j <= i__1; ++j) {
1004 temp = g[j + i * g_dim1] * w[id];
1012 for (j = 1; j <= i__1; ++j) {
1014 temp = g[i + j * g_dim1] * (w[ix] + x[j]);
1021 fdiff += sum * (x[i] - w[ix]);
1023 fdiffa += sumx * (d__1 = x[i] - w[ix], abs(d__1));
1026 sum = fdiffa + fdiff;
1027 if (sum <= fdiffa) {
1030 temp = fdiffa + onha * fdiff;
1038 for (i = 1; i <= i__2; ++i) {
1050 if (iterc <= *maxit) {
1056 iws = iwr + (*nact + *nact * *nact) / 2;
1061 for (i = 1; i <= i__2; ++i) {
1064 w[iw] = a[knext + i * a_dim1];
1069 for (i = 1; i <= i__2; ++i) {
1082 for (i = 1; i <= i__2; ++i) {
1095 for (i = 1; i <= i__2; ++i) {
1128 iz = iwz + *nact * *n;
1130 for (i = 1; i <= i__2; ++i) {
1133 suma += w[iw] * w[iz];
1134 sumb += (d__1 = w[iw] * w[iz], abs(d__1));
1138 sumc += d__1 * d__1;
1140 temp = sumb + abs(suma) * .1;
1141 tempa = sumb + abs(suma) * .2;
1145 if (tempa <= temp) {
1148 if (sumb > *vsmall) {
1158 temp = sumc + abs(suma) * .1;
1159 tempa = sumc + abs(suma) * .2;
1163 if (tempa <= temp) {
1186 for (i = 1; i <= i__2; ++i) {
1187 suma = a[knext + i * a_dim1];
1193 for (k = 1; k <= i__1; ++k) {
1205 temp = -w[iww + kk];
1210 temp = w[iw] * a[kk + i * a_dim1];
1217 if (suma <= *vsmall) {
1220 temp = sumb + abs(suma) * .1;
1221 tempa = sumb + abs(suma) * .2;
1225 if (tempa <= temp) {
1240 for (i = 1; i <= i__2; ++i) {
1255 for (k = 1; k <= i__1; ++k) {
1267 temp = -w[iww + kk];
1272 temp = w[iw] * a[kk + i * a_dim1];
1279 temp = sumb + abs(suma) * .1;
1280 tempa = sumb + abs(suma) * .2;
1284 if (tempa <= temp) {
1311 for (k = 1; k <= i__2; ++k) {
1313 w[k] -= parinc * w[iw];
1314 if (iact[k] > *meq) {
1316 d__1 = zero, d__2 = w[k];
1317 w[k] = max(d__1,d__2);
1334 iws = iws - *nact - 1;
1337 for (i = 1; i <= i__2; ++i) {
1353 parinc = step / sumy;
1367 temp = one - ratio / parinc;
1374 step = ratio * sumy;
1382 iwy = iwz + *nact * *n;
1384 for (i = 1; i <= i__2; ++i) {
1387 x[i] += step * w[iy];
1399 iact[*nact] = knext;
1412 if (sum < xmagr * xmag) {
1438 for (i = 1; i <= i__2; ++i) {
1441 g[i + i * g_dim1] = w[id];
1458 ir = iwr + (*nact + *nact * *nact) / 2;
1469 for (j = i; j <= i__2; ++j) {
1471 sum += w[ira] * w[iw];
1481 w[iw] = (w[is] - sum) / w[ir];
1502 for (k = 1; k <= i__2; ++k) {
1503 if (iact[k] <= *meq) {
1507 if (res * w[iw] >= zero) {
1510 temp = w[k] / w[iw];
1514 if (abs(temp) >= abs(ratio)) {
1524 switch ((
int)lflag) {
1537 ia = iwa + iact[kdrop];
1538 if (iact[kdrop] > *mn) {
1542 if (kdrop == *nact) {
1549 iz = iwz + kdrop * *n;
1550 ir = iwr + (kdrop + kdrop * kdrop) / 2;
1553 ir = ir + kdrop + 1;
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);
1558 d__1 = w[ir - 1] / temp;
1560 d__2 = w[ir] / temp;
1561 sum = temp * sqrt(d__1 * d__1 + d__2 * d__2);
1562 ga = w[ir - 1] / sum;
1568 for (i = 1; i <= i__2; ++i) {
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];
1594 for (i = 1; i <= i__2; ++i) {
1597 temp = ga * w[j] + gb * w[iz];
1598 w[iz] = ga * w[iz] - gb * w[j];
1605 iact[kdrop - 1] = iact[kdrop];
1606 w[kdrop - 1] = w[kdrop];
1607 if (kdrop < *nact) {
1612 switch ((
int)mflag) {
1635 if (w[is] == zero) {
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);
1642 d__1 = w[is - 1] / temp;
1644 d__2 = w[is] / temp;
1645 sum = temp * sqrt(d__1 * d__1 + d__2 * d__2);
1646 ga = w[is - 1] / sum;
1650 for (i = 1; i <= i__2; ++i) {
1652 temp = ga * w[iz] + gb * w[k];
1653 w[k] = ga * w[k] - gb * w[iz];
1660 switch ((
int)nflag) {
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)));
1691 xmag = max(xmag,sum);
1692 switch ((
int)jflag) {
1708 for (i = 1; i <= i__2; ++i) {
1713 for (j = jl; j <= i__1; ++j) {
1716 w[is] += w[iz] * w[j];
1719 switch ((
int)kflag) {
1727 int ObjQLD::resize(
void)
1729 if(_war.size() <_lwar)
1731 if (_liwar>_iwarCapacity)
1735 _iwar =
new int[_liwar];
1736 _iwarCapacity = _liwar;
1740 if (_u.size() <_mnn)
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)
const VectorXd & getLagrangeMultipliers(void) const
double getSizeFactor(void) const
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
void setSizeFactor(double f)
Declaration file of the ObjQLD class. This class should be merged with ocra::ObjQLD. It has been created to have a cml-free solver.