/*
 *	Q P r o b l e m _ h o t s t a r t
 */
int_t QProblem_hotstart(	int_t handle,
							const real_t* const g,
							const real_t* const lb, const real_t* const ub,
							const real_t* const lbA, const real_t* const ubA,
							int_t nWSRin, real_t maxCpuTimeIn,
							Options* options,
							int_t nOutputs, mxArray* plhs[]
							)
{
	int_t nWSRout = nWSRin;
	real_t maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY;

	QProblem* globalSQP = getQPInstance(handle)->sqp;

	if ( globalSQP == 0 )
	{
		myMexErrMsgTxt( "ERROR (qpOASES): QP needs to be initialised first!" );
		return -1;
	}

	int_t nV = globalSQP->getNV();
	int_t nC = globalSQP->getNC();

	/* 1) Solve QP with given options. */
	globalSQP->setOptions( *options );
	returnValue returnvalue = globalSQP->hotstart( g,lb,ub,lbA,ubA, nWSRout,&maxCpuTimeOut );

	/* 2) Assign lhs arguments. */
	obtainOutputs(	0,globalSQP,returnvalue,nWSRout,maxCpuTimeOut,
					nOutputs,plhs,nV,nC );

	return 0;
}
Beispiel #2
0
static void mdlStart(SimStruct *S)
{
	#ifndef __DSPACE__
	using namespace qpOASES;
	#endif

	int nU = NCONTROLINPUTS;
	int size_H, size_g, size_A, size_lb, size_ub, size_lbA, size_ubA;
	int nV, nC;

	QProblem* problem;
	real_t* count;


	/* get block inputs dimensions */
	size_H   = ssGetInputPortWidth(S, 0);
	size_g   = ssGetInputPortWidth(S, 1);
	size_A   = ssGetInputPortWidth(S, 2);
	size_lb  = ssGetInputPortWidth(S, 3);
	size_ub  = ssGetInputPortWidth(S, 4);
	size_lbA = ssGetInputPortWidth(S, 5);
	size_ubA = ssGetInputPortWidth(S, 6);


	/* dimension checks */
	nV = size_g;
	nC = (int) ( ((real_t) size_A) / ((real_t) nV) );

	if ( nV == 0 )
	{
		#ifndef __DSPACE__
		#ifndef __XPCTARGET__
		mexErrMsgTxt( "ERROR (qpOASES): Dimension mismatch!" );
		#endif
		#endif
		return;
	}

	if ( size_H != nV*nV )
	{
		#ifndef __DSPACE__
		#ifndef __XPCTARGET__
		mexErrMsgTxt( "ERROR (qpOASES): Dimension mismatch!" );
		#endif
		#endif
		return;
	}

	if ( nU > nV )
	{
		#ifndef __DSPACE__
		#ifndef __XPCTARGET__
		mexErrMsgTxt( "ERROR (qpOASES): Dimension mismatch!" );
		#endif
		#endif
		return;
	}

	if ( size_lb != nV )
	{
		#ifndef __DSPACE__
		#ifndef __XPCTARGET__
		mexErrMsgTxt( "ERROR (qpOASES): Dimension mismatch!" );
		#endif
		#endif
		return;
	}

	if ( size_ub != nV )
	{
		#ifndef __DSPACE__
		#ifndef __XPCTARGET__
		mexErrMsgTxt( "ERROR (qpOASES): Dimension mismatch!" );
		#endif
		#endif
		return;
	}

	if ( size_lbA != nC )
	{
		#ifndef __DSPACE__
		#ifndef __XPCTARGET__
		mexErrMsgTxt( "ERROR (qpOASES): Dimension mismatch!" );
		#endif
		#endif
		return;
	}

	if ( size_ubA != nC )
	{
		#ifndef __DSPACE__
		#ifndef __XPCTARGET__
		mexErrMsgTxt( "ERROR (qpOASES): Dimension mismatch!" );
		#endif
		#endif
		return;
	}


	/* allocate QProblem object */
	problem = new QProblem( nV,nC );
	if ( problem == 0 )
	{
		#ifndef __DSPACE__
		#ifndef __XPCTARGET__
		mexErrMsgTxt( "ERROR (qpOASES): Unable to create QProblem object!" );
		#endif
		#endif
		return;
	}
	
	Options problemOptions;
	problemOptions.setToMPC();
	problem->setOptions( problemOptions );

	#ifndef __DEBUG__
	problem->setPrintLevel( PL_LOW );
	#endif
	#ifdef __SUPPRESSANYOUTPUT__
	problem->setPrintLevel( PL_NONE );
	#endif
	#ifdef __DSPACE__
	problem->setPrintLevel( PL_NONE );
	#endif

	ssGetPWork(S)[0] = (void *) problem;

	/* allocate memory for QP data ... */
	ssGetPWork(S)[1] = (void *) calloc( size_H, sizeof(real_t) );	/* H */
	ssGetPWork(S)[2] = (void *) calloc( size_g, sizeof(real_t) );	/* g */
	ssGetPWork(S)[3] = (void *) calloc( size_A, sizeof(real_t) );	/* A */
	ssGetPWork(S)[4] = (void *) calloc( size_lb, sizeof(real_t) );	/* lb */
	ssGetPWork(S)[5] = (void *) calloc( size_ub, sizeof(real_t) );	/* ub */
	ssGetPWork(S)[6] = (void *) calloc( size_lbA, sizeof(real_t) );	/* lbA */
	ssGetPWork(S)[7] = (void *) calloc( size_ubA, sizeof(real_t) );	/* ubA */
	ssGetPWork(S)[8] = (void *) calloc( 1, sizeof(real_t) ); /* count */

	/* reset counter */
	count = (real_t *) ssGetPWork(S)[8];
	count[0] = 0.0;
}