예제 #1
0
void QPInstanceCON(	QPInstance* _THIS,
					int _nV,
					int _nC,
					HessianType _hessianType,
					BooleanType _isSimplyBounded
					)
{
	if ( _nV > NVMAX )
	{
		myMexErrMsgTxt( "ERROR (qpOASES_e): Too many primal variables (try increasing QPOASES_NVMAX)!" );
		return;
	}

	if ( _nC > NCMAX )
	{
		myMexErrMsgTxt( "ERROR (qpOASES_e): Too many constraints (try increasing QPOASES_NCMAX)!" );
		return;
	}

	_THIS->handle = QPInstance_nexthandle;
	
	if ( _nC > 0 )
		_THIS->isSimplyBounded = BT_FALSE;
	else
		_THIS->isSimplyBounded = _isSimplyBounded;
	
	if ( _THIS->isSimplyBounded == BT_FALSE )
		QProblemCON( &(_THIS->sqp),_nV,_nC,_hessianType );
	else
		QProblemBCON( &(_THIS->qpb),_nV,_hessianType );
}	
예제 #2
0
/** 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;
}
예제 #3
0
파일: qpOASES.c 프로젝트: fengxh/Julia
/** 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;
}
예제 #4
0
파일: OQPinterface.c 프로젝트: fengxh/Julia
/*
 *	s o l v e O Q P b e n c h m a r k
 */
returnValue solveOQPbenchmark(	int nQP, int nV, int nC, int nEC,
								real_t* _H, const real_t* const g, real_t* _A,
								const real_t* const lb, const real_t* const ub,
								const real_t* const lbA, const real_t* const ubA,
								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 QProblem 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;
	const real_t* lbACur;
	const real_t* ubACur;

	/* 3) Vectors for solution obtained by qpOASES. */
	myStatic real_t x[NVMAX];
	myStatic real_t y[NVMAX+NCMAX];

	/* 4) Prepare matrix objects */
	DenseMatrix *H, *A;
	myStatic DenseMatrix HH, AA;


	DenseMatrixCON( &HH, nV, nV, nV, _H );
	DenseMatrixCON( &AA, nC, nV, nV, _A );
	
	H = &HH;
	A = &AA;
	
	*maxNWSR = 0;
	*avgNWSR = 0;
	*maxCPUtime = 0.0;
	*avgCPUtime = 0.0;
	*maxStationarity = 0.0;
	*maxFeasibility = 0.0;
	*maxComplementarity = 0.0;
	
	/*DenseMatrix_print( H );*/

	/* II) SETUP QPROBLEM OBJECT */
	QProblemCON( &qp,nV,nC,HST_UNKNOWN );
	QProblem_setOptions( &qp,*options );
	/*QProblem_setPrintLevel( &qp,PL_LOW );*/

	 /* QProblem_printOptions( &qp ); */

	/* 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] );
		lbACur = &( lbA[k*nC] );
		ubACur = &( ubA[k*nC] );

		/* 2) Set nWSR and maximum CPU time. */
		nWSRcur = maxAllowedNWSR;
		CPUtimeCur = CPUtimeLimit;

		/* 3) Solve current QP. */
		if ( ( k == 0 ) || ( useHotstarts == BT_FALSE ) )
		{
			/* initialise */
			returnvalue = QProblem_initM( &qp, H,gCur,A,lbCur,ubCur,lbACur,ubACur, &nWSRcur,&CPUtimeCur );
			if ( ( returnvalue != SUCCESSFUL_RETURN ) && ( returnvalue != RET_MAX_NWSR_REACHED ) )
				return THROWERROR( returnvalue );
		}
		else
		{
			/* hotstart */
			returnvalue = QProblem_hotstart( &qp, gCur,lbCur,ubCur,lbACur,ubACur, &nWSRcur,&CPUtimeCur );
			if ( ( returnvalue != SUCCESSFUL_RETURN ) && ( returnvalue != RET_MAX_NWSR_REACHED ) )
				return THROWERROR( returnvalue );
		}

		/* 4) Obtain solution vectors and objective function value */
		QProblem_getPrimalSolution( &qp,x );
		QProblem_getDualSolution( &qp,y );

		/* 5) Compute KKT residuals */
		qpOASES_getKktViolation( nV,nC, _H,gCur,_A,lbCur,ubCur,lbACur,ubACur, 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;
}