本文整理汇总了C++中ExportVariable::getSubMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ ExportVariable::getSubMatrix方法的具体用法?C++ ExportVariable::getSubMatrix怎么用?C++ ExportVariable::getSubMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExportVariable
的用法示例。
在下文中一共展示了ExportVariable::getSubMatrix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: runObj
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 );
//.........这里部分代码省略.........
示例3: setupObjectiveEvaluation
//.........这里部分代码省略.........
setObjQN1QN2.setup("setObjQN1QN2", tmpFxEnd, tmpObjSEndTerm, tmpQN1, tmpQN2);
setObjQN1QN2.addStatement( tmpQN2 == (tmpFxEnd ^ tmpObjSEndTerm) );
setObjQN1QN2.addStatement( tmpQN1 == tmpQN2 * tmpFxEnd );
if (tmpFxEnd.isGiven() == true)
evaluateObjective.addFunctionCall(
setObjQN1QN2,
tmpFxEnd, objSEndTerm,
QN1.getAddress(0, 0), QN2.getAddress(0, 0)
);
else
evaluateObjective.addFunctionCall(
setObjQN1QN2,
objValueOut.getAddress(0, indexX), objSEndTerm,
QN1.getAddress(0, 0), QN2.getAddress(0, 0)
);
evaluateObjective.addLinebreak( );
}
//
// Hessian setup
//
ExportVariable stageH;
ExportIndex index( "index" );
stageH.setup("stageH", dimHRows, dimHCols, REAL, ACADO_LOCAL);
setStageH.setup("setStageH", stageH, index);
if (Q1.isGiven() == false)
{
if (diagH == false)
setStageH.addStatement(
stageH.getSubMatrix(0, NX, 0, NX) == Q1.getSubMatrix(index * NX, (index + 1) * NX, 0, NX) + evLmX
);
else
for (unsigned el = 0; el < NX; ++el)
setStageH.addStatement(
stageH.getElement(el, 0) == Q1.getElement(index * NX + el, el)
);
}
else
{
setStageH << index.getFullName() << " = " << index.getFullName() << ";\n";
if (diagH == false)
{
setStageH.addStatement(
stageH.getSubMatrix(0, NX, 0, NX) == Q1 + evLmX
);
}
else
{
setStageH.addStatement(
stageH.getRows(0, NX) == Q1.getGivenMatrix().getDiag() + evLmX.getGivenMatrix().getDiag()
);
}
}
setStageH.addLinebreak();
if (R1.isGiven() == false)
{
if (diagH == false)
setStageH.addStatement(
stageH.getSubMatrix(NX, NX + NU, NX, NX + NU) == R1.getSubMatrix(index * NU, (index + 1) * NU, 0, NU) + evLmU
);
else