本文整理汇总了C++中BlockMatrix::getSubBlock方法的典型用法代码示例。如果您正苦于以下问题:C++ BlockMatrix::getSubBlock方法的具体用法?C++ BlockMatrix::getSubBlock怎么用?C++ BlockMatrix::getSubBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlockMatrix
的用法示例。
在下文中一共展示了BlockMatrix::getSubBlock方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: evaluateSensitivities
returnValue Constraint::evaluateSensitivities( const BlockMatrix &seed, BlockMatrix &hessian ) {
uint run1 ;
int count;
returnValue returnvalue;
count = 0;
Matrix tmp;
// EVALUATE BOUNDARY CONSTRAINS:
// -----------------------------
if( boundary_constraint->getNC() != 0 ) {
seed.getSubBlock( count, 0, tmp, boundary_constraint->getNC(), 1 );
returnvalue = boundary_constraint->evaluateSensitivities( tmp, hessian );
if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
count++;
}
// EVALUATE COUPLED PATH CONSTRAINS:
// ---------------------------------
if( coupled_path_constraint->getNC() != 0 ) {
seed.getSubBlock( count, 0, tmp, coupled_path_constraint->getNC(), 1 );
returnvalue = coupled_path_constraint->evaluateSensitivities( tmp, hessian );
if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
count++;
}
// EVALUATE PATH CONSTRAINS:
// -------------------------
if( path_constraint->getNC() != 0 ) {
returnvalue = path_constraint->evaluateSensitivities( count, seed, hessian );
if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
}
// EVALUATE ALGEBRAIC CONSISTENCY CONSTRAINS:
// ------------------------------------------
if( algebraic_consistency_constraint->getNC() != 0 ) {
returnvalue = algebraic_consistency_constraint->evaluateSensitivities( count, seed, hessian );
if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
}
// EVALUATE POINT CONSTRAINS:
// --------------------------
if( point_constraints != 0 ) {
for( run1 = 0; run1 < grid.getNumPoints(); run1++ ) {
if( point_constraints[run1] != 0 ) {
seed.getSubBlock( count, 0, tmp, point_constraints[run1]->getNC(), 1 );
returnvalue = point_constraints[run1]->evaluateSensitivities( tmp, hessian );
if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
count++;
}
}
}
return SUCCESSFUL_RETURN;
}
示例2: getForwardSensitivities
returnValue Constraint::getForwardSensitivities( BlockMatrix &D, int order ) {
const int N = grid.getNumPoints();
returnValue returnvalue;
BlockMatrix result;
result.init( getNumberOfBlocks(), 5*N );
int nc, run1, run2;
nc = 0;
// BOUNDARY CONSTRAINTS:
// ---------------------
if( boundary_constraint->getNC() != 0 ) {
BlockMatrix res;
returnvalue = boundary_constraint->getForwardSensitivities( &res, order );
if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
Matrix res_;
for( run2 = 0; run2 < 5*N; run2++ ) {
res.getSubBlock( 0 , run2, res_ );
if( res_.getDim() > 0 )
result.setDense( nc, run2, res_ );
}
nc++;
}
// COUPLED PATH CONSTRAINTS:
// -------------------------
if( coupled_path_constraint->getNC() != 0 ) {
BlockMatrix res;
returnvalue = coupled_path_constraint->getForwardSensitivities( &res, order );
if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
Matrix res_;
for( run2 = 0; run2 < 5*N; run2++ ) {
res.getSubBlock( 0 , run2, res_ );
if( res_.getDim() > 0 )
result.setDense( nc, run2, res_ );
}
nc++;
}
// PATH CONSTRAINTS:
// -----------------
if( path_constraint->getNC() != 0 ) {
BlockMatrix res;
returnvalue = path_constraint->getForwardSensitivities( &res, order );
if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
Matrix res_;
for( run1 = 0; run1 < N; run1++ ) {
for( run2 = 0; run2 < 5*N; run2++ ) {
res.getSubBlock( run1, run2, res_ );
if( res_.getDim() > 0 )
result.setDense( nc , run2, res_ );
}
nc++;
}
}
// ALGEBRAIC CONSISTENCY CONSTRAINTS:
// ----------------------------------
if( algebraic_consistency_constraint->getNC() != 0 ) {
BlockMatrix res;
returnvalue = algebraic_consistency_constraint->getForwardSensitivities( &res, order );
if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
Matrix res_;
for( run1 = 0; run1 < N; run1++ ) {
for( run2 = 0; run2 < 5*N; run2++ ) {
res.getSubBlock( run1, run2, res_ );
if( res_.getDim() > 0 )
result.setDense( nc , run2, res_ );
}
nc++;
}
}
// POINT CONSTRAINTS:
// ------------------
if( point_constraints != 0 ) {
for( run1 = 0; run1 < (int) grid.getNumPoints(); run1++ ) {
if( point_constraints[run1] != 0 ) {
BlockMatrix res;
returnvalue = point_constraints[run1]->getForwardSensitivities( &res, order );
if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
Matrix res_;
for( run2 = 0; run2 < 5*N; run2++ ) {
res.getSubBlock( 0 , run2, res_ );
if( res_.getDim() > 0 )
result.setDense( nc, run2, res_ );
}
nc++;
//.........这里部分代码省略.........
示例3: evaluateSensitivities
returnValue ShootingMethod::evaluateSensitivities( const BlockMatrix &seed, BlockMatrix &hessian ){
const int NN = N+1;
dForward.init( N, 5 );
int i;
for( i = 0; i < N; i++ ){
Matrix X, P, U, W, D, E, HX, HP, HU, HW, S;
if( xSeed.isEmpty() == BT_FALSE ) xSeed.getSubBlock( i, 0, X );
if( pSeed.isEmpty() == BT_FALSE ) pSeed.getSubBlock( i, 0, P );
if( uSeed.isEmpty() == BT_FALSE ) uSeed.getSubBlock( i, 0, U );
if( wSeed.isEmpty() == BT_FALSE ) wSeed.getSubBlock( i, 0, W );
seed.getSubBlock( i, 0, S, nx, 1 );
if( nx > 0 ){
ACADO_TRY( differentiateForwardBackward( i, X, E, E, E, S, D, HX, HP, HU, HW ));
dForward.setDense( i, 0, D );
if( nx > 0 ) hessian.addDense( i, i, HX );
if( np > 0 ) hessian.addDense( i, 2*NN+i, HP );
if( nu > 0 ) hessian.addDense( i, 3*NN+i, HU );
if( nw > 0 ) hessian.addDense( i, 4*NN+i, HW );
}
if( np > 0 ){
ACADO_TRY( differentiateForwardBackward( i, E, P, E, E, S, D, HX, HP, HU, HW ));
dForward.setDense( i, 2, D );
if( nx > 0 ) hessian.addDense( 2*NN+i, i, HX );
if( np > 0 ) hessian.addDense( 2*NN+i, 2*NN+i, HP );
if( nu > 0 ) hessian.addDense( 2*NN+i, 3*NN+i, HU );
if( nw > 0 ) hessian.addDense( 2*NN+i, 4*NN+i, HW );
}
if( nu > 0 ){
ACADO_TRY( differentiateForwardBackward( i, E, E, U, E, S, D, HX, HP, HU, HW ));
dForward.setDense( i, 3, D );
if( nx > 0 ) hessian.addDense( 3*NN+i, i, HX );
if( np > 0 ) hessian.addDense( 3*NN+i, 2*NN+i, HP );
if( nu > 0 ) hessian.addDense( 3*NN+i, 3*NN+i, HU );
if( nw > 0 ) hessian.addDense( 3*NN+i, 4*NN+i, HW );
}
if( nw > 0 ){
ACADO_TRY( differentiateForwardBackward( i, E, E, E, W, S, D, HX, HP, HU, HW ));
dForward.setDense( i, 4, D );
if( nx > 0 ) hessian.addDense( 4*NN+i, i, HX );
if( np > 0 ) hessian.addDense( 4*NN+i, 2*NN+i, HP );
if( nu > 0 ) hessian.addDense( 4*NN+i, 3*NN+i, HU );
if( nw > 0 ) hessian.addDense( 4*NN+i, 4*NN+i, HW );
}
}
return SUCCESSFUL_RETURN;
}