35 #include <QProblemB.hpp> 42 printf(
"%s = [...\n", name);
43 for (i = 0; i < m; i++) {
44 for (j = 0; j < n; j++)
45 printf(
" % 9.4f", A[i*n+j]);
140 for( i=0; i<_nV; ++i )
141 for( j=0; j<_nV; ++j )
146 for( i=0; i<_nV; ++i )
149 for( i=0; i<_nV; ++i )
152 for( i=0; i<_nV; ++i )
158 for( i=0; i<_nV; ++i )
159 for( j=0; j<_nV; ++j )
163 for( i=0; i<_nV; ++i )
166 for( i=0; i<_nV; ++i )
202 for( i=0; i<_nV; ++i )
203 for( j=0; j<_nV; ++j )
208 for( i=0; i<_nV; ++i )
211 for( i=0; i<_nV; ++i )
214 for( i=0; i<_nV; ++i )
219 for( i=0; i<_nV; ++i )
220 for( j=0; j<_nV; ++j )
225 for( i=0; i<_nV; ++i )
228 for( i=0; i<_nV; ++i )
264 for( i=0; i<nV; ++i )
265 for( j=0; j<nV; ++j )
361 char messageString[80];
365 for( l=0; l<
nWSR; ++l )
372 sprintf( messageString,
"%d ...",l );
387 delta_g,delta_lb,delta_ub,
399 delta_g,delta_lb,delta_ub,
401 delta_xFX,delta_xFR,delta_yFX
425 delta_g,delta_lb,delta_ub,
426 delta_xFX,delta_xFR,delta_yFX,
494 sprintf( messageString,
"(nWSR = %d)",nWSR );
503 return returnvalueKKTcheck;
553 for( i=0; i<nV; ++i )
555 obj_tmp += _x[i]*
g[i];
557 for( j=0; j<nV; ++j )
558 obj_tmp += 0.5*_x[i]*
H[i*
NVMAX + j]*_x[j];
578 for( i=0; i<
getNV( ); ++i )
603 for( i=0; i<
getNV( ); ++i )
673 for ( i=0; i<nV; ++i )
677 for ( i=0; i<nV; ++i )
679 for ( j=0; j<i; ++j )
702 for( i=0; i<nV; ++i )
711 for( i=0; i<nV; ++i )
722 for( i=0; i<nV; ++i )
765 for( i=0; i<nV; ++i )
766 for( j=0; j<nV; ++j )
773 for( i=0; i<nFR; ++i )
788 for( i=0; i<nFR; ++i )
794 for( k=(i-1); k>=0; --k )
800 inv = 1.0 /
R[i*
NVMAX + i];
809 for( j=(i+1); j<nFR; ++j )
814 for( k=(i-1); k>=0; --k )
817 R[i*
NVMAX + j] = sum * inv;
831 const Bounds*
const guessedBounds,
870 static Bounds auxiliaryBounds;
872 auxiliaryBounds.
init( nV );
893 for( i=0; i<nV; ++i )
894 g_original[i] =
g[i];
895 for( i=0; i<nV; ++i )
896 lb_original[i] =
lb[i];
897 for( i=0; i<nV; ++i )
898 ub_original[i] =
ub[i];
944 const Bounds*
const guessedBounds,
Bounds* auxiliaryBounds
952 if ( ( auxiliaryBounds == 0 ) || ( auxiliaryBounds == guessedBounds ) )
957 if ( guessedBounds != 0 )
961 for( i=0; i<nV; ++i )
977 if ( (
xOpt != 0 ) && ( yOpt == 0 ) )
980 for( i=0; i<nV; ++i )
1010 if ( (
xOpt == 0 ) && ( yOpt != 0 ) )
1013 for( i=0; i<nV; ++i )
1015 if ( yOpt[i] >
ZERO )
1022 if ( yOpt[i] < -
ZERO )
1046 if ( (
xOpt == 0 ) && ( yOpt == 0 ) )
1048 for( i=0; i<nV; ++i )
1080 if ( auxiliaryBounds != 0 )
1082 for( i=0; i<nV; ++i )
1107 for( i=0; i<nV; ++i )
1123 for( i=0; i<nV; ++i )
1152 for( i=0; i<nV; ++i )
1157 for( i=0; i<nV; ++i )
1164 for( i=0; i<nV; ++i )
1169 for( i=0; i<nV; ++i )
1187 for ( i=0; i<nV; ++i )
1193 for ( j=0; j<nV; ++j )
1211 for ( i=0; i<nV; ++i )
1216 if ( useRelaxation ==
BT_TRUE )
1239 if ( useRelaxation ==
BT_TRUE )
1252 if ( useRelaxation ==
BT_TRUE )
1304 for( i=number_idx+1; i<nFR; ++i )
1308 for( j=(1+i); j<nFR; ++j )
1313 for( i=0; i<nFR-1; ++i )
1314 for( j=number_idx+1; j<nFR; ++j )
1317 for( i=0; i<nFR; ++i )
1318 R[i*
NVMAX + nFR-1] = 0.0;
1367 for( i=0; i<nFR; ++i )
1370 rhs[i] =
H[number*
NVMAX + ii];
1376 for( i=0; i<nFR; ++i )
1380 for( i=0; i<nFR; ++i )
1422 if ( removingBound ==
BT_TRUE )
1434 for( i=(nR-1); i>=0; --i )
1437 for( j=(i+1); j<nR; ++j )
1438 sum -=
R[i*
NVMAX + j] * a[j];
1441 a[i] = sum /
R[i*
NVMAX + i];
1449 for( i=0; i<nR; ++i )
1453 for( j=0; j<i; ++j )
1454 sum -=
R[j*
NVMAX + i] * a[j];
1457 a[i] = sum /
R[i*
NVMAX + i];
1482 for( i=0; i<nV; ++i )
1483 delta_g[i] =
g_new[i] -
g[i];
1487 for( i=0; i<nV; ++i )
1493 for( i=0; i<nV; ++i )
1499 for( i=0; i<nV; ++i )
1505 for( i=0; i<nV; ++i )
1512 for ( i=0; i<nFX; ++i )
1537 for( i=0; i<
getNV( ); ++i )
1538 if ( (
lb[i] >
ub[i] -
BOUNDTOL ) && ( delta_lb[i] > delta_ub[i] +
EPS ) )
1558 for( i=0; i<nV; ++i )
1559 for( j=0; j<nV; ++j )
1560 H[i*
NVMAX + j] = _H[i*nV + j];
1568 for( i=0; i<nV; ++i )
1569 for( j=0; j<nV; ++j )
1570 R[i*
NVMAX + j] = _R[i*nV + j];
1576 for( i=0; i<nV; ++i )
1577 for( j=0; j<nV; ++j )
1578 H[i*
NVMAX + j] = _R[i*nV + j];
1590 for( i=0; i<nV; ++i )
1596 for( i=0; i<nV; ++i )
1602 for( i=0; i<nV; ++i )
1609 for( i=0; i<nV; ++i )
1615 for( i=0; i<nV; ++i )
1638 const real_t*
const delta_g,
const real_t*
const delta_lb,
const real_t*
const delta_ub,
1651 for( i=0; i<nFR; ++i )
1652 HMX_delta_xFX[i] = 0.0;
1658 for( i=0; i<nFX; ++i )
1680 for( i=0; i<nFR; ++i )
1683 for( j=0; j<nFX; ++j )
1691 if ( Delta_bB_isZero ==
BT_TRUE )
1693 for( j=0; j<nFR; ++j )
1696 delta_xFRz_RHS[j] = delta_g[jj];
1701 for( j=0; j<nFR; ++j )
1704 delta_xFRz_RHS[j] = delta_g[jj] + HMX_delta_xFX[j];
1708 for( i=0; i<nFR; ++i )
1722 for( i=0; i<nFX; ++i )
1727 for( j=0; j<nFR; ++j )
1735 for( j=0; j<nFX; ++j )
1742 delta_yFX[i] += delta_g[ii];
1754 const real_t*
const delta_lb,
const real_t*
const delta_ub,
1773 for( i=0; i<nFX; ++i )
1785 if ( tau_tmp < tau_new )
1787 if ( tau_tmp >= 0.0 )
1802 if ( tau_tmp < tau_new )
1804 if ( tau_tmp >= 0.0 )
1822 for( i=0; i<nFR; ++i )
1830 if (
x[ii] >
lb[ii] )
1831 tau_tmp = (
x[ii] -
lb[ii] ) / ( delta_lb[ii] -
delta_xFR[i] );
1835 if ( tau_tmp < tau_new )
1837 if ( tau_tmp >= 0.0 )
1852 for( i=0; i<nFR; ++i )
1860 if (
x[ii] <
ub[ii] )
1861 tau_tmp = (
x[ii] -
ub[ii] ) / ( delta_ub[ii] -
delta_xFR[i] );
1865 if ( tau_tmp < tau_new )
1867 if ( tau_tmp >= 0.0 )
1886 char messageString[80];
1889 sprintf( messageString,
"Stepsize is %.6e!",
tau );
1891 sprintf( messageString,
"Stepsize is %.6e! (BC_idx = %d, BC_status = %d)",
tau,BC_idx,BC_status );
1905 const real_t*
const delta_g,
const real_t*
const delta_lb,
const real_t*
const delta_ub,
1931 for( i=0; i<nFR; ++i )
1937 for( i=0; i<nFX; ++i )
1945 for( i=0; i<nV; ++i )
1947 g[i] +=
tau*delta_g[i];
1948 lb[i] +=
tau*delta_lb[i];
1949 ub[i] +=
tau*delta_ub[i];
1956 char messageString[80];
1957 sprintf( messageString,
"Stepsize is %.6e",
tau );
1965 char messageString[80];
1976 switch ( BC_status )
1986 sprintf( messageString,
"bound no. %d.", BC_idx );
2001 sprintf( messageString,
"lower bound no. %d.", BC_idx );
2003 sprintf( messageString,
"upper bound no. %d.", BC_idx );
2025 char myPrintfString[160];
2028 if ( iteration < 0 )
2037 if ( iteration == 0 )
2039 sprintf( myPrintfString,
"\n############## qpOASES -- QP NO.%4.1d ###############\n",
count );
2042 sprintf( myPrintfString,
" Iter | StepLength | Info | nFX \n" );
2049 sprintf( myPrintfString,
" %4.1d | %1.5e | QP SOLVED | %4.1d \n", iteration,
tau,
getNFX( ) );
2057 sprintf( info,
"REM BND" );
2059 sprintf( info,
"ADD BND" );
2061 sprintf( myPrintfString,
" %4.1d | %1.5e | %s%4.1d | %4.1d \n", iteration,
tau,info,BC_idx,
getNFX( ) );
2077 #ifdef __PERFORM_KKT_TEST__ 2083 real_t maxKKTviolation = 0.0;
2087 for( i=0; i<nV; ++i )
2091 for( j=0; j<nV; ++j )
2092 tmp +=
H[i*nV + j] *
x[j];
2096 if (
getAbs( tmp ) > maxKKTviolation )
2097 maxKKTviolation =
getAbs( tmp );
2101 for( i=0; i<nV; ++i )
2103 if (
lb[i] -
x[i] > maxKKTviolation )
2104 maxKKTviolation =
lb[i] -
x[i];
2106 if ( x[i] -
ub[i] > maxKKTviolation )
2107 maxKKTviolation = x[i] -
ub[i];
2111 for( i=0; i<nV; ++i )
2116 if ( -
y[i] > maxKKTviolation )
2117 maxKKTviolation = -
y[i];
2118 if (
getAbs( (
x[i] -
lb[i] ) *
y[i] ) > maxKKTviolation )
2119 maxKKTviolation =
getAbs( (
x[i] -
lb[i] ) *
y[i] );
2123 if (
y[i] > maxKKTviolation )
2124 maxKKTviolation =
y[i];
2125 if (
getAbs( (
ub[i] -
x[i] ) *
y[i] ) > maxKKTviolation )
2126 maxKKTviolation =
getAbs( (
ub[i] -
x[i] ) *
y[i] );
2130 if (
getAbs(
y[i] ) > maxKKTviolation )
2131 maxKKTviolation =
getAbs(
y[i] );
returnValue getPrimalSolution(real_t *const xOpt) const
returnValue setupCholeskyDecomposition()
void setNoLower(BooleanType _status)
returnValue setType(int i, SubjectToType value)
IntermediateState sqrt(const Expression &arg)
BooleanType isInfeasible() const
BooleanType isNoLower() const
Implements the online active set strategy for box-constrained QPs.
returnValue getNumberArray(int *const numberarray) const
returnValue moveFixedToFree(int _number)
BooleanType isUnbounded() const
returnValue checkForIdentityHessian()
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)
const real_t CRITICALACCURACY
Allows to pass back messages to the calling function.
returnValue setupAuxiliaryWorkingSet(const Bounds *const auxiliaryBounds, BooleanType setupAfresh)
void printmatrix(char *name, double *A, int m, int n)
#define THROWERROR(retval)
returnValue setupAuxiliaryQPsolution(const real_t *const xOpt, const real_t *const yOpt)
returnValue backsolveR(const real_t *const b, BooleanType transposed, real_t *const a)
returnValue init(const real_t *const _H, const real_t *const _g, const real_t *const _lb, const real_t *const _ub, int &nWSR, const real_t *const yOpt=0, real_t *const cputime=0)
returnValue throwWarning(returnValue Wnumber, const char *additionaltext, const char *functionname, const char *filename, const unsigned long linenumber, VisibilityStatus localVisibilityStatus)
returnValue setupAuxiliaryQPgradient()
returnValue myPrintf(const char *s)
returnValue setupBound(int _number, SubjectToStatus _status)
returnValue setNUV(int n)
returnValue setNBV(int n)
SubjectToStatus getStatus(int i) const
returnValue hotstart(const real_t *const g_new, const real_t *const lb_new, const real_t *const ub_new, int &nWSR, real_t *const cputime)
returnValue getDualSolution(real_t *const yOpt) const
returnValue addBound(int number, SubjectToStatus B_status, BooleanType updateCholesky)
returnValue hotstart_determineStepLength(const int *const FR_idx, const int *const FX_idx, const real_t *const delta_lb, const real_t *const delta_ub, const real_t *const delta_xFR, const real_t *const delta_yFX, int &BC_idx, SubjectToStatus &BC_status)
returnValue setupQPdata(const real_t *const _H, const real_t *const _g, const real_t *const _lb, const real_t *const _ub)
returnValue setNFV(int n)
returnValue setupSubjectToType()
returnValue setupAllFree()
void setInfoVisibilityStatus(VisibilityStatus _infoVisibility)
returnValue printIteration(int iteration, int BC_idx, SubjectToStatus BC_status)
BooleanType areBoundsConsistent(const real_t *const delta_lb, const real_t *const delta_ub) const
returnValue hotstart_performStep(const int *const FR_idx, const int *const FX_idx, const real_t *const delta_g, 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_yFX, int BC_idx, SubjectToStatus BC_status)
returnValue setupAuxiliaryQPbounds(BooleanType useRelaxation)
void rhs(const real_t *x, real_t *f)
SubjectToType getType(int i) const
BooleanType isNoUpper() const
#define HST_POSDEF_NULLSPACE
QProblemStatus getStatus() const
void setErrorVisibilityStatus(VisibilityStatus _errorVisibility)
const real_t DESIREDACCURACY
returnValue hotstart_determineDataShift(const int *const FX_idx, 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 removeBound(int number, BooleanType updateCholesky)
void setNoUpper(BooleanType _status)
QProblemB & operator=(const QProblemB &rhs)
returnValue checkKKTconditions()
int getIndex(int givennumber) const
void setWarningVisibilityStatus(VisibilityStatus _warningVisibility)
Manages working sets of bounds (= box constraints).
returnValue hotstart_determineStepDirection(const int *const FR_idx, const int *const FX_idx, const real_t *const delta_g, const real_t *const delta_lb, const real_t *const delta_ub, BooleanType Delta_bB_isZero, real_t *const delta_xFX, real_t *const delta_xFR, real_t *const delta_yFX)
void applyGivens(real_t c, real_t s, real_t xold, real_t yold, real_t &xnew, real_t &ynew) const
MessageHandling * getGlobalMessageHandler()
returnValue solveInitialQP(const real_t *const xOpt, const real_t *const yOpt, const Bounds *const guessedBounds, int &nWSR, real_t *const cputime)
const double BOUNDRELAXATION
returnValue moveFreeToFixed(int _number, SubjectToStatus _status)
returnValue setPrintLevel(PrintLevel _printlevel)