コード例 #1
0
ファイル: Utils.c プロジェクト: RobotXiaoFeng/acado
/*
 *	r e a d F r o m F i l e
 */
returnValue qpOASES_readFromFileV(	real_t* data, int n,
									const char* datafilename
									)
{
	return qpOASES_readFromFileM( data, n, 1, datafilename );
}
コード例 #2
0
ファイル: OQPinterface.c プロジェクト: fengxh/Julia
/*
 *	r e a d O Q P d a t a
 */
returnValue readOQPdata(	const char* path,
							int* nQP, int* nV, int* nC, int* nEC,
							real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
							real_t* xOpt, real_t* yOpt, real_t* objOpt
							)
{
	char filename[QPOASES_MAX_STRING_LENGTH];

	/* consistency check */
	if ( ( H == 0 ) || ( g == 0 ) || ( lb == 0 ) || ( ub == 0 ) )
		return THROWERROR( RET_INVALID_ARGUMENTS );


	/* 1) Obtain OQP dimensions. */
	if ( readOQPdimensions( path, nQP,nV,nC,nEC ) != SUCCESSFUL_RETURN )
		return THROWERROR( RET_UNABLE_TO_READ_FILE );


	/* another consistency check */
	if ( ( *nC > 0 ) && ( ( A == 0 ) || ( lbA == 0 ) || ( ubA == 0 ) ) )
		return THROWERROR( RET_FILEDATA_INCONSISTENT );


	/* 2) Allocate memory and load OQP data: */
	/* Hessian matrix */
	snprintf( filename,QPOASES_MAX_STRING_LENGTH,"%sH.oqp",path );
	if ( qpOASES_readFromFileM( H,(*nV),(*nV),filename ) != SUCCESSFUL_RETURN )
		return THROWERROR( RET_UNABLE_TO_READ_FILE );

	/* gradient vector sequence */
	snprintf( filename,QPOASES_MAX_STRING_LENGTH,"%sg.oqp",path );
	if ( qpOASES_readFromFileM( g,(*nQP),(*nV),filename ) != SUCCESSFUL_RETURN )
		return THROWERROR( RET_UNABLE_TO_READ_FILE );
	
	/* lower bound vector sequence */
	snprintf( filename,QPOASES_MAX_STRING_LENGTH,"%slb.oqp",path );
	if ( qpOASES_readFromFileM( lb,(*nQP),(*nV),filename ) != SUCCESSFUL_RETURN )
		return THROWERROR( RET_UNABLE_TO_READ_FILE );

	/* upper bound vector sequence */
	snprintf( filename,QPOASES_MAX_STRING_LENGTH,"%sub.oqp",path );
	if ( qpOASES_readFromFileM( ub,(*nQP),(*nV),filename ) != SUCCESSFUL_RETURN )
		return THROWERROR( RET_UNABLE_TO_READ_FILE );
	
	if ( (*nC) > 0 )
	{
		/* Constraint matrix */
		snprintf( filename,QPOASES_MAX_STRING_LENGTH,"%sA.oqp",path );
		if ( qpOASES_readFromFileM( A,(*nC),(*nV),filename ) != SUCCESSFUL_RETURN )
			return THROWERROR( RET_UNABLE_TO_READ_FILE );

		/* lower constraints' bound vector sequence */
		snprintf( filename,QPOASES_MAX_STRING_LENGTH,"%slbA.oqp",path );
		if ( qpOASES_readFromFileM( lbA,(*nQP),(*nC),filename ) != SUCCESSFUL_RETURN )
			return THROWERROR( RET_UNABLE_TO_READ_FILE );

		/* upper constraints' bound vector sequence */
		snprintf( filename,QPOASES_MAX_STRING_LENGTH,"%subA.oqp",path );
		if ( qpOASES_readFromFileM( ubA,(*nQP),(*nC),filename ) != SUCCESSFUL_RETURN )
			return THROWERROR( RET_UNABLE_TO_READ_FILE );
	}

	if ( xOpt != 0 )
	{
		/* primal solution vector sequence */
		snprintf( filename,QPOASES_MAX_STRING_LENGTH,"%sx_opt.oqp",path );
		if ( qpOASES_readFromFileM( xOpt,(*nQP),(*nV),filename ) != SUCCESSFUL_RETURN )
			return THROWERROR( RET_UNABLE_TO_READ_FILE );
	}

	if ( yOpt != 0 )
	{
		/* dual solution vector sequence */
		snprintf( filename,QPOASES_MAX_STRING_LENGTH,"%sy_opt.oqp",path );
		if ( qpOASES_readFromFileM( yOpt,(*nQP),(*nV)+(*nC),filename ) != SUCCESSFUL_RETURN )
			return THROWERROR( RET_UNABLE_TO_READ_FILE );
	}

	if ( objOpt != 0 )
	{
		/* dual solution vector sequence */
		snprintf( filename,QPOASES_MAX_STRING_LENGTH,"%sobj_opt.oqp",path );
		if ( qpOASES_readFromFileM( objOpt,(*nQP),1,filename ) != SUCCESSFUL_RETURN )
			return THROWERROR( RET_UNABLE_TO_READ_FILE );
	}
	
	return SUCCESSFUL_RETURN;
}