示例#1
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. */
	QProblemB example( 2 );

	Options options;
	//options.enableFlippingBounds = BT_FALSE;
	options.initialStatusBounds = ST_INACTIVE;
	options.numRefinementSteps = 1;
	options.enableCholeskyRefactorisation = 1;
	example.setOptions( options );

	/* Solve first QP. */
	int nWSR = 10;
	example.init( H,g,lb,ub, nWSR,0 );
// 	printf( "\nnWSR = %d\n\n", nWSR );

	real_t xOpt[2];
	real_t yOpt[2];
	example.getPrimalSolution( xOpt );
	example.getDualSolution( yOpt );

	/* Compute KKT tolerances */
	real_t stat, feas, cmpl;
	SolutionAnalysis analyzer;

	analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
	printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );

	QPOASES_TEST_FOR_TOL( stat,1e-15 );
	QPOASES_TEST_FOR_TOL( feas,1e-15 );
	QPOASES_TEST_FOR_TOL( cmpl,1e-15 );

	
	/* Solve second QP. */
	nWSR = 10;
	example.hotstart( g_new,lb_new,ub_new, nWSR,0 );
// 	printf( "\nnWSR = %d\n\n", nWSR );

	/* Get and print solution of second QP. */
	example.getPrimalSolution( xOpt );
	example.getDualSolution( yOpt );
	printf( "\nxOpt = [ %e, %e ];  objVal = %e\n\n", xOpt[0],xOpt[1],example.getObjVal() );

	/* Compute KKT tolerances */
	analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
	printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );

	QPOASES_TEST_FOR_TOL( stat,1e-15 );
	QPOASES_TEST_FOR_TOL( feas,1e-15 );
	QPOASES_TEST_FOR_TOL( cmpl,1e-15 );

	return TEST_PASSED;
}
示例#2
0
/** Example for qpOASES main function using the SolutionAnalysis 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 H_new[2*2] = { 1.0, 0.5, 0.5, 0.5 };
	real_t A_new[1*2] = { 1.0, 5.0 };
	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 SQProblem object and solution analyser. */
	SQProblem example( 2,1 );
	SolutionAnalysis analyser;

	/* Solve first QP ... */
	int_t nWSR = 10;
	example.init( H,g,A,lb,ub,lbA,ubA, nWSR,0 );

	/* ... and analyse it. */
	real_t maxKktViolation = analyser.getKktViolation( &example );
    printf( "maxKktViolation: %e\n", maxKktViolation );

	QPOASES_TEST_FOR_TOL( maxKktViolation,1e-15 );


	/* Solve second QP ... */
	nWSR = 10;
	example.hotstart( H_new,g_new,A_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,0 );

	/* ... and analyse it. */
	maxKktViolation = analyser.getKktViolation( &example );
    printf( "maxKktViolation: %e\n", maxKktViolation );

	QPOASES_TEST_FOR_TOL( maxKktViolation,1e-15 );


//  ------------ VARIANCE-COVARIANCE EVALUATION --------------------

        real_t *Var              = new real_t[5*5];
        real_t *Primal_Dual_Var  = new real_t[5*5];

        int_t run1, run2;
        for( run1 = 0; run1 < 5*5; run1++ )
            Var[run1] = 0.0;

        Var[0] = 1.0;
        Var[6] = 1.0;

