170 if ( ( mxGetM(pm) == 1 ) && ( mxGetN(pm) == 1 ) )
187 if ( ( inst->
sqp != 0 ) && ( options != 0 ) )
190 if ( ( inst->
qpb != 0 ) && ( options != 0 ) )
219 for (std::vector<QPInstance*>::iterator itor =
g_instances.begin ();
221 if ((*itor)->handle == handle) {
235 const mxArray* prhs[],
int_t idx
246 if ( mxIsEmpty( prhs[ idx ] ) )
249 if ( ( emptyAllowed ==
BT_TRUE ) || ( idx == 0 ) )
258 snprintf(msg,
MAX_STRING_LENGTH,
"ERROR (qpOASES): Empty argument %d not allowed!", idx+1);
266 if ( mxIsSparse( prhs[ idx ] ) == 0 )
268 if ( ( mxGetM( prhs[ idx ] ) == m ) && ( mxGetN( prhs[ idx ] ) == n ) )
270 *input = (
real_t*) mxGetPr( prhs[ idx ] );
277 snprintf(msg,
MAX_STRING_LENGTH,
"ERROR (qpOASES): Input dimension mismatch for argument %d ([%ld,%ld] ~= [%d,%d]).",
278 idx+1, (
long int)mxGetM(prhs[idx]), (
long int)mxGetN(prhs[idx]), (
int)m,(
int)n);
280 snprintf(msg,
MAX_STRING_LENGTH,
"ERROR (qpOASES): Input dimension mismatch for some auxInput entry ([%ld,%ld] ~= [%d,%d]).",
281 (
long int)mxGetM(prhs[idx]), (
long int)mxGetN(prhs[idx]), (
int)m,(
int)n);
290 snprintf(msg,
MAX_STRING_LENGTH,
"ERROR (qpOASES): Vector argument %d must not be in sparse format!", idx+1);
292 snprintf(msg,
MAX_STRING_LENGTH,
"ERROR (qpOASES): auxInput entries must not be in sparse format!" );
313 for ( i = 0; i < dim; ++i )
314 if ( mxIsNaN(data[i]) == 1 )
331 for ( i = 0; i < dim; ++i )
332 if ( mxIsInf(data[i]) == 1 )
353 if (mxIsSparse(prhs[rhs_index]) == 1)
354 dim = (
uint_t)mxGetNzmax(prhs[rhs_index]);
356 dim = (
uint_t)(mxGetM(prhs[rhs_index]) * mxGetN(prhs[rhs_index]));
360 "ERROR (qpOASES): Argument %d contains 'NaN' !", rhs_index + 1);
365 if (mayContainInf == 0) {
368 "ERROR (qpOASES): Argument %d contains 'Inf' !",
386 if ( ( M_for == 0 ) || ( M == 0 ) )
389 if ( ( nV < 0 ) || ( nC < 0 ) )
392 for ( i=0; i<nC; ++i )
393 for ( j=0; j<nV; ++j )
394 M[i*nV + j] = M_for[j*nC + i];
405 mxArray* optionName = mxGetField( optionsPtr,0,optionString );
407 if ( optionName == 0 )
410 snprintf(msg,
MAX_STRING_LENGTH,
"Option struct does not contain entry '%s', using default value instead!", optionString );
411 mexWarnMsgTxt( msg );
415 if ( ( mxIsEmpty(optionName) ==
false ) && (
mxIsScalar( optionName ) ==
true ) )
417 *optionValue = mxGetPr( optionName );
423 snprintf(msg,
MAX_STRING_LENGTH,
"Option '%s' is not a scalar, using default value instead!", optionString );
424 mexWarnMsgTxt( msg );
436 int_t optionValueInt;
440 if ( mxGetNumberOfFields(optionsPtr) != 31 )
441 mexWarnMsgTxt(
"Options might be set incorrectly as struct has wrong number of entries!\n Type 'help qpOASES_options' for further information." );
445 if ( *optionValue >= 0.0 )
446 nWSRin = (
int_t)*optionValue;
449 if ( *optionValue >= 0.0 )
450 maxCpuTime = *optionValue;
454 #ifdef __SUPPRESSANYOUTPUT__ 457 optionValueInt = (
int_t)*optionValue;
468 optionValueInt = (
int_t)*optionValue;
474 optionValueInt = (
int_t)*optionValue;
480 optionValueInt = (
int_t)*optionValue;
486 optionValueInt = (
int_t)*optionValue;
492 optionValueInt = (
int_t)*optionValue;
498 optionValueInt = (
int_t)*optionValue;
510 optionValueInt = (
int_t)*optionValue;
525 options->
epsNum = *optionValue;
528 options->
epsDen = *optionValue;
551 optionValueInt = (
int_t)*optionValue;
552 if ( optionValueInt < -1 )
554 if ( optionValueInt > 1 )
589 HessianType* hessianType,
double** x0,
double** guessedBounds,
double** guessedConstraints,
double**
R 592 mxArray* curField = 0;
595 curField = mxGetField( auxInput,0,
"hessianType" );
596 if ( curField == NULL )
597 mexWarnMsgTxt(
"auxInput struct does not contain entry 'hessianType'!\n Type 'help qpOASES_auxInput' for further information." );
600 if ( mxIsEmpty(curField) ==
true )
609 double* hessianTypeTmp = mxGetPr(curField);
610 int_t hessianTypeInt = (
int_t)*hessianTypeTmp;
611 if ( hessianTypeInt < 0 )
613 if ( hessianTypeInt > 5 )
620 curField = mxGetField( auxInput,0,
"x0" );
621 if ( curField == NULL )
622 mexWarnMsgTxt(
"auxInput struct does not contain entry 'x0'!\n Type 'help qpOASES_auxInput' for further information." );
625 *x0 = mxGetPr(curField);
631 curField = mxGetField( auxInput,0,
"guessedWorkingSetB" );
632 if ( curField == NULL )
633 mexWarnMsgTxt(
"auxInput struct does not contain entry 'guessedWorkingSetB'!\n Type 'help qpOASES_auxInput' for further information." );
636 *guessedBounds = mxGetPr(curField);
642 curField = mxGetField( auxInput,0,
"guessedWorkingSetC" );
643 if ( curField == NULL )
644 mexWarnMsgTxt(
"auxInput struct does not contain entry 'guessedWorkingSetC'!\n Type 'help qpOASES_auxInput' for further information." );
647 *guessedConstraints = mxGetPr(curField);
653 curField = mxGetField( auxInput,0,
"R" );
654 if ( curField == NULL )
655 mexWarnMsgTxt(
"auxInput struct does not contain entry 'R'!\n Type 'help qpOASES_auxInput' for further information." );
658 *R = mxGetPr(curField);
679 plhs[curIdx++] = mxCreateDoubleMatrix( 1, 1, mxREAL );
682 plhs[curIdx++] = mxCreateDoubleMatrix( nV, nP, mxREAL );
687 plhs[curIdx++] = mxCreateDoubleMatrix( 1, nP, mxREAL );
692 plhs[curIdx++] = mxCreateDoubleMatrix( 1, nP, mxREAL );
697 plhs[curIdx++] = mxCreateDoubleMatrix( 1, nP, mxREAL );
702 plhs[curIdx++] = mxCreateDoubleMatrix( nV+nC, nP, mxREAL );
707 mxArray* auxOutput = mxCreateStructMatrix( 1,1,0,0 );
711 curFieldNum = mxAddField( auxOutput,
"workingSetB" );
712 if ( curFieldNum >= 0 )
713 mxSetFieldByNumber( auxOutput,0,curFieldNum,mxCreateDoubleMatrix( nV, nP, mxREAL ) );
715 curFieldNum = mxAddField( auxOutput,
"workingSetC" );
716 if ( curFieldNum >= 0 )
717 mxSetFieldByNumber( auxOutput,0,curFieldNum,mxCreateDoubleMatrix( nC, nP, mxREAL ) );
719 curFieldNum = mxAddField( auxOutput,
"cpuTime" );
720 if ( curFieldNum >= 0 )
721 mxSetFieldByNumber( auxOutput,0,curFieldNum,mxCreateDoubleMatrix( 1, nP, mxREAL ) );
723 plhs[curIdx] = auxOutput;
746 plhs[curIdx++] = mxCreateDoubleScalar(
handle );
749 double* x = mxGetPr( plhs[curIdx++] );
755 double* obj = mxGetPr( plhs[curIdx++] );
761 double* status = mxGetPr( plhs[curIdx++] );
767 double* nWSRout = mxGetPr( plhs[curIdx++] );
768 nWSRout[k] = (double) _nWSRout;
773 double*
y = mxGetPr( plhs[curIdx++] );
782 mxArray* auxOutput = plhs[curIdx];
783 mxArray* curField = 0;
788 curField = mxGetField( auxOutput,0,
"workingSetB" );
789 double* workingSetB = mxGetPr(curField);
792 if (problemPointer != NULL) {
802 curField = mxGetField( auxOutput,0,
"workingSetC" );
803 double* workingSetC = mxGetPr(curField);
806 if (problemPointer != NULL) {
814 curField = mxGetField( auxOutput,0,
"cpuTime" );
815 double* cpuTime = mxGetPr(curField);
816 cpuTime[0] = (double) _cpuTime;
838 if ( mxIsSparse( prhsH ) != 0 )
840 mwIndex *mat_ir = mxGetIr( prhsH );
841 mwIndex *mat_jc = mxGetJc( prhsH );
842 double *
v = (
double*)mxGetPr( prhsH );
852 *Hv =
new real_t[mat_jc[nV] + nV];
853 for (j = 0; j < nV; j++)
859 for (i = mat_jc[j]; i < mat_jc[j+1]; i++)
861 if ( mat_ir[i] == j )
865 if ( ( mat_ir[i] > j ) && ( needInsertDiag ==
BT_TRUE ) )
868 (*Hv)[i + nfill] = 0.0;
875 (*Hv)[i + nfill] = (
real_t)(v[i]);
889 memcpy( H_mem,H_for, nV*nV*
sizeof(
real_t) );
892 (*H)->doFreeMemory( );
909 if ( mxIsSparse( prhsA ) != 0 )
914 mwIndex *mat_ir = mxGetIr( prhsA );
915 mwIndex *mat_jc = mxGetJc( prhsA );
916 double *
v = (
double*)mxGetPr( prhsA );
921 for (i = 0; i < mat_jc[nV]; i++)
923 for (i = 0; i < nV + 1; i++)
927 *Av =
new real_t[(*Ajc)[nV]];
928 for (j = 0; j < (*Ajc)[nV]; j++)
929 (*Av)[j] = (
real_t)(v[j]);
941 (*A)->doFreeMemory();
returnValue getPrimalSolution(real_t *const xOpt) const
Interfaces matrix-vector operations tailored to symmetric sparse matrices.
returnValue convertFortranToC(const real_t *const M_for, int_t nV, int_t nC, real_t *const M)
virtual returnValue getWorkingSetBounds(real_t *workingSetB)
Implements the online active set strategy for box-constrained QPs.
returnValue setupHessianMatrix(const mxArray *prhsH, int_t nV, SymmetricMatrix **H, sparse_int_t **Hir, sparse_int_t **Hjc, real_t **Hv)
BooleanType enableFarBounds
returnValue deleteQPMatrices()
BooleanType isSimplyBounded
returnValue allocateOutputs(int nlhs, mxArray *plhs[], int_t nV, int_t nC=0, int_t nP=1, int_t handle=-1)
Implements the online active set strategy for QPs with varying matrices.
Allows to pass back messages to the calling function.
QPInstance(uint_t _nV=0, uint_t _nC=0, HessianType _hessianType=HST_UNKNOWN, BooleanType _isSimplyBounded=BT_FALSE)
Interfaces matrix-vector operations tailored to symmetric dense matrices.
returnValue obtainOutputs(int_t k, QProblemB *qp, returnValue returnvalue, int_t _nWSRout, double _cpuTime, int nlhs, mxArray *plhs[], int_t nV, int_t nC=0, int_t handle=-1)
BooleanType enableFullLITests
BooleanType enableEqualities
static std::vector< QPInstance * > g_instances
returnValue smartDimensionCheck(real_t **input, uint_t m, uint_t n, BooleanType emptyAllowed, const mxArray *prhs[], int_t idx)
BooleanType enableRamping
virtual returnValue getWorkingSetConstraints(real_t *workingSetC)
QPInstance * getQPInstance(int_t handle)
BooleanType enableFlippingBounds
returnValue setOptions(const Options &_options)
void deleteQPInstance(int_t handle)
Interfaces matrix-vector operations tailored to general dense matrices.
returnValue getDualSolution(real_t *const yOpt) const
virtual returnValue getWorkingSetConstraints(real_t *workingSetC)
Interfaces matrix-vector operations tailored to general sparse matrices.
bool mxIsScalar(const mxArray *pm)
Provides a generic way to set and pass user-specified options.
int_t allocateQPInstance(int_t nV, int_t nC, HessianType hessianType, BooleanType isSimplyBounded, const Options *options)
BooleanType containsNaNorInf(const mxArray *prhs[], int_t rhs_index, bool mayContainInf)
int enableDriftCorrection
Abstract base class for interfacing tailored matrix-vector operations.
BooleanType containsInf(const real_t *const data, uint_t dim)
BooleanType enableRegularisation
virtual returnValue getWorkingSetBounds(real_t *workingSetB)
returnValue setupAuxiliaryInputs(const mxArray *auxInput, uint_t nV, uint_t nC, HessianType *hessianType, double **x0, double **guessedBounds, double **guessedConstraints, double **R)
real_t terminationTolerance
BooleanType hasOptionsValue(const mxArray *optionsPtr, const char *const optionString, double **optionValue)
const uint_t MAX_STRING_LENGTH
int numRegularisationSteps
int enableCholeskyRefactorisation
BooleanType enableNZCTests
static int_t s_nexthandle
BooleanType containsNaN(const real_t *const data, uint_t dim)
returnValue setupOptions(Options *options, const mxArray *optionsPtr, int_t &nWSRin, real_t &maxCpuTime)
int_t getSimpleStatus(returnValue returnvalue, BooleanType doPrintStatus=BT_FALSE)
Implements the online active set strategy for QPs with general constraints.
returnValue setupConstraintMatrix(const mxArray *prhsA, int_t nV, int_t nC, Matrix **A, sparse_int_t **Air, sparse_int_t **Ajc, real_t **Av)
SubjectToStatus initialStatusBounds
#define REFER_NAMESPACE_QPOASES
Abstract base class for interfacing matrix-vector operations tailored to symmetric matrices...