本文整理汇总了C++中ExportVariable::getRows方法的典型用法代码示例。如果您正苦于以下问题:C++ ExportVariable::getRows方法的具体用法?C++ ExportVariable::getRows怎么用?C++ ExportVariable::getRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExportVariable
的用法示例。
在下文中一共展示了ExportVariable::getRows方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupObjectiveEvaluation
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() );
//.........这里部分代码省略.........
示例2: setupObjectiveEvaluation
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;
//.........这里部分代码省略.........