36 #include <qpOASES/QProblem.hpp> 217 for( i=0; i<nV*nV; ++i )
287 const char*
const lb_file,
const char*
const ub_file,
288 const char*
const lbA_file,
const char*
const ubA_file,
336 if ( guessedBounds != 0 )
338 for( i=0; i<nV; ++i )
345 if ( guessedConstraints != 0 )
347 for( i=0; i<nC; ++i )
353 if ( ( xOpt == 0 ) && ( yOpt != 0 ) && ( ( guessedBounds != 0 ) || ( guessedConstraints != 0 ) ) )
361 return solveInitialQP( xOpt,yOpt,guessedBounds,guessedConstraints, nWSR,cputime );
390 if ( guessedBounds != 0 )
392 for( i=0; i<nV; ++i )
399 if ( guessedConstraints != 0 )
401 for( i=0; i<nC; ++i )
407 if ( ( xOpt == 0 ) && ( yOpt != 0 ) && ( ( guessedBounds != 0 ) || ( guessedConstraints != 0 ) ) )
415 return solveInitialQP( xOpt,yOpt,guessedBounds,guessedConstraints, nWSR,cputime );
423 const char*
const lb_file,
const char*
const ub_file,
424 const char*
const lbA_file,
const char*
const ubA_file,
444 for( i=0; i<nV; ++i )
450 for( i=0; i<nC; ++i )
455 if ( ( xOpt == 0 ) && ( yOpt != 0 ) && ( ( guessedBounds != 0 ) || ( guessedConstraints != 0 ) ) )
463 return solveInitialQP( xOpt,yOpt,guessedBounds,guessedConstraints, nWSR,cputime );
532 int nWSR_performed = 0;
535 real_t cputime_needed = 0.0;
563 for (i = 0; i < nV; i++)
566 for (i = 0; i < nV; i++)
569 for (i = 0; i < nC; i++)
572 for (i = 0; i < nC; i++)
578 for ( i=0; i<nV; ++i )
580 t =
static_cast<real_t>(i) / static_cast<real_t>(nV+nC-1);
581 rampVal = farbound + (1.0-t) *
ramp0 + t *
ramp1;
584 lb_new_far[i] = - rampVal;
586 lb_new_far[i] =
lb_new[i];
588 ub_new_far[i] = rampVal;
590 ub_new_far[i] =
ub_new[i];
592 for ( i=0; i<nC; ++i )
594 t =
static_cast<real_t>(nV+i) / static_cast<real_t>(nV+nC-1);
595 rampVal = farbound + (1.0-t) *
ramp0 + t *
ramp1;
598 lbA_new_far[i] = - rampVal;
602 ubA_new_far[i] = rampVal;
609 for ( i=0; i<nV; ++i )
611 lb_new_far[i] =
lb_new[i];
612 ub_new_far[i] =
ub_new[i];
615 for ( i=0; i<nC; ++i )
633 cputime_remaining = *cputime - cputime_needed;
638 returnvalue =
solveQP(
g_new,lb_new_far,ub_new_far,lbA_new_far,ubA_new_far,
nWSR,&cputime_remaining,nWSR_performed );
640 nWSR_performed =
nWSR;
641 cputime_needed += cputime_remaining;
647 real_t maxFarbound = 1e20;
650 if ( farbound > maxFarbound )
659 for ( i=0; i<nV; ++i )
661 t =
static_cast<real_t>(i) / static_cast<real_t>(nV+nC-1);
662 rampVal = farbound + (1.0-t) *
ramp0 + t *
ramp1;
665 lb_new_far[i] = - rampVal;
670 ub_new_far[i] = rampVal;
674 for ( i=0; i<nC; ++i )
676 t =
static_cast<real_t>(nV+i) / static_cast<real_t>(nV+nC-1);
677 rampVal = farbound + (1.0-t) *
ramp0 + t *
ramp1;
680 lbA_new_far[i] = - rampVal;
685 ubA_new_far[i] = rampVal;
692 for ( i=0; i<nV; ++i )
694 lb_new_far[i] =
lb_new[i];
695 ub_new_far[i] =
ub_new[i];
698 for ( i=0; i<nC; ++i )
711 for ( i=0; i<nV; ++i )
713 if ( ( (
lb_new == 0 ) || ( lb_new_far[i] >
lb_new[i] ) ) && ( fabs ( lb_new_far[i] -
x[i] ) < tol ) )
715 if ( ( (
ub_new == 0 ) || ( ub_new_far[i] <
ub_new[i] ) ) && ( fabs ( ub_new_far[i] -
x[i] ) < tol ) )
718 for ( i=0; i<nC; ++i )
720 if ( ( (
lbA_new == 0 ) || ( lbA_new_far[i] >
lbA_new[i] ) ) && ( fabs ( lbA_new_far[i] -
Ax[i] ) < tol ) )
722 if ( ( (
ubA_new == 0 ) || ( ubA_new_far[i] <
ubA_new[i] ) ) && ( fabs ( ubA_new_far[i] -
Ax[i] ) < tol ) )
729 if ( farbound > maxFarbound )
739 for ( i=0; i<nV; ++i )
741 t =
static_cast<real_t>(i) / static_cast<real_t>(nV+nC-1);
742 rampVal = farbound + (1.0-t) *
ramp0 + t *
ramp1;
745 lb_new_far[i] = - rampVal;
750 ub_new_far[i] = rampVal;
754 for ( i=0; i<nC; ++i )
756 t =
static_cast<real_t>(nV+i) / static_cast<real_t>(nV+nC-1);
757 rampVal = farbound + (1.0-t) *
ramp0 + t *
ramp1;
760 lbA_new_far[i] = - rampVal;
765 ubA_new_far[i] = rampVal;
772 for ( i=0; i<nV; ++i )
774 lb_new_far[i] =
lb_new[i];
775 ub_new_far[i] =
ub_new[i];
778 for ( i=0; i<nC; ++i )
797 *cputime = cputime_needed;
798 delete[] lbA_new_far;
delete[] ubA_new_far;
799 delete[] lb_new_far;
delete[] ub_new_far;
810 const char*
const lb_file,
const char*
const ub_file,
811 const char*
const lbA_file,
const char*
const ubA_file,
845 g_new,lb_new,ub_new,lbA_new,ubA_new
863 returnvalue =
hotstart( g_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,cputime );
904 if ( ( guessedBounds != 0 ) && ( guessedConstraints != 0 ) )
910 if ( ( guessedBounds == 0 ) && ( guessedConstraints != 0 ) )
921 if ( ( guessedBounds != 0 ) && ( guessedConstraints == 0 ) )
932 if ( ( guessedBounds == 0 ) && ( guessedConstraints == 0 ) )
969 const char*
const lb_file,
const char*
const ub_file,
970 const char*
const lbA_file,
const char*
const ubA_file,
1000 ubA_new =
new real_t[nC];
1005 g_new,lb_new,ub_new,lbA_new,ubA_new
1009 if ( ubA_file != 0 )
1011 if ( lbA_file != 0 )
1023 returnvalue =
hotstart( g_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,cputime,
1024 guessedBounds,guessedConstraints
1028 if ( ubA_file != 0 )
1030 if ( lbA_file != 0 )
1077 for ( ii = 0 ; ii < n_rhs; ++ii )
1081 delta_xFX, delta_xFR, delta_yAC, delta_yFX );
1083 for ( jj = 0; jj < nFX; ++jj )
1084 x_out[FX_idx[jj]] = delta_xFX[jj];
1085 for ( jj = 0; jj < nFR; ++jj )
1086 x_out[FR_idx[jj]] = delta_xFR[jj];
1087 for ( jj = 0; jj < nFX; ++jj )
1088 y_out[FX_idx[jj]] = delta_yFX[jj];
1089 for ( jj = 0; jj < nAC; ++jj )
1090 y_out[nV+AC_idx[jj]] = delta_yAC[jj];
1091 for ( jj = 0; jj < nFR; ++jj )
1092 y_out[FR_idx[jj]] = 0.0;
1166 #ifndef __XPCTARGET__ 1171 char myPrintfString[80];
1173 myPrintf(
"\n################# qpOASES -- QP PROPERTIES #################\n" );
1177 snprintf( myPrintfString,80,
"Number of Variables: %4.1d\n",
getNV( ) );
1181 myPrintf(
"Variables are not bounded from below.\n" );
1183 myPrintf(
"Variables are bounded from below.\n" );
1186 myPrintf(
"Variables are not bounded from above.\n" );
1188 myPrintf(
"Variables are bounded from above.\n" );
1194 snprintf( myPrintfString,80,
"Total number of Constraints: %4.1d\n",
getNC( ) );
1197 snprintf( myPrintfString,80,
"Number of Equality Constraints: %4.1d\n",
getNEC( ) );
1200 snprintf( myPrintfString,80,
"Number of Inequality Constraints: %4.1d\n",
getNC( )-
getNEC( ) );
1206 myPrintf(
"Constraints are not bounded from below.\n" );
1208 myPrintf(
"Constraints are bounded from below.\n" );
1211 myPrintf(
"Constraints are not bounded from above.\n" );
1213 myPrintf(
"Constraints are bounded from above.\n" );
1223 myPrintf(
"Hessian is zero matrix (i.e. actually an LP is solved).\n" );
1227 myPrintf(
"Hessian is identity matrix.\n" );
1231 myPrintf(
"Hessian matrix is (strictly) positive definite.\n" );
1235 myPrintf(
"Hessian matrix is positive definite on null space of active constraints.\n" );
1239 myPrintf(
"Hessian matrix is positive semi-definite.\n" );
1243 myPrintf(
"Hessian matrix has unknown type.\n" );
1248 myPrintf(
"QP was found to be infeasible.\n" );
1250 myPrintf(
"QP seems to be feasible.\n" );
1253 myPrintf(
"QP was found to be unbounded from below.\n" );
1255 myPrintf(
"QP seems to be bounded from below.\n" );
1264 myPrintf(
"Status of QP object: freshly instantiated or reset.\n" );
1268 myPrintf(
"Status of QP object: an auxiliary QP is currently setup.\n" );
1272 myPrintf(
"Status of QP object: an auxilary QP was solved.\n" );
1276 myPrintf(
"Status of QP object: a homotopy step is performed.\n" );
1280 myPrintf(
"Status of QP object: an intermediate QP along the homotopy path was solved.\n" );
1284 myPrintf(
"Status of QP object: solution of the actual QP was found.\n" );
1291 myPrintf(
"Print level of QP object is low, i.e. only error are printed.\n" );
1295 myPrintf(
"Print level of QP object is medium, i.e. error and warnings are printed.\n" );
1299 myPrintf(
"Print level of QP object is high, i.e. all available output is printed.\n" );
1417 int _nV = rhs.
getNV( );
1418 int _nC = rhs.
getNC( );
1431 A = rhs.
A->duplicate();
1455 memcpy(
y,rhs.
y,(_nV+_nC)*
sizeof(
real_t) );
1473 memcpy(
Q,rhs.
Q,_nV*_nV*
sizeof(
real_t) );
1486 if ( rhs.
Ax_l != 0 )
1494 if ( rhs.
Ax_u != 0 )
1553 #ifdef __MANY_CONSTRAINTS__ 1557 for( i=0; i<nC; ++i )
1560 for( j=0; j<nV; ++j )
1561 l1 += fabs(
AA(i,j) );
1563 if ( l1 > 1.0 + 10.0*
EPS )
1592 Bounds auxiliaryBounds( nV );
1624 for( i=0; i<nV; ++i )
1626 g_original[i] =
g[i];
1627 lb_original[i] =
lb[i];
1628 ub_original[i] =
ub[i];
1631 for( i=0; i<nC; ++i )
1633 lbA_original[i] =
lbA[i];
1634 ubA_original[i] =
ubA[i];
1641 delete[] ubA_original;
delete[] lbA_original;
delete[] ub_original;
delete[] lb_original;
delete[] g_original;
1647 delete[] ubA_original;
delete[] lbA_original;
delete[] ub_original;
delete[] lb_original;
delete[] g_original;
1664 returnValue returnvalue =
hotstart( g_original,lb_original,ub_original,lbA_original,ubA_original,
nWSR,cputime );
1667 delete[] ubA_original;
delete[] lbA_original;
delete[] ub_original;
delete[] lb_original;
delete[] g_original;
1697 int&
nWSR,
real_t*
const cputime,
int nWSRperformed
1741 char messageString[80];
1754 for( iter=nWSRperformed; iter<
nWSR; ++iter )
1768 #ifndef __XPCTARGET__ 1769 snprintf( messageString,80,
"%d ...",iter );
1775 delta_g,delta_lbA,delta_ubA,delta_lb,delta_ub,
1776 Delta_bC_isZero, Delta_bB_isZero
1780 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1781 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1794 Delta_bC_isZero, Delta_bB_isZero,
1795 delta_xFX,delta_xFR,delta_yAC,delta_yFX
1799 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1800 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1813 returnvalue =
performStep( delta_g, delta_lbA,delta_ubA,delta_lb,delta_ub,
1814 delta_xFX,delta_xFR,delta_yAC,delta_yFX,
1815 BC_idx,BC_status,BC_isBound
1819 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1820 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1846 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1847 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1857 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1858 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1887 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1888 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1894 #ifdef __DEBUG_ITER__ 1898 real_t stat, bfeas, cfeas, bcmpl, ccmpl, errUnitary, errTQ, Tmaxomin;
1903 stat = bfeas = cfeas = bcmpl = ccmpl = errUnitary = errTQ = Tmaxomin = 0.0;
1906 for (i = 0; i < nV; i++) grad[i] =
g[i] -
y[i];
1907 H->
times(1, 1.0,
x, nV, 1.0, grad, nV);
1908 A->transTimes(1, -1.0,
y+nV, nC, 1.0, grad, nV);
1909 for (i = 0; i < nV; i++) if (fabs(grad[i]) > stat) stat = fabs(grad[i]);
1912 for (i = 0; i < nV; i++)
if (
lb[i] -
x[i] > bfeas) bfeas =
lb[i] -
x[i];
1913 for (i = 0; i < nV; i++)
if (x[i] -
ub[i] > bfeas) bfeas = x[i] -
ub[i];
1914 A->times(1, 1.0, x, nV, 0.0, AX, nC);
1915 for (i = 0; i < nC; i++)
if (
lbA[i] - AX[i] > cfeas) cfeas =
lbA[i] - AX[i];
1916 for (i = 0; i < nC; i++)
if (AX[i] -
ubA[i] > cfeas) cfeas = AX[i] -
ubA[i];
1919 for (i = 0; i < nV; i++) if (y[i] > +
EPS && fabs((
lb[i] - x[i])*
y[i]) > bcmpl) bcmpl = fabs((
lb[i] - x[i])*
y[i]);
1920 for (i = 0; i < nV; i++)
if (
y[i] < -
EPS && fabs((ub[i] - x[i])*
y[i]) > bcmpl) bcmpl = fabs((ub[i] - x[i])*
y[i]);
1921 for (i = 0; i < nC; i++) if (y[nV+i] > +
EPS && fabs((
lbA[i]-AX[i])*
y[nV+i]) > ccmpl) ccmpl = fabs((
lbA[i]-AX[i])*
y[nV+i]);
1922 for (i = 0; i < nC; i++)
if (
y[nV+i] < -
EPS && fabs((ubA[i]-AX[i])*
y[nV+i]) > ccmpl) ccmpl = fabs((ubA[i]-AX[i])*
y[nV+i]);
1924 Tmin = 1.0e16; Tmax = 0.0;
1925 for (i = 0; i < nAC; i++)
1926 if (fabs(
TT(i,
sizeT-i-1)) < Tmin)
1928 else if (fabs(
TT(i,
sizeT-i-1)) > Tmax)
1930 Tmaxomin = Tmax/Tmin;
1933 fprintf(stderr,
"\n%5s %4s %4s %4s %4s %9s %9s %9s %9s %9s %9s %9s %9s\n",
1934 "iter",
"addB",
"remB",
"addC",
"remC",
"hom len",
"tau",
"stat",
1935 "bfeas",
"cfeas",
"bcmpl",
"ccmpl",
"Tmin");
1936 fprintf(stderr,
"%5d ", iter);
1938 else fprintf(stderr,
"%4s ",
" ");
1940 else fprintf(stderr,
"%4s ",
" ");
1942 else fprintf(stderr,
"%4s ",
" ");
1944 else fprintf(stderr,
"%4s ",
" ");
1945 fprintf(stderr,
"%9.2e %9.2e %9.2e %9.2e %9.2e %9.2e %9.2e %9.2e\n",
1946 homotopyLength,
tau, stat, bfeas, cfeas, bcmpl, ccmpl, Tmin);
1954 fprintf(stdout,
"\n%5s %5s %5s %5s %5s %9s %9s\n",
1955 "iter",
"addB",
"remB",
"addC",
"remC",
"hom len",
"tau");
1956 fprintf(stdout,
"%5d ", iter);
1958 else fprintf(stdout,
"%5s ",
" ");
1960 else fprintf(stdout,
"%5s ",
" ");
1962 else fprintf(stdout,
"%5s ",
" ");
1964 else fprintf(stdout,
"%5s ",
" ");
1965 fprintf(stdout,
"%9.2e %9.2e\n", homotopyLength,
tau);
1985 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1986 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1997 #ifndef __XPCTARGET__ 1998 snprintf( messageString,80,
"(nWSR = %d)",iter );
2017 int&
nWSR,
real_t*
const cputime,
int nWSRperformed
2026 return solveQP( g_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,cputime,nWSRperformed );
2032 int nWSR_max =
nWSR;
2033 int nWSR_total = nWSRperformed;
2035 real_t cputime_total = 0.0;
2036 real_t cputime_cur = 0.0;
2040 returnvalue =
solveQP( g_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,0,nWSRperformed );
2044 cputime_cur = *cputime;
2045 returnvalue =
solveQP( g_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,&cputime_cur,nWSRperformed );
2048 cputime_total += cputime_cur;
2054 *cputime = cputime_total;
2070 for( i=0; i<nV; ++i )
2079 returnvalue =
solveQP( gMod,lb_new,ub_new,lbA_new,ubA_new, nWSR,0,nWSR_total );
2084 cputime_cur = *cputime - cputime_total;
2085 returnvalue =
solveQP( gMod,lb_new,ub_new,lbA_new,ubA_new, nWSR,&cputime_cur,nWSR_total );
2089 cputime_total += cputime_cur;
2097 *cputime = cputime_total;
2109 *cputime = cputime_total;
2145 for( i=0; i<nC; ++i )
2147 if ( lbA_new[i] > -
INFTY )
2159 for( i=0; i<nC; ++i )
2161 if ( ubA_new[i] <
INFTY )
2170 if ( ( lbA_new != 0 ) && ( ubA_new != 0 ) )
2172 for( i=0; i<nC; ++i )
2190 if ( ( lbA_new == 0 ) && ( ubA_new == 0 ) )
2192 for( i=0; i<nC; ++i )
2197 for( i=0; i<nC; ++i )
2216 for( i=0; i<nV*nV; ++i )
2229 for( i=0; i<nV; ++i )
2238 for( i=0; i<nV; ++i )
2255 for ( j=0; j < nZ; ++j ) {
2256 for ( i=0; i < nV; ++i )
2258 QQ(FR_idx[j],j) = 1.0;
2262 for ( j=0; j < nFR; ++j )
2271 unsigned long _nZ = nZ, _nV = nV;
2273 POTRF (
"U", &_nZ,
R, &_nV, &info);
2282 for (i=0;i<nZ-1;++i)
2304 for( i=0; i<nV*nV; ++i )
2307 for( i=0; i<nFR; ++i )
2335 if ( ( auxiliaryBounds == 0 ) || ( auxiliaryBounds == guessedBounds ) )
2338 if ( ( auxiliaryConstraints == 0 ) || ( auxiliaryConstraints == guessedConstraints ) )
2349 if ( guessedConstraints != 0 )
2353 for( i=0; i<nC; ++i )
2356 guessedStatus = guessedConstraints->
getStatus( i );
2358 #ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ 2375 if ( (
xOpt != 0 ) && ( yOpt == 0 ) )
2377 for( i=0; i<nC; ++i )
2394 #ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ 2410 if ( (
xOpt == 0 ) && ( yOpt != 0 ) )
2412 for( i=0; i<nC; ++i )
2414 if ( yOpt[nV+i] >
EPS )
2421 if ( yOpt[nV+i] < -
EPS )
2429 #ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ 2447 if ( (
xOpt == 0 ) && ( yOpt == 0 ) )
2449 for( i=0; i<nC; ++i )
2452 #ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ 2487 if ( auxiliaryBounds != 0 )
2489 for( i=0; i<nV; ++i )
2498 if ( auxiliaryConstraints != 0 )
2500 for( i=0; i<nC; ++i )
2510 for (i = 0; i < nV; i++)
2516 for (i = 0; i < nC; i++)
2525 for (i = 0; i < nV; i++)
2553 for( i=0; i<nC; ++i )
2566 for( i=0; i<nV; ++i )
2582 for( i=0; i<nV; ++i )
2593 for( i=0; i<nC; ++i )
2614 for( i=0; i<nV; ++i )
2629 for( i=0; i<nC; ++i )
2670 for( i=0; i<nV; ++i )
2673 A->times(1, 1.0,
x, nV, 0.0,
Ax, nC);
2675 for ( j=0; j<nC; ++j )
2683 for( i=0; i<nV; ++i )
2686 for ( j=0; j<nC; ++j )
2697 for( i=0; i<nV+nC; ++i )
2702 for( i=0; i<nV+nC; ++i )
2726 for ( i=0; i<nV; ++i )
2729 for ( i=0; i<nV; ++i )
2734 for ( i=0; i<nV; ++i )
2740 for ( i=0; i<nV; ++i )
2744 H->
times(1, -1.0,
x, nV, 1.0,
g, nV);
2749 A->transTimes(1, 1.0,
y + nV, nC, 1.0,
g, nV);
2769 for ( i=0; i<nV; ++i )
2774 if ( useRelaxation ==
BT_TRUE )
2807 if ( useRelaxation ==
BT_TRUE )
2820 if ( useRelaxation ==
BT_TRUE )
2831 for ( i=0; i<nC; ++i )
2836 if ( useRelaxation ==
BT_TRUE )
2869 if ( useRelaxation ==
BT_TRUE )
2882 if ( useRelaxation ==
BT_TRUE )
2931 switch ( ensureLIreturnvalue )
2956 int tcol =
sizeT - nAC;
2964 for( i=0; i<nZ; ++i )
2973 for( i=0; i<nFR; ++i )
2976 for( j=0; j<nZ; ++j )
2977 wZ[j] += aFR[i] *
QQ(ii,j);
2983 for( j=0; j<nAC; ++j )
2984 TT(nAC,tcol+j) = 0.0;
2985 for( i=0; i<nFR; ++i )
2988 for( j=0; j<nAC; ++j )
2989 TT(nAC,tcol+j) += aFR[i] *
QQ(ii,nZ+j);
3003 for( j=0; j<nZ-1; ++j )
3008 for( i=0; i<nFR; ++i )
3011 applyGivens( c,s,nu,
QQ(ii,1+j),
QQ(ii,j),
QQ(ii,1+j),
QQ(ii,j) );
3014 if ( ( updateCholesky ==
BT_TRUE ) &&
3017 for( i=0; i<=j+1; ++i )
3018 applyGivens( c,s,nu,
RR(i,1+j),
RR(i,j),
RR(i,1+j),
RR(i,j) );
3022 TT(nAC,tcol-1) = wZ[nZ-1];
3025 if ( ( updateCholesky ==
BT_TRUE ) &&
3030 for( i=0; i<nZ-1; ++i )
3035 for( j=(1+i); j<(nZ-1); ++j )
3036 applyGivens( c,s,nu,
RR(i,j),
RR(1+i,j),
RR(i,j),
RR(1+i,j) );
3039 for( i=0; i<nZ; ++i )
3085 int *FX_idx, *AC_idx, *IAC_idx;
3097 int dim = (nC>nV)?nC:nV;
3099 for (ii = 0; ii < dim; ++ii)
3102 A->getRow (number, 0, 1.0, delta_g);
3107 delta_xFX, delta_xFR, delta_yAC, delta_yFX);
3112 for (ii = 0; ii < nAC; ++ii)
3114 real_t a = fabs (delta_yAC[ii]);
3115 if (weight < a) weight = a;
3117 for (ii = 0; ii < nFX; ++ii)
3119 real_t a = fabs (delta_yFX[ii]);
3120 if (weight < a) weight = a;
3125 for (ii = 0; ii < nFX; ++ii)
3127 real_t a = fabs (delta_xFX[ii]);
3128 if (zero < a) zero = a;
3130 for (ii = 0; ii < nFR; ++ii)
3132 real_t a = fabs (delta_xFR[ii]);
3133 if (zero < a) zero = a;
3161 for (i = 0; i < nFR; i++)
3162 l2 += Arow[i]*Arow[i];
3164 for( j=0; j<nZ; ++j )
3167 for( i=0; i<nFR; ++i )
3170 sum += Arow[i] *
QQ(ii,j);
3232 for( i=0; i<nAC; ++i )
3235 for( j=0; j<nFR; ++j )
3238 xiC_TMP[i] +=
QQ(jj,nZ+i) * Arow[j];
3245 delete[] xiB;
delete[] xiC_TMP;
delete[] xiC;
3259 int y_min_number = -1;
3260 int y_min_number_bound = -1;
3266 for( i=0; i<nAC; ++i )
3276 for( i=0; i<nFX; ++i )
3284 if ( y_min_number_bound >= 0 )
3286 y_min_number = y_min_number_bound;
3293 char messageString[80];
3296 if ( y_min_number >= 0 )
3299 for( i=0; i<nAC; ++i )
3302 y[nV+ii] -= y_min * xiC[i];
3304 for( i=0; i<nFX; ++i )
3307 y[ii] -= y_min * xiB[i];
3312 y[nV+number] = y_min;
3314 y[nV+number] = -y_min;
3317 if ( y_min_isBound ==
BT_TRUE )
3319 #ifndef __XPCTARGET__ 3320 snprintf( messageString,80,
"bound no. %d.",y_min_number );
3327 delete[] xiB;
delete[] xiC_TMP;
delete[] xiC;
3331 y[y_min_number] = 0.0;
3335 #ifndef __XPCTARGET__ 3336 snprintf( messageString,80,
"constraint no. %d.",y_min_number );
3343 delete[] xiB;
delete[] xiC_TMP;
delete[] xiC;
3348 y[nV+y_min_number] = 0.0;
3355 delete[] xiB;
delete[] xiC_TMP;
delete[] xiC;
3361 delete[] xiB;
delete[] xiC_TMP;
delete[] xiC;
3401 switch ( ensureLIreturnvalue )
3427 int tcol =
sizeT - nAC;
3433 if ( lastfreenumber != number )
3446 for( i=0; i<nFR; ++i )
3447 w[i] =
QQ(FR_idx[nFR-1],i);
3454 for( j=0; j<nZ-1; ++j )
3459 for( i=0; i<nFR; ++i )
3462 applyGivens( c,s,nu,
QQ(ii,1+j),
QQ(ii,j),
QQ(ii,1+j),
QQ(ii,j) );
3465 if ( ( updateCholesky ==
BT_TRUE ) &&
3468 for( i=0; i<=j+1; ++i )
3469 applyGivens( c,s,nu,
RR(i,1+j),
RR(i,j),
RR(i,1+j),
RR(i,j) );
3478 for( i=0; i<nAC; ++i )
3487 for( i=0; i<nFR; ++i )
3490 applyGivens( c,s,nu,
QQ(ii,1+j),
QQ(ii,j),
QQ(ii,1+j),
QQ(ii,j) );
3493 applyGivens( c,s,nu,
TT(nAC-1,tcol),tmp[nAC-1], tmp[nAC-1],
TT(nAC-1,tcol) );
3496 for( j=nZ; j<nFR-1; ++j )
3501 for( i=0; i<nFR; ++i )
3504 applyGivens( c,s,nu,
QQ(ii,1+j),
QQ(ii,j),
QQ(ii,1+j),
QQ(ii,j) );
3507 for( i=(nFR-2-j); i<nAC; ++i )
3508 applyGivens( c,s,nu,
TT(i,1+tcol-nZ+j),tmp[i], tmp[i],
TT(i,1+tcol-nZ+j) );
3517 if ( ( updateCholesky ==
BT_TRUE ) &&
3522 for( i=0; i<nZ-1; ++i )
3527 for( j=(1+i); j<nZ-1; ++j )
3528 applyGivens( c,s,nu,
RR(i,j),
RR(1+i,j),
RR(i,j),
RR(1+i,j) );
3531 for( i=0; i<nZ; ++i )
3578 for (ii = 0; ii < nV; ++ii)
3580 delta_g[number] = 1.0;
3582 int dim = (nC>nV)?nC:nV;
3584 for (ii = 0; ii < dim; ++ii)
3590 delta_xFX, delta_xFR, delta_yAC, delta_yFX);
3596 for (ii = 0; ii < nAC; ++ii)
3598 real_t a = fabs (delta_yAC[ii]);
3599 if (weight < a) weight = a;
3601 for (ii = 0; ii < nFX; ++ii)
3603 real_t a = fabs (delta_yFX[ii]);
3604 if (weight < a) weight = a;
3609 for (ii = 0; ii < nFX; ++ii)
3611 real_t a = fabs (delta_xFX[ii]);
3612 if (zero < a) zero = a;
3614 for (ii = 0; ii < nFR; ++ii)
3616 real_t a = fabs (delta_xFR[ii]);
3617 if (zero < a) zero = a;
3642 for( i=0; i<nZ; ++i )
3699 for( i=0; i<nAC; ++i )
3700 xiC_TMP[i] =
QQ(number,nZ+i);
3704 for( i=0; i<nAC; ++i )
3705 xiC_TMP[i] = -
QQ(number,nZ+i);
3710 delete[] xiB;
delete[] xiC_TMP;
delete[] xiC;
3721 int y_min_number = -1;
3722 int y_min_number_bound = -1;
3728 for( i=0; i<nAC; ++i )
3738 for( i=0; i<nFX; ++i )
3746 if ( y_min_number_bound >= 0 )
3748 y_min_number = y_min_number_bound;
3756 char messageString[80];
3758 if ( y_min_number >= 0 )
3761 for( i=0; i<nAC; ++i )
3764 y[nV+ii] -= y_min * xiC[i];
3766 for( i=0; i<nFX; ++i )
3769 y[ii] -= y_min * xiB[i];
3779 if ( y_min_isBound ==
BT_TRUE )
3781 #ifndef __XPCTARGET__ 3782 snprintf( messageString,80,
"bound no. %d.",y_min_number );
3788 delete[] xiB;
delete[] xiC_TMP;
delete[] xiC;
3792 y[y_min_number] = 0.0;
3796 #ifndef __XPCTARGET__ 3797 snprintf( messageString,80,
"constraint no. %d.",y_min_number );
3803 delete[] xiB;
delete[] xiC_TMP;
delete[] xiC;
3808 y[nV+y_min_number] = 0.0;
3814 delete[] xiB;
delete[] xiC_TMP;
delete[] xiC;
3819 delete[] xiB;
delete[] xiC_TMP;
delete[] xiC;
3854 int tcol =
sizeT - nAC;
3867 if ( ( number_idx < 0 ) || ( number_idx >= nAC ) )
3890 if ( number_idx < nAC-1 )
3892 for( i=(number_idx+1); i<nAC; ++i )
3893 for( j=(nAC-i-1); j<nAC; ++j )
3894 TT(i-1,tcol+j) =
TT(i,tcol+j);
3896 for( j=0; j<nAC; ++j )
3897 TT(nAC-1,tcol+j) = 0.0;
3905 for( j=(nAC-2-number_idx); j>=0; --j )
3907 computeGivens(
TT(nAC-2-j,tcol+1+j),
TT(nAC-2-j,tcol+j),
TT(nAC-2-j,tcol+1+j),
TT(nAC-2-j,tcol+j),c,s );
3910 for( i=(nAC-j-1); i<(nAC-1); ++i )
3911 applyGivens( c,s,nu,
TT(i,tcol+1+j),
TT(i,tcol+j),
TT(i,tcol+1+j),
TT(i,tcol+j) );
3913 for( i=0; i<nFR; ++i )
3916 applyGivens( c,s,nu,
QQ(ii,nZ+1+j),
QQ(ii,nZ+j),
QQ(ii,nZ+1+j),
QQ(ii,nZ+j) );
3923 for( j=0; j<nAC; ++j )
3924 TT(nAC-1,tcol+j) = 0.0;
3928 if ( ( updateCholesky ==
BT_TRUE ) &&
3940 for( j=0; j<nFR; ++j )
3941 z[j] =
QQ(FR_idx[j],nZ);
3948 for ( i=0; i<nZ; ++i )
3953 for( j=0; j<nFR; ++j )
3957 for( i=0; i<nZ; ++i )
3958 ZHz[i] +=
QQ(jj,i) * Hz[j];
3964 delete[] Hz;
delete[] r;
delete[] ZHz;
3970 for( i=0; i<nZ; ++i )
3976 delete[] r;
delete[] ZHz;
3980 for( j=0; j<nFR; ++j )
3981 rho2 +=
QQ(FR_idx[j],nZ) * Hz[j];
3988 RR(nZ,nZ) =
sqrt( rho2 );
4010 else if ( exchangeHappened ==
BT_FALSE )
4013 RR(nZ,nZ) =
sqrt( rho2 );
4018 RR(nZ,nZ) = 100.0*
EPS;
4038 if (exchangeHappened ==
BT_TRUE)
4045 if ( addBoundNotConstraint )
4090 int tcol =
sizeT - nAC;
4114 int nnFRp1 = FR_idx[nFR];
4115 for( i=0; i<nFR; ++i )
4121 QQ(nnFRp1,nFR) = 1.0;
4138 for( j=(nAC-1); j>=0; --j )
4140 computeGivens( tmp[nAC-1-j],
TT(nAC-1-j,tcol+j),
TT(nAC-1-j,tcol+j),tmp[nAC-1-j],c,s );
4143 for( i=(nAC-j); i<nAC; ++i )
4146 for( i=0; i<=nFR; ++i )
4150 applyGivens( c,s,nu,
QQ(ii,nZ+1+j),
QQ(ii,nZ+j),
QQ(ii,nZ+1+j),
QQ(ii,nZ+j) );
4158 if ( ( updateCholesky ==
BT_TRUE ) &&
4174 for( j=0; j<nFR; ++j )
4175 z[j] =
QQ(FR_idx[j],nZ);
4185 for( i=0; i<nZ; ++i )
4189 for( j=0; j<nFR; ++j )
4192 for( i=0; i<nZ; ++i )
4194 rhs[i] +=
QQ(jj,i) * ( Hz[j] + z2 * z[j] );
4201 delete[] Hz;
delete[] r;
delete[]
rhs;
4208 for( i=0; i<nZ; ++i )
4214 delete[]
rhs;
delete[] r;
4217 for( j=0; j<nFR; ++j )
4221 rho2 +=
QQ(jj,nZ) * ( Hz[j] + 2.0*z2*z[j] );
4232 RR(nZ,nZ) =
sqrt( rho2 );
4250 else if ( exchangeHappened ==
BT_FALSE )
4253 RR(nZ,nZ) =
sqrt( rho2 );
4257 RR(nZ,nZ) = 100.0*
EPS;
4272 if ( addBoundNotConstraint )
4285 const int*
const idxList,
4295 for (i = 0; i < nIdx; i++)
4296 if ( (num[i] > epsNum) && (den[i] > epsDen) && (t * den[i] > num[i]) )
4298 t = num[i] / den[i];
4299 BC_idx = idxList[i];
4316 int addLBndIdx = -1, addLCnstrIdx = -1, addUBndIdx = -1, addUCnstrIdx = -1;
4317 int *FX_idx, *AC_idx, *IAC_idx;
4340 addBoundNotConstraint =
BT_TRUE;
4344 if (removeBoundNotConstraint)
4346 int dim = nV < nC ? nC : nV;
4349 for (ii = 0; ii < dim; ++ii)
4351 for (ii = 0; ii < nV; ++ii)
4357 delta_xFX, delta_xFR, delta_yAC, delta_yFX);
4365 for (ii = 0; ii < nV; ++ii)
4367 for (ii = 0; ii < nC; ++ii)
4374 delta_xFX, delta_xFR, delta_yAC, delta_yFX);
4381 for (ii = 0; ii < nAC; ++ii)
4383 real_t a = fabs (delta_yAC[ii]);
4384 if (normXi < a) normXi = a;
4386 for (ii = 0; ii < nFX; ++ii)
4388 real_t a = fabs (delta_yFX[ii]);
4389 if (normXi < a) normXi = a;
4394 for (ii = 0; ii < nFX; ++ii)
4396 real_t a = fabs (delta_xFX[ii]);
4397 if (normS < a) normS = a;
4399 for (ii = 0; ii < nFR; ++ii)
4401 real_t a = fabs (delta_xFR[ii]);
4402 if (normS < a) normS = a;
4409 real_t sigmaLBnd, sigmaLCnstr, sigmaUBnd, sigmaUCnstr, sigma;
4415 for (i = 0; i < nFR; i++)
4418 x_W[i] =
ub[ii] -
x[ii];
4428 x_W[0] =
ub[remIdx] -
x[remIdx];
4433 for (i = 0; i < nFR; i++)
4436 x_W[i] =
x[ii] -
lb[ii];
4438 for (i = 0; i < nFR; i++)
4439 delta_xFR[i] = -delta_xFR[i];
4448 x_W[0] =
x[remIdx] -
lb[remIdx];
4451 for (i = 0; i < nFR; i++)
4452 delta_xFR[i] = -delta_xFR[i];
4465 for (i = 0; i < nIAC; i++)
4482 for (i = 0; i < nIAC; i++)
4487 for (i = 0; i < nIAC; i++)
4502 if (sigmaUCnstr < sigma) { sigma = sigmaUCnstr; addStatus =
ST_UPPER; addBoundNotConstraint =
BT_FALSE; addIdx = addUCnstrIdx; }
4503 if (sigmaLCnstr < sigma) { sigma = sigmaLCnstr; addStatus =
ST_LOWER; addBoundNotConstraint =
BT_FALSE; addIdx = addLCnstrIdx; }
4504 if (sigmaUBnd < sigma) { sigma = sigmaUBnd; addStatus =
ST_UPPER; addBoundNotConstraint =
BT_TRUE; addIdx = addUBndIdx; }
4505 if (sigmaLBnd < sigma) { sigma = sigmaLBnd; addStatus =
ST_LOWER; addBoundNotConstraint =
BT_TRUE; addIdx = addLBndIdx; }
4514 for (i = 0; i < nFR; i++)
4515 x[FR_idx[i]] += sigma * delta_xFR[i];
4517 for (i = 0; i < nFX; i++)
4518 x[FX_idx[i]] += sigma * delta_xFX[i];
4521 A->times(1, 1.0,
x, nV, 0.0,
Ax, nC);
4522 for (i = 0; i < nC; i++)
Ax_u[i] =
ubA[i] -
Ax[i];
4523 for (i = 0; i < nC; i++)
Ax_l[i] =
Ax[i] -
lbA[i];
4551 int tcol =
sizeT - nT;
4564 for( i=0; i<nT; ++i )
4567 for( j=0; j<i; ++j )
4568 sum -=
TT(i,
sizeT-1-j) * a[nT-1-j];
4571 a[nT-1-i] = sum /
TT(i,
sizeT-1-i);
4579 for( i=0; i<nT; ++i )
4582 for( j=0; j<i; ++j )
4583 sum -=
TT(nT-1-j,tcol+i) * a[nT-1-j];
4585 if ( fabs(
TT(nT-1-i,tcol+i) ) >
EPS )
4586 a[nT-1-i] = sum /
TT(nT-1-i,tcol+i);
4621 delta_g,delta_lb,delta_ub,
4627 for( i=0; i<nC; ++i )
4631 delta_lbA[i] = lbA_new[i] -
lbA[i];
4633 delta_lbA[i] = -
INFTY - lbA[i];
4636 for( i=0; i<nC; ++i )
4640 delta_ubA[i] = ubA_new[i] -
ubA[i];
4642 delta_ubA[i] =
INFTY - ubA[i];
4648 for ( i=0; i<nAC; ++i )
4652 if ( ( fabs( delta_lbA[ii] ) >
EPS ) || ( fabs( delta_ubA[ii] ) >
EPS ) )
4667 const real_t*
const delta_lb,
const real_t*
const delta_ub,
4673 int i, j, ii, jj, r;
4692 for( i=0; i<nFX; ++i )
4697 delta_xFX[i] = delta_lb[ii];
4699 delta_xFX[i] = delta_ub[ii];
4704 for( i=0; i<nFX; ++i )
4711 for ( i=0; i<nFR; ++i )
4714 tempA[i] = delta_g[ii];
4717 for ( i=0; i<nAC; ++i )
4721 for ( i=0; i<nAC; ++i )
4725 tempB[i] = delta_lbA[ii];
4727 tempB[i] = delta_ubA[ii];
4732 for ( i=0; i<nAC; ++i )
4742 for( i=0; i<nFR; ++i )
4748 if ( ( Delta_bC_isZero ==
BT_TRUE ) && ( Delta_bB_isZero ==
BT_TRUE ) )
4750 for( i=0; i<nAC; ++i )
4757 if ( ( Delta_bB_isZero ==
BT_FALSE ) && ( r == 0 ) )
4763 for( i=0; i<nFR; ++i )
4766 for( j=0; j<nAC; ++j )
4774 for( i=0; i<nZ; ++i )
4780 for( j=0; j<nFR; ++j )
4783 for( i=0; i<nZ; ++i )
4789 for( i=0; i<nZ; ++i )
4796 if ( ( Delta_bB_isZero ==
BT_FALSE ) && ( r == 0 ) )
4800 if ( ( nAC > 0 ) && ( ( Delta_bC_isZero ==
BT_FALSE ) || ( Delta_bB_isZero ==
BT_FALSE ) ) )
4806 for( j=0; j<nFR; ++j )
4809 for( i=0; i<nZ; ++i )
4824 for( i=0; i<nFR; ++i )
4829 for( j=0; j<nZ; ++j )
4850 for( j=0; j<nAC; ++j )
4857 for( j=0; j<nAC; ++j )
4862 for( j=0; j<nAC; ++j )
4867 for( j=0; j<nAC; ++j )
4869 for( i=0; i<nFR; ++i )
4883 for( i=0; i<nAC; ++i)
4886 for( j=0; j<nFR; ++j )
4899 for ( i=0; i<nFR; ++i )
4901 for ( i=0; i<nAC; ++i )
4907 for ( i=0; i<nFR; ++i )
4910 tempA[i] = delta_g[ii];
4919 for ( i=0; i<nFR; ++i )
4920 tempA[i] += delta_xFR[i];
4931 for ( i=0; i<nFR; ++i )
4932 if (rnrm < fabs (
tempA[i]))
4933 rnrm = fabs (
tempA[i]);
4935 if (!Delta_bC_isZero)
4937 for ( i=0; i<nAC; ++i )
4941 tempB[i] = delta_lbA[ii];
4943 tempB[i] = delta_ubA[ii];
4948 for ( i=0; i<nAC; ++i )
4953 for ( i=0; i<nAC; ++i )
4954 if (rnrm < fabs (
tempB[i]))
4955 rnrm = fabs (
tempB[i]);
4967 for( i=0; i<nFX; ++i )
4968 delta_yFX[i] = delta_g[FX_idx[i]];
4975 for( i=0; i<nFX; ++i )
4980 for( i=0; i<nFX; ++i )
4981 delta_yFX[i] += delta_xFX[i];
4998 const real_t*
const delta_lbA,
const real_t*
const delta_ubA,
4999 const real_t*
const delta_lb,
const real_t*
const delta_ub,
5000 const real_t*
const delta_xFX,
const real_t*
const delta_xFR,
5001 const real_t*
const delta_yAC,
const real_t*
const delta_yFX,
5029 int BC_idx_tmp = -1;
5039 for( j=0; j<nFR; ++j )
5042 delta_x[jj] = delta_xFR[j];
5044 for( j=0; j<nFX; ++j )
5047 delta_x[jj] = delta_xFX[j];
5054 for( i=0; i<nAC; ++i )
5059 den[i] = -delta_yAC[i];
5064 if ( BC_idx_tmp >= 0 )
5066 BC_idx = BC_idx_tmp;
5074 for( i=0; i<nFX; ++i )
5078 den[i] = -delta_yFX[i];
5083 if ( BC_idx_tmp >= 0 )
5085 BC_idx = BC_idx_tmp;
5095 #ifdef __MANY_CONSTRAINTS__ 5096 real_t delta_x_max = 0.0;
5097 for( i=0; i<nV; ++i )
5099 if ( fabs( delta_x[i] ) > delta_x_max )
5100 delta_x_max = fabs( delta_x[i] );
5103 for( i=0; i<nIAC; ++i )
5109 delta_Ax_l[ii] = -delta_x_max;
5110 if ( delta_lbA[ii] > 0.0 )
5111 delta_Ax_l[ii] -= delta_lbA[ii];
5113 delta_Ax_u[ii] = -delta_x_max;
5114 if ( delta_ubA[ii] > 0.0 )
5115 delta_Ax_u[ii] -= delta_ubA[ii];
5117 if ( ( -delta_Ax_l[ii] >=
Ax_l[ii] ) || ( -delta_Ax_u[ii] >=
Ax_u[ii] ) )
5124 for( j=0; j<nV; ++j )
5126 Ax[ii] +=
AA(ii,j) *
x[j];
5127 delta_Ax[ii] +=
AA(ii,j) * delta_x[j];
5134 delete[] den;
delete[] num;
5135 delete[] delta_Ax;
delete[] delta_Ax_u;
delete[] delta_Ax;
delete[] delta_x;
5141 delete[] den;
delete[] num;
5142 delete[] delta_Ax;
delete[] delta_Ax_u;
delete[] delta_Ax_l;
delete[] delta_x;
5154 den[i] = delta_lbA[ii] - delta_Ax[ii];
5158 tau = num[i]/den[i];
5164 delta_Ax_l[ii] = delta_Ax[ii] - delta_lbA[ii];
5170 den[i] = delta_Ax[ii] - delta_ubA[ii];
5174 tau = num[i]/den[i];
5179 delta_Ax_u[ii] = delta_ubA[ii] - delta_Ax[ii];
5191 for( i=0; i<nIAC; ++i )
5199 delete[] den;
delete[] num;
5200 delete[] delta_Ax;
delete[] delta_Ax_u;
delete[] delta_Ax_l;
delete[] delta_x;
5209 for( i=0; i<nIAC; ++i )
5213 den[i] = delta_lbA[ii] - delta_Ax[ii];
5218 if ( BC_idx_tmp >= 0 )
5220 BC_idx = BC_idx_tmp;
5228 for( i=0; i<nIAC; ++i )
5232 den[i] = delta_Ax[ii] - delta_ubA[ii];
5237 if ( BC_idx_tmp >= 0 )
5239 BC_idx = BC_idx_tmp;
5246 for( i=0; i<nIAC; ++i )
5252 delta_Ax_l[ii] = delta_Ax[ii] - delta_lbA[ii];
5253 delta_Ax_u[ii] = delta_ubA[ii] - delta_Ax[ii];
5264 for( i=0; i<nFR; ++i )
5268 den[i] = delta_lb[ii] - delta_xFR[i];
5273 if ( BC_idx_tmp >= 0 )
5275 BC_idx = BC_idx_tmp;
5284 for( i=0; i<nFR; ++i )
5288 den[i] = delta_xFR[i] - delta_ub[ii];
5293 if ( BC_idx_tmp >= 0 )
5295 BC_idx = BC_idx_tmp;
5306 #ifndef __XPCTARGET__ 5307 char messageString[80];
5310 snprintf( messageString,80,
"Stepsize is %.16e!",
tau );
5312 snprintf( messageString,80,
"Stepsize is %.16e! (BC_idx = %d, BC_isBound = %d, BC_status = %d)",
tau,BC_idx,BC_isBound,BC_status );
5322 for( i=0; i<nFR; ++i )
5325 x[ii] +=
tau*delta_xFR[i];
5328 for( i=0; i<nFX; ++i )
5331 x[ii] +=
tau*delta_xFX[i];
5332 y[ii] +=
tau*delta_yFX[i];
5335 for( i=0; i<nAC; ++i )
5338 y[nV+ii] +=
tau*delta_yAC[i];
5342 for( i=0; i<nV; ++i )
5344 g[i] +=
tau*delta_g[i];
5345 lb[i] +=
tau*delta_lb[i];
5346 ub[i] +=
tau*delta_ub[i];
5349 for( i=0; i<nC; ++i )
5351 lbA[i] +=
tau*delta_lbA[i];
5352 ubA[i] +=
tau*delta_ubA[i];
5364 for( i=0; i<nAC; ++i )
5370 for( i=0; i<nIAC; ++i )
5375 Ax[ii] +=
tau*delta_Ax[ii];
5376 Ax_l[ii] +=
tau*delta_Ax_l[ii];
5377 Ax_u[ii] +=
tau*delta_Ax_u[ii];
5384 #ifndef __XPCTARGET__ 5385 snprintf( messageString,80,
"Stepsize is %.16e",
tau );
5390 delete[] delta_Ax;
delete[] delta_Ax_u;
delete[] delta_Ax_l;
5403 char messageString[80];
5405 switch ( BC_status )
5415 #ifndef __XPCTARGET__ 5416 snprintf( messageString,80,
"bound no. %d.", BC_idx );
5427 #ifndef __XPCTARGET__ 5428 snprintf( messageString,80,
"constraint no. %d.", BC_idx );
5445 #ifndef __XPCTARGET__ 5447 snprintf( messageString,80,
"lower bound no. %d.", BC_idx );
5449 snprintf( messageString,80,
"upper bound no. %d.", BC_idx );
5461 #ifndef __XPCTARGET__ 5463 snprintf( messageString,80,
"lower constraint's bound no. %d.", BC_idx );
5465 snprintf( messageString,80,
"upper constraint's bound no. %d.", BC_idx );
5488 int nC =
getNC( ), i;
5493 for (i = 0; i < nC &&
lbA_new; i++)
5495 s = fabs(lbA_new[i]);
5496 if (s < 1.0) s = 1.0;
5497 d = fabs(lbA_new[i] -
lbA[i]) / s;
5498 if (d > len) len = d;
5502 for (i = 0; i < nC &&
ubA_new; i++)
5504 s = fabs(ubA_new[i]);
5505 if (s < 1.0) s = 1.0;
5506 d = fabs(ubA_new[i] -
ubA[i]) / s;
5507 if (d > len) len = d;
5519 int nV =
getNV( ), nC =
getNC( ), bstat, cstat, i;
5523 for (i = 0; i < nV; i++)
5532 t =
static_cast<real_t>(i) / static_cast<real_t>(nV+nC-1);
5535 if (bstat !=
ST_LOWER) {
lb[i] =
x[i] - rampVal; }
5536 if (bstat !=
ST_UPPER) {
ub[i] =
x[i] + rampVal; }
5537 if (bstat ==
ST_LOWER) {
lb[i] =
x[i];
y[i] = +rampVal; }
5538 if (bstat ==
ST_UPPER) {
ub[i] =
x[i];
y[i] = -rampVal; }
5543 for (i = 0; i < nC; i++)
5552 t =
static_cast<real_t>(nV+i) / static_cast<real_t>(nV+nC-1);
5581 for ( i=0; i<nV; ++i )
5617 for ( i=0; i<nC; ++i )
5639 lbA[i] =
getMin (lbA[i], Ax[i]);
5640 Ax_l[i] = Ax[i] - lbA[i];
5676 if ( ( guessedBounds == 0 ) || ( guessedConstraints == 0 ) )
5736 for ( i=0; i<nV; ++i )
5740 for ( i=0; i<nC; ++i )
5748 A->times(1, 1.0,
x, nV, 0.0,
Ax, nC);
5749 for ( j=0; j<nC; ++j )
5781 int differenceNumberBounds = 0;
5783 for( i=0; i<nV; ++i )
5785 ++differenceNumberBounds;
5789 int differenceNumberConstraints = 0;
5791 for( i=0; i<nC; ++i )
5793 ++differenceNumberConstraints;
5796 if ( 2*(differenceNumberBounds+differenceNumberConstraints) > guessedConstraints->
getNAC( )+guessedBounds->
getNFX( ) )
5820 if ( ( nC > 0 ) && ( _A == 0 ) )
5835 for( i=0; i<nC; ++i )
5847 for( i=0; i<nC; ++i )
5873 if ( ( nC > 0 ) && ( _A == 0 ) )
5888 for( i=0; i<nC; ++i )
5900 for( i=0; i<nC; ++i )
5913 const char*
const lb_file,
const char*
const ub_file,
5914 const char*
const lbA_file,
const char*
const ubA_file
5930 if ( ( nC > 0 ) && ( A_file == 0 ) )
5946 if ( lbA_file != 0 )
5955 for( i=0; i<nC; ++i )
5960 if ( ubA_file != 0 )
5969 for( i=0; i<nC; ++i )
5982 const char*
const lbA_file,
const char*
const ubA_file,
6000 if ( lbA_file != 0 )
6016 if ( ubA_file != 0 )
6043 #ifndef __XPCTARGET__ 6044 char myPrintfString[80];
6048 if ( iteration < 0 )
6057 if ( iteration == 0 )
6059 snprintf( myPrintfString,80,
"\n\n#################### qpOASES -- QP NO. %3.0d #####################\n\n",
count );
6062 myPrintf(
" Iter | StepLength | Info | nFX | nAC \n" );
6063 myPrintf(
" ----------+------------------+------------------+---------+--------- \n" );
6070 snprintf( info,3,
"LP" );
6072 snprintf( info,3,
"QP" );
6074 snprintf( myPrintfString,80,
" %5.1d | %1.6e | %s SOLVED | %4.1d | %4.1d \n", iteration,
tau,info,
getNFX( ),
getNAC( ) );
6080 snprintf( info,5,
"REM " );
6082 snprintf( info,5,
"ADD " );
6085 snprintf( &(info[4]),4,
"BND" );
6087 snprintf( &(info[4]),4,
"CON" );
6089 snprintf( myPrintfString,80,
" %5.1d | %1.6e | %s %4.1d | %4.1d | %4.1d \n", iteration,
tau,info,BC_idx,
getNFX( ),
getNAC( ) );
returnValue addConstraint_ensureLI(int number, SubjectToStatus C_status)
HessianType getHessianType() const
returnValue setupCholeskyDecomposition()
returnValue flipFixed(int number)
void setNoLower(BooleanType _status)
returnValue addBound_ensureLI(int number, SubjectToStatus B_status)
returnValue setupQPdataFromFile(const char *const H_file, const char *const g_file, const char *const A_file, const char *const lb_file, const char *const ub_file, const char *const lbA_file, const char *const ubA_file)
returnValue solveCurrentEQP(const int n_rhs, const real_t *g_in, const real_t *lb_in, const real_t *ub_in, const real_t *lbA_in, const real_t *ubA_in, real_t *x_out, real_t *y_out)
returnValue setType(int i, SubjectToType value)
returnValue init(const real_t *const _H, const real_t *const _g, const real_t *const _A, const real_t *const _lb, const real_t *const _ub, const real_t *const _lbA, const real_t *const _ubA, int &nWSR, const real_t *const yOpt=0, real_t *const cputime=0)
IntermediateState sqrt(const Expression &arg)
Interface for specifying user-defined evaluations of constraint products.
BooleanType isInfeasible() const
Manages working sets of constraints.
returnValue swapFree(int number1, int number2)
returnValue addConstraint_checkLI(int number)
BooleanType shallRefactorise(const Bounds *const guessedBounds, const Constraints *const guessedConstraints) const
returnValue removeConstraint(int number, BooleanType updateCholesky)
returnValue moveInactiveToActive(int _number, SubjectToStatus _status)
Implements the online active set strategy for box-constrained QPs.
returnValue setupAuxiliaryQPgradient()
returnValue getNumberArray(int *const numberarray) const
returnValue performDriftCorrection()
returnValue solveRegularisedQP(const real_t *const g_new, const real_t *const lb_new, const real_t *const ub_new, const real_t *const lbA_new, const real_t *const ubA_new, int &nWSR, real_t *const cputime, int nWSRperformed=0)
BooleanType enableFarBounds
returnValue moveFixedToFree(int _number)
real_t relativeHomotopyLength(const real_t *const g_new, const real_t *const lb_new, const real_t *const ub_new, const real_t *const lbA_new, const real_t *const ubA_new)
int getLastNumber() const
BooleanType isUnbounded() const
returnValue setupAuxiliaryQPsolution(const real_t *const xOpt, const real_t *const yOpt)
virtual returnValue getCol(int cNum, const Indexlist *const irows, real_t alpha, real_t *col) const
ConstraintProduct * constraintProduct
returnValue flipFixed(int number)
void computeGivens(real_t xold, real_t yold, real_t &xnew, real_t &ynew, real_t &c, real_t &s) const
BEGIN_NAMESPACE_ACADO const double EPS
#define THROWINFO(retval)
returnValue obtainAuxiliaryWorkingSet(const real_t *const xOpt, const real_t *const yOpt, const Bounds *const guessedBounds, Bounds *auxiliaryBounds) const
returnValue throwInfo(returnValue Inumber, const char *additionaltext, const char *functionname, const char *filename, const unsigned long linenumber, VisibilityStatus localVisibilityStatus)
Allows to pass back messages to the calling function.
returnValue determineHessianType()
returnValue setLBA(const real_t *const lbA_new)
returnValue ensureNonzeroCurvature(BooleanType removeBoundNotConstraint, int remIdx, BooleanType &exchangeHappened, BooleanType &addBoundNotConstraint, int &addIdx, SubjectToStatus &addStatus)
real_t getMin(real_t x, real_t y)
virtual returnValue performRamping()
#define THROWERROR(retval)
BooleanType enableFullLITests
Indexlist * getInactive()
returnValue setInfeasibilityFlag(returnValue returnvalue)
BooleanType enableEqualities
returnValue hotstart(const real_t *const g_new, const real_t *const lb_new, const real_t *const ub_new, const real_t *const lbA_new, const real_t *const ubA_new, int &nWSR, real_t *const cputime)
returnValue set(const Bounds *const _bounds, const double *const _R, const Constraints *const _constraints=0, const double *const _Q=0, const double *const _T=0)
BooleanType enableRamping
returnValue throwWarning(returnValue Wnumber, const char *additionaltext, const char *functionname, const char *filename, const unsigned long linenumber, VisibilityStatus localVisibilityStatus)
BooleanType freeConstraintMatrix
returnValue setupAllInactive()
returnValue readFromFile(real_t *data, int nrow, int ncol, const char *datafilename)
returnValue myPrintf(const char *s)
returnValue performPlainRatioTest(int nIdx, const int *const idxList, const real_t *const num, const real_t *const den, real_t epsNum, real_t epsDen, real_t &t, int &BC_idx) const
returnValue obtainAuxiliaryWorkingSet(const real_t *const xOpt, const real_t *const yOpt, const Bounds *const guessedBounds, const Constraints *const guessedConstraints, Bounds *auxiliaryBounds, Constraints *auxiliaryConstraints) const
returnValue solveInitialQP(const real_t *const xOpt, const real_t *const yOpt, const Bounds *const guessedBounds, const Constraints *const guessedConstraints, int &nWSR, real_t *const cputime)
returnValue setupCholeskyDecompositionProjected()
BooleanType enableFlippingBounds
returnValue setupQPdata(const real_t *const _H, const real_t *const _g, const real_t *const _A, const real_t *const _lb, const real_t *const _ub, const real_t *const _lbA, const real_t *const _ubA)
returnValue backsolveT(const real_t *const b, BooleanType transposed, real_t *const a)
virtual real_t diag(int i) const
returnValue changeActiveSet(int BC_idx, SubjectToStatus BC_status, BooleanType BC_isBound)
BooleanType usingRegularisation() const
real_t relativeHomotopyLength(const real_t *const g_new, const real_t *const lb_new, const real_t *const ub_new)
BooleanType isCPUtimeLimitExceeded(const real_t *const cputime, real_t starttime, int nWSR) const
returnValue setupSubjectToType()
SubjectToStatus getStatus(int i) const
Interfaces matrix-vector operations tailored to general dense matrices.
returnValue setConstraintProduct(ConstraintProduct *const _constraintProduct)
returnValue performRatioTest(int nIdx, const int *const idxList, const SubjectTo *const subjectTo, const real_t *const num, const real_t *const den, real_t epsNum, real_t epsDen, real_t &t, int &BC_idx) const
BooleanType isBlocking(real_t num, real_t den, real_t epsNum, real_t epsDen, real_t &t) const
returnValue determineDataShift(const real_t *const g_new, const real_t *const lb_new, const real_t *const ub_new, real_t *const delta_g, real_t *const delta_lb, real_t *const delta_ub, BooleanType &Delta_bB_isZero)
returnValue setupQPdata(const real_t *const _H, const real_t *const _g, const real_t *const _lb, const real_t *const _ub)
returnValue setupAuxiliaryQPbounds(const Bounds *const auxiliaryBounds, const Constraints *const auxiliaryConstraints, BooleanType useRelaxation)
returnValue setupSubjectToType()
returnValue setupAllFree()
returnValue setupConstraint(int _number, SubjectToStatus _status)
real_t A[NCMAX_ALLOC *NVMAX]
int enableDriftCorrection
returnValue determineStepDirection(const real_t *const delta_g, const real_t *const delta_lbA, const real_t *const delta_ubA, const real_t *const delta_lb, const real_t *const delta_ub, BooleanType Delta_bC_isZero, BooleanType Delta_bB_isZero, real_t *const delta_xFX, real_t *const delta_xFR, real_t *const delta_yAC, real_t *const delta_yFX)
Abstract base class for interfacing tailored matrix-vector operations.
returnValue setupQPdataFromFile(const char *const H_file, const char *const g_file, const char *const lb_file, const char *const ub_file)
returnValue regulariseHessian()
returnValue loadQPvectorsFromFile(const char *const g_file, const char *const lb_file, const char *const ub_file, const char *const lbA_file, const char *const ubA_file, real_t *const g_new, real_t *const lb_new, real_t *const ub_new, real_t *const lbA_new, real_t *const ubA_new) const
void rhs(const real_t *x, real_t *f)
#define END_NAMESPACE_QPOASES
returnValue solveQP(const real_t *const g_new, const real_t *const lb_new, const real_t *const ub_new, const real_t *const lbA_new, const real_t *const ubA_new, int &nWSR, real_t *const cputime, int nWSRperformed=0)
returnValue addBound(int number, SubjectToStatus B_status, BooleanType updateCholesky)
SubjectToType getType(int i) const
returnValue copy(const QProblem &rhs)
returnValue performStep(const real_t *const delta_g, const real_t *const delta_lbA, const real_t *const delta_ubA, const real_t *const delta_lb, const real_t *const delta_ub, const real_t *const delta_xFX, const real_t *const delta_xFR, const real_t *const delta_yAC, const real_t *const delta_yFX, int &BC_idx, SubjectToStatus &BC_status, BooleanType &BC_isBound)
#define HST_POSDEF_NULLSPACE
returnValue computeInitialCholesky()
virtual returnValue setupAuxiliaryQP(const Bounds *const guessedBounds, const Constraints *const guessedConstraints)
BooleanType isInitialised() const
QProblemStatus getStatus() const
real_t terminationTolerance
returnValue removeBound(int number, BooleanType updateCholesky)
returnValue determineDataShift(const real_t *const g_new, const real_t *const lbA_new, const real_t *const ubA_new, const real_t *const lb_new, const real_t *const ub_new, real_t *const delta_g, real_t *const delta_lbA, real_t *const delta_ubA, real_t *const delta_lb, real_t *const delta_ub, BooleanType &Delta_bC_isZero, BooleanType &Delta_bB_isZero)
real_t delta_xFR_TMP[NVMAX]
int numRegularisationSteps
returnValue times(int xN, real_t alpha, const real_t *x, int xLD, real_t beta, real_t *y, int yLD) const
#define THROWWARNING(retval)
returnValue moveActiveToInactive(int _number)
int enableCholeskyRefactorisation
void setNoUpper(BooleanType _status)
BooleanType enableNZCTests
QProblemB & operator=(const QProblemB &rhs)
virtual returnValue printProperties()
int getIndex(int givennumber) const
BooleanType hasNoUpper() const
Manages working sets of bounds (= box constraints).
BooleanType hasNoLower() const
#define BEGIN_NAMESPACE_QPOASES
returnValue backsolveR(const real_t *const b, BooleanType transposed, real_t *const a)
returnValue printIteration(int iteration, int BC_idx, SubjectToStatus BC_status, BooleanType BC_isBound)
Implements the online active set strategy for QPs with general constraints.
returnValue setupAuxiliaryWorkingSet(const Bounds *const auxiliaryBounds, const Constraints *const auxiliaryConstraints, BooleanType setupAfresh)
void applyGivens(real_t c, real_t s, real_t xold, real_t yold, real_t &xnew, real_t &ynew) const
returnValue init(int _nV=0, int _nC=0)
QProblem & operator=(const QProblem &rhs)
returnValue loadQPvectorsFromFile(const char *const g_file, const char *const lb_file, const char *const ub_file, real_t *const g_new, real_t *const lb_new, real_t *const ub_new) const
MessageHandling * getGlobalMessageHandler()
returnValue addBound_checkLI(int number)
returnValue setA(const real_t *const A_new)
returnValue setupTQfactorisation()
returnValue setUBA(const real_t *const ubA_new)
returnValue get(Bounds *const _bounds, double *const R, Constraints *const _constraints=0, double *const _Q=0, double *const _T=0) const
returnValue addConstraint(int number, SubjectToStatus C_status, BooleanType updateCholesky)
returnValue moveFreeToFixed(int _number, SubjectToStatus _status)
Abstract base class for interfacing matrix-vector operations tailored to symmetric matrices...
returnValue getDualSolution(real_t *const yOpt) const