/* * o b t a i n O u t p u t s S B */ returnValue obtainOutputsSB( int k, QProblemB* qp, returnValue returnvalue, int _nWSRout, double _cpuTime, int nlhs, mxArray* plhs[], int nV, int handle ) { double *x=0, *obj=0, *status=0, *nWSRout=0, *y=0, *workingSetB=0, *workingSetC=0, *cpuTime; mxArray *auxOutput=0, *curField=0; /* Create output vectors and assign pointers to them. */ int curIdx = 0; /* handle */ if ( handle >= 0 ) plhs[curIdx++] = mxCreateDoubleScalar( handle ); /* x */ x = mxGetPr( plhs[curIdx++] ); QProblemB_getPrimalSolution( qp,&(x[k*nV]) ); if ( nlhs > curIdx ) { /* fval */ obj = mxGetPr( plhs[curIdx++] ); obj[k] = QProblemB_getObjVal( qp ); if ( nlhs > curIdx ) { /* exitflag */ status = mxGetPr( plhs[curIdx++] ); status[k] = (double)qpOASES_getSimpleStatus( returnvalue,0 ); if ( nlhs > curIdx ) { /* iter */ nWSRout = mxGetPr( plhs[curIdx++] ); nWSRout[k] = (double) _nWSRout; if ( nlhs > curIdx ) { /* lambda */ y = mxGetPr( plhs[curIdx++] ); QProblemB_getDualSolution( qp,&(y[k*nV]) ); /* auxOutput */ if ( nlhs > curIdx ) { auxOutput = plhs[curIdx]; curField = 0; /* working set bounds */ if ( nV > 0 ) { curField = mxGetField( auxOutput,0,"workingSetB" ); workingSetB = mxGetPr(curField); QProblemB_getWorkingSetBounds( qp,&(workingSetB[k*nV]) ); } /* cpu time */ curField = mxGetField( auxOutput,0,"cpuTime" ); cpuTime = mxGetPr(curField); cpuTime[0] = (double) _cpuTime; } } } } } return SUCCESSFUL_RETURN; }
/* * s o l v e O Q P b e n c h m a r k */ returnValue solveOQPbenchmarkB( int nQP, int nV, real_t* _H, const real_t* const g, const real_t* const lb, const real_t* const ub, BooleanType isSparse, BooleanType useHotstarts, const Options* options, int maxAllowedNWSR, real_t* maxNWSR, real_t* avgNWSR, real_t* maxCPUtime, real_t* avgCPUtime, real_t* maxStationarity, real_t* maxFeasibility, real_t* maxComplementarity ) { int k; myStatic QProblemB qp; returnValue returnvalue; /* I) SETUP AUXILIARY VARIABLES: */ /* 1) Keep nWSR and store current and maximum number of * working set recalculations in temporary variables */ int nWSRcur; real_t CPUtimeLimit = *maxCPUtime; real_t CPUtimeCur = CPUtimeLimit; real_t stat, feas, cmpl; /* 2) Pointers to data of current QP ... */ const real_t* gCur; const real_t* lbCur; const real_t* ubCur; /* 3) Vectors for solution obtained by qpOASES. */ myStatic real_t x[NVMAX]; myStatic real_t y[NVMAX]; /* 4) Prepare matrix objects */ DenseMatrix *H; myStatic DenseMatrix HH; DenseMatrixCON( &HH, nV, nV, nV, _H ); H = &HH; *maxNWSR = 0; *avgNWSR = 0; *maxCPUtime = 0.0; *avgCPUtime = 0.0; *maxStationarity = 0.0; *maxFeasibility = 0.0; *maxComplementarity = 0.0; /* II) SETUP QPROBLEM OBJECT */ QProblemBCON( &qp,nV,HST_UNKNOWN ); QProblemB_setOptions( &qp,*options ); /*QProblemB_setPrintLevel( &qp,PL_LOW );*/ /* III) RUN BENCHMARK SEQUENCE: */ for( k=0; k<nQP; ++k ) { /* 1) Update pointers to current QP data. */ gCur = &( g[k*nV] ); lbCur = &( lb[k*nV] ); ubCur = &( ub[k*nV] ); /* 2) Set nWSR and maximum CPU time. */ nWSRcur = maxAllowedNWSR; CPUtimeCur = CPUtimeLimit; /* 3) Solve current QP. */ if ( ( k == 0 ) || ( useHotstarts == BT_FALSE ) ) { /* initialise */ returnvalue = QProblemB_initM( &qp,H,gCur,lbCur,ubCur, &nWSRcur,&CPUtimeCur ); if ( ( returnvalue != SUCCESSFUL_RETURN ) && ( returnvalue != RET_MAX_NWSR_REACHED ) ) return THROWERROR( returnvalue ); } else { /* hotstart */ returnvalue = QProblemB_hotstart( &qp,gCur,lbCur,ubCur, &nWSRcur,&CPUtimeCur ); if ( ( returnvalue != SUCCESSFUL_RETURN ) && ( returnvalue != RET_MAX_NWSR_REACHED ) ) return THROWERROR( returnvalue ); } /* 4) Obtain solution vectors and objective function value ... */ QProblemB_getPrimalSolution( &qp,x ); QProblemB_getDualSolution( &qp,y ); /* 5) Compute KKT residuals */ qpOASES_getKktViolationSB( nV, _H,gCur,lbCur,ubCur, x,y, &stat,&feas,&cmpl ); /* 6) update maximum values. */ if ( nWSRcur > *maxNWSR ) *maxNWSR = nWSRcur; if (stat > *maxStationarity) *maxStationarity = stat; if (feas > *maxFeasibility) *maxFeasibility = feas; if (cmpl > *maxComplementarity) *maxComplementarity = cmpl; if ( CPUtimeCur > *maxCPUtime ) *maxCPUtime = CPUtimeCur; *avgNWSR += nWSRcur; *avgCPUtime += CPUtimeCur; } *avgNWSR /= nQP; *avgCPUtime /= ((double)nQP); return SUCCESSFUL_RETURN; }