/** 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 QProblemB 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 g[2] = { 1.5, 1.0 }; real_t lb[2] = { 0.5, -2.0 }; real_t ub[2] = { 5.0, 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 }; /* Setting up QProblemB object. */ static QProblemB example; static Options options; int nWSR = 10; real_t xOpt[2]; QProblemBCON( &example,2,HST_UNKNOWN ); Options_setToDefault( &options ); /* options.enableFlippingBounds = BT_FALSE; */ options.initialStatusBounds = ST_INACTIVE; options.numRefinementSteps = 1; /* options.enableCholeskyRefactorisation = 1; */ QProblemB_setOptions( &example,options ); /* Solve first QP. */ nWSR = 10; QProblemB_init( &example,H,g,lb,ub, &nWSR,0 ); /* Get and print solution of second QP. */ QProblemB_getPrimalSolution( &example,xOpt ); printf( "\nxOpt = [ %e, %e ]; objVal = %e\n\n", xOpt[0],xOpt[1],QProblemB_getObjVal(&example) ); /* Solve second QP. */ nWSR = 10; QProblemB_hotstart( &example,g_new,lb_new,ub_new, &nWSR,0 ); /* Get and print solution of second QP. */ QProblemB_getPrimalSolution( &example,xOpt ); printf( "\nxOpt = [ %e, %e ]; objVal = %e\n\n", xOpt[0],xOpt[1],QProblemB_getObjVal(&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; }
/** Try to solve a list of or all OQP examples in testing/problems */ int main(int argc, char *argv[]) { const real_t TOL = 1e-5; /* 1) Define benchmark arguments. */ BooleanType isSparse = BT_FALSE; BooleanType useHotstarts = BT_FALSE; static Options options; int maxAllowedNWSR; real_t maxNWSR, avgNWSR, maxCPUtime, avgCPUtime; real_t maxStationarity, maxFeasibility, maxComplementarity; int scannedDir = 0; int nfail = 0, npass = 0; int nproblems, i; struct dirent **namelist; char resstr[200], OQPproblem[200]; char *problem; returnValue returnvalue; Options_setToDefault( &options ); /*options.enableFlippingBounds = BT_FALSE;*/ /*Options_setToReliable( &options );*/ Options_setToMPC( &options ); /*options.printLevel = PL_DEBUG_ITER;*/ options.printLevel = PL_LOW; /*options.enableRamping = BT_FALSE;*/ /*options.enableFarBounds = BT_FALSE;*/ if (argc == 1) { /* 2a) Scan problem directory */ nproblems = scandir("../testing/c/data/problems", &namelist, NULL, alphasort); if (nproblems <= 0) { qpOASES_myPrintf( "No test problems found!\n" ); return -1; } scannedDir = 1; } else { /* 2b) Use problem list given by arguments */ nproblems = argc - 1; scannedDir = 0; } /* 3) Run benchmark. */ printf("%10s %9s %9s %9s %6s %-12s\n", "problem", "stat", "feas", "compl", "nWSR", "result"); for (i = 0; i < nproblems; i++) { if (scannedDir) { /* skip special directories and zip file cuter.*bz2 */ if (namelist[i]->d_name[0] == '.' || namelist[i]->d_name[0] == 'c') { free(namelist[i]); continue; } problem = namelist[i]->d_name; } else { problem = argv[i+1]; } fprintf(stdout, "%-10s ", problem); fflush(stdout); snprintf(OQPproblem, 199, "../testing/c/data/problems/%s/", problem); maxCPUtime = 300.0; maxAllowedNWSR = 3500; returnvalue = runOQPbenchmark( OQPproblem, isSparse,useHotstarts, &options,maxAllowedNWSR, &maxNWSR,&avgNWSR,&maxCPUtime,&avgCPUtime, &maxStationarity,&maxFeasibility,&maxComplementarity ); if (returnvalue == SUCCESSFUL_RETURN && maxStationarity < TOL && maxFeasibility < TOL && maxComplementarity < TOL) { npass++; strncpy(resstr, "pass", 199); } else { nfail++; snprintf (resstr, 199, "fail (%d)", returnvalue); } fprintf(stdout, "%9.2e %9.2e %9.2e %6d %-12s\n", maxStationarity, maxFeasibility, maxComplementarity, (int)maxNWSR, resstr); if (scannedDir) free(namelist[i]); } if (scannedDir) free(namelist); /* 4) Print results. */ printf("\n\n" ); printf("Testbench results:\n" ); printf("======================\n\n" ); printf("Pass: %3d\n", npass); printf("Fail: %3d\n", nfail); printf("Ratio: %5.1f%%\n", 100.0 * (real_t)npass / (real_t)(npass+nfail)); printf("\n" ); return 0; }