当前位置: 首页>>代码示例>>C++>>正文


C++ ExportVariable类代码示例

本文整理汇总了C++中ExportVariable的典型用法代码示例。如果您正苦于以下问题:C++ ExportVariable类的具体用法?C++ ExportVariable怎么用?C++ ExportVariable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ExportVariable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getAuxVariable

ExportVariable DiscreteTimeExport::getAuxVariable() const
{
	ExportVariable max;
	if( NX1 > 0 ) {
		max = lin_input.getGlobalExportVariable();
	}
	if( NX2 > 0 ) {
		if( rhs.getGlobalExportVariable().getDim() >= max.getDim() ) {
			max = rhs.getGlobalExportVariable();
		}
		if( diffs_rhs.getGlobalExportVariable().getDim() >= max.getDim() ) {
			max = diffs_rhs.getGlobalExportVariable();
		}
	}
	if( NX3 > 0 ) {
		if( rhs3.getGlobalExportVariable().getDim() >= max.getDim() ) {
			max = rhs3.getGlobalExportVariable();
		}
		if( diffs_rhs3.getGlobalExportVariable().getDim() >= max.getDim() ) {
			max = diffs_rhs3.getGlobalExportVariable();
		}
	}

	return max;
}
开发者ID:RobotXiaoFeng,项目名称:acado,代码行数:25,代码来源:discrete_export.cpp

示例2: run1

returnValue ExportGaussElim::setupSolveReuseComplete( ExportFunction& _solveReuse, ExportVariable& _bPerm ) {

	ExportIndex run1( "i" );
	ExportIndex run2( "j" );
	ExportIndex tmp_index1( "index1" );
	ExportIndex tmp_index2( "index2" );
	ExportVariable tmp( "tmp_var", 1, 1, _bPerm.getType(), ACADO_LOCAL, true );
	_solveReuse.addIndex( run1 );
	_solveReuse.addIndex( run2 );
	_solveReuse.addIndex( tmp_index1 );
	_solveReuse.addIndex( tmp_index2 );
	_solveReuse.addDeclaration(tmp);
	uint run3;

	if (nRightHandSides <= 0)
		return ACADOERROR(RET_INVALID_OPTION);

	ExportForLoop loop1( run1, 0, dim );
	loop1 << run2.getName() << " = " << rk_perm.getFullName() << "[" << run1.getName() << "]*" << toString(nRightHandSides) << ";\n";
	for( run3 = 0; run3 < nRightHandSides; run3++ ) {
		loop1 << _bPerm.get( run1,run3 ) << " = b[" << run2.getName() << "+" << toString(run3) << "];\n";
	}
	_solveReuse.addStatement( loop1 );

	ExportForLoop loop2( run2, 1, dim );	// row run2
	loop2.addStatement( tmp_index1 == run2*nRightHandSides );
	ExportForLoop loop3( run1, 0, run2 );	// column run1
	loop3.addStatement( tmp_index2 == run1*nRightHandSides );
	loop3.addStatement( tmp == A.getElement(run2,run1) );
	for( run3 = 0; run3 < nRightHandSides; run3++ ) {
//		loop3.addStatement( _bPerm.getElement( run2,run3 ) += tmp * _bPerm.getElement( run1,run3 ) );
		loop3 << _bPerm.getFullName() << "[" << tmp_index1.getName() << "+" << toString(run3) << "] += " << tmp.getName() << "*" << _bPerm.getFullName() << "[" << tmp_index2.getName() << "+" << toString(run3) << "];\n";
	}
	loop2.addStatement( loop3 );
	_solveReuse.addStatement( loop2 );


	// Solve the upper triangular system of equations:
	ExportForLoop loop4( run1, dim-1, -1, -1 );
	loop4.addStatement( tmp_index1 == run1*nRightHandSides );
	ExportForLoop loop5( run2, dim-1, run1, -1 );
	loop5.addStatement( tmp_index2 == run2*nRightHandSides );
	loop5.addStatement( tmp == A.getElement( run1,run2 ) );
	for( run3 = 0; run3 < nRightHandSides; run3++ ) {
//		loop5.addStatement( _bPerm.getElement( run1,run3 ) -= tmp * _bPerm.getElement( run2,run3 ) );
		loop5 << _bPerm.getFullName() << "[" << tmp_index1.getName() << "+" << toString(run3) << "] -= " << tmp.getName() << "*" << _bPerm.getFullName() << "[" << tmp_index2.getName() << "+" << toString(run3) << "];\n";
	}
	loop4.addStatement( loop5 );
	loop4 << tmp.getName() << " = 1.0/A[" << run1.getName() << "*" << toString(dim+1) << "];\n";
	for( run3 = 0; run3 < nRightHandSides; run3++ ) {
//		loop4 << _bPerm.get( run1,run3 ) << " = " << _bPerm.get( run1,run3 ) << "*" << tmp.getName() << ";\n";
		loop4 << _bPerm.getFullName() << "[" << tmp_index1.getName() << "+" << toString(run3) << "] = " << tmp.getName() << "*" << _bPerm.getFullName() << "[" << tmp_index1.getName() << "+" << toString(run3) << "];\n";
	}
	_solveReuse.addStatement( loop4 );

	_solveReuse.addStatement( b == _bPerm );

	return SUCCESSFUL_RETURN;
}
开发者ID:RobotXiaoFeng,项目名称:acado,代码行数:59,代码来源:gaussian_elimination_export.cpp

示例3: clone

ExportVariable ExportVariable::clone() const
{
	ExportVariable ret;
	if( !isNull() )
		ret.assignNode( (*this)->clone() );

	return ret;
}
开发者ID:skyhawkf119,项目名称:acado,代码行数:8,代码来源:export_variable.cpp

示例4: deepcopy

