/** Example for qpOASES main function using the QProblem class. */ int main( ) { USING_NAMESPACE_QPOASES /* Setup data of first QP. */ real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 }; real_t A[1*2] = { 1.0, 1.0 }; real_t g[2] = { 1.5, 1.0 }; real_t lb[2] = { 0.5, -2.0 }; real_t ub[2] = { 5.0, 2.0 }; real_t lbA[1] = { -1.0 }; real_t ubA[1] = { 2.0 }; /* Setup data of second QP. */ real_t g_new[2] = { 1.0, 1.5 }; real_t lb_new[2] = { 0.0, -1.0 }; real_t ub_new[2] = { 5.0, -0.5 }; real_t lbA_new[1] = { -2.0 }; real_t ubA_new[1] = { 1.0 }; /* Setting up QProblem object. */ static Options options; static QProblem example; int nWSR; real_t xOpt[2]; real_t yOpt[2+1]; QProblemCON( &example,2,1,HST_UNKNOWN ); Options_setToDefault( &options ); QProblem_setOptions( &example,options ); /* Solve first QP. */ nWSR = 10; QProblem_init( &example,H,g,A,lb,ub,lbA,ubA, &nWSR,0 ); /* Get and print solution of first QP. */ QProblem_getPrimalSolution( &example,xOpt ); QProblem_getDualSolution( &example,yOpt ); printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", xOpt[0],xOpt[1],yOpt[0],yOpt[1],yOpt[2], QProblem_getObjVal( &example ) ); /* Solve second QP. */ nWSR = 10; QProblem_hotstart( &example,g_new,lb_new,ub_new,lbA_new,ubA_new, &nWSR,0 ); /* Get and print solution of second QP. */ QProblem_getPrimalSolution( &example,xOpt ); QProblem_getDualSolution( &example,yOpt ); printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", xOpt[0],xOpt[1],yOpt[0],yOpt[1],yOpt[2], QProblem_getObjVal( &example ) ); QProblem_printOptions( &example ); /*QProblem_printProperties( &example );*/ return 0; }
/** Example for qpOASES main function using the QProblem class. */ double qpOASES(double* H, double* g, double* A, double* lb, double* ub, double* lbA, double* ubA, double* xOpt, double* yOpt, int nV, int nC ) { USING_NAMESPACE_QPOASES /* Setting up QProblem object. */ static Options options; static QProblem example; int nWSR; //double xOpt[nV]; double fval; QProblemCON( &example, nV, nC, HST_UNKNOWN ); Options_setToDefault( &options ); QProblem_setOptions( &example,options ); /* Solve QP. */ nWSR = 10000; QProblem_init( &example,H,g,A,lb,ub,lbA,ubA,&nWSR,0 ); /* Get and print solution of first QP. */ QProblem_getPrimalSolution( &example,xOpt ); QProblem_getDualSolution( &example,yOpt ); //for(int i = 0; i < nV; i++) { // printf("%d %e\n", i+1, xOpt[i]); //} fval = QProblem_getObjVal( &example ); //printf("%e\n", fval); return fval; }
/* * o b t a i n O u t p u t s */ returnValue obtainOutputs( int k, QProblem* qp, returnValue returnvalue, int _nWSRout, double _cpuTime, int nlhs, mxArray* plhs[], int nV, int nC, 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++] ); QProblem_getPrimalSolution( qp,&(x[k*nV]) ); if ( nlhs > curIdx ) { /* fval */ obj = mxGetPr( plhs[curIdx++] ); obj[k] = QProblem_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++] ); QProblem_getDualSolution( qp,&(y[k*(nV+nC)]) ); /* auxOutput */ if ( nlhs > curIdx ) { auxOutput = plhs[curIdx]; curField = 0; /* working set bounds */ if ( nV > 0 ) { curField = mxGetField( auxOutput,0,"workingSetB" ); workingSetB = mxGetPr(curField); QProblem_getWorkingSetBounds( qp,&(workingSetB[k*nV]) ); } /* working set constraints */ if ( nC > 0 ) { curField = mxGetField( auxOutput,0,"workingSetC" ); workingSetC = mxGetPr(curField); QProblem_getWorkingSetConstraints( qp,&(workingSetC[k*nC]) ); } /* cpu time */ curField = mxGetField( auxOutput,0,"cpuTime" ); cpuTime = mxGetPr(curField); cpuTime[0] = (double) _cpuTime; } } } } } return SUCCESSFUL_RETURN; }