コード例 #1
0
ファイル: ocp_export.cpp プロジェクト: liangdong158/acado
returnValue OCPexport::exportAcadoHeader(	const std::string& _dirName,
											const std::string& _fileName,
											const std::string& _realString,
											const std::string& _intString,
											int _precision
											) const
{
	string moduleName, modulePrefix;
	get(CG_MODULE_NAME, moduleName);
    get(CG_MODULE_PREFIX, modulePrefix);

	int qpSolver;
	get(QP_SOLVER, qpSolver);

	int useSinglePrecision;
	get(USE_SINGLE_PRECISION, useSinglePrecision);

	int hardcodeConstraintValues;
	get(CG_HARDCODE_CONSTRAINT_VALUES, hardcodeConstraintValues);

	int fixInitialState;
	get(FIX_INITIAL_STATE, fixInitialState);
	int useAC;
	get(CG_USE_ARRIVAL_COST, useAC);
	int covCalc;
	get(CG_COMPUTE_COVARIANCE_MATRIX, covCalc);

	int linSolver;
	get(LINEAR_ALGEBRA_SOLVER, linSolver);
	bool useComplexArithmetic = false;

	if( (LinearAlgebraSolver)linSolver == SIMPLIFIED_IRK_NEWTON ) useComplexArithmetic = true;

	string fileName;
	fileName = _dirName + "/" + _fileName;

	map<string, pair<string, string> > options;

	options[ modulePrefix + "_N" ]   = make_pair(toString( ocp.getN() ),   "Number of control/estimation intervals.");
	options[ modulePrefix + "_NX" ]  = make_pair(toString( ocp.getNX() ),  "Number of differential variables.");
	options[ modulePrefix + "_NXD" ] = make_pair(toString( ocp.getNDX() ), "Number of differential derivative variables.");
	options[ modulePrefix + "_NXA" ] = make_pair(toString( ocp.getNXA() ), "Number of algebraic variables.");
	options[ modulePrefix + "_NU" ]  = make_pair(toString( ocp.getNU() ),  "Number of control variables.");
	options[ modulePrefix + "_NOD" ]  = make_pair(toString( ocp.getNOD() ),  "Number of online data values.");
	options[ modulePrefix + "_NY" ]  = make_pair(toString( solver->getNY() ),  "Number of references/measurements per node on the first N nodes.");
	options[ modulePrefix + "_NYN" ] = make_pair(toString( solver->getNYN() ), "Number of references/measurements on the last (N + 1)st node.");

	Grid integrationGrid;
	ocp.getIntegrationGrid(integrationGrid);
	uint NIS = integrationGrid.getNumIntervals();
	if( ocp.hasEquidistantControlGrid() ) options[ modulePrefix + "_RK_NIS" ] = make_pair(toString( NIS ),   "Number of integration steps per shooting interval.");

	RungeKuttaExport *rk_integrator = static_cast<RungeKuttaExport *>(integrator.get());  // Note: As long as only Runge-Kutta type methods are exported.
	options[ modulePrefix + "_RK_NSTAGES" ] = make_pair(toString( rk_integrator->getNumStages() ),   "Number of Runge-Kutta stages per integration step.");

	options[ modulePrefix + "_INITIAL_STATE_FIXED" ] =
			make_pair(toString( fixInitialState ), "Indicator for fixed initial state.");
	options[ modulePrefix + "_WEIGHTING_MATRICES_TYPE" ] =
			make_pair(toString( (unsigned)solver->weightingMatricesType() ), "Indicator for type of fixed weighting matrices.");
	options[ modulePrefix + "_USE_LINEAR_TERMS" ] =
				make_pair(toString( (unsigned)solver->usingLinearTerms() ), "Indicator for usage of non-hard-coded linear terms in the objective.");
	options[ modulePrefix + "_HARDCODED_CONSTRAINT_VALUES" ] =
			make_pair(toString( hardcodeConstraintValues ), "Flag indicating whether constraint values are hard-coded or not.");
	options[ modulePrefix + "_USE_ARRIVAL_COST" ] =
			make_pair(toString( useAC ), "Providing interface for arrival cost.");
	options[ modulePrefix + "_COMPUTE_COVARIANCE_MATRIX" ] =
			make_pair(toString( covCalc ), "Compute covariance matrix of the last state estimate.");
	options[ modulePrefix + "_QP_NV" ] =
			make_pair(toString( solver->getNumQPvars() ), "Total number of QP optimization variables.");

	int qpSolution;
	get(SPARSE_QP_SOLUTION, qpSolution);
	if( (QPSolverName)qpSolver == QP_FORCES && (SparseQPsolutionMethods)qpSolution != BLOCK_CONDENSING_N2 ) {
		ExportGaussNewtonForces *blockSolver = static_cast<ExportGaussNewtonForces*>(solver.get());
		options[ modulePrefix + "_QP_NLB" ] =
				make_pair(toString( blockSolver->getNumLowerBounds() ), "Total number of QP lower bound values.");
		options[ modulePrefix + "_QP_NUB" ] =
				make_pair(toString( blockSolver->getNumUpperBounds() ), "Total number of QP upper bound values.");
	}

	// QPDunes block based condensing:
	if ( (SparseQPsolutionMethods)qpSolution == BLOCK_CONDENSING_N2 ) {
		ExportGaussNewtonBlockCN2 *blockSolver = static_cast<ExportGaussNewtonBlockCN2*>(solver.get());

		options[ modulePrefix + "_BLOCK_CONDENSING" ] =
				make_pair(toString( 1 ), "User defined block based condensing.");
		options[ modulePrefix + "_QP_NCA" ] =
				make_pair(toString( blockSolver->getNumStateBoundsPerBlock()*blockSolver->getNumberOfBlocks() ), "Total number of QP affine constraints.");
	}
	else {
		options[ modulePrefix + "_BLOCK_CONDENSING" ] =
						make_pair(toString( 0 ), "User defined block based condensing.");
	}


	//
	// ACADO variables and workspace
	//
	ExportStatementBlock variablesBlock;
	stringstream variables;

	if (collectDataDeclarations(variablesBlock, ACADO_VARIABLES) != SUCCESSFUL_RETURN)
		return ACADOERROR( RET_UNABLE_TO_EXPORT_CODE );
	variablesBlock.exportCode(variables, _realString, _intString, _precision);

	ExportStatementBlock workspaceBlock;
	stringstream workspace;

	if (collectDataDeclarations(workspaceBlock, ACADO_WORKSPACE) != SUCCESSFUL_RETURN)
		return ACADOERROR( RET_UNABLE_TO_EXPORT_CODE );
	workspaceBlock.exportCode(workspace, _realString, _intString, _precision);

	ExportStatementBlock functionsBlock;
	stringstream functions;

	if (collectFunctionDeclarations( functionsBlock ) != SUCCESSFUL_RETURN)
		return ACADOERROR( RET_UNABLE_TO_EXPORT_CODE );
	functionsBlock.exportCode(functions, _realString);

	ExportCommonHeader ech(fileName, "", _realString, _intString, _precision);
	ech.configure( moduleName, modulePrefix, useSinglePrecision, useComplexArithmetic, (QPSolverName)qpSolver,
			options, variables.str(), workspace.str(), functions.str());

	return ech.exportCode();
}
コード例 #2
0
ファイル: sim_export.cpp プロジェクト: ferreau/acado
returnValue SIMexport::exportAcadoHeader(	const std::string& _dirName,
											const std::string& _fileName,
											const std::string& _realString,
											const std::string& _intString,
											int _precision
											) const
{
	string moduleName;
	get(CG_MODULE_NAME, moduleName);

	int qpSolver;
	get(QP_SOLVER, qpSolver);

	int useSinglePrecision;
	get(USE_SINGLE_PRECISION, useSinglePrecision);

	string fileName;
	fileName = _dirName + "/" + _fileName;


	map<string, pair<string, string> > options;

	DVector nMeasV = getNumMeas();
	DVector nOutV = getDimOutputs();

	options[ "ACADO_N" ]   = make_pair(toString( getN() ),   "Number of control/estimation intervals.");
	options[ "ACADO_NX" ]  = make_pair(toString( getNX() ),  "Number of differential variables.");
	options[ "ACADO_NXD" ] = make_pair(toString( getNDX() ), "Number of differential derivative variables.");
	options[ "ACADO_NXA" ] = make_pair(toString( getNXA() ), "Number of algebraic variables.");
	options[ "ACADO_NU" ]  = make_pair(toString( getNU() ),  "Number of control variables.");
	options[ "ACADO_NOD" ]  = make_pair(toString( getNOD() ),  "Number of online data values.");
	options[ "ACADO_NUMOUT" ]  = make_pair(toString( nOutV.getDim() ),  "Number of output functions.");

	if( !nMeasV.isEmpty() && !nOutV.isEmpty() ) {
		std::ostringstream acado_nout;
		ExportVariable( "ACADO_NOUT",nOutV,STATIC_CONST_INT ).exportDataDeclaration(acado_nout);
		std::ostringstream acado_nmeas;
		ExportVariable( "ACADO_NMEAS",nMeasV,STATIC_CONST_INT ).exportDataDeclaration(acado_nmeas);
		options[ "ACADO_OUTPUTS_DEFINED" ]  = make_pair("\n" + acado_nout.str() + acado_nmeas.str(),  "Dimension and measurements of the output functions per shooting interval.");
	}

	//
	// ACADO variables and workspace
	//
	ExportStatementBlock variablesBlock;
	stringstream variables;

	if (collectDataDeclarations(variablesBlock, ACADO_VARIABLES) != SUCCESSFUL_RETURN)
		return ACADOERROR( RET_UNABLE_TO_EXPORT_CODE );
	variablesBlock.exportCode(variables, _realString, _intString, _precision);

	ExportStatementBlock workspaceBlock;
	stringstream workspace;

	if (collectDataDeclarations(workspaceBlock, ACADO_WORKSPACE) != SUCCESSFUL_RETURN)
		return ACADOERROR( RET_UNABLE_TO_EXPORT_CODE );
	workspaceBlock.exportCode(workspace, _realString, _intString, _precision);

	ExportStatementBlock functionsBlock;
	stringstream functions;

	if (collectFunctionDeclarations( functionsBlock ) != SUCCESSFUL_RETURN)
		return ACADOERROR( RET_UNABLE_TO_EXPORT_CODE );
	functionsBlock.exportCode(functions, _realString);

	ExportCommonHeader ech(fileName, "", _realString, _intString, _precision);
	ech.configure( moduleName, useSinglePrecision, false, (QPSolverName)qpSolver,
			options, variables.str(), workspace.str(), functions.str());

	return ech.exportCode();
}