ExportVariable ExportVariable::operator()(	const String& _name
											) const
{
	ExportVariable tmp = deepcopy( *this );

	tmp.setName( _name );

	return tmp;
}
开发者ID:skyhawkf119,项目名称:acado,代码行数:9,代码来源:export_variable.cpp

示例5: getAuxVariable

ExportVariable ExplicitRungeKuttaExport::getAuxVariable() const
{
    ExportVariable max;
    max = rhs.getGlobalExportVariable();
    if( diffs_rhs.getGlobalExportVariable().getDim() > max.getDim() ) {
        max = diffs_rhs.getGlobalExportVariable();
    }
    return max;
}
开发者ID:rienq,项目名称:acado,代码行数:9,代码来源:erk_export.cpp

示例6: getAuxVariable

ExportVariable ThreeSweepsERKExport::getAuxVariable() const
{
	ExportVariable max;
	max = rhs.getGlobalExportVariable();
	if( diffs_rhs.getGlobalExportVariable().getDim() > max.getDim() ) {
		max = diffs_rhs.getGlobalExportVariable();
	}
	if( diffs_sweep3.getGlobalExportVariable().getDim() > max.getDim() ) {
		max = diffs_sweep3.getGlobalExportVariable();
	}
	return max;
}
开发者ID:RobotXiaoFeng,项目名称:acado,代码行数:12,代码来源:erk_3sweep_export.cpp

示例7: getAuxVariable

ExportVariable LiftedERKExport::getAuxVariable() const
{
	ExportVariable max;
	max = rhs.getGlobalExportVariable();
	if( diffs_rhs.getGlobalExportVariable().getDim() > max.getDim() ) {
		max = diffs_rhs.getGlobalExportVariable();
	}
	if( alg_rhs.getGlobalExportVariable().getDim() > max.getDim() ) {
		max = alg_rhs.getGlobalExportVariable();
	}
	return max;
}
开发者ID:RobotXiaoFeng,项目名称:acado,代码行数:12,代码来源:lifted_erk_export.cpp

示例8: setupSolveReuse

returnValue ExportGaussElim::setupSolveReuse( ExportFunction& _solveReuse, ExportFunction& _solveTriangular, ExportVariable& _bPerm ) {

	uint run1, run2;

	if (nRightHandSides > 0)
		return ACADOERROR(RET_INVALID_OPTION);

	for( run1 = 0; run1 < dim; run1++ ) {
		_solveReuse << _bPerm.get( run1,0 ) << " = b[" << rk_perm.getFullName() << "[" << toString( run1 ) << "]];\n";
	}

	for( run2 = 1; run2 < dim; run2++ ) { 		// row run2
		for( run1 = 0; run1 < run2; run1++ ) { 	// column run1
			_solveReuse << _bPerm.get( run2,0 ) << " += A[" << toString( run2*dim+run1 ) << "]*" << _bPerm.getFullName() << "[" << toString( run1 ) << "];\n";
		}
		_solveReuse.addLinebreak();
	}
	_solveReuse.addLinebreak();

	_solveReuse.addFunctionCall( _solveTriangular, A, _bPerm );
	_solveReuse.addStatement( b == _bPerm );

	return SUCCESSFUL_RETURN;
}
开发者ID:RobotXiaoFeng,项目名称:acado,代码行数:24,代码来源:gaussian_elimination_export.cpp

示例9: get

