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


C++ ExportVariable::setDataStruct方法代码示例

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


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

示例1: setup

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

示例2: setup

returnValue ExplicitRungeKuttaExport::setup( )
{
    int sensGen;
    get( DYNAMIC_SENSITIVITY,sensGen );
    if ( (ExportSensitivityType)sensGen != FORWARD && (ExportSensitivityType)sensGen != NO_SENSITIVITY ) ACADOERROR( RET_INVALID_OPTION );

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

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

    // export RK scheme
    uint rhsDim   = NX*(NX+NU+1);
    if( !DERIVATIVES ) rhsDim = NX;
    inputDim = NX*(NX+NU+1) + NU + NOD;
    if( !DERIVATIVES ) inputDim = NX + 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 );

    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);
    rk_kkk.setup("rk_kkk", rkOrder, rhsDim, REAL, structWspace);

    if ( useOMP )
    {
        ExportVariable auxVar;

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

    ExportIndex run( "run1" );

    // setup INTEGRATE function
    if( equidistantControlGrid() ) {
        integrate = ExportFunction( "integrate", rk_eta, reset_int );
    }
    else {
        integrate = ExportFunction( "integrate", rk_eta, reset_int, rk_index );
    }
    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 );

    ExportVariable numInt( "numInts", 1, 1, INT );
    if( !equidistantControlGrid() ) {
        integrate.addStatement( std::string( "int numSteps[" ) + toString( numSteps.getDim() ) + "] = {" + toString( numSteps(0) ) );
        uint i;
        for( i = 1; i < numSteps.getDim(); i++ ) {
            integrate.addStatement( std::string( ", " ) + toString( numSteps(i) ) );
        }
        integrate.addStatement( std::string( "};\n" ) );
        integrate.addStatement( std::string( "int " ) + numInt.getName() + " = numSteps[" + rk_index.getName() + "];\n" );
    }

    integrate.addStatement( rk_ttt == DMatrix(grid.getFirstTime()) );

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

    if( inputDim > rhsDim ) {
        integrate.addStatement( rk_xxx.getCols( rhsDim,inputDim ) == rk_eta.getCols( rhsDim,inputDim ) );
    }
    integrate.addLinebreak( );

    // integrator loop
    ExportForLoop loop;
    if( equidistantControlGrid() ) {
        loop = ExportForLoop( run, 0, grid.getNumIntervals() );
    }
    else {
        loop = ExportForLoop( run, 0, 1 );
        loop.addStatement( std::string("for(") + run.getName() + " = 0; " + run.getName() + " < " + numInt.getName() + "; " + run.getName() + "++ ) {\n" );
    }
//.........这里部分代码省略.........
开发者ID:rienq,项目名称:acado,代码行数:101,代码来源:erk_export.cpp

示例3: setupMultiplicationRoutines

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

示例4: setup

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

示例5: getCode

returnValue DiscreteTimeExport::getCode(	ExportStatementBlock& code
                                        )
{
    int useOMP;
    get(CG_USE_OPENMP, useOMP);
    if ( useOMP ) {
        ExportVariable max = getAuxVariable();
        max.setName( "auxVar" );
        max.setDataStruct( ACADO_LOCAL );
        if( NX2 > 0 ) {
            rhs.setGlobalExportVariable( max );
            diffs_rhs.setGlobalExportVariable( max );
        }
        if( NX3 > 0 ) {
            rhs3.setGlobalExportVariable( max );
            diffs_rhs3.setGlobalExportVariable( max );
        }

        getDataDeclarations( code, ACADO_LOCAL );

        stringstream s;
        s << "#pragma omp threadprivate( "
                << max.getFullName() << ", "
                << rk_xxx.getFullName();
        if( NX1 > 0 ) {
            if( grid.getNumIntervals() > 1 || !equidistantControlGrid() ) s << ", " << rk_diffsPrev1.getFullName();
            s << ", " << rk_diffsNew1.getFullName();
        }
        if( NX2 > 0 || NXA > 0 ) {
            if( grid.getNumIntervals() > 1 || !equidistantControlGrid() ) s << ", " << rk_diffsPrev2.getFullName();
            s << ", " << rk_diffsNew2.getFullName();
        }
        if( NX3 > 0 ) {
            if( grid.getNumIntervals() > 1 || !equidistantControlGrid() ) s << ", " << rk_diffsPrev3.getFullName();
            s << ", " << rk_diffsNew3.getFullName();
            s << ", " << rk_diffsTemp3.getFullName();
        }
        s << " )" << endl << endl;
        code.addStatement( s.str().c_str() );
    }

    if( NX1 > 0 ) {
        code.addFunction( lin_input );
        code.addStatement( "\n\n" );
    }

    if( NX2 > 0 ) {
        code.addFunction( rhs );
        code.addStatement( "\n\n" );
        code.addFunction( diffs_rhs );
        code.addStatement( "\n\n" );
    }

    if( NX3 > 0 ) {
        code.addFunction( rhs3 );
        code.addStatement( "\n\n" );
        code.addFunction( diffs_rhs3 );
        code.addStatement( "\n\n" );
    }

    if( !equidistantControlGrid() ) {
        ExportVariable numStepsV( "numSteps", numSteps, STATIC_CONST_INT );
        code.addDeclaration( numStepsV );
        code.addLinebreak( 2 );
    }
    double h = (grid.getLastTime() - grid.getFirstTime())/grid.getNumIntervals();
    code.addComment(std::string("Fixed step size:") + toString(h));

    code.addFunction( integrate );

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


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