45 va_start(ap, pformat);
47 vfprintf(stdout, pformat, ap);
53 # define MyPrintf mexPrintf 72 #elif defined SOLVER_MA27 74 #elif defined SOLVER_NONE 111 #elif defined SOLVER_MA27 113 #elif defined SOLVER_NONE 117 nSmax = maxSchurUpdates;
158 #elif defined SOLVER_MA27 160 #elif defined SOLVER_NONE 261 for ( i=0; i<
nS; i++)
262 for ( j=0; j<
nS; j++)
349 for ( i=0; i<nC; ++i )
359 for ( i=0; i<nC; ++i )
366 for ( i=0; i<nC; ++i )
416 MyPrintf(
"In hotstart for new matrices, old working set is linearly independent and has correct inertia.\n");
425 MyPrintf(
"WARNING: In hotstart for new matrices, reduced Hessian for initial working set has %i negative eigenvalues, should be %i.\n", neig,
getNAC( ) );
445 MyPrintf(
"WARNING: hotstart for old active set failed. Trying to rebuild a working set.\n");
451 for ( i=0; i<nV; i++ )
453 #ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ 469 #ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ 470 for( i=0; i<nC; ++i )
479 for( i=0; i<nC; ++i )
504 for (
int_t ii = 0; ii < nC; ++ii)
527 if ( auxiliaryBounds != 0 )
529 for( i=0; i<nV; ++i )
538 if ( auxiliaryConstraints != 0 )
540 for( i=0; i<nC; ++i )
553 for( i=0; i<nV; ++i )
566 for( i=0; i<nC; ++i )
580 for( i=0; i<nV; ++i )
588 for( i=0; i<nC; ++i )
614 MyPrintf(
"WARNING: In setupAuxiliaryWorkingSet: Initial working set reduced Hessian has %i negative eigenvalues, should be %i.\n", neig,
getNAC( ) );
659 int_t idxDeleted = -1;
683 switch ( ensureLIreturnvalue )
728 if ( nS < 0 || nS==
nSmax )
736 MyPrintf(
"In addConstraint: KKT matrix singular when resetting Schur complement\n" );
738 MyPrintf(
"In addConstraint, resetSchurComplement failed with retval = %d\n", retval);
759 for (
int_t i=0; i<nFRStart; i++)
760 icolsNumber[i] = FR_idxStart[i];
762 int_t icolsLength = nFRStart;
767 icolsSIdx[icolsLength-nFRStart] = i;
773 MyPrintf(
"In SQProblemSchur::addConstraint, constraintProduct not yet implemented.\n");
777 A->getSparseSubmatrix( 1, &number, icolsLength, icolsNumber, 0, 0, numNonzerosA, irn, jcn, vals );
780 int_t numNonzerosM = 0;
781 int_t numNonzerosN = 0;
782 for (
int_t i=0; i<numNonzerosA; i++ )
783 if ( jcn[i] < nFRStart )
785 MNpos[numNonzerosM] = jcn[i];
786 MNvals[numNonzerosM] = vals[i];
791 MNpos[nFRStart+numNonzerosN] = icolsSIdx[jcn[i]-nFRStart];
792 MNvals[nFRStart+numNonzerosN] = vals[i];
799 delete [] icolsNumber;
824 MyPrintf(
"In addConstraint: KKT matrix singular when resetting Schur complement\n" );
826 MyPrintf(
"In addConstraint, resetSchurComplement failed with retval = %d\n", retval);
853 return returnvalueCheckLI;
894 int_t dim = (nC>nV)?nC:nV;
896 for (ii = 0; ii < dim; ++ii)
899 A->getRow (number, 0, 1.0, delta_g);
904 delta_xFX, delta_xFR, delta_yAC, delta_yFX);
906 returnvalue = dsdreturnvalue;
912 for (ii = 0; ii < nAC; ++ii)
915 if (weight < a) weight = a;
917 for (ii = 0; ii < nFX; ++ii)
920 if (weight < a) weight = a;
925 for (ii = 0; ii < nFX; ++ii)
928 if (zero < a) zero = a;
930 for (ii = 0; ii < nFR; ++ii)
933 if (zero < a) zero = a;
983 for( i=0; i<nAC; ++i )
985 for( i=0; i<nFX; ++i )
1000 int_t y_min_number = -1;
1001 int_t y_min_number_bound = -1;
1009 for( i=0; i<nAC; ++i )
1018 for( i=0; i<nFX; ++i )
1026 if ( y_min_number_bound >= 0 )
1028 y_min_number = y_min_number_bound;
1032 #ifndef __XPCTARGET__ 1034 char messageString[80];
1038 if ( y_min_number >= 0 )
1041 for( i=0; i<nAC; ++i )
1044 y[nV+ii] -= y_min * xiC[i];
1046 for( i=0; i<nFX; ++i )
1049 y[ii] -= y_min * xiB[i];
1054 y[nV+number] = y_min;
1056 y[nV+number] = -y_min;
1059 if ( y_min_isBound ==
BT_TRUE )
1061 #ifndef __XPCTARGET__ 1062 snprintf( messageString,80,
"bound no. %d.",(
int)y_min_number );
1073 y[y_min_number] = 0.0;
1077 #ifndef __XPCTARGET__ 1078 snprintf( messageString,80,
"constraint no. %d.",(
int)y_min_number );
1089 y[nV+y_min_number] = 0.0;
1126 int_t idxDeleted = -1;
1150 switch ( ensureLIreturnvalue )
1195 if ( nS < 0 || nS==
nSmax )
1203 MyPrintf(
"In addBound: KKT matrix singular when resetting Schur complement\n" );
1205 MyPrintf(
"In addBound, resetSchurComplement failed with retval = %d\n", retval);
1216 for (
int_t i=0; i<nFRStart; i++ )
1217 if ( FR_idxStart[i] == number )
1241 MyPrintf(
"In addBound: KKT matrix singular when resetting Schur complement\n" );
1243 MyPrintf(
"In addBound, resetSchurComplement failed with retval = %d\n", retval);
1269 return returnvalueCheckLI;
1304 for (ii = 0; ii < nV; ++ii)
1306 delta_g[number] = 1.0;
1308 int_t dim = (nC>nV)?nC:nV;
1310 for (ii = 0; ii < dim; ++ii)
1315 delta_xFX, delta_xFR, delta_yAC, delta_yFX);
1317 returnvalue = dsdReturnValue;
1321 for (ii = 0; ii < nAC; ++ii)
1324 if (weight < a) weight = a;
1326 for (ii = 0; ii < nFX; ++ii)
1329 if (weight < a) weight = a;
1334 for (ii = 0; ii < nFX; ++ii)
1337 if (zero < a) zero = a;
1339 for (ii = 0; ii < nFR; ++ii)
1342 if (zero < a) zero = a;
1393 for( i=0; i<nAC; ++i )
1395 for( i=0; i<nFX; ++i )
1410 int_t y_min_number = -1;
1411 int_t y_min_number_bound = -1;
1419 for( i=0; i<nAC; ++i )
1428 for( i=0; i<nFX; ++i )
1436 if ( y_min_number_bound >= 0 )
1438 y_min_number = y_min_number_bound;
1443 char messageString[80];
1445 if ( y_min_number >= 0 )
1448 for( i=0; i<nAC; ++i )
1451 y[nV+ii] -= y_min * xiC[i];
1453 for( i=0; i<nFX; ++i )
1456 y[ii] -= y_min * xiB[i];
1466 if ( y_min_isBound ==
BT_TRUE )
1468 #ifndef __XPCTARGET__ 1469 snprintf( messageString,80,
"bound no. %d.",(
int)y_min_number );
1480 y[y_min_number] = 0.0;
1484 #ifndef __XPCTARGET__ 1485 snprintf( messageString,80,
"constraint no. %d.",(
int)y_min_number );
1496 y[nV+y_min_number] = 0.0;
1537 int_t idxDeleted = -1;
1564 if ( ( number_idx < 0 ) || ( number_idx >= nAC ) )
1604 if ( nS < 0 || nS==
nSmax )
1612 MyPrintf(
"In removeConstraint: KKT matrix singular when resetting Schur complement\n" );
1614 MyPrintf(
"In removeConstraint, resetSchurComplement failed with retval = %d\n", retval);
1628 for (
int_t i=0; i<nACStart; i++ )
1629 if ( AC_idxStart[i] == number )
1651 if ( sModType == 1 )
1657 if ( oldDet * newDet > 0 )
1667 switch ( oldStatus )
1671 ubA[number] =
lbA[number];
1676 lbA[number] =
ubA[number];
1688 else if ( sModType == 2 )
1694 if ( oldDet * newDet < 0.0 )
1704 switch ( oldStatus )
1708 ubA[number] =
lbA[number];
1713 lbA[number] =
ubA[number];
1725 else if ( sModType == 3 )
1735 switch ( oldStatus )
1738 ubA[number] =
lbA[number];
1743 lbA[number] =
ubA[number];
1773 MyPrintf(
"In removeConstraint: KKT matrix singular when resetting Schur complement\n" );
1775 MyPrintf(
"In removeConstraint, resetSchurComplement failed with retval = %d\n", retval);
1780 if ( exchangeHappened ==
BT_TRUE )
1784 if ( addBoundNotConstraint )
1816 int_t idxDeleted = -1;
1869 if ( nS < 0 || nS==
nSmax )
1877 MyPrintf(
"In removeBound: KKT matrix singular when resetting Schur complement\n" );
1879 MyPrintf(
"In removeBound, resetSchurComplement failed with retval = %d\n", retval);
1895 int_t numNonzerosM = 0;
1898 int_t numNonzerosN = 0;
1903 int_t* irn =
new int_t[nFRStart+nACStart+nS+1];
1904 int_t* jcn =
new int_t[nFRStart+nACStart+nS+1];
1907 int_t* iNumber =
new int_t[nFRStart+nACStart+nS+1];
1916 N_diag = regularisation;
1920 N_diag = 1.0 + regularisation;
1924 N_diag = regularisation;
1925 for (
int_t i=0; i<nFRStart; i++ )
1926 iNumber[i] = FR_idxStart[i];
1932 iSIdx[iLength-nFRStart] = i;
1935 iNumber[iLength++] = number;
1939 for (
int_t i=0; i<numNonzeros; i++ )
1941 if ( irn[i] < nFRStart )
1943 Mpos[numNonzerosM] = irn[i];
1944 Mvals[numNonzerosM] = vals[i];
1947 else if ( irn[i] != iLength-1 )
1949 Npos[numNonzerosN] = iSIdx[irn[i] - nFRStart];
1950 Nvals[numNonzerosN] = vals[i];
1961 MyPrintf(
"In SQProblemSchur::removeBound, constraintProduct not yet implemented.\n");
1965 for (
int_t i=0; i<nACStart; i++ )
1966 iNumber[i] = AC_idxStart[i];
1972 iSIdx[iLength-nACStart] = i;
1976 A->getSparseSubmatrix( iLength, iNumber, 1, &number, 0, 0, numNonzeros, irn, jcn, vals );
1978 for (
int_t i=0; i<numNonzeros; i++ )
1980 if ( irn[i] < nACStart )
1982 Mpos[numNonzerosM] = irn[i] + nFRStart;
1983 Mvals[numNonzerosM] = vals[i];
1988 Npos[numNonzerosN] = iSIdx[irn[i] - nACStart];
1989 Nvals[numNonzerosN] = vals[i];
2023 if ( sModType == 1 )
2029 if ( oldDet * newDet > 0.0 )
2039 switch ( oldStatus )
2043 ub[number] =
lb[number];
2047 lb[number] =
ub[number];
2058 else if ( sModType == 2 )
2064 if ( oldDet * newDet < 0.0 )
2074 switch ( oldStatus )
2078 ub[number] =
lb[number];
2082 lb[number] =
ub[number];
2093 else if ( sModType == 3 )
2103 switch ( oldStatus )
2106 ub[number] =
lb[number];
2110 lb[number] =
ub[number];
2139 MyPrintf(
"In removeBound: KKT matrix singular when resetting Schur complement\n" );
2141 MyPrintf(
"In removeBound, resetSchurComplement failed with retval = %d\n", retval);
2146 if ( exchangeHappened ==
BT_TRUE )
2150 if ( addBoundNotConstraint )
2211 for( i=0; i<
nS-1; i++ )
2212 temp1[i] =
S[i + (nS-1)*
nSmax];
2215 newDet =
S[(nS-1) + (nS-1)*
nSmax];
2216 for( i=0; i<nS-1; i++ )
2217 newDet -= temp1[i]*temp2[i];
2230 for( j=0; j<idxDel; j++ )
2231 for( i=0; i<dim; i++ )
2232 tempR[i+j*dim] =
R_[i+j*
nSmax];
2233 for( j=idxDel; j<dim-1; j++ )
2234 for( i=0; i<dim; i++ )
2235 tempR[i+j*dim] =
R_[i+(j+1)*
nSmax];
2237 for( j=0; j<dim; j++ )
2238 tempColQ[j] =
Q_[idxDel+j*
nSmax];
2241 for ( i=idxDel; i<
nS; i++ )
2243 computeGivens( tempR[i+i*dim], tempR[(i+1)+i*dim], tempR[i+i*dim], tempR[(i+1)+i*dim], c, s );
2246 for ( j=i+1; j<
nS; j++ )
2247 applyGivens( c, s, nu, tempR[i+j*dim], tempR[(i+1)+j*dim], tempR[i+j*dim], tempR[(i+1)+j*dim] );
2250 applyGivens( c, s, nu, tempColQ[i], tempColQ[i+1], tempColQ[i], tempColQ[i+1] );
2254 for ( i=nS; i>0; i-- )
2256 computeGivens( tempColQ[nS], tempColQ[i-1], tempColQ[nS], tempColQ[i-1], c, s );
2260 applyGivens( c, s, nu, tempR[nS+(i-1)*dim], tempR[(i-1)+(i-1)*dim], tempR[nS+(i-1)*dim], tempR[(i-1)+(i-1)*dim] );
2267 if ( (( (nS - idxDel) % 2 == 1 ) && ( tempColQ[nS] > 0.0 )) ||
2268 (( (nS - idxDel) % 2 == 0 ) && ( tempColQ[nS] < 0.0 )) )
2270 tempR[0] = -tempR[0];
2276 for( i=0; i<
nS; i++ )
2277 if( tempR[i+i*dim] < 0.0 ) newDet = -newDet;
2305 for ( i=0; i<
nS; i++ )
2310 Q_[(nS-1)+(nS-1)*
nSmax] = 1.0;
2313 for ( i=0; i<
nS; i++ )
2317 for ( i=0; i<
nS; i++ )
2320 for ( j=0; j<
nS; j++ )
2325 for ( i=0; i<nS-1; i++ )
2329 for ( j=i+1; j<
nS; j++ )
2333 for ( j=0; j<
nS; j++ )
2341 for ( j=idxDel; j<
nS; j++ )
2342 for ( i=0; i<nS+1; i++ )
2346 for ( i=idxDel; i<
nS; i++ )
2350 for ( j=i+1; j<
nS; j++ )
2354 for ( j=0; j<nS+1; j++ )
2360 for ( j=0; j<nS+1; j++ )
2363 for ( i=idxDel; i<
nS; i++ )
2369 for ( i=nS; i>0; i-- )
2373 for ( j=0; j<
nS; j++ )
2377 for ( j=i-1; j<
nS; j++ )
2384 if ( (( (nS - idxDel) % 2 == 1 ) && (
Q_[nS+nS*
nSmax] > 0.0 )) ||
2385 (( (nS - idxDel) % 2 == 0 ) && (
Q_[nS+nS*
nSmax] < 0.0 )) )
2387 for ( i=0; i<nS+1; i++ )
2389 for ( i=0; i<
nS; i++ )
2398 for ( i=0; i<
nS; i++ )
2403 unsigned long N = (
unsigned long)nS;
2404 unsigned long LDA = (
unsigned long)
nSmax;
2405 unsigned long *IWORK;
2407 IWORK =
new unsigned long[
N];
2409 TRCON(
"1",
"U",
"N", &N,
R_, &LDA, &
rcondS, WORK, IWORK, &INFO );
2412 MyPrintf(
"TRCON returns INFO = %d\n",(
int)INFO );
2430 if( dimS < 1 || dimRhs < 1 )
2435 MyPrintf(
"backsolve not implemented for dimRhs = %d\n", dimRhs);
2441 unsigned long NRHS = 1;
2442 unsigned long M = (
unsigned long)dimS;
2443 unsigned long LDA = (
unsigned long)
nSmax;
2444 unsigned long LDC = (
unsigned long)dimS;
2446 for( i=0; i<dimS; i++ )
2450 for( i=0; i<dimS; i++ )
2451 for( j=0; j<dimS; j++ )
2452 sol[i] +=
Q_[j+i*
nSmax] * rhs[j];
2455 TRTRS(
"U",
"N",
"N", &M, &NRHS,
R_, &LDA, sol, &LDC, &INFO );
2458 MyPrintf(
"TRTRS returns INFO = %d\n", INFO);
2467 const real_t*
const delta_g,
const real_t*
const delta_lbA,
const real_t*
const delta_ubA,
2468 const real_t*
const delta_lb,
const real_t*
const delta_ub,
2482 MyPrintf(
"In SQProblemSchur::stepCalcRhs, resetSchurComplement returns %d\n", retval);
2489 for ( i=0; i<nFR; ++i )
2492 tempA[i] = delta_g[ii];
2495 for ( i=0; i<nAC; ++i )
2499 for ( i=0; i<nAC; ++i )
2503 tempB[i] = delta_lbA[ii];
2505 tempB[i] = delta_ubA[ii];
2510 for ( i=0; i<nAC; ++i )
2525 for ( i=0; i<nFR; i++ )
2527 for ( i=0; i<nAC; i++ )
2533 returnValue SQProblemSchur::stepCalcReorder(
int_t nFR,
int_t nAC,
int_t*
FR_idx,
int_t*
AC_idx,
int_t nFRStart,
int_t nACStart,
int_t* FR_idxStart,
int_t* AC_idxStart,
int_t* FR_iSort,
int_t* FR_iSortStart,
int_t* AC_iSort,
int_t* AC_iSortStart,
real_t*
rhs)
2539 while ( ii < nFRStart )
2542 rhs[FR_iSortStart[ii++]] = 0.0;
2545 int_t idx = FR_idx[FR_iSort[i]];
2546 int_t idxStart = FR_idxStart[FR_iSortStart[ii]];
2548 if ( idx == idxStart )
2549 rhs[FR_iSortStart[ii++]] = -
tempA[FR_iSort[i++]];
2550 else if ( idx < idxStart )
2553 rhs[FR_iSortStart[ii++]] = 0.0;
2559 while ( ii < nACStart )
2562 rhs[nFRStart+AC_iSortStart[ii++]] = 0.0;
2565 int_t idx = AC_idx[AC_iSort[i]];
2566 int_t idxStart = AC_idxStart[AC_iSortStart[ii]];
2568 if ( idx == idxStart )
2569 rhs[nFRStart+AC_iSortStart[ii++]] =
tempB[AC_iSort[i++]];
2570 else if ( idx < idxStart )
2573 rhs[nFRStart+AC_iSortStart[ii++]] = 0.0;
2587 for ( ii=0; ii<
nS; ii++ )
2598 for( i=0; i<nFR; ++i )
2599 if ( FR_idx[i] == idx )
2608 for( i=0; i<nAC; ++i )
2609 if ( AC_idx[i] == idx )
2637 MyPrintf(
"sparseSolver->solve (second time) failed.\n");
2642 for ( ii=0; ii<
nS; ii++ )
2652 for( i=0; i<nFR; ++i )
2653 if ( FR_idx[i] == idx )
2662 for( i=0; i<nAC; ++i )
2663 if ( AC_idx[i] == idx )
2683 returnValue SQProblemSchur::stepCalcReorder2(
int_t nFR,
int_t nAC,
int_t*
FR_idx,
int_t*
AC_idx,
int_t nFRStart,
int_t nACStart,
int_t* FR_idxStart,
int_t* AC_idxStart,
int_t* FR_iSort,
int_t* FR_iSortStart,
int_t* AC_iSort,
int_t* AC_iSortStart,
real_t* sol,
real_t*
const delta_xFR,
real_t*
const delta_yAC)
2688 while ( ii < nFRStart && i < nFR )
2690 int_t idx = FR_idx[FR_iSort[i]];
2691 int_t idxStart = FR_idxStart[FR_iSortStart[ii]];
2693 if ( idx == idxStart )
2695 else if ( idx < idxStart )
2703 while ( ii < nACStart && i < nAC )
2705 int_t idx = AC_idx[AC_iSort[i]];
2706 int_t idxStart = AC_idxStart[AC_iSortStart[ii]];
2708 if ( idx == idxStart )
2709 delta_yAC_TMP[AC_iSort[i++]] = -sol[nFRStart+AC_iSortStart[ii++]];
2710 else if ( idx < idxStart )
2717 for ( i=0; i<nFR; ++i )
2719 for ( i=0; i<nAC; ++i )
2724 returnValue SQProblemSchur::stepCalcResid(
int_t nFR,
int_t nFX,
int_t nAC,
int_t*
FR_idx,
int_t*
FX_idx,
int_t*
AC_idx,
BooleanType Delta_bC_isZero,
real_t*
const delta_xFX,
real_t*
const delta_xFR,
real_t*
const delta_yAC,
const real_t*
const delta_g,
const real_t*
const delta_lbA,
const real_t*
const delta_ubA,
real_t& rnrm)
2728 for ( i=0; i<nFR; ++i )
2731 tempA[i] = delta_g[ii];
2740 for ( i=0; i<nFR; ++i )
2741 tempA[i] += delta_xFR[i];
2750 for ( i=0; i<nFR; ++i )
2755 for ( i=0; i<nFR; ++i )
2759 if (!Delta_bC_isZero)
2761 for ( i=0; i<nAC; ++i )
2765 tempB[i] = delta_lbA[ii];
2767 tempB[i] = delta_ubA[ii];
2772 for ( i=0; i<nAC; ++i )
2779 for ( i=0; i<nAC; ++i )
2789 for( i=0; i<nFX; ++i )
2790 delta_yFX[i] = delta_g[FX_idx[i]];
2797 for( i=0; i<nFX; ++i )
2802 for( i=0; i<nFX; ++i )
2803 delta_yFX[i] += delta_xFX[i];
2814 const real_t*
const delta_lb,
const real_t*
const delta_ub,
2821 Delta_bC_isZero, Delta_bB_isZero, delta_xFX, delta_xFR,
2822 delta_yAC, delta_yFX
2830 MyPrintf(
"In SQProblem::determineStepDirection, resetSchurComplement returns %d\n", retval);
2834 Delta_bC_isZero, Delta_bB_isZero, delta_xFX, delta_xFR,
2835 delta_yAC, delta_yFX
2845 const real_t*
const delta_lb,
const real_t*
const delta_ub,
2882 for( i=0; i<nFX; ++i )
2887 delta_xFX[i] = delta_lb[ii];
2889 delta_xFX[i] = delta_ub[ii];
2894 for( i=0; i<nFX; ++i )
2900 retval =
stepCalcRhs( nFR, nFX, nAC, FR_idx, FX_idx, AC_idx, rhs_max, delta_g, delta_lbA, delta_ubA,
2901 delta_lb, delta_ub, Delta_bC_isZero, Delta_bB_isZero, delta_xFX, delta_xFR,
2902 delta_yAC, delta_yFX );
2919 int_t* FR_iSortStart;
2920 int_t* AC_iSortStart;
2924 int_t dim = nFRStart + nACStart;
2931 retval =
stepCalcReorder(nFR, nAC, FR_idx, AC_idx, nFRStart, nACStart, FR_idxStart, AC_idxStart, FR_iSort, FR_iSortStart, AC_iSort, AC_iSortStart, rhs);
2939 MyPrintf(
"sparseSolver->solve (first time) failed.\n");
2951 retval =
stepCalcReorder2(nFR, nAC, FR_idx, AC_idx, nFRStart, nACStart, FR_idxStart, AC_idxStart, FR_iSort, FR_iSortStart, AC_iSort, AC_iSortStart, sol, delta_xFR, delta_yAC);
2958 retval =
stepCalcResid(nFR, nFX, nAC, FR_idx, FX_idx, AC_idx, Delta_bC_isZero, delta_xFX, delta_xFR, delta_yAC, delta_g, delta_lbA, delta_ubA, rnrm);
2964 MyPrintf(
"In iterative refinement (iter %d) rnrm = %e and epsIterRef*rhs_max = %e.\n", r, rnrm,
options.
epsIterRef*rhs_max);
2979 retval =
stepCalcDeltayFx(nFR, nFX, nAC, FX_idx, delta_g, delta_xFX, delta_xFR, delta_yAC, delta_yFX);
2994 MyPrintf(
"Resetting Schur complement.\n");
3005 int_t dim = nFR+nAC;
3030 MyPrintf(
"In SQProblemSchur::determineStepDirection, constraintProduct not yet implemented.\n");
3034 numNonzeros += numNonzerosA;
3048 for (j = 0; j<nFR; j++)
3064 for (j = 0; j<nFR; j++)
3066 irn[numNonzeros] = j+1;
3067 jcn[numNonzeros] = j+1;
3073 numNonzeros += numNonzerosA;
3105 MyPrintf(
"WARNING: After new factorization, reduced Hessian has %i negative eigenvalues, should be %i.\n", neig,
getNAC( ) );
3126 for ( j=0; j<
nS; j++ )
3128 const real_t xval = x_[j];
3145 for ( j=0; j<
nS; j++ )
3154 for ( j=0; j<
nS; j++ )
3174 int_t dim = nFRStart + nACStart;
3178 for ( i=0; i<dim; i++ )
3181 for ( i=0; i<numNonzerosM; i++ )
3182 rhs[Mpos[i]] = Mvals[i];
3187 MyPrintf(
"sparseSolver->solve in SQProblemSchur::addToSchurComplement failed.\n");
3194 for ( i=0; i<numNonzerosN; i++ )
3195 new_Scol[Npos[i]] -= Nvals[i];
3198 for ( i=0; i<numNonzerosM; i++ )
3199 sdiag += Mvals[i] * sol[Mpos[i]];
3202 for ( i=0; i<
nS; i++)
3203 S[nS*
nSmax + i] = new_Scol[i];
3204 for ( i=0; i<
nS; i++)
3205 S[i*
nSmax + nS] = new_Scol[i];
3227 for ( i=0; i<numNonzerosM; i++ )
3230 M_ir[M_jc[
nS] + i] = Mpos[i];
3241 MyPrintf(
"added index %d with update type %d to Schur complement. nS = %d\n", number, update, nS);
3254 real_t *temp_vals = NULL;
3255 int_t *temp_ir = NULL;
3256 int_t schurUpdateIndexTemp = -1;
3264 temp_vals[i] =
S[idx*
nSmax + i];
3271 for (
int_t i=0; i<idx; i++ )
3272 for (
int_t j=idx+1; j<
nS; j++ )
3274 for (
int_t i=idx+1; i<
nS; i++ )
3276 for (
int_t j=0; j<idx; j++ )
3278 for (
int_t j=idx+1; j<
nS; j++ )
3281 for (
int_t i=idx+1; i<
nS; i++ )
3292 S[(nS-1)*
nSmax + i] = temp_vals[i];
3293 S[i*
nSmax + (nS-1)] = temp_vals[i];
3304 temp_ir =
new int_t[numEntries];
3305 temp_vals =
new real_t[numEntries];
3307 for (
int_t i=M_jc[idx]; i<M_jc[idx+1]; i++ )
3309 temp_ir[i-M_jc[idx]] =
M_ir[i];
3310 temp_vals[i-M_jc[idx]] =
M_vals[i];
3315 for (
int_t i=M_jc[idx+1]; i<M_jc[
nS]; i++ )
3320 for (
int_t i=idx; i<
nS; i++ )
3321 M_jc[i] = M_jc[i+1] - numEntries;
3326 for (
int_t i=M_jc[nS-1]; i<M_jc[
nS]; i++ )
3328 M_ir[i] = temp_ir[i-M_jc[nS-1]];
3329 M_vals[i] = temp_vals[i-M_jc[nS-1]];
3355 int_t schurUpdateIndexTemp = -1;
3360 for (
int_t i=0; i<
nS+1; i++ )
3361 temp_vals[i] =
S[i+nS*
nSmax];
3367 for (
int_t i=idx-1; i>-1; i-- )
3368 for (
int_t j=nS-1; j>idx-1; j-- )
3370 for (
int_t i=nS-1; i>idx-1; i-- )
3372 for (
int_t j=idx-1; j>-1; j-- )
3374 for (
int_t j=nS-1; j>idx-1; j-- )
3377 for (
int_t i=nS-1; i>idx-1; i-- )
3384 for (
int_t i=0; i<nS+1; i++ )
3386 S[idx*
nSmax + i] = temp_vals[i];
3387 S[i*
nSmax + idx] = temp_vals[i];
3395 temp_ir =
new int_t[numEntries];
3396 temp_vals =
new real_t[numEntries];
3397 for (
int_t i=M_jc[nS]; i<M_jc[nS+1]; i++ )
3399 temp_ir[i-M_jc[
nS]] =
M_ir[i];
3404 for (
int_t i=M_jc[nS]-1; i>M_jc[idx]-1; i-- )
3409 for (
int_t i=nS; i>idx-1; i-- )
3410 M_jc[i+1] = M_jc[i] + numEntries;
3413 for (
int_t i=M_jc[idx]; i<M_jc[idx+1]; i++ )
3415 M_ir[i] = temp_ir[i-M_jc[idx]];
3416 M_vals[i] = temp_vals[i-M_jc[idx]];
3436 int_t k, number, neig, nAdded;
3442 if(
nS != 0 &&
nS != 1 )
3447 if(
nS == 1 &&
detS < 0 )
3456 for( k=0; k<nFR; k++ )
3457 freeBoundIdx[k] = numberarray[k];
3461 while ( neig >
getNAC( ) && k < nFR )
3466 number = freeBoundIdx[k];
3470 if (
x[number] -
lb[number] <
ub[number] -
x[number] )
3479 MyPrintf(
"In correctInertia: Adding bound[%i] = %i failed!\n", k, number );
3485 lb[number] =
x[number];
3487 ub[number] =
x[number];
3492 MyPrintf(
"bound[%i] = %i is linearly dependent. Do not add.\n", k, number );
3501 else if( oldDetS *
detS < 0 )
3510 delete[] freeBoundIdx;
3516 MyPrintf(
"Added %i bounds but KKT matrix still has %i negative eigenvalues, should be %i.\n", nAdded, neig,
getNAC( ) );
3522 MyPrintf(
"After adding %i bounds, reduced Hessian has correct inertia.\n", nAdded, neig );
3549 if ( zeroPivots == 0 )
3555 int_t bndsAdded = 0;
3556 for ( k=defect-1; k>-1; k-- )
3559 if ( zeroPivots[k] < nFR )
3564 MyPrintf(
"WARNING: KKT matrix singular! Add bound %i before refactorization.\n", number);
3567 if (
x[number] -
lb[number] <
ub[number] -
x[number] )
3578 lb[number] =
x[number];
3580 ub[number] =
x[number];
3589 MyPrintf(
"WARNING: KKT matrix singular! Removing constraint %i before refactorization.\n", number);
3603 MyPrintf(
"WARNING: Making this constraint no longer an equality.\n");
3613 MyPrintf(
"WARNING: KKT matrix singular! Removed %i constraints and added %i bounds before refactorization.\n",
3614 defect-bndsAdded, bndsAdded );
3616 delete[] zeroPivots;
virtual returnValue factorize()=0
returnValue stepCalcBacksolveSchur(int_t nFR, int_t nFX, int_t nAC, int_t *FR_idx, int_t *FX_idx, int_t *AC_idx, int_t dim, real_t *rhs, real_t *sol)
virtual returnValue addBound(int_t number, SubjectToStatus B_status, BooleanType updateCholesky, BooleanType ensureLI=BT_TRUE)
returnValue setType(int i, SubjectToType value)
Manages working sets of constraints.
virtual returnValue setupTQfactorisation()
returnValue deleteFromSchurComplement(int_t idx, BooleanType allowUndo=BT_FALSE)
virtual returnValue setMatrixData(int_t dim, int_t numNonzeros, const int_t *const airn, const int_t *const acjn, const real_t *const avals)=0
returnValue moveInactiveToActive(int _number, SubjectToStatus _status)
BooleanType enableInertiaCorrection
BooleanType isZero(real_t x, real_t TOL=ZERO)
returnValue setupAuxiliaryQPgradient()
returnValue getNumberArray(int *const numberarray) const
virtual returnValue backsolveT(const real_t *const b, BooleanType transposed, real_t *const a) const
returnValue moveFixedToFree(int _number)
ConstraintProduct * constraintProduct
void computeGivens(real_t xold, real_t yold, real_t &xnew, real_t &ynew, real_t &c, real_t &s) const
returnValue undoDeleteFromSchurComplement(int_t idx)
Implements the online active set strategy for QPs with varying matrices.
#define THROWINFO(retval)
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()
virtual returnValue getSparseSubmatrix(int_t irowsLength, const int_t *const irowsNumber, int_t icolsLength, const int_t *const icolsNumber, int_t rowoffset, int_t coloffset, int_t &numNonzeros, int_t *irn, int_t *jcn, real_t *avals, BooleanType only_lower_triangular=BT_FALSE) const
returnValue ensureNonzeroCurvature(BooleanType removeBoundNotConstraint, int remIdx, BooleanType &exchangeHappened, BooleanType &addBoundNotConstraint, int &addIdx, SubjectToStatus &addStatus)
virtual returnValue addConstraint_checkLI(int_t number)
virtual returnValue computeProjectedCholesky()
returnValue resetSchurComplement(BooleanType allowInertiaCorrection)
returnValue setH(const real_t *const H_new)
returnValue computeMTimes(real_t alpha, const real_t *const x, real_t beta, real_t *const y)
SparseSolver * sparseSolver
#define THROWERROR(retval)
SQProblem & operator=(const SQProblem &rhs)
Indexlist * getInactive()
returnValue setInfeasibilityFlag(returnValue returnvalue)
returnValue setupAllInactive()
virtual returnValue determineStepDirection2(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)
real_t calcDetSchur(int_t idxDel)
virtual returnValue reset()
returnValue addToSchurComplement(int_t number, SchurUpdateType update, int_t numNonzerosM, const sparse_int_t *M_pos, const real_t *const M_vals, int_t numNonzerosN, const sparse_int_t *Npos, const real_t *const Nvals, real_t N_diag)
returnValue correctInertia()
virtual returnValue addBound_ensureLI(int_t number, SubjectToStatus B_status)
BooleanType enableFlippingBounds
virtual SQProblemSchur & operator=(const SQProblemSchur &rhs)
void MyPrintf(const char *pformat,...)
virtual returnValue addBound_checkLI(int_t number)
returnValue updateSchurQR(int_t idxDel)
BooleanType usingRegularisation() const
virtual int_t getNegativeEigenvalues()
returnValue setupSubjectToType()
SubjectToStatus getStatus(int i) const
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
Indexlist constraintsActiveStart
virtual ~SQProblemSchur()
returnValue stepCalcRhs(int_t nFR, int_t nFX, int_t nAC, int_t *FR_idx, int_t *FX_idx, int_t *AC_idx, real_t &rhs_max, 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)
returnValue setupAuxiliaryQPbounds(const Bounds *const auxiliaryBounds, const Constraints *const auxiliaryConstraints, BooleanType useRelaxation)
returnValue setupAllFree()
returnValue repairSingularWorkingSet()
returnValue stepCalcResid(int_t nFR, int_t nFX, int_t nAC, int_t *FR_idx, int_t *FX_idx, int_t *AC_idx, BooleanType Delta_bC_isZero, real_t *const delta_xFX, real_t *const delta_xFR, real_t *const delta_yAC, const real_t *const delta_g, const real_t *const delta_lbA, const real_t *const delta_ubA, real_t &rnrm)
virtual returnValue addConstraint_ensureLI(int_t number, SubjectToStatus C_status)
real_t A[NCMAX_ALLOC *NVMAX]
virtual returnValue addConstraint(int_t number, SubjectToStatus C_status, BooleanType updateCholesky, BooleanType ensureLI=BT_TRUE)
TabularOutput tabularOutput
SchurUpdateType * schurUpdate
returnValue addConstraint_checkLISchur(int_t number, real_t *const xiC, real_t *const xiX)
Abstract base class for interfacing tailored matrix-vector operations.
returnValue regulariseHessian()
virtual returnValue setupAuxiliaryWorkingSet(const Bounds *const auxiliaryBounds, const Constraints *const auxiliaryConstraints, BooleanType setupAfresh)
virtual 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)
void rhs(const real_t *x, real_t *f)
#define END_NAMESPACE_QPOASES
returnValue stepCalcReorder2(int_t nFR, int_t nAC, int_t *FR_idx, int_t *AC_idx, int_t nFRStart, int_t nACStart, int_t *FR_idxStart, int_t *AC_idxStart, int_t *FR_iSort, int_t *FR_iSortStart, int_t *AC_iSort, int_t *AC_iSortStart, real_t *sol, real_t *const delta_xFR, real_t *const delta_yAC)
SubjectToType getType(int i) const
virtual returnValue removeConstraint(int_t number, BooleanType updateCholesky, BooleanType allowFlipping=BT_FALSE, BooleanType ensureNZC=BT_FALSE)
QProblemStatus getStatus() const
returnValue computeMTransTimes(real_t alpha, const real_t *const x, real_t beta, real_t *const y)
returnValue copy(const SQProblemSchur &rhs)
real_t delta_xFR_TMP[NVMAX]
returnValue times(int xN, real_t alpha, const real_t *x, int xLD, real_t beta, real_t *y, int yLD) const
returnValue moveActiveToInactive(int _number)
virtual returnValue setupAuxiliaryQP(SymmetricMatrix *H_new, Matrix *A_new, const real_t *lb_new, const real_t *ub_new, const real_t *lbA_new, const real_t *ubA_new)
virtual returnValue reset()
Indexlist boundsFreeStart
virtual returnValue backsolveR(const real_t *const b, BooleanType transposed, real_t *const a) const
virtual returnValue removeBound(int_t number, BooleanType updateCholesky, BooleanType allowFlipping=BT_FALSE, BooleanType ensureNZC=BT_FALSE)
returnValue setStatus(int i, SubjectToStatus value)
virtual returnValue computeInitialCholesky()
returnValue addBound_checkLISchur(int_t number, real_t *const xiC, real_t *const xiX)
int getIndex(int givennumber) const
Manages working sets of bounds (= box constraints).
Implements the online active set strategy for QPs with varying, sparse matrices.
returnValue dropInfeasibles(int_t BC_number, SubjectToStatus BC_status, BooleanType BC_isBound, real_t *xiB, real_t *xiC)
#define BEGIN_NAMESPACE_QPOASES
void applyGivens(real_t c, real_t s, real_t xold, real_t yold, real_t &xnew, real_t &ynew) const
int getNumber(int physicalindex) const
virtual returnValue solve(double *b)=0
returnValue stepCalcDeltayFx(int_t nFR, int_t nFX, int_t nAC, int_t *FX_idx, const real_t *const delta_g, real_t *const delta_xFX, real_t *const delta_xFR, real_t *const delta_yAC, real_t *const delta_yFX)
MessageHandling * getGlobalMessageHandler()
returnValue setA(const real_t *const A_new)
BooleanType isEqual(real_t x, real_t y, real_t TOL=ZERO)
SubjectToStatus initialStatusBounds
returnValue backsolveSchurQR(int_t dimS, const real_t *const rhs, int_t dimRhs, real_t *const sol)
returnValue stepCalcReorder(int_t nFR, int_t nAC, int_t *FR_idx, int_t *AC_idx, int_t nFRStart, int_t nACStart, int_t *FR_idxStart, int_t *AC_idxStart, int_t *FR_iSort, int_t *FR_iSortStart, int_t *AC_iSort, int_t *AC_iSortStart, real_t *rhs)
returnValue getISortArray(int_t **const iSortArray) const
BooleanType enableDropInfeasibles
returnValue moveFreeToFixed(int _number, SubjectToStatus _status)
virtual returnValue getZeroPivots(int_t *&zeroPivots)
Abstract base class for interfacing matrix-vector operations tailored to symmetric matrices...