36 #include <qpOASES/QProblem.hpp> 103 for( i=0; i<_nC; ++i )
lbA[i] = 0.0;
106 for( i=0; i<_nC; ++i )
ubA[i] = 0.0;
123 for( i=0; i<_nV+_nC; ++i )
y[i] = 0.0;
228 for( i=0; i<nV*nV; ++i )
267 if ( guessedBounds != 0 )
269 for( i=0; i<nV; ++i )
276 if ( guessedConstraints != 0 )
278 for( i=0; i<nC; ++i )
284 if ( ( xOpt == 0 ) && ( yOpt != 0 ) && ( ( guessedBounds != 0 ) || ( guessedConstraints != 0 ) ) )
287 if ( ( _R != 0 ) && ( ( xOpt != 0 ) || ( yOpt != 0 ) || ( guessedBounds != 0 ) || ( guessedConstraints != 0 ) ) )
295 return solveInitialQP( xOpt,yOpt,guessedBounds,guessedConstraints,_R, nWSR,cputime );
325 if ( guessedBounds != 0 )
327 for( i=0; i<nV; ++i )
334 if ( guessedConstraints != 0 )
336 for( i=0; i<nC; ++i )
342 if ( ( xOpt == 0 ) && ( yOpt != 0 ) && ( ( guessedBounds != 0 ) || ( guessedConstraints != 0 ) ) )
345 if ( ( _R != 0 ) && ( ( xOpt != 0 ) || ( yOpt != 0 ) || ( guessedBounds != 0 ) || ( guessedConstraints != 0 ) ) )
353 return solveInitialQP( xOpt,yOpt,guessedBounds,guessedConstraints,_R, nWSR,cputime );
361 const char*
const lb_file,
const char*
const ub_file,
362 const char*
const lbA_file,
const char*
const ubA_file,
366 const char*
const R_file
383 if ( guessedBounds != 0 )
385 for( i=0; i<nV; ++i )
392 if ( guessedConstraints != 0 )
394 for( i=0; i<nC; ++i )
400 if ( ( xOpt == 0 ) && ( yOpt != 0 ) && ( ( guessedBounds != 0 ) || ( guessedConstraints != 0 ) ) )
403 if ( ( R_file != 0 ) && ( ( xOpt != 0 ) || ( yOpt != 0 ) || ( guessedBounds != 0 ) || ( guessedConstraints != 0 ) ) )
413 return solveInitialQP( xOpt,yOpt,guessedBounds,guessedConstraints,0, nWSR,cputime );
423 return solveInitialQP( xOpt,yOpt,guessedBounds,guessedConstraints,
R, nWSR,cputime );
450 if ( ( guessedBounds != 0 ) || ( guessedConstraints != 0 ) )
455 const Bounds* actualGuessedBounds = ( guessedBounds != 0 ) ? guessedBounds : &
bounds;
456 const Constraints* actualGuessedConstraints = ( guessedConstraints != 0 ) ? guessedConstraints : &
constraints;
480 int_t nWSR_performed = 0;
483 real_t cputime_needed = 0.0;
516 for (i = 0; i < nV; i++)
517 if ((ub_new[i] <
INFTY) && (ub_new[i] > farbound)) farbound = ub_new[i];
519 for (i = 0; i < nV; i++)
520 if ((lb_new[i] > -
INFTY) && (lb_new[i] < -farbound)) farbound = -lb_new[i];
522 for (i = 0; i < nC; i++)
523 if ((ubA_new[i] <
INFTY) && (ubA_new[i] > farbound)) farbound = ubA_new[i];
525 for (i = 0; i < nC; i++)
526 if ((lbA_new[i] > -
INFTY) && (lbA_new[i] < -farbound)) farbound = -lbA_new[i];
529 lb_new,lb_new_far, ub_new,ub_new_far,
530 lbA_new,lbA_new_far, ubA_new,ubA_new_far
538 cputime_remaining = *cputime - cputime_needed;
539 pcputime_rem = &cputime_remaining;
545 returnvalue =
solveRegularisedQP( g_new,lb_new_far,ub_new_far,lbA_new_far,ubA_new_far,
546 nWSR,pcputime_rem,nWSR_performed,
550 nWSR_performed =
nWSR;
551 cputime_needed += cputime_remaining;
560 if ( farbound >=
INFTY )
567 lb_new,lb_new_far, ub_new,ub_new_far,
568 lbA_new,lbA_new_far, ubA_new,ubA_new_far
575 for ( i=0; i<nV; ++i )
577 if ( ( ( lb_new == 0 ) || ( lb_new_far[i] > lb_new[i] ) ) && (
getAbs ( lb_new_far[i] -
x[i] ) < tol ) )
579 if ( ( ( ub_new == 0 ) || ( ub_new_far[i] < ub_new[i] ) ) && (
getAbs ( ub_new_far[i] -
x[i] ) < tol ) )
582 for ( i=0; i<nC; ++i )
584 if ( ( ( lbA_new == 0 ) || ( lbA_new_far[i] > lbA_new[i] ) ) && (
getAbs ( lbA_new_far[i] -
Ax[i] ) < tol ) )
586 if ( ( ( ubA_new == 0 ) || ( ubA_new_far[i] < ubA_new[i] ) ) && (
getAbs ( ubA_new_far[i] -
Ax[i] ) < tol ) )
590 if ( nActiveFar == 0 )
595 if ( farbound >=
INFTY )
603 lb_new,lb_new_far, ub_new,ub_new_far,
604 lbA_new,lbA_new_far, ubA_new,ubA_new_far
620 *cputime = cputime_needed + auxTime;
621 delete[] lbA_new_far;
delete[] ubA_new_far;
622 delete[] lb_new_far;
delete[] ub_new_far;
633 const char*
const lb_file,
const char*
const ub_file,
634 const char*
const lbA_file,
const char*
const ubA_file,
654 real_t* lbA_new = ( lbA_file != 0 ) ?
new real_t[nC] : 0;
655 real_t* ubA_new = ( ubA_file != 0 ) ?
new real_t[nC] : 0;
661 g_new,lb_new,ub_new,lbA_new,ubA_new
680 returnvalue =
hotstart( g_new,lb_new,ub_new,lbA_new,ubA_new,
682 guessedBounds,guessedConstraints
714 if ( ( x_out == 0 ) || ( y_out == 0 ) )
739 for ( ii = 0 ; ii < (nV+nC)*n_rhs; ++ii )
742 for ( ii = 0 ; ii < n_rhs; ++ii )
746 delta_xFX, delta_xFR, delta_yAC, delta_yFX );
748 for ( jj = 0; jj < nFX; ++jj )
749 x_out[FX_idx[jj]] = delta_xFX[jj];
750 for ( jj = 0; jj < nFR; ++jj )
751 x_out[FR_idx[jj]] = delta_xFR[jj];
752 for ( jj = 0; jj < nFX; ++jj )
753 y_out[FX_idx[jj]] = delta_yFX[jj];
754 for ( jj = 0; jj < nAC; ++jj )
755 y_out[nV+AC_idx[jj]] = delta_yAC[jj];
784 if ( workingSet == 0 )
814 if ( workingSetC == 0 )
817 for ( i=0; i<nC; ++i )
821 case ST_LOWER: workingSetC[i] = -1.0;
break;
822 case ST_UPPER: workingSetC[i] = +1.0;
break;
823 default: workingSetC[i] = 0.0;
break;
884 #ifndef __SUPPRESSANYOUTPUT__ 892 myPrintf(
"\n################# qpOASES -- QP PROPERTIES #################\n" );
900 myPrintf(
"Variables are not bounded from below.\n" );
902 myPrintf(
"Variables are bounded from below.\n" );
905 myPrintf(
"Variables are not bounded from above.\n" );
907 myPrintf(
"Variables are bounded from above.\n" );
925 myPrintf(
"Constraints are not bounded from below.\n" );
927 myPrintf(
"Constraints are bounded from below.\n" );
930 myPrintf(
"Constraints are not bounded from above.\n" );
932 myPrintf(
"Constraints are bounded from above.\n" );
942 myPrintf(
"Hessian is zero matrix (i.e. actually an LP is solved).\n" );
946 myPrintf(
"Hessian is identity matrix.\n" );
950 myPrintf(
"Hessian matrix is (strictly) positive definite.\n" );
954 myPrintf(
"Hessian matrix is positive definite on null space of active constraints.\n" );
958 myPrintf(
"Hessian matrix is positive semi-definite.\n" );
962 myPrintf(
"Hessian matrix is indefinite.\n" );
966 myPrintf(
"Hessian matrix has unknown type.\n" );
971 myPrintf(
"QP was found to be infeasible.\n" );
973 myPrintf(
"QP seems to be feasible.\n" );
976 myPrintf(
"QP was found to be unbounded from below.\n" );
978 myPrintf(
"QP seems to be bounded from below.\n" );
987 myPrintf(
"Status of QP object: freshly instantiated or reset.\n" );
991 myPrintf(
"Status of QP object: an auxiliary QP is currently setup.\n" );
995 myPrintf(
"Status of QP object: an auxilary QP was solved.\n" );
999 myPrintf(
"Status of QP object: a homotopy step is performed.\n" );
1003 myPrintf(
"Status of QP object: an intermediate QP along the homotopy path was solved.\n" );
1007 myPrintf(
"Status of QP object: solution of the actual QP was found.\n" );
1014 myPrintf(
"Print level of QP object is set to display a tabular output for debugging.\n" );
1018 myPrintf(
"Print level of QP object is set to display a tabular output.\n" );
1022 myPrintf(
"Print level of QP object is low, i.e. only error are printed.\n" );
1026 myPrintf(
"Print level of QP object is medium, i.e. error and warnings are printed.\n" );
1030 myPrintf(
"Print level of QP object is high, i.e. all available output is printed.\n" );
1047 for (
int_t i=0; i<nV; i++ )
1054 for (
int_t i=0; i<nFR; i++ )
1055 varIsFree[FR_idx[i]] =
BT_TRUE;
1178 A = rhs.
A->duplicate();
1202 memcpy(
y,rhs.
y,(_nV+_nC)*
sizeof(
real_t) );
1220 memcpy(
Q,rhs.
Q,_nV*_nV*
sizeof(
real_t) );
1233 if ( rhs.
Ax_l != 0 )
1241 if ( rhs.
Ax_u != 0 )
1325 Bounds auxiliaryBounds( nV );
1364 else if ( ( xOpt == 0 ) && ( yOpt == 0 ) && ( guessedBounds == 0 ) && ( guessedConstraints == 0 ) )
1366 for( i=0; i<nV; ++i )
1367 for( j=i; j<nV; ++j )
1368 RR(i,j) = _R[i*nV+j];
1385 for( i=0; i<nV; ++i )
1387 g_original[i] =
g[i];
1388 lb_original[i] =
lb[i];
1389 ub_original[i] =
ub[i];
1392 for( i=0; i<nC; ++i )
1394 lbA_original[i] =
lbA[i];
1395 ubA_original[i] =
ubA[i];
1402 delete[] ubA_original;
delete[] lbA_original;
delete[] ub_original;
delete[] lb_original;
delete[] g_original;
1408 delete[] ubA_original;
delete[] lbA_original;
delete[] ub_original;
delete[] lb_original;
delete[] g_original;
1425 returnValue returnvalue =
hotstart( g_original,lb_original,ub_original,lbA_original,ubA_original, nWSR,cputime );
1428 delete[] ubA_original;
delete[] lbA_original;
delete[] ub_original;
delete[] lb_original;
delete[] g_original;
1456 const real_t*
const lb_new,
const real_t*
const ub_new,
1457 const real_t*
const lbA_new,
const real_t*
const ubA_new,
1512 #ifndef __SUPPRESSANYOUTPUT__ 1533 for( iter=nWSRperformed; iter<
nWSR; ++iter )
1548 #ifndef __SUPPRESSANYOUTPUT__ 1558 delta_g,delta_lbA,delta_ubA,delta_lb,delta_ub,
1559 Delta_bC_isZero, Delta_bB_isZero
1563 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1564 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1577 Delta_bC_isZero, Delta_bB_isZero,
1578 delta_xFX,delta_xFR,delta_yAC,delta_yFX
1582 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1583 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1596 returnvalue =
performStep( delta_g, delta_lbA,delta_ubA,delta_lb,delta_ub,
1597 delta_xFX,delta_xFR,delta_yAC,delta_yFX,
1598 BC_idx,BC_status,BC_isBound
1602 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1603 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1632 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1633 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1642 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1643 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1672 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1673 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1702 delete[] delta_yAC;
delete[] delta_yFX;
delete[] delta_xFX;
delete[] delta_xFR;
1703 delete[] delta_ub;
delete[] delta_lb;
delete[] delta_ubA;
delete[] delta_lbA;
delete[] delta_g;
1714 #ifndef __SUPPRESSANYOUTPUT__ 1732 const real_t*
const lb_new,
const real_t*
const ub_new,
1733 const real_t*
const lbA_new,
const real_t*
const ubA_new,
1744 return solveQP( g_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,cputime,nWSRperformed,isFirstCall );
1751 int_t nWSR_total = nWSRperformed;
1753 real_t cputime_total = 0.0;
1754 real_t cputime_cur = 0.0;
1758 returnvalue =
solveQP( g_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,0,nWSRperformed,isFirstCall );
1762 cputime_cur = *cputime;
1763 returnvalue =
solveQP( g_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,&cputime_cur,nWSRperformed,isFirstCall );
1766 cputime_total += cputime_cur;
1773 *cputime = cputime_total;
1789 for( i=0; i<nV; ++i )
1790 gMod[i] = g_new[i] -
regVal*
x[i];
1799 returnvalue =
solveQP( gMod,lb_new,ub_new,lbA_new,ubA_new, nWSR,0,nWSR_total,isFirstCall );
1803 cputime_cur = *cputime - cputime_total;
1804 returnvalue =
solveQP( gMod,lb_new,ub_new,lbA_new,ubA_new, nWSR,&cputime_cur,nWSR_total,isFirstCall );
1808 cputime_total += cputime_cur;
1816 *cputime = cputime_total;
1825 for( i=0; i<nV; ++i )
1831 *cputime = cputime_total;
1840 const real_t*
const lbA_new,
const real_t*
const ubA_new
1851 for ( i=0; i<nV; i++ )
1881 for ( i=0; i<nV; i++ )
1923 const real_t*
const lbA_new,
const real_t*
const ubA_new
1940 for( i=0; i<nC; ++i )
1942 if ( lbA_new[i] > -
INFTY )
1954 for( i=0; i<nC; ++i )
1956 if ( ubA_new[i] <
INFTY )
1965 if ( ( lbA_new != 0 ) && ( ubA_new != 0 ) )
1967 for( i=0; i<nC; ++i )
1989 if ( ( lbA_new == 0 ) && ( ubA_new == 0 ) )
1991 for( i=0; i<nC; ++i )
1996 for( i=0; i<nC; ++i )
2021 for( i=0; i<nV*nV; ++i )
2062 for ( j=0; j < nZ; ++j ) {
2063 for ( i=0; i < nV; ++i )
2065 QQ(FR_idx[j],j) = 1.0;
2069 for ( j=0; j < nFR; ++j )
2079 unsigned long _nZ = (
unsigned long)nZ, _nV = (
unsigned long)nV;
2081 POTRF(
"U", &_nZ,
R, &_nV, &info );
2097 for (i=0;i<nZ-1;++i)
2151 for( i=0; i<nV*nV; ++i )
2154 for( i=0; i<nFR; ++i )
2161 for( i=0; i<sizeT*
sizeT; ++i )
2182 if ( ( auxiliaryBounds == 0 ) || ( auxiliaryBounds == guessedBounds ) )
2185 if ( ( auxiliaryConstraints == 0 ) || ( auxiliaryConstraints == guessedConstraints ) )
2196 if ( guessedConstraints != 0 )
2200 for( i=0; i<nC; ++i )
2203 guessedStatus = guessedConstraints->
getStatus( i );
2205 #ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ 2222 if ( ( xOpt != 0 ) && ( yOpt == 0 ) )
2224 for( i=0; i<nC; ++i )
2241 #ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ 2257 if ( ( xOpt == 0 ) && ( yOpt != 0 ) )
2259 for( i=0; i<nC; ++i )
2261 if ( yOpt[nV+i] >
EPS )
2268 if ( yOpt[nV+i] < -
EPS )
2276 #ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ 2294 if ( ( xOpt == 0 ) && ( yOpt == 0 ) )
2296 for( i=0; i<nC; ++i )
2299 #ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ 2334 if ( auxiliaryBounds != 0 )
2336 for( i=0; i<nV; ++i )
2345 if ( auxiliaryConstraints != 0 )
2347 for( i=0; i<nC; ++i )
2357 for (i = 0; i < nV; i++)
2363 for (i = 0; i < nC; i++)
2375 for (i = 0; i < nV; i++)
2404 for( i=0; i<nC; ++i )
2417 for( i=0; i<nV; ++i )
2433 for( i=0; i<nV; ++i )
2449 for( i=0; i<nC; ++i )
2475 for( i=0; i<nV; ++i )
2490 for( i=0; i<nC; ++i )
2531 for( i=0; i<nV; ++i )
2534 A->times(1, 1.0,
x, nV, 0.0,
Ax, nC);
2536 for ( j=0; j<nC; ++j )
2544 for( i=0; i<nV; ++i )
2547 for ( j=0; j<nC; ++j )
2558 for( i=0; i<nV+nC; ++i )
2563 for( i=0; i<nV+nC; ++i )
2587 for ( i=0; i<nV; ++i )
2590 for ( i=0; i<nV; ++i )
2595 for ( i=0; i<nV; ++i )
2601 for ( i=0; i<nV; ++i )
2605 H->
times(1, -1.0,
x, nV, 1.0,
g, nV);
2610 A->transTimes(1, 1.0,
y + nV, nC, 1.0,
g, nV);
2620 const real_t*
const lbA_new,
const real_t*
const ubA_new)
const 2625 if (lbA_new && ubA_new) {
2627 if (lbA_new[i] > ubA_new[i]+
EPS) {
2651 for ( i=0; i<nV; ++i )
2656 if ( useRelaxation ==
BT_TRUE )
2689 if ( useRelaxation ==
BT_TRUE )
2702 if ( useRelaxation ==
BT_TRUE )
2716 for ( i=0; i<nC; ++i )
2721 if ( useRelaxation ==
BT_TRUE )
2754 if ( useRelaxation ==
BT_TRUE )
2767 if ( useRelaxation ==
BT_TRUE )
2819 switch ( ensureLIreturnvalue )
2847 int_t tcol = sizeT - nAC;
2855 for( i=0; i<nZ; ++i )
2864 for( i=0; i<nFR; ++i )
2867 for( j=0; j<nZ; ++j )
2868 wZ[j] += aFR[i] *
QQ(ii,j);
2874 for( j=0; j<nAC; ++j )
2875 TT(nAC,tcol+j) = 0.0;
2876 for( i=0; i<nFR; ++i )
2879 for( j=0; j<nAC; ++j )
2880 TT(nAC,tcol+j) += aFR[i] *
QQ(ii,nZ+j);
2894 for( j=0; j<nZ-1; ++j )
2899 for( i=0; i<nFR; ++i )
2902 applyGivens( c,s,nu,
QQ(ii,1+j),
QQ(ii,j),
QQ(ii,1+j),
QQ(ii,j) );
2905 if ( ( updateCholesky ==
BT_TRUE ) &&
2908 for( i=0; i<=j+1; ++i )
2909 applyGivens( c,s,nu,
RR(i,1+j),
RR(i,j),
RR(i,1+j),
RR(i,j) );
2913 TT(nAC,tcol-1) = wZ[nZ-1];
2916 if ( ( updateCholesky ==
BT_TRUE ) &&
2921 for( i=0; i<nZ-1; ++i )
2926 for( j=(1+i); j<(nZ-1); ++j )
2927 applyGivens( c,s,nu,
RR(i,j),
RR(1+i,j),
RR(i,j),
RR(1+i,j) );
2930 for( i=0; i<nZ; ++i )
2976 int_t *FX_idx, *AC_idx, *IAC_idx;
2988 int_t dim = (nC>nV)?nC:nV;
2990 for (ii = 0; ii < dim; ++ii)
2993 A->getRow (number, 0, 1.0, delta_g);
3000 delta_xFX, delta_xFR, delta_yAC, delta_yFX);
3002 returnvalue = dsdreturnvalue;
3008 for (ii = 0; ii < nAC; ++ii)
3011 if (weight < a) weight = a;
3013 for (ii = 0; ii < nFX; ++ii)
3016 if (weight < a) weight = a;
3021 for (ii = 0; ii < nFX; ++ii)
3024 if (zero < a) zero = a;
3026 for (ii = 0; ii < nFR; ++ii)
3029 if (zero < a) zero = a;
3057 for (i = 0; i < nFR; i++)
3058 l2 += Arow[i]*Arow[i];
3060 for( j=0; j<nZ; ++j )
3063 for( i=0; i<nFR; ++i )
3066 sum += Arow[i] *
QQ(ii,j);
3127 int_t y_min_number = -1;
3128 int_t y_min_number_bound = -1;
3136 for( i=0; i<nAC; ++i )
3139 for( j=0; j<nFR; ++j )
3142 xiC_TMP[i] +=
QQ(jj,nZ+i) * Arow[j];
3163 for( i=0; i<nAC; ++i )
3172 for( i=0; i<nFX; ++i )
3180 if ( y_min_number_bound >= 0 )
3182 y_min_number = y_min_number_bound;
3186 #ifndef __SUPPRESSANYOUTPUT__ 3192 if ( y_min_number >= 0 )
3195 for( i=0; i<nAC; ++i )
3198 y[nV+ii] -= y_min * xiC[i];
3200 for( i=0; i<nFX; ++i )
3203 y[ii] -= y_min * xiB[i];
3208 y[nV+number] = y_min;
3210 y[nV+number] = -y_min;
3213 if ( y_min_isBound ==
BT_TRUE )
3215 #ifndef __SUPPRESSANYOUTPUT__ 3227 y[y_min_number] = 0.0;
3231 #ifndef __SUPPRESSANYOUTPUT__ 3232 snprintf( messageString,
MAX_STRING_LENGTH,
"constraint no. %d.",(
int)y_min_number );
3243 y[nV+y_min_number] = 0.0;
3307 switch ( ensureLIreturnvalue )
3336 int_t tcol = sizeT - nAC;
3342 if ( lastfreenumber != number )
3355 for( i=0; i<nFR; ++i )
3356 w[i] =
QQ(FR_idx[nFR-1],i);
3363 for( j=0; j<nZ-1; ++j )
3368 for( i=0; i<nFR; ++i )
3371 applyGivens( c,s,nu,
QQ(ii,1+j),
QQ(ii,j),
QQ(ii,1+j),
QQ(ii,j) );
3374 if ( ( updateCholesky ==
BT_TRUE ) &&
3377 for( i=0; i<=j+1; ++i )
3378 applyGivens( c,s,nu,
RR(i,1+j),
RR(i,j),
RR(i,1+j),
RR(i,j) );
3387 for( i=0; i<nAC; ++i )
3396 for( i=0; i<nFR; ++i )
3399 applyGivens( c,s,nu,
QQ(ii,1+j),
QQ(ii,j),
QQ(ii,1+j),
QQ(ii,j) );
3402 applyGivens( c,s,nu,
TT(nAC-1,tcol),tmp[nAC-1], tmp[nAC-1],
TT(nAC-1,tcol) );
3405 for( j=nZ; j<nFR-1; ++j )
3410 for( i=0; i<nFR; ++i )
3413 applyGivens( c,s,nu,
QQ(ii,1+j),
QQ(ii,j),
QQ(ii,1+j),
QQ(ii,j) );
3416 for( i=(nFR-2-j); i<nAC; ++i )
3417 applyGivens( c,s,nu,
TT(i,1+tcol-nZ+j),tmp[i], tmp[i],
TT(i,1+tcol-nZ+j) );
3426 if ( ( updateCholesky ==
BT_TRUE ) &&
3431 for( i=0; i<nZ-1; ++i )
3436 for( j=(1+i); j<nZ-1; ++j )
3437 applyGivens( c,s,nu,
RR(i,j),
RR(1+i,j),
RR(i,j),
RR(1+i,j) );
3440 for( i=0; i<nZ; ++i )
3487 for (ii = 0; ii < nV; ++ii)
3489 delta_g[number] = 1.0;
3491 int_t dim = (nC>nV)?nC:nV;
3493 for (ii = 0; ii < dim; ++ii)
3498 delta_xFX, delta_xFR, delta_yAC, delta_yFX);
3500 returnvalue = dsdReturnValue;
3504 for (ii = 0; ii < nAC; ++ii)
3507 if (weight < a) weight = a;
3509 for (ii = 0; ii < nFX; ++ii)
3512 if (weight < a) weight = a;
3517 for (ii = 0; ii < nFX; ++ii)
3520 if (zero < a) zero = a;
3522 for (ii = 0; ii < nFR; ++ii)
3525 if (zero < a) zero = a;
3551 for( i=0; i<nZ; ++i )
3605 int_t y_min_number = -1;
3606 int_t y_min_number_bound = -1;
3617 for( i=0; i<nAC; ++i )
3618 xiC_TMP[i] =
QQ(number,nZ+i);
3622 for( i=0; i<nAC; ++i )
3623 xiC_TMP[i] = -
QQ(number,nZ+i);
3640 for( i=0; i<nAC; ++i )
3649 for( i=0; i<nFX; ++i )
3657 if ( y_min_number_bound >= 0 )
3659 y_min_number = y_min_number_bound;
3664 #ifndef __SUPPRESSANYOUTPUT__ 3668 if ( y_min_number >= 0 )
3671 for( i=0; i<nAC; ++i )
3674 y[nV+ii] -= y_min * xiC[i];
3676 for( i=0; i<nFX; ++i )
3679 y[ii] -= y_min * xiB[i];
3689 if ( y_min_isBound ==
BT_TRUE )
3691 #ifndef __SUPPRESSANYOUTPUT__ 3703 y[y_min_number] = 0.0;
3707 #ifndef __SUPPRESSANYOUTPUT__ 3708 snprintf( messageString,
MAX_STRING_LENGTH,
"constraint no. %d.",(
int)y_min_number );
3719 y[nV+y_min_number] = 0.0;
3777 int_t tcol = sizeT - nAC;
3790 if ( ( number_idx < 0 ) || ( number_idx >= nAC ) )
3813 if ( number_idx < nAC-1 )
3815 for( i=(number_idx+1); i<nAC; ++i )
3816 for( j=(nAC-i-1); j<nAC; ++j )
3817 TT(i-1,tcol+j) =
TT(i,tcol+j);
3819 for( j=0; j<nAC; ++j )
3820 TT(nAC-1,tcol+j) = 0.0;
3828 for( j=(nAC-2-number_idx); j>=0; --j )
3830 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 );
3833 for( i=(nAC-j-1); i<(nAC-1); ++i )
3834 applyGivens( c,s,nu,
TT(i,tcol+1+j),
TT(i,tcol+j),
TT(i,tcol+1+j),
TT(i,tcol+j) );
3836 for( i=0; i<nFR; ++i )
3839 applyGivens( c,s,nu,
QQ(ii,nZ+1+j),
QQ(ii,nZ+j),
QQ(ii,nZ+1+j),
QQ(ii,nZ+j) );
3846 for( j=0; j<nAC; ++j )
3847 TT(nAC-1,tcol+j) = 0.0;
3851 if ( ( updateCholesky ==
BT_TRUE ) &&
3863 for( j=0; j<nFR; ++j )
3864 z[j] =
QQ(FR_idx[j],nZ);
3871 for ( i=0; i<nZ; ++i )
3876 for( j=0; j<nFR; ++j )
3880 for( i=0; i<nZ; ++i )
3881 ZHz[i] +=
QQ(jj,i) * Hz[j];
3887 delete[] Hz;
delete[] r;
delete[] ZHz;
3893 for( i=0; i<nZ; ++i )
3899 delete[] r;
delete[] ZHz;
3903 for( j=0; j<nFR; ++j )
3904 rho2 +=
QQ(FR_idx[j],nZ) * Hz[j];
3934 else if ( exchangeHappened ==
BT_FALSE )
3942 RR(nZ,nZ) = 100.0*
EPS;
3962 if (exchangeHappened ==
BT_TRUE)
3969 if ( addBoundNotConstraint )
4020 int_t tcol = sizeT - nAC;
4044 int_t nnFRp1 = FR_idx[nFR];
4045 for( i=0; i<nFR; ++i )
4051 QQ(nnFRp1,nFR) = 1.0;
4068 for( j=(nAC-1); j>=0; --j )
4070 computeGivens( tmp[nAC-1-j],
TT(nAC-1-j,tcol+j),
TT(nAC-1-j,tcol+j),tmp[nAC-1-j],c,s );
4073 for( i=(nAC-j); i<nAC; ++i )
4076 for( i=0; i<=nFR; ++i )
4080 applyGivens( c,s,nu,
QQ(ii,nZ+1+j),
QQ(ii,nZ+j),
QQ(ii,nZ+1+j),
QQ(ii,nZ+j) );
4088 if ( ( updateCholesky ==
BT_TRUE ) &&
4104 for( j=0; j<nFR; ++j )
4105 z[j] =
QQ(FR_idx[j],nZ);
4115 for( i=0; i<nZ; ++i )
4119 for( j=0; j<nFR; ++j )
4122 for( i=0; i<nZ; ++i )
4124 rhs[i] +=
QQ(jj,i) * ( Hz[j] + z2 * z[j] );
4131 delete[] Hz;
delete[] r;
delete[]
rhs;
4138 for( i=0; i<nZ; ++i )
4144 delete[]
rhs;
delete[] r;
4147 for( j=0; j<nFR; ++j )
4151 rho2 +=
QQ(jj,nZ) * ( Hz[j] + 2.0*z2*z[j] );
4176 lb[number] =
ub[number];
4179 ub[number] =
lb[number];
4186 else if ( exchangeHappened ==
BT_FALSE )
4193 RR(nZ,nZ) = 100.0*
EPS;
4208 if ( addBoundNotConstraint )
4227 const int_t*
const idxList,
4237 for (i = 0; i < nIdx; i++)
4238 if ( (num[i] > epsNum) && (den[i] > epsDen) && (t * den[i] > num[i]) )
4240 t = num[i] / den[i];
4241 BC_idx = idxList[i];
4257 int_t addLBndIdx = -1, addLCnstrIdx = -1, addUBndIdx = -1, addUCnstrIdx = -1;
4258 int_t *FX_idx, *AC_idx, *IAC_idx;
4281 addBoundNotConstraint =
BT_TRUE;
4285 if (removeBoundNotConstraint)
4287 int_t dim = nV < nC ? nC : nV;
4290 for (ii = 0; ii < dim; ++ii)
4292 for (ii = 0; ii < nV; ++ii)
4298 delta_xFX, delta_xFR, delta_yAC, delta_yFX);
4306 for (ii = 0; ii < nV; ++ii)
4308 for (ii = 0; ii < nC; ++ii)
4315 delta_xFX, delta_xFR, delta_yAC, delta_yFX);
4322 for (ii = 0; ii < nAC; ++ii)
4325 if (normXi < a) normXi = a;
4327 for (ii = 0; ii < nFX; ++ii)
4330 if (normXi < a) normXi = a;
4335 for (ii = 0; ii < nFX; ++ii)
4338 if (normS < a) normS = a;
4340 for (ii = 0; ii < nFR; ++ii)
4343 if (normS < a) normS = a;
4350 real_t sigmaLBnd, sigmaLCnstr, sigmaUBnd, sigmaUCnstr, sigma;
4356 for (i = 0; i < nFR; i++)
4359 x_W[i] =
ub[ii] -
x[ii];
4369 x_W[0] =
ub[remIdx] -
x[remIdx];
4374 for (i = 0; i < nFR; i++)
4377 x_W[i] =
x[ii] -
lb[ii];
4379 for (i = 0; i < nFR; i++)
4380 delta_xFR[i] = -delta_xFR[i];
4389 x_W[0] =
x[remIdx] -
lb[remIdx];
4392 for (i = 0; i < nFR; i++)
4393 delta_xFR[i] = -delta_xFR[i];
4406 for (i = 0; i < nIAC; i++)
4423 for (i = 0; i < nIAC; i++)
4428 for (i = 0; i < nIAC; i++)
4443 if (sigmaUCnstr < sigma) { sigma = sigmaUCnstr; addStatus =
ST_UPPER; addBoundNotConstraint =
BT_FALSE; addIdx = addUCnstrIdx; }
4444 if (sigmaLCnstr < sigma) { sigma = sigmaLCnstr; addStatus =
ST_LOWER; addBoundNotConstraint =
BT_FALSE; addIdx = addLCnstrIdx; }
4445 if (sigmaUBnd < sigma) { sigma = sigmaUBnd; addStatus =
ST_UPPER; addBoundNotConstraint =
BT_TRUE; addIdx = addUBndIdx; }
4446 if (sigmaLBnd < sigma) { sigma = sigmaLBnd; addStatus =
ST_LOWER; addBoundNotConstraint =
BT_TRUE; addIdx = addLBndIdx; }
4455 for (i = 0; i < nFR; i++)
4456 x[FR_idx[i]] += sigma * delta_xFR[i];
4458 for (i = 0; i < nFX; i++)
4459 x[FX_idx[i]] += sigma * delta_xFX[i];
4462 A->times(1, 1.0,
x, nV, 0.0,
Ax, nC);
4463 for (i = 0; i < nC; i++)
Ax_u[i] =
ubA[i] -
Ax[i];
4464 for (i = 0; i < nC; i++)
Ax_l[i] =
Ax[i] -
lbA[i];
4492 int_t tcol = sizeT - nT;
4505 for( i=0; i<nT; ++i )
4508 for( j=0; j<i; ++j )
4509 sum -=
TT(i,sizeT-1-j) * a[nT-1-j];
4512 a[nT-1-i] = sum /
TT(i,sizeT-1-i);
4520 for( i=0; i<nT; ++i )
4523 for( j=0; j<i; ++j )
4524 sum -=
TT(nT-1-j,tcol+i) * a[nT-1-j];
4527 a[nT-1-i] = sum /
TT(nT-1-i,tcol+i);
4542 const real_t*
const lb_new,
const real_t*
const ub_new,
4562 delta_g,delta_lb,delta_ub,
4568 for( i=0; i<nC; ++i )
4572 delta_lbA[i] = lbA_new[i] -
lbA[i];
4574 delta_lbA[i] = -
INFTY - lbA[i];
4577 for( i=0; i<nC; ++i )
4581 delta_ubA[i] = ubA_new[i] -
ubA[i];
4583 delta_ubA[i] =
INFTY - ubA[i];
4589 for ( i=0; i<nAC; ++i )
4608 const real_t*
const delta_lb,
const real_t*
const delta_ub,
4614 int_t i, j, ii, jj, r;
4633 for( i=0; i<nFX; ++i )
4638 delta_xFX[i] = delta_lb[ii];
4640 delta_xFX[i] = delta_ub[ii];
4645 for( i=0; i<nFX; ++i )
4652 for ( i=0; i<nFR; ++i )
4655 tempA[i] = delta_g[ii];
4658 for ( i=0; i<nAC; ++i )
4662 for ( i=0; i<nAC; ++i )
4666 tempB[i] = delta_lbA[ii];
4668 tempB[i] = delta_ubA[ii];
4673 for ( i=0; i<nAC; ++i )
4683 for( i=0; i<nFR; ++i )
4689 if ( ( Delta_bC_isZero ==
BT_TRUE ) && ( Delta_bB_isZero ==
BT_TRUE ) )
4691 for( i=0; i<nAC; ++i )
4698 if ( ( Delta_bB_isZero ==
BT_FALSE ) && ( r == 0 ) )
4704 for( i=0; i<nFR; ++i )
4707 for( j=0; j<nAC; ++j )
4715 for( i=0; i<nZ; ++i )
4721 for( j=0; j<nFR; ++j )
4724 for( i=0; i<nZ; ++i )
4732 for( i=0; i<nZ; ++i )
4746 if ( ( Delta_bB_isZero ==
BT_FALSE ) && ( r == 0 ) )
4750 if ( ( nAC > 0 ) && ( ( Delta_bC_isZero ==
BT_FALSE ) || ( Delta_bB_isZero ==
BT_FALSE ) ) )
4756 for( j=0; j<nFR; ++j )
4759 for( i=0; i<nZ; ++i )
4774 for( i=0; i<nFR; ++i )
4779 for( j=0; j<nZ; ++j )
4800 for( j=0; j<nAC; ++j )
4807 for( j=0; j<nAC; ++j )
4812 for( j=0; j<nAC; ++j )
4817 for( j=0; j<nAC; ++j )
4819 for( i=0; i<nFR; ++i )
4833 for( i=0; i<nAC; ++i)
4836 for( j=0; j<nFR; ++j )
4849 for ( i=0; i<nFR; ++i )
4851 for ( i=0; i<nAC; ++i )
4857 for ( i=0; i<nFR; ++i )
4860 tempA[i] = delta_g[ii];
4867 for ( i=0; i<nFR; ++i )
4872 for ( i=0; i<nFR; ++i )
4873 tempA[i] += delta_xFR[i];
4884 for ( i=0; i<nFR; ++i )
4888 if (!Delta_bC_isZero)
4890 for ( i=0; i<nAC; ++i )
4894 tempB[i] = delta_lbA[ii];
4896 tempB[i] = delta_ubA[ii];
4901 for ( i=0; i<nAC; ++i )
4906 for ( i=0; i<nAC; ++i )
4920 for( i=0; i<nFX; ++i )
4921 delta_yFX[i] = delta_g[FX_idx[i]];
4929 for( i=0; i<nFX; ++i )
4930 delta_yFX[i] +=
regVal*delta_xFX[i];
4934 for( i=0; i<nFX; ++i )
4935 delta_yFX[i] += 1.0 * delta_xFX[i];
4952 const real_t*
const delta_lbA,
const real_t*
const delta_ubA,
4953 const real_t*
const delta_lb,
const real_t*
const delta_ub,
4954 const real_t*
const delta_xFX,
const real_t*
const delta_xFR,
4955 const real_t*
const delta_yAC,
const real_t*
const delta_yFX,
4982 int_t BC_idx_tmp = -1;
4992 for( j=0; j<nFR; ++j )
4995 delta_x[jj] = delta_xFR[j];
4997 for( j=0; j<nFX; ++j )
5000 delta_x[jj] = delta_xFX[j];
5007 for( i=0; i<nAC; ++i )
5012 den[i] = -delta_yAC[i];
5017 if ( BC_idx_tmp >= 0 )
5019 BC_idx = BC_idx_tmp;
5027 for( i=0; i<nFX; ++i )
5031 den[i] = -delta_yFX[i];
5036 if ( BC_idx_tmp >= 0 )
5038 BC_idx = BC_idx_tmp;
5055 for( i=0; i<nIAC; ++i )
5063 delete[] den;
delete[] num;
5064 delete[] delta_Ax;
delete[] delta_Ax_u;
delete[] delta_Ax_l;
delete[] delta_x;
5073 for( i=0; i<nIAC; ++i )
5077 den[i] = delta_lbA[ii] - delta_Ax[ii];
5082 if ( BC_idx_tmp >= 0 )
5084 BC_idx = BC_idx_tmp;
5092 for( i=0; i<nIAC; ++i )
5096 den[i] = delta_Ax[ii] - delta_ubA[ii];
5101 if ( BC_idx_tmp >= 0 )
5103 BC_idx = BC_idx_tmp;
5110 for( i=0; i<nIAC; ++i )
5116 delta_Ax_l[ii] = delta_Ax[ii] - delta_lbA[ii];
5117 delta_Ax_u[ii] = delta_ubA[ii] - delta_Ax[ii];
5127 for( i=0; i<nFR; ++i )
5131 den[i] = delta_lb[ii] - delta_xFR[i];
5136 if ( BC_idx_tmp >= 0 )
5138 BC_idx = BC_idx_tmp;
5147 for( i=0; i<nFR; ++i )
5151 den[i] = delta_xFR[i] - delta_ub[ii];
5156 if ( BC_idx_tmp >= 0 )
5158 BC_idx = BC_idx_tmp;
5169 #ifndef __SUPPRESSANYOUTPUT__ 5175 snprintf( messageString,
MAX_STRING_LENGTH,
"Stepsize is %.15e! (idx = %d, isBound = %d, status = %d)",
tau,(
int)BC_idx,(
int)BC_isBound,(
int)BC_status );
5185 for( i=0; i<nFR; ++i )
5188 x[ii] +=
tau*delta_xFR[i];
5191 for( i=0; i<nFX; ++i )
5194 x[ii] +=
tau*delta_xFX[i];
5195 y[ii] +=
tau*delta_yFX[i];
5198 for( i=0; i<nAC; ++i )
5201 y[nV+ii] +=
tau*delta_yAC[i];
5205 for( i=0; i<nV; ++i )
5207 g[i] +=
tau*delta_g[i];
5208 lb[i] +=
tau*delta_lb[i];
5209 ub[i] +=
tau*delta_ub[i];
5212 for( i=0; i<nC; ++i )
5214 lbA[i] +=
tau*delta_lbA[i];
5215 ubA[i] +=
tau*delta_ubA[i];
5219 for( i=0; i<nAC; ++i )
5225 for( i=0; i<nIAC; ++i )
5230 Ax[ii] +=
tau*delta_Ax[ii];
5231 Ax_l[ii] +=
tau*delta_Ax_l[ii];
5232 Ax_u[ii] +=
tau*delta_Ax_u[ii];
5239 #ifndef __SUPPRESSANYOUTPUT__ 5245 delete[] delta_Ax;
delete[] delta_Ax_u;
delete[] delta_Ax_l;
5258 #ifndef __SUPPRESSANYOUTPUT__ 5262 switch ( BC_status )
5272 #ifndef __SUPPRESSANYOUTPUT__ 5284 #ifndef __SUPPRESSANYOUTPUT__ 5302 #ifndef __SUPPRESSANYOUTPUT__ 5318 #ifndef __SUPPRESSANYOUTPUT__ 5320 snprintf( messageString,
MAX_STRING_LENGTH,
"lower constraint's bound no. %d.",(
int)BC_idx );
5322 snprintf( messageString,
MAX_STRING_LENGTH,
"upper constraint's bound no. %d.",(
int)BC_idx );
5343 const real_t*
const lbA_new,
const real_t*
const ubA_new
5356 for (i = 0; i < nC; i++)
5359 if (s < 1.0) s = 1.0;
5361 if (d > len) len = d;
5369 for (i = 0; i < nC; i++)
5372 if (s < 1.0) s = 1.0;
5374 if (d > len) len = d;
5389 real_t tP, rampValP, tD, rampValD, sca;
5392 nRamp = nV + nC + nC + nV;
5395 for (i = 0; i < nV; i++)
5400 lb[i] =
x[i];
ub[i] =
x[i];
5411 if (bstat ==
ST_LOWER) {
lb[i] =
x[i];
y[i] = +rampValD; }
5412 if (bstat ==
ST_UPPER) {
ub[i] =
x[i];
y[i] = -rampValD; }
5424 for (i = 0; i < nC; i++)
5471 const real_t*
const lbA_new,
real_t*
const lbA_new_far,
5481 lb_new,lb_new_far, ub_new,ub_new_far
5488 for ( i=0; i<nC; ++i )
5491 rampVal = curFarBound * (1.0 + (1.0-t)*
ramp0 + t*
ramp1);
5494 lbA_new_far[i] = -rampVal;
5496 lbA_new_far[i] =
getMax( -rampVal,lbA_new[i] );
5499 ubA_new_far[i] = rampVal;
5501 ubA_new_far[i] =
getMin( rampVal,ubA_new[i] );
5506 for ( i=0; i<nC; ++i )
5509 lbA_new_far[i] = -curFarBound;
5511 lbA_new_far[i] =
getMax( -curFarBound,lbA_new[i] );
5514 ubA_new_far[i] = curFarBound;
5516 ubA_new_far[i] =
getMin( curFarBound,ubA_new[i] );
5534 for ( i=0; i<nV; ++i )
5573 for ( i=0; i<nC; ++i )
5595 lbA[i] =
getMin (lbA[i], Ax[i]);
5596 Ax_l[i] = Ax[i] - lbA[i];
5634 if ( ( guessedBounds == 0 ) || ( guessedConstraints == 0 ) )
5685 for ( i=0; i<nV; ++i )
5689 for ( i=0; i<nC; ++i )
5697 A->times(1, 1.0,
x, nV, 0.0,
Ax, nC);
5698 for ( j=0; j<nC; ++j )
5730 int_t differenceNumberBounds = 0;
5732 for( i=0; i<nV; ++i )
5734 ++differenceNumberBounds;
5738 int_t differenceNumberConstraints = 0;
5740 for( i=0; i<nC; ++i )
5742 ++differenceNumberConstraints;
5745 if ( 2*(differenceNumberBounds+differenceNumberConstraints) > guessedConstraints->
getNAC( )+guessedBounds->
getNFX( ) )
5762 #ifdef __WRITE_DATA_FILES__ 5767 GlobalOutputFileCounter++;
5769 snprintf(buf,256,
"QP%d_setupQPdata.dat",GlobalOutputFileCounter);
5770 MyPrintf(
"+++ Writing output file %s\n", buf);
5772 FILE* output_file = fopen(buf,
"w");
5774 fprintf(output_file,
"nVar = %d\n", nV);
5775 fprintf(output_file,
"nCon = %d\n", nC);
5778 for (i=0; i<nV; i++) {
5779 fprintf(output_file,
"g[%d] = %23.16e\n",i,_g[i]);
5782 for (i=0; i<nV; i++) {
5783 fprintf(output_file,
"lb[%d] = %23.16e\n",i,
getMax(-Infinity,_lb[i]));
5785 for (i=0; i<nV; i++) {
5786 fprintf(output_file,
"ub[%d] = %23.16e\n",i,
getMin(Infinity,_ub[i]));
5789 for (i=0; i<nC; i++) {
5790 fprintf(output_file,
"lbA[%d] = %23.16e\n",i,
getMax(-Infinity,_lbA[i]));
5792 for (i=0; i<nC; i++) {
5793 fprintf(output_file,
"ubA[%d] = %23.16e\n",i,
getMin(Infinity,_ubA[i]));
5795 fclose(output_file);
5803 if ( ( nC > 0 ) && ( _A == 0 ) )
5834 if ( ( nC > 0 ) && ( _A == 0 ) )
5855 const char*
const lb_file,
const char*
const ub_file,
5856 const char*
const lbA_file,
const char*
const ubA_file
5871 if ( ( nC > 0 ) && ( A_file == 0 ) )
5877 if ( lbA_file != 0 )
5886 for( i=0; i<nC; ++i )
5891 if ( ubA_file != 0 )
5900 for( i=0; i<nC; ++i )
5924 const char*
const lbA_file,
const char*
const ubA_file,
5942 if ( lbA_file != 0 )
5958 if ( ubA_file != 0 )
5986 #ifndef __SUPPRESSANYOUTPUT__ 5997 real_t stat, bfeas, cfeas, bcmpl, ccmpl, Tmaxomin;
6004 const char excStr[] =
" ef";
6011 stat = bfeas = cfeas = bcmpl = ccmpl = Tmaxomin = 0.0;
6014 for (i = 0; i < nV; i++) grad[i] =
g[i] -
y[i];
6019 for( i=0; i<nV; ++i )
6024 for( i=0; i<nV; ++i )
6025 grad[i] += 1.0 *
x[i];
6029 H->
times(1, 1.0,
x, nV, 1.0, grad, nV);
6033 A->transTimes(1, -1.0,
y+nV, nC, 1.0, grad, nV);
6034 for (i = 0; i < nV; i++) if (getAbs(grad[i]) > stat) stat =
getAbs(grad[i]);
6037 for (i = 0; i < nV; i++)
if (
lb[i] -
x[i] > bfeas) bfeas =
lb[i] -
x[i];
6038 for (i = 0; i < nV; i++)
if (x[i] -
ub[i] > bfeas) bfeas = x[i] -
ub[i];
6039 A->times(1, 1.0, x, nV, 0.0, AX, nC);
6040 for (i = 0; i < nC; i++)
if (
lbA[i] - AX[i] > cfeas) cfeas =
lbA[i] - AX[i];
6041 for (i = 0; i < nC; i++)
if (AX[i] -
ubA[i] > cfeas) cfeas = AX[i] -
ubA[i];
6044 for (i = 0; i < nV; i++) if (y[i] > +
EPS &&
getAbs((
lb[i] - x[i])*
y[i]) > bcmpl) bcmpl =
getAbs((
lb[i] - x[i])*
y[i]);
6045 for (i = 0; i < nV; i++)
if (
y[i] < -
EPS &&
getAbs((ub[i] - x[i])*
y[i]) > bcmpl) bcmpl =
getAbs((ub[i] - x[i])*
y[i]);
6046 for (i = 0; i < nC; i++) if (y[nV+i] > +
EPS &&
getAbs((
lbA[i]-AX[i])*
y[nV+i]) > ccmpl) ccmpl =
getAbs((
lbA[i]-AX[i])*
y[nV+i]);
6047 for (i = 0; i < nC; i++)
if (
y[nV+i] < -
EPS &&
getAbs((ubA[i]-AX[i])*
y[nV+i]) > ccmpl) ccmpl =
getAbs((ubA[i]-AX[i])*
y[nV+i]);
6049 Tmin = 1.0e16; Tmax = 0.0;
6050 for (i = 0; i < nAC; i++)
6051 if (
getAbs(
TT(i,sizeT-i-1)) < Tmin)
6053 else if (
getAbs(
TT(i,sizeT-i-1)) > Tmax)
6055 Tmaxomin = Tmax/Tmin;
6057 if ( (iter % 10 == 0) && ( isFirstCall ==
BT_TRUE ) )
6059 snprintf( myPrintfString,
MAX_STRING_LENGTH,
"\n%5s %4s %4s %4s %4s %9s %9s %9s %9s %9s %9s %9s %9s\n",
6060 "iter",
"addB",
"remB",
"addC",
"remC",
"hom len",
"tau",
"stat",
6061 "bfeas",
"cfeas",
"bcmpl",
"ccmpl",
"Tmin");
6111 snprintf( myPrintfString,
MAX_STRING_LENGTH,
"%9.2e %9.2e %9.2e %9.2e %9.2e %9.2e %9.2e %9.2e\n",
6112 homotopyLength,
tau, stat, bfeas, cfeas, bcmpl, ccmpl, Tmin);
6120 if ( (iter % 10 == 0) && ( isFirstCall ==
BT_TRUE ) )
6123 "iter",
"addB",
"remB",
"addC",
"remC",
"hom len",
"tau" );
6178 if ( ( iter == 0 ) && ( isFirstCall ==
BT_TRUE ) )
6180 snprintf( myPrintfString,
MAX_STRING_LENGTH,
"\n\n#################### qpOASES -- QP NO. %3.0d #####################\n\n",(
int)
count );
6183 myPrintf(
" Iter | StepLength | Info | nFX | nAC \n" );
6184 myPrintf(
" ----------+------------------+------------------+---------+--------- \n" );
6191 snprintf( info,3,
"LP" );
6193 snprintf( info,3,
"QP" );
6204 snprintf( info,5,
"REM " );
6206 snprintf( info,5,
"ADD " );
6209 snprintf( &(info[4]),4,
"BND" );
6211 snprintf( &(info[4]),4,
"CON" );
6242 int_t y_min_number = -1;
6244 int_t y_min_priority = blockingPriority;
6255 for ( i = 0; i < nAC; ++i )
6259 y_min_number = AC_idx[i];
6269 for ( i = 0; i < nAC; ++i )
6273 y_min_number = AC_idx[i];
6283 for ( i = 0; i < nFX; ++i )
6286 y_min_number = FX_idx[i];
6293 if (y_min_number >= 0) {
6296 if (y_min_isBound) {
6336 #ifndef __SUPPRESSANYOUTPUT__ 6339 matFile = fopen( filename,
"w+" );
6380 #ifndef __SUPPRESSANYOUTPUT__ 6383 matFile = fopen( filename,
"w+" );
6404 int_t *FR_idx, *FX_idx, *AC_idx, *IAC_idx;
real_t getRelativeHomotopyLength(const real_t *const g_new, const real_t *const lb_new, const real_t *const ub_new)
BooleanType areBoundsConsistent(const real_t *const delta_lb, const real_t *const delta_ub, const real_t *const delta_lbA, const real_t *const delta_ubA) const
returnValue addConstraint_ensureLI(int number, SubjectToStatus C_status)
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)
Interfaces matrix-vector operations tailored to symmetric sparse matrices.
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)
returnValue writeQpWorkspaceIntoMatFile(const char *const filename)
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)
virtual returnValue getWorkingSetBounds(real_t *workingSetB)
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)
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
virtual real_t * full() 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
void MyPrintf(const char *pformat,...)
returnValue updateFarBounds(real_t curFarBound, int_t nRamp, const real_t *const lb_new, real_t *const lb_new_far, const real_t *const ub_new, real_t *const ub_new_far) const
#define THROWINFO(retval)
returnValue obtainAuxiliaryWorkingSet(const real_t *const xOpt, const real_t *const yOpt, const Bounds *const guessedBounds, Bounds *auxiliaryBounds) const
#define ST_INFEASIBLE_UPPER
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)
virtual returnValue setupInitialCholesky()
virtual returnValue updateActivitiesForHotstart(const real_t *const lb_new, const real_t *const ub_new, const real_t *const lbA_new, const real_t *const ubA_new)
returnValue ensureNonzeroCurvature(BooleanType removeBoundNotConstraint, int remIdx, BooleanType &exchangeHappened, BooleanType &addBoundNotConstraint, int &addIdx, SubjectToStatus &addStatus)
real_t getRelativeHomotopyLength(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)
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)
#define ST_INFEASIBLE_LOWER
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)
virtual returnValue getWorkingSetConstraints(real_t *workingSetC)
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
SymSparseMat * createDiagSparseMat(int_t n, real_t diagVal=1.0)
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)
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
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
returnValue updateFarBounds(real_t curFarBound, int_t nRamp, const real_t *const lb_new, real_t *const lb_new_far, const real_t *const ub_new, real_t *const ub_new_far, const real_t *const lbA_new, real_t *const lbA_new_far, const real_t *const ubA_new, real_t *const ubA_new_far) const
virtual returnValue writeToFile(FILE *output_file, const char *prefix) const =0
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)
virtual returnValue computeProjectedCholesky()
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]
BooleanType areBoundsConsistent(const real_t *const delta_lb, const real_t *const delta_ub) const
int_t dropIneqConPriority
returnValue getFreeVariablesFlags(BooleanType *varIsFree)
int enableDriftCorrection
TabularOutput tabularOutput
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.
virtual returnValue bilinear(const Indexlist *const icols, int xN, const real_t *x, int xLD, real_t *y, int yLD) const
returnValue setupQPdataFromFile(const char *const H_file, const char *const g_file, const char *const lb_file, const char *const ub_file)
virtual returnValue computeCholesky()
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
BooleanType enableRegularisation
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)
virtual returnValue getWorkingSetBounds(real_t *workingSetB)
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
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)
returnValue writeIntoMatFile(FILE *const matFile, const real_t *const data, int_t nRows, int_t nCols, const char *name)
real_t delta_xFR_TMP[NVMAX]
const uint_t MAX_STRING_LENGTH
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)
returnValue setStatus(int i, SubjectToStatus value)
BooleanType enableNZCTests
QProblemB & operator=(const QProblemB &rhs)
virtual returnValue getWorkingSet(real_t *workingSet)
virtual returnValue printProperties()
int getIndex(int givennumber) const
BooleanType hasNoUpper() const
Manages working sets of bounds (= box constraints).
returnValue dropInfeasibles(int_t BC_number, SubjectToStatus BC_status, BooleanType BC_isBound, real_t *xiB, real_t *xiC)
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)
returnValue writeQpDataIntoMatFile(const char *const filename) const
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)
SubjectToStatus initialStatusBounds
returnValue get(Bounds *const _bounds, double *const R, Constraints *const _constraints=0, double *const _Q=0, double *const _T=0) const
BooleanType enableDropInfeasibles
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