//                  (  1   0   0   0   0   )
//                  (  0   1   0   0   0   )
//     Var     =    (  0   0   0   0   0   )
//                  (  0   0   0   0   0   )
//                  (  0   0   0   0   0   )


        analyser.getVarianceCovariance( &example, Var,Primal_Dual_Var );

        printf("\nPrimal_Dual_VAR = \n");
        for( run1 = 0; run1 < 5; run1++ ){
          for( run2 = 0; run2 < 5; run2++ ){
            printf(" %10f", Primal_Dual_Var[run1*5+run2]);
          }
          printf("\n");
        }

        delete[] Primal_Dual_Var;
        delete[] Var;

		QPOASES_TEST_FOR_NEAR( Primal_Dual_Var[3*5+3], 26.0 );

	return TEST_PASSED;
}
/** Example for qpOASES main function using the QProblem class. */
int main( )
{
	USING_NAMESPACE_QPOASES

	/* Setup data of first QP. */
	real_t H[4*4] = { 1.0, 0.0, 0.0, 0.5, 
	                  0.0, 1.0, 0.0, 0.0,
	                  0.0, 0.0, 1.0, 0.0,
	                  0.5, 0.0, 0.0, 1.0 };
	real_t A[3*4] = { 1.0, 1.0, 0.0, 0.0,
	                  1.0, 1.0, 1.0, 0.0,
	                  1.0, 1.0, 1.0, 1.0 };
	real_t g[4] = { 1.5, 1.0, -1.0, -1.0 };
	real_t lb[4] = { 0.5, -2.0, 0.0, 0.0 };
	real_t ub[4] = { 1.0, 2.0, 1.0, 0.5 };
	real_t lbA[3] = { -1.0, -1.0, -1.0 };
	real_t ubA[3] = { 0.0, 0.25, 1.0 };

	

	/* Setting up QProblem object. */
	QProblem example( 4,3 );

	Options options;
	example.setOptions( options );

	/* Solve first QP. */
	int_t nWSR = 10;
	example.init( H,g,A,lb,ub,lbA,ubA, nWSR );

	/* Get and print solution of second QP. */
	real_t xOpt[4];
	real_t yOpt[4+3];
	example.getPrimalSolution( xOpt );
	example.getDualSolution( yOpt );
	print( xOpt,4,"xOpt" );
	print( yOpt,4+3,"yOpt" );
	printf( "objVal = %e\n\n", example.getObjVal() );
	
	/* Compute KKT tolerances */
	real_t stat, feas, cmpl;
	SolutionAnalysis analyzer;

	analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
	printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );

	QPOASES_TEST_FOR_TOL( stat,1e-15 );
	QPOASES_TEST_FOR_TOL( feas,1e-15 );
	QPOASES_TEST_FOR_TOL( cmpl,1e-15 );


	/* Solve first QP again (with optimal guess for working set). */
	Bounds prevBounds;
	Constraints prevConstraints;
	
	example.getBounds( prevBounds );
	example.getConstraints( prevConstraints );

	nWSR = 10;
	example.hotstart( g,lb,ub,lbA,ubA, nWSR,0,&prevBounds,&prevConstraints );

	/* Get and print solution of second QP. */
	example.getPrimalSolution( xOpt );
	example.getDualSolution( yOpt );
	print( xOpt,4,"xOpt" );
	print( yOpt,4+3,"yOpt" );
	printf( "objVal = %e\n\n", example.getObjVal() );
	
	/* Compute KKT tolerances */
	analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
	printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );

	QPOASES_TEST_FOR_TOL( stat,1e-15 );
	QPOASES_TEST_FOR_TOL( feas,1e-15 );
	QPOASES_TEST_FOR_TOL( cmpl,1e-15 );


	/* Solve first QP again (with inaccurate guess for working set). */
	prevBounds.print();
	prevBounds.rotate(1);
	//prevBounds.moveFixedToFree(0);
	prevBounds.print();

	prevConstraints.print();
	//prevConstraints.moveInactiveToActive(0,ST_LOWER);
	prevConstraints.moveActiveToInactive(1);
	prevConstraints.print();

	nWSR = 10;
	example.hotstart( g,lb,ub,lbA,ubA, nWSR,0,&prevBounds,&prevConstraints );

	/* Get and print solution of second QP. */
	example.getPrimalSolution( xOpt );
	example.getDualSolution( yOpt );
	print( xOpt,4,"xOpt" );
	print( yOpt,4+3,"yOpt" );
	printf( "objVal = %e\n\n", example.getObjVal() );
	
	/* Compute KKT tolerances */
	analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
	printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );

	QPOASES_TEST_FOR_TOL( stat,1e-15 );
	QPOASES_TEST_FOR_TOL( feas,1e-15 );
	QPOASES_TEST_FOR_TOL( cmpl,1e-15 );

	return TEST_PASSED;
}
示例#4
0
/** Example for qpOASES main function using the SQProblem 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 H_new[2*2] = { 1.0, 0.5, 0.5, 0.5 };
	real_t A_new[1*2] = { 1.0, 5.0 };
	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 SQProblem object. */
	SQProblem example( 2,1 );

	/* Solve first QP. */
	int nWSR = 10;
	example.init( H,g,A,lb,ub,lbA,ubA, nWSR,0 );

	real_t xOpt[2];
	real_t yOpt[2+1];
	example.getPrimalSolution( xOpt );
	example.getDualSolution( yOpt );

	/* Compute KKT tolerances */
	real_t stat, feas, cmpl;
	SolutionAnalysis analyzer;

	analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
	printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );

	QPOASES_TEST_FOR_TOL( stat,1e-15 );
	QPOASES_TEST_FOR_TOL( feas,1e-15 );
	QPOASES_TEST_FOR_TOL( cmpl,1e-15 );


	/* Solve second QP. */
	nWSR = 10;
	example.hotstart( H_new,g_new,A_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,0 );

	/* Get and print solution of second QP. */
	example.getPrimalSolution( xOpt );
	example.getDualSolution( yOpt );
	printf( "\nxOpt = [ %e, %e ];  objVal = %e\n\n", xOpt[0],xOpt[1],example.getObjVal() );

	/* Compute KKT tolerances */
	analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
	printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );

	QPOASES_TEST_FOR_TOL( stat,1e-15 );
	QPOASES_TEST_FOR_TOL( feas,1e-15 );
	QPOASES_TEST_FOR_TOL( cmpl,1e-15 );

	return TEST_PASSED;
}
/** Example for qpOASES main function using the QProblem class. */
int main( )
{
	USING_NAMESPACE_QPOASES

	/* Setup data of first QP. */
	real_t H[5*5] = {	1.224642131370767e+01, 2.908638763113702e+00, 0.0, 0.0, 0.0,
						2.908638763113702e+00, 2.497106275003180e+00, 0.0, 0.0, 0.0,
						0.0, 0.0, 1.0, 0.0, 0.0,
						0.0, 0.0, 0.0, 5.158460640334052e-02, 4.723556059962540e-02,
						0.0, 0.0, 0.0, 4.723556059962540e-02, 4.325317843302175e-02 };
	real_t A[2*5] = { 	-1.404358970692652e+00, -2.556613491156063e+00, 3.202524559238066e+00, -1.0, 0.0,
						6.587910295430314e-01, -5.349454475937998e-01, 4.391976356955536e-01, 0.0, -1.0 };
	real_t g[5] = { 	2.474135331302147e+01,
						5.857286430296258e+00,
						2.359382646348721e-01,
						1.721047069188781e-01,
						1.575947337774199e-01 };
	real_t lb[5] = { -10.0, -10.0, -10.0, -10.0, -10.0 };
	real_t ub[5] = {  10.0,  10.0,  10.0,  10.0,  10.0 };
	real_t lbA[2] = { 1.643135416077167e+00, 1.056813028189597e+00 };
	real_t ubA[2] = { 1.643135416077167e+00, 1.056813028189597e+00 };

	/* Setting up QProblem object. */
	QProblem example( 5,2 );

	Options options;
 	//options.enableFlippingBounds = BT_FALSE;
	//options.enableEqualities = BT_TRUE;
	//options.initialStatusBounds = ST_INACTIVE;
	example.setOptions( options );
	example.setPrintLevel( PL_NONE );
	
	/* Solve first QP. */
	returnValue retVal;
	int_t simpleStatus = -1;

	int_t nWSR = 10;
	retVal = example.init( H,g,A,lb,ub,lbA,ubA, nWSR,0 );
	simpleStatus = getSimpleStatus( retVal,BT_TRUE );

	QPOASES_TEST_FOR_TRUE( simpleStatus == 0 );


	/* Get and print solution of second QP. */
	real_t xOpt[5];
	real_t yOpt[5+2];
	
	example.getPrimalSolution( xOpt );
	example.getDualSolution( yOpt );
	printf( "\nxOpt = [ %e, %e, ... ];  objVal = %e\n\n", xOpt[0],xOpt[1],example.getObjVal() );
	
	/* Compute KKT tolerances */
	real_t stat, feas, cmpl;
	SolutionAnalysis analyzer;

	analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
	printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );

	QPOASES_TEST_FOR_TOL( stat,1e-14 );
	QPOASES_TEST_FOR_TOL( feas,1e-14 );
	QPOASES_TEST_FOR_TOL( cmpl,1e-15 );

	return TEST_PASSED;
}