void TwoStageDynamicBayesianNetwork::
ScopeBackup(    const Scope & stateScope, 
                const Scope & agentScope,
                Scope & X,
                Scope & A) const
{
    //first we compute the 'closure' of the NS state factors Y and
    //observations O. I.e., within stage connections can grow the set
    //of Y and O that need to be considered:
    Scope Y = stateScope;
    Scope O = agentScope;
    ComputeWithinNextStageClosure(Y,O);    

    X.clear();
    A.clear();
    //Next we do the backup of the Ys and Os
    for( Scope::iterator y_it = Y.begin(); y_it != Y.end(); y_it++)
    {
        Index yI = *y_it;
        X.Insert( _m_XSoI_Y.at(yI) );
        A.Insert( _m_ASoI_Y.at(yI) );
    }
    for( Scope::iterator o_it = O.begin(); o_it != O.end(); o_it++)
    {
        X.Insert( _m_XSoI_O.at(*o_it) );
        A.Insert( _m_ASoI_O.at(*o_it) );
    }
    X.Sort();
    A.Sort();
    return;
}
void FactoredDecPOMDPDiscrete::SetScopeForLRF(Index LRF, 
            const Scope& X, //the X scope
            const Scope& A, //the A scope
            const Scope& Y,
            const Scope& O
        )
{
    Scope Xbackedup = StateScopeBackup( Y, O);
    Scope Abackedup = AgentScopeBackup( Y, O);
    // X'' = X' + X
    Xbackedup.Insert(X);
    Xbackedup.Sort();
    // A'' = A' + A
    Abackedup.Insert(A);
    Abackedup.Sort();
    SetScopeForLRF(LRF, Xbackedup, Abackedup);
}