returnValue ThreeSweepsERKExport::setup( )
{
	int sensGen;
	get( DYNAMIC_SENSITIVITY,sensGen );
	if ( (ExportSensitivityType)sensGen != SYMMETRIC ) ACADOERROR( RET_INVALID_OPTION );

	// NOT SUPPORTED: since the forward sweep needs to be saved
	if( !equidistantControlGrid() ) 	ACADOERROR( RET_INVALID_OPTION );

	// NOT SUPPORTED: since the adjoint derivatives could be 'arbitrarily bad'
	if( !is_symmetric ) 				ACADOERROR( RET_INVALID_OPTION );

	LOG( LVL_DEBUG ) << "Preparing to export ThreeSweepsERKExport... " << endl;

	// export RK scheme
	uint numX = NX*(NX+1)/2.0;
	uint numU = NU*(NU+1)/2.0;
	uint rhsDim   = NX + NX + NX*(NX+NU) + numX + NX*NU + numU;
	inputDim = rhsDim + NU + NOD;
	const uint rkOrder  = getNumStages();

	double h = (grid.getLastTime() - grid.getFirstTime())/grid.getNumIntervals();    

	ExportVariable Ah ( "A*h",  DMatrix( AA )*=h );
	ExportVariable b4h( "b4*h", DMatrix( bb )*=h );

	rk_index = ExportVariable( "rk_index", 1, 1, INT, ACADO_LOCAL, true );
	rk_eta = ExportVariable( "rk_eta", 1, inputDim );
//	seed_backward.setup( "seed", 1, NX );

	int useOMP;
	get(CG_USE_OPENMP, useOMP);
	ExportStruct structWspace;
	structWspace = useOMP ? ACADO_LOCAL : ACADO_WORKSPACE;

	rk_ttt.setup( "rk_ttt", 1, 1, REAL, structWspace, true );
	uint timeDep = 0;
	if( timeDependant ) timeDep = 1;
	
	rk_xxx.setup("rk_xxx", 1, inputDim+timeDep, REAL, structWspace);
	uint numK = NX*(NX+NU)+numX+NX*NU+numU;
	rk_kkk.setup("rk_kkk", rkOrder, numK, REAL, structWspace);
	rk_forward_sweep.setup("rk_sweep1", 1, grid.getNumIntervals()*rkOrder*NX, REAL, structWspace);
	rk_backward_sweep.setup("rk_sweep2", 1, grid.getNumIntervals()*rkOrder*NX, REAL, structWspace);

	if ( useOMP )
	{
		ExportVariable auxVar;

		auxVar = diffs_rhs.getGlobalExportVariable();
		auxVar.setName( "odeAuxVar" );
		auxVar.setDataStruct( ACADO_LOCAL );
		diffs_rhs.setGlobalExportVariable( auxVar );
	}

	ExportIndex run( "run1" );

	// setup INTEGRATE function
	integrate = ExportFunction( "integrate", rk_eta, reset_int );
	integrate.setReturnValue( error_code );
	rk_eta.setDoc( "Working array to pass the input values and return the results." );
	reset_int.setDoc( "The internal memory of the integrator can be reset." );
	rk_index.setDoc( "Number of the shooting interval." );
	error_code.setDoc( "Status code of the integrator." );
	integrate.doc( "Performs the integration and sensitivity propagation for one shooting interval." );
	integrate.addIndex( run );
	
	integrate.addStatement( rk_ttt == DMatrix(grid.getFirstTime()) );

	if( inputDim > rhsDim ) {
		// initialize sensitivities:
//		integrate.addStatement( rk_eta.getCols( NX,2*NX ) == seed_backward );
		DMatrix idX    = eye<double>( NX );
		DMatrix zeroXU = zeros<double>( NX,NU );
		integrate.addStatement( rk_eta.getCols( 2*NX,NX*(2+NX) ) == idX.makeVector().transpose() );
		integrate.addStatement( rk_eta.getCols( NX*(2+NX),NX*(2+NX+NU) ) == zeroXU.makeVector().transpose() );

		integrate.addStatement( rk_eta.getCols( NX*(2+NX+NU),rhsDim ) == zeros<double>( 1,numX+NX*NU+numU ) );
		// FORWARD SWEEP FIRST
		integrate.addStatement( rk_xxx.getCols( NX,NX+NU+NOD ) == rk_eta.getCols( rhsDim,inputDim ) );
	}
	integrate.addLinebreak( );

    // integrator loop: FORWARD SWEEP
	ExportForLoop loop = ExportForLoop( run, 0, grid.getNumIntervals() );
	for( uint run1 = 0; run1 < rkOrder; run1++ )
	{
		loop.addStatement( rk_xxx.getCols( 0,NX ) == rk_eta.getCols( 0,NX ) + Ah.getRow(run1)*rk_kkk.getCols( 0,NX ) );
		// save forward trajectory
		loop.addStatement( rk_forward_sweep.getCols( run*rkOrder*NX+run1*NX,run*rkOrder*NX+(run1+1)*NX ) == rk_xxx.getCols( 0,NX ) );
		if( timeDependant ) loop.addStatement( rk_xxx.getCol( NX+NU+NOD ) == rk_ttt + ((double)cc(run1))/grid.getNumIntervals() );
		loop.addFunctionCall( getNameRHS(),rk_xxx,rk_kkk.getAddress(run1,0) );
	}
	loop.addStatement( rk_eta.getCols( 0,NX ) += b4h^rk_kkk.getCols( 0,NX ) );
	loop.addStatement( rk_ttt += DMatrix(1.0/grid.getNumIntervals()) );
    // end of integrator loop: FORWARD SWEEP
	integrate.addStatement( loop );

	if( inputDim > rhsDim ) {
		// BACKWARD SWEEP NEXT
//.........这里部分代码省略.........
开发者ID:RobotXiaoFeng,项目名称:acado,代码行数:101,代码来源:erk_3sweep_export.cpp

示例10: get

returnValue ExportExactHessianCN2::setupObjectiveEvaluation( void )
{
	evaluateObjective.setup("evaluateObjective");

	int gradientUp;
	get( LIFTED_GRADIENT_UPDATE, gradientUp );
	bool gradientUpdate = (bool) gradientUp;

	//
	// A loop the evaluates objective and corresponding gradients
	//
	ExportIndex runObj( "runObj" );
	ExportForLoop loopObjective( runObj, 0, N );

	evaluateObjective.addIndex( runObj );

	unsigned offset = performFullCondensing() == true ? 0 : NX;

	if( evaluateStageCost.getFunctionDim() > 0 ) {
		loopObjective.addStatement( objValueIn.getCols(0, getNX()) == x.getRow( runObj ) );
		loopObjective.addStatement( objValueIn.getCols(NX, NX + NU) == u.getRow( runObj ) );
		loopObjective.addStatement( objValueIn.getCols(NX + NU, NX + NU + NOD) == od.getRow( runObj ) );
		loopObjective.addLinebreak( );

		// Evaluate the objective function
		loopObjective.addFunctionCall(evaluateStageCost, objValueIn, objValueOut);
		loopObjective.addLinebreak( );

		ExportVariable tmpFxx, tmpFxu, tmpFuu;
		tmpFxx.setup("tmpFxx", NX, NX, REAL, ACADO_LOCAL);
		tmpFxu.setup("tmpFxu", NX, NU, REAL, ACADO_LOCAL);
		tmpFuu.setup("tmpFuu", NU, NU, REAL, ACADO_LOCAL);

		//
		// Optional computation of Q1, Q2
		//
		ExportVariable tmpEH;
		tmpEH.setup("tmpEH", NX+NU, NX+NU, REAL, ACADO_LOCAL);

		setObjQ1Q2.setup("addObjTerm", tmpFxx, tmpFxu, tmpFuu, tmpEH);
		setObjQ1Q2.addStatement( tmpEH.getSubMatrix(0,NX,0,NX) += tmpFxx );
		setObjQ1Q2.addStatement( tmpEH.getSubMatrix(0,NX,NX,NX+NU) += tmpFxu );
		setObjQ1Q2.addStatement( tmpEH.getSubMatrix(NX,NX+NU,0,NX) += tmpFxu.getTranspose() );
		setObjQ1Q2.addStatement( tmpEH.getSubMatrix(NX,NX+NU,NX,NX+NU) += tmpFuu );

		loopObjective.addFunctionCall(
				setObjQ1Q2, objValueOut.getAddress(0, 1+NX+NU), objValueOut.getAddress(0, 1+NX+NU+NX*NX),
				objValueOut.getAddress(0, 1+NX+NU+NX*(NX+NU)), objS.getAddress(runObj*(NX+NU), 0) );

		ExportVariable tmpDx, tmpDu, tmpDF;
		tmpDx.setup("tmpDx", NX, 1, REAL, ACADO_LOCAL);
		tmpDu.setup("tmpDu", NU, 1, REAL, ACADO_LOCAL);
		tmpDF.setup("tmpDF", NX+NU, 1, REAL, ACADO_LOCAL);
		setObjR1R2.setup("addObjLinearTerm", tmpDx, tmpDu, tmpDF);
		setObjR1R2.addStatement( tmpDx == tmpDF.getRows(0,NX) );
		setObjR1R2.addStatement( tmpDu == tmpDF.getRows(NX,NX+NU) );

		int sensitivityProp;
		get( DYNAMIC_SENSITIVITY, sensitivityProp );
		bool adjoint = ((ExportSensitivityType) sensitivityProp == BACKWARD);
		if( gradientUpdate || adjoint ) {
			loopObjective.addStatement( objValueOut.getCols(1,1+NX+NU) += objg.getRows(runObj*(NX+NU),(runObj+1)*(NX+NU)).getTranspose() );
		}
		loopObjective.addFunctionCall(
				setObjR1R2, QDy.getAddress(runObj * NX), g.getAddress(offset+runObj * NU, 0), objValueOut.getAddress(0, 1) );

		loopObjective.addLinebreak( );
	}
	else {
		DMatrix Du(NU,1); Du.setAll(0);
		DMatrix Dx(NX,1); Dx.setAll(0);
		loopObjective.addStatement( g.getRows(offset+runObj*NU, offset+runObj*NU+NU) == Du );
		loopObjective.addStatement( QDy.getRows(runObj*NX, runObj*NX+NX) == Dx );
	}

	evaluateObjective.addStatement( loopObjective );

	//
	// Evaluate the quadratic Mayer term
	//
	if( evaluateTerminalCost.getFunctionDim() > 0 ) {
		evaluateObjective.addStatement( objValueIn.getCols(0, NX) == x.getRow( N ) );
		evaluateObjective.addStatement( objValueIn.getCols(NX, NX + NOD) == od.getRow( N ) );

		// Evaluate the objective function, last node.
		evaluateObjective.addFunctionCall(evaluateTerminalCost, objValueIn, objValueOut);
		evaluateObjective.addLinebreak( );

		ExportVariable tmpFxxEnd;
		tmpFxxEnd.setup("tmpFxxEnd", NX, NX, REAL, ACADO_LOCAL);

		//
		// Optional computation of QN1
		//
		ExportVariable tmpEH_N;
		tmpEH_N.setup("tmpEH_N", NX, NX, REAL, ACADO_LOCAL);

		setObjQN1QN2.setup("addObjEndTerm", tmpFxxEnd, tmpEH_N);
		setObjQN1QN2.addStatement( tmpEH_N == tmpFxxEnd );

//.........这里部分代码省略.........
开发者ID:ferreau,项目名称:acado,代码行数:101,代码来源:export_exact_hessian_cn2.cpp

示例11: get

returnValue LiftedERKExport::setup( )
{
	int useOMP;
	get(CG_USE_OPENMP, useOMP);
	ExportStruct structWspace;
	structWspace = useOMP ? ACADO_LOCAL : ACADO_WORKSPACE;

	int sensGen;
	get( DYNAMIC_SENSITIVITY,sensGen );
	if ( (ExportSensitivityType)sensGen != FORWARD && (ExportSensitivityType)sensGen != NO_SENSITIVITY && (ExportSensitivityType)sensGen != INEXACT ) ACADOERROR( RET_INVALID_OPTION );

	int liftMode = 1;
	// liftMode == 1 --> EXACT LIFTING
	// liftMode == 2 --> INEXACT LIFTING
	if( (ExportSensitivityType)sensGen == INEXACT ) liftMode = 2;

	bool DERIVATIVES = ((ExportSensitivityType)sensGen != NO_SENSITIVITY);

	LOG( LVL_DEBUG ) << "Preparing to export ExplicitRungeKuttaExport... " << endl;

	// setup linear solver:
	int solverType;
	userInteraction->get( LINEAR_ALGEBRA_SOLVER,solverType );

	if ( solver )
		delete solver;
	solver = 0;

	switch( (LinearAlgebraSolver) solverType ) {
	case GAUSS_LU:
		solver = new ExportGaussElim( userInteraction,commonHeaderName );
		solver->init( NXA, NX+NU+1 );
		solver->setReuse( true ); 	// IFTR method
		solver->setup();
		rk_auxSolver = solver->getGlobalExportVariable( 1 );
		break;
	default:
		return ACADOERROR( RET_INVALID_OPTION );
	}
	rk_A = ExportVariable( "rk_A", NXA, NXA, REAL, structWspace );
	rk_b = ExportVariable( "rk_b", NXA, 1+NX+NU, REAL, structWspace );

	// export RK scheme
	uint rhsDim   = NX*(NX+NU+1);
	uint zDim = NXA*(NX+NU+1);
	inputDim = (NX+NXA)*(NX+NU+1) + NU + NOD;
	if( !DERIVATIVES ) return ACADOERROR( RET_INVALID_OPTION );
	const uint rkOrder  = getNumStages();

	double h = (grid.getLastTime() - grid.getFirstTime())/grid.getNumIntervals();

	ExportVariable Ah ( "A*h",  DMatrix( AA )*=h );
	ExportVariable b4h( "b4*h", DMatrix( bb )*=h );

	rk_index = ExportVariable( "rk_index", 1, 1, INT, ACADO_LOCAL, true );
	rk_eta = ExportVariable( "rk_eta", 1, inputDim );

	rk_ttt.setup( "rk_ttt", 1, 1, REAL, structWspace, true );
	uint timeDep = 0;
	if( timeDependant ) timeDep = 1;

	rk_xxx.setup("rk_xxx", 1, inputDim+NXA+timeDep, REAL, structWspace);
	rk_kkk.setup("rk_kkk", rkOrder, rhsDim, REAL, structWspace);

	rk_zzz.setup("rk_zzz", getN()*grid.getNumIntervals()*rkOrder, NXA, REAL, structWspace);
	rk_zTemp.setup("rk_zTemp", 1, NXA*(1+NX+NXA+NU), REAL, structWspace);
//	if( liftMode == 1 ) {
		rk_diffZ.setup("rk_diffZ", getN()*grid.getNumIntervals()*rkOrder*NXA, NX+NU, REAL, structWspace);
		rk_delta.setup( "rk_delta", 1, NX+NU, REAL, ACADO_WORKSPACE );
		rk_prev.setup( "rk_prev", getN(), NX+NU, REAL, ACADO_WORKSPACE );
//	}

	if ( useOMP )
	{
		ExportVariable auxVar;

		auxVar = getAuxVariable();
		auxVar.setName( "odeAuxVar" );
		auxVar.setDataStruct( ACADO_LOCAL );
		rhs.setGlobalExportVariable( auxVar );
		diffs_rhs.setGlobalExportVariable( auxVar );
	}

	ExportIndex run( "run1" );
	ExportIndex shoot_index( "shoot_index" );
	ExportIndex k_index( "k_index" );

	// setup INTEGRATE function
	integrate = ExportFunction( "integrate", rk_eta, rk_index ); // you need the rk_index for LIFTING !
	integrate.setReturnValue( error_code );
	rk_eta.setDoc( "Working array to pass the input values and return the results." );
	reset_int.setDoc( "The internal memory of the integrator can be reset." );
	rk_index.setDoc( "Number of the shooting interval." );
	error_code.setDoc( "Status code of the integrator." );
	integrate.doc( "Performs the integration and sensitivity propagation for one shooting interval." );
	integrate.addIndex( run );
	integrate.addIndex( shoot_index );
	integrate.addIndex( k_index );

	ExportVariable det( "det", 1, 1, REAL, ACADO_LOCAL, true );
//.........这里部分代码省略.........
开发者ID:RobotXiaoFeng,项目名称:acado,代码行数:101,代码来源:lifted_erk_export.cpp

示例12: runObj

returnValue ExportExactHessianQpDunes::setupObjectiveEvaluation( void )
{
	evaluateObjective.setup("evaluateObjective");

	//
	// A loop the evaluates objective and corresponding gradients
	//
	ExportIndex runObj( "runObj" );
	ExportForLoop loopObjective( runObj, 0, N );

	evaluateObjective.addIndex( runObj );

	// Interface variable to qpDUNES
	qpH.setup("qpH", N * (NX + NU) * (NX + NU) + NX * NX, 1, REAL, ACADO_WORKSPACE);   // --> to be used only after regularization to pass to qpDUNES
	qpg.setup("qpG", N * (NX + NU) + NX, 1, REAL, ACADO_WORKSPACE);

	// LM regularization preparation

	ExportVariable evLmX = zeros<double>(NX, NX);
	ExportVariable evLmU = zeros<double>(NU, NU);

	if  (levenbergMarquardt > 0.0)
	{
		DMatrix lmX = eye<double>( NX );
		lmX *= levenbergMarquardt;

		DMatrix lmU = eye<double>( NU );
		lmU *= levenbergMarquardt;

		evLmX = lmX;
		evLmU = lmU;
	}

	ExportVariable stagef;
	stagef.setup("stagef", NX + NU, 1, REAL, ACADO_LOCAL);

	ExportVariable stageH;
	stageH.setup("stageH", NX + NU, NX + NU, REAL, ACADO_LOCAL);

	if( evaluateStageCost.getFunctionDim() > 0 ) {
		loopObjective.addStatement( objValueIn.getCols(0, getNX()) == x.getRow( runObj ) );
		loopObjective.addStatement( objValueIn.getCols(NX, NX + NU) == u.getRow( runObj ) );
		loopObjective.addStatement( objValueIn.getCols(NX + NU, NX + NU + NOD) == od.getRow( runObj ) );
		loopObjective.addLinebreak( );

		// Evaluate the objective function
		loopObjective.addFunctionCall(evaluateStageCost, objValueIn, objValueOut);
		loopObjective.addLinebreak( );

		ExportVariable tmpFxx, tmpFxu, tmpFuu;
		tmpFxx.setup("tmpFxx", NX, NX, REAL, ACADO_LOCAL);
		tmpFxu.setup("tmpFxu", NX, NU, REAL, ACADO_LOCAL);
		tmpFuu.setup("tmpFuu", NU, NU, REAL, ACADO_LOCAL);

		setStageH.setup("addObjTerm", tmpFxx, tmpFxu, tmpFuu, stageH);
		setStageH.addStatement( stageH.getSubMatrix(0,NX,0,NX) += tmpFxx + evLmX );
		setStageH.addStatement( stageH.getSubMatrix(0,NX,NX,NX+NU) += tmpFxu );
		setStageH.addStatement( stageH.getSubMatrix(NX,NX+NU,0,NX) += tmpFxu.getTranspose() );
		setStageH.addStatement( stageH.getSubMatrix(NX,NX+NU,NX,NX+NU) += tmpFuu + evLmU );

		loopObjective.addFunctionCall(
				setStageH, objValueOut.getAddress(0, 1+NX+NU), objValueOut.getAddress(0, 1+NX+NU+NX*NX),
				objValueOut.getAddress(0, 1+NX+NU+NX*(NX+NU)), objS.getAddress(runObj*(NX+NU), 0) );

		ExportVariable tmpDF;
		tmpDF.setup("tmpDF", NX+NU, 1, REAL, ACADO_LOCAL);
		setStagef.setup("addObjLinearTerm", tmpDF, stagef);
		setStagef.addStatement( stagef == tmpDF.getRows(0,NX+NU) );

		loopObjective.addFunctionCall(
				setStagef, objValueOut.getAddress(0, 1), qpg.getAddress(runObj * (NX+NU)) );

		loopObjective.addLinebreak( );
	}
	else {
		if(levenbergMarquardt > 0.0) {
			setStageH.setup("addObjTerm", stageH);
			setStageH.addStatement( stageH.getSubMatrix(0,NX,0,NX) += evLmX );
			setStageH.addStatement( stageH.getSubMatrix(NX,NX+NU,NX,NX+NU) += evLmU );

			loopObjective.addFunctionCall( setStageH, objS.getAddress(runObj*(NX+NU), 0) );
		}
		DMatrix D(NX+NU,1); D.setAll(0);
		loopObjective.addStatement( qpg.getRows(runObj*(NX+NU), runObj*(NX+NU)+NX+NU) == D );
	}

	evaluateObjective.addStatement( loopObjective );

	//
	// Evaluate the quadratic Mayer term
	//
	if( evaluateTerminalCost.getFunctionDim() > 0 ) {
		evaluateObjective.addStatement( objValueIn.getCols(0, NX) == x.getRow( N ) );
		evaluateObjective.addStatement( objValueIn.getCols(NX, NX + NOD) == od.getRow( N ) );

		// Evaluate the objective function, last node.
		evaluateObjective.addFunctionCall(evaluateTerminalCost, objValueIn, objValueOut);
		evaluateObjective.addLinebreak( );

		evaluateObjective.addStatement( objSEndTerm.makeRowVector() == objValueOut.getCols(1+NX,1+NX+NX*NX) + evLmX.makeRowVector() );
//.........这里部分代码省略.........
开发者ID:RobotXiaoFeng,项目名称:acado,代码行数:101,代码来源:export_exact_hessian_qpdunes.cpp

示例13: deepcopy

returnValue CondensingExport::setupMultiplicationRoutines( )
{
	ExportVariable QQ = deepcopy( Q );
	QQ.setDataStruct( ACADO_LOCAL );

	ExportVariable QC1( "QC1",  getNX(),getNX() );
	ExportVariable QE1( "QE1",  getNX(),getNU()*getN() );
	ExportVariable Dx1( "Dx1",  getNX(),1 );
	ExportVariable QDx1("QDx1", getNX(),1 );
	ExportVariable Du1( "Du1",  getNU(),1 );
	ExportVariable RDu1("RDu1", getNU(),1 );
	ExportVariable Gx ( "Gx",   getNX(),getNX() );
	ExportVariable Gu ( "Gu",   getNX(),getNU() );
	ExportVariable C1 ( "C1",   getNX(),getNX() );
	ExportVariable E1 ( "E1",   getNX(),getNU()*getN() );
	ExportVariable d1 ( "d1",   getNX(),1 );
	ExportVariable u1 ( "u1",   getNU(),1 );
	ExportVariable C  ( "C",    getNX()*getN(),getNX() );
	ExportVariable QC ( "QC",   getNX()*getN(),getNX() );
	ExportVariable E  ( "E",    getNX()*getN(),getNU()*getN() );
	ExportVariable QE ( "QE",   getNX()*getN(),getNU()*getN() );
	ExportVariable QDx( "QDx",  getNX()*getN(),1 );
	ExportVariable g0 ( "g0",   getNX(),1 );
	ExportVariable g1 ( "g1",   getNU()*getN(),1 );
	ExportVariable H00( "H00",  getNX(),getNX() );
	ExportVariable H01( "H01",  getNX(),getNU()*getN() );
	ExportVariable H11( "H11",  getNU()*getN(),getNU()*getN() );

	multiplyQC1.setup( "multiplyQC1", QQ,C1,QC1 );
	multiplyQC1.addStatement( QC1 == QQ*C1 );

	multiplyQE1.setup( "multiplyQE1", QQ,E1,QE1 );
	multiplyQE1.addStatement( QE1 == QQ*E1 );

	multiplyQDX1.setup( "multiplyQDX1", QQ,Dx1,QDx1 );
	multiplyQDX1.addStatement( QDx1 == QQ*Dx1 );

	multiplyRDU1.setup( "multiplyRDU1", R,Du1,RDu1 );
	multiplyRDU1.addStatement( RDu1 == R*Du1 );

	multiplyQC2.setup( "multiplyQC2", QQF,C1,QC1 );
	multiplyQC2.addStatement( QC1 == QQF*C1 );

	multiplyQE2.setup( "multiplyQE2", QQF,E1,QE1 );
	multiplyQE2.addStatement( QE1 == QQF*E1 );

	multiplyQDX2.setup( "multiplyQDX2", QQF,Dx1,QDx1 );
	multiplyQDX2.addStatement( QDx1 == QQF*Dx1 );

	multiplyC.setup( "multiplyC", Gx,C1,C1("C1_new") );
	multiplyC.addStatement( C1("C1_new") == Gx*C1 );

	multiplyE.setup( "multiplyE", Gx,E1,E1("E1_new") );
	multiplyE.addStatement( E1("E1_new") == Gx*E1 );
	
	if ( performsSingleShooting() == BT_FALSE )
	{
		multiplyCD1.setup( "multiplyCD1", Gx,d1,d1("d1_new") );
		multiplyCD1.addStatement( d1("d1_new") == Gx*d1 );

		multiplyEU1.setup( "multiplyEU1", Gu,u1,d1("d1_new") );
		multiplyEU1.addStatement( d1("d1_new") += Gu*u1 );
	}

	if ( performsFullCondensing() == BT_FALSE )
	{
		multiplyG0.setup( "multiplyG0", C,QDx,g0 );
		multiplyG0.addStatement( g0 == (C^QDx) );
	}
	
	multiplyG1.setup( "multiplyG1", E,QDx,g1 );
	multiplyG1.addStatement( g1 == (E^QDx) );

	if ( performsFullCondensing() == BT_FALSE )
	{
		multiplyH00.setup( "multiplyH00", C,QC,H00 );
		multiplyH00.addStatement( H00 == (C^QC) );
	}

	multiplyH01.setup( "multiplyH01", C,QE,H01 );
	multiplyH01.addStatement( H01 == (C^QE) );

	multiplyH11.setup( "multiplyH11", E,QE,H11 );
	multiplyH11.addStatement( (H11 == (E^QE)) );

	return SUCCESSFUL_RETURN;
}
开发者ID:drewm1980,项目名称:acado,代码行数:87,代码来源:condensing_export.cpp

示例14: get

returnValue ExportGaussNewtonForces::setupObjectiveEvaluation( void )
{
	evaluateObjective.setup("evaluateObjective");

	int variableObjS;
	get(CG_USE_VARIABLE_WEIGHTING_MATRIX, variableObjS);
	int forceDiagHessian;
	get(CG_FORCE_DIAGONAL_HESSIAN, forceDiagHessian);

	diagH = false;
	diagHN = false;
	unsigned dimHRows = NX + NU;
	unsigned dimHCols = NX + NU;
	unsigned dimHNRows = NX;
	unsigned dimHNCols = NX;
	if (objS.isGiven() == true || forceDiagHessian == true)
		if (objS.getGivenMatrix().isDiagonal())
		{
			diagH = true;
			dimHCols = 1;
		}

	if (objSEndTerm.isGiven() == true || forceDiagHessian == true)
		if (objSEndTerm.getGivenMatrix().isDiagonal() == true)
		{
			diagHN = true;
			dimHNCols = 1;
		}

	objHessians.resize(N + 1);
	for (unsigned i = 0; i < N; ++i)
	{
		objHessians[ i ].setup(string("H") + toString(i + 1), dimHRows, dimHCols, REAL, FORCES_PARAMS, false, qpObjPrefix);
	}
	objHessians[ N ].setup(string("H") + toString(N + 1), dimHNRows, dimHNCols, REAL, FORCES_PARAMS, false, qpObjPrefix);

	objGradients.resize(N + 1);
	for (unsigned i = 0; i < N; ++i)
	{
		objGradients[ i ].setup(string("f") + toString(i + 1), NX + NU, 1, REAL, FORCES_PARAMS, false, qpObjPrefix);
	}
	objGradients[ N ].setup(string("f") + toString(N + 1), NX, 1, REAL, FORCES_PARAMS, false, qpObjPrefix);

	//
	// LM regularization preparation
	//

	ExportVariable evLmX = zeros<double>(NX, NX);
	ExportVariable evLmU = zeros<double>(NU, NU);

	if (levenbergMarquardt > 0.0)
	{
		DMatrix lmX = eye<double>( NX );
		lmX *= levenbergMarquardt;

		DMatrix lmU = eye<double>( NU );
		lmU *= levenbergMarquardt;

		evLmX = lmX;
		evLmU = lmU;
	}

	//
	// Main loop that calculates Hessian and gradients
	//

	ExportIndex runObj( "runObj" );
	ExportForLoop loopObjective( runObj, 0, N );

	evaluateObjective.addIndex( runObj );

	loopObjective.addStatement( objValueIn.getCols(0, getNX()) == x.getRow( runObj ) );
	loopObjective.addStatement( objValueIn.getCols(NX, NX + NU) == u.getRow( runObj ) );
	loopObjective.addStatement( objValueIn.getCols(NX + NU, NX + NU + NOD) == od.getRow( runObj ) );
	loopObjective.addLinebreak( );

	// Evaluate the objective function
	loopObjective.addFunctionCall(evaluateStageCost, objValueIn, objValueOut);

	// Stack the measurement function value
	loopObjective.addStatement(
			Dy.getRows(runObj * NY, (runObj + 1) * NY) ==  objValueOut.getTranspose().getRows(0, getNY())
	);
	loopObjective.addLinebreak( );

	// Optionally compute derivatives
	unsigned indexX = getNY();
	//	unsigned indexG = indexX;

	ExportVariable tmpObjS, tmpFx, tmpFu;
	ExportVariable tmpFxEnd, tmpObjSEndTerm;
	tmpObjS.setup("tmpObjS", NY, NY, REAL, ACADO_LOCAL);
	if (objS.isGiven() == true)
		tmpObjS = objS;
	tmpFx.setup("tmpFx", NY, NX, REAL, ACADO_LOCAL);
	if (objEvFx.isGiven() == true)
		tmpFx = objEvFx;
	tmpFu.setup("tmpFu", NY, NU, REAL, ACADO_LOCAL);
	if (objEvFu.isGiven() == true)
		tmpFu = objEvFu;
//.........这里部分代码省略.........
开发者ID:ferreau,项目名称:acado,代码行数:101,代码来源:export_gauss_newton_forces.cpp

示例15: i

returnValue ExportGaussElim::setupFactorization( ExportFunction& _solve, ExportVariable& _swap, ExportVariable& _determinant, const string& absF ) {

	uint run1, run2, run3;
	ExportIndex i( "i" );
	_solve.addIndex( i );
	ExportIndex j( "j" );
	ExportIndex k( "k" );
	ExportVariable indexMax( "indexMax", 1, 1, INT, ACADO_LOCAL, true );
	ExportVariable intSwap( "intSwap", 1, 1, INT, ACADO_LOCAL, true );
	ExportVariable valueMax( "valueMax", 1, 1, REAL, ACADO_LOCAL, true );
	ExportVariable temp( "temp", 1, 1, REAL, ACADO_LOCAL, true );
	if( !UNROLLING ) {
		_solve.addIndex( j );
		_solve.addIndex( k );
		_solve.addDeclaration( indexMax );
		if( REUSE ) _solve.addDeclaration( intSwap );
		_solve.addDeclaration( valueMax );
		_solve.addDeclaration( temp );
	}

	// initialise rk_perm (the permutation vector)
	if( REUSE ) {
		ExportForLoop loop1( i,0,dim );
		loop1 << rk_perm.get( 0,i ) << " = " << i.getName() << ";\n";
		_solve.addStatement( loop1 );
	}

	_solve.addStatement( _determinant == 1 );
	if( UNROLLING || dim <= 5 ) {
		// Start the factorization:
		for( run1 = 0; run1 < (dim-1); run1++ ) {
			// Search for pivot in column run1:
			for( run2 = run1+1; run2 < dim; run2++ ) {
				// add the test (if or else if):
				stringstream test;
				if( run2 == (run1+1) ) {
					test << "if(";
				} else {
					test << "else if(";
				}
				test << absF << "(A[" << toString( run2*dim+run1 ) << "]) > " << absF << "(A[" << toString( run1*dim+run1 ) << "])";
				for( run3 = run1+1; run3 < dim; run3++ ) {
					if( run3 != run2) {
						test << " && " << absF << "(A[" << toString( run2*dim+run1 ) << "]) > " << absF << "(A[" << toString( run3*dim+run1 ) << "])";
					}
				}
				test << ") {\n";
				_solve.addStatement( test.str() );

				// do the row swaps:
				// for A:
				for( run3 = 0; run3 < dim; run3++ ) {
					_solve.addStatement( _swap == A.getSubMatrix( run1,run1+1,run3,run3+1 ) );
					_solve.addStatement( A.getSubMatrix( run1,run1+1,run3,run3+1 ) == A.getSubMatrix( run2,run2+1,run3,run3+1 ) );
					_solve.addStatement( A.getSubMatrix( run2,run2+1,run3,run3+1 ) == _swap );
				}

				if( REUSE ) { // rk_perm also needs to be updated if it needs to be possible to reuse the factorization
					_solve.addStatement( intSwap == rk_perm.getCol( run1 ) );
					_solve.addStatement( rk_perm.getCol( run1 ) == rk_perm.getCol( run2 ) );
					_solve.addStatement( rk_perm.getCol( run2 ) == intSwap );
				}

				_solve.addStatement( "}\n" );
			}
			// potentially needed row swaps are done
			_solve.addLinebreak();
			// update of the next rows:
			for( run2 = run1+1; run2 < dim; run2++ ) {
				_solve << "A[" << toString( run2*dim+run1 ) << "] = -A[" << toString( run2*dim+run1 ) << "]/A[" << toString( run1*dim+run1 ) << "];\n";
				_solve.addStatement( A.getSubMatrix( run2,run2+1,run1+1,dim ) += A.getSubMatrix( run2,run2+1,run1,run1+1 ) * A.getSubMatrix( run1,run1+1,run1+1,dim ) );
				_solve.addLinebreak();
			}
			_solve.addStatement( _determinant == _determinant*A.getSubMatrix(run1,run1+1,run1,run1+1) );
			_solve.addLinebreak();
		}
		_solve.addStatement( _determinant == _determinant*A.getSubMatrix(dim-1,dim,dim-1,dim) );
		_solve.addLinebreak();
	}
	else { // without UNROLLING:
		_solve << "for( i=0; i < (" << toString( dim-1 ) << "); i++ ) {\n";
		_solve << "	indexMax = i;\n";
		_solve << "	valueMax = " << absF << "(A[i*" << toString( dim ) << "+i]);\n";
		_solve << "	for( j=(i+1); j < " << toString( dim ) << "; j++ ) {\n";
		_solve << "		temp = " << absF << "(A[j*" << toString( dim ) << "+i]);\n";
		_solve << "		if( temp > valueMax ) {\n";
		_solve << "			indexMax = j;\n";
		_solve << "			valueMax = temp;\n";
		_solve << "		}\n";
		_solve << "	}\n";
		_solve << "	if( indexMax > i ) {\n";
		ExportForLoop loop2( k,0,dim );
		loop2 << "	" << _swap.getFullName() << " = A[i*" << toString( dim ) << "+" << k.getName() << "];\n";
		loop2 << "	A[i*" << toString( dim ) << "+" << k.getName() << "] = A[indexMax*" << toString( dim ) << "+" << k.getName() << "];\n";
		loop2 << "	A[indexMax*" << toString( dim ) << "+" << k.getName() << "] = " << _swap.getFullName() << ";\n";
		_solve.addStatement( loop2 );
		if( REUSE ) {
			_solve << "	" << intSwap.getFullName() << " = " << rk_perm.getFullName() << "[i];\n";
			_solve << "	" << rk_perm.getFullName() << "[i] = " << rk_perm.getFullName() << "[indexMax];\n";
			_solve << "	" << rk_perm.getFullName() << "[indexMax] = " << intSwap.getFullName() << ";\n";
//.........这里部分代码省略.........
开发者ID:RobotXiaoFeng,项目名称:acado,代码行数:101,代码来源:gaussian_elimination_export.cpp


注:本文中的ExportVariable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。