/**
 * Overloaded assignment operator.
 * We need a deep copy of the operator.
 */
MetropolisHastingsMove& MetropolisHastingsMove::operator=(const RevBayesCore::MetropolisHastingsMove &m)
{

    if ( this != &m )
    {
        // free memory
        delete proposal;

        for (std::set<DagNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it)
        {
            // get the pointer to the current node
            DagNode* theNode = *it;

            // add myself to the set of moves
            theNode->removeMove( this );

            // decrease the DAG node reference count because we also have a pointer to it
            if ( theNode->decrementReferenceCount() == 0 )
            {
                delete theNode;
            }

        }

        affectedNodes   = m.affectedNodes;
        nodes           = m.nodes;
        numAccepted     = m.numAccepted;
        proposal        = m.proposal->clone();


        for (std::set<DagNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it)
        {
            // get the pointer to the current node
            DagNode* theNode = *it;

            // add myself to the set of moves
            theNode->addMove( this );

            // increase the DAG node reference count because we also have a pointer to it
            theNode->incrementReferenceCount();

        }
    }

    return *this;
}
Esempio n. 2
0
/**
 * Overloaded assignment operator.
 * We need a deep copy of the operator.
 */
AbstractMove& AbstractMove::operator=(const RevBayesCore::AbstractMove &m)
{
    
    if ( this != &m )
    {
        // delegate
        Move::operator=(m);
        
        for (size_t i = 0; i < nodes.size(); ++i)
        {
            // get the pointer to the current node
            DagNode* theNode = nodes[i];
            
            // add myself to the set of moves
            theNode->removeMove( this );
            
            // decrease the DAG node reference count because we also have a pointer to it
            if ( theNode->decrementReferenceCount() == 0 )
            {
                delete theNode;
            }
            
        }
        
        affectedNodes   = m.affectedNodes;
        nodes           = m.nodes;
        
        
        for (size_t i = 0; i < nodes.size(); ++i)
        {
            // get the pointer to the current node
            DagNode* theNode = nodes[i];
            
            // add myself to the set of moves
            theNode->addMove( this );
            
            // increase the DAG node reference count because we also have a pointer to it
            theNode->incrementReferenceCount();
            
        }
        
    }
    
    return *this;
}
/**
 * Basic destructor doing nothing.
 */
MetropolisHastingsMove::~MetropolisHastingsMove( void )
{
    for (std::set<DagNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it)
    {
        // get the pointer to the current node
        DagNode* theNode = *it;

        // add myself to the set of moves
        theNode->removeMove( this );

        // decrease the DAG node reference count because we also have a pointer to it
        if ( theNode->decrementReferenceCount() == 0 )
        {
            delete theNode;
        }

    }

    delete proposal;
}
Esempio n. 4
0
/**
 * Basic destructor doing nothing.
 */
AbstractMove::~AbstractMove( void )
{
    
    // clean up my pointers to the nodes
    for (size_t i = 0; i < nodes.size(); ++i)
    {
        // get the pointer to the current node
        DagNode* theNode = nodes[i];
        
        // add myself to the set of moves
        theNode->removeMove( this );
        
        // decrease the DAG node reference count because we also have a pointer to it
        if ( theNode->decrementReferenceCount() == 0 )
        {
            delete theNode;
        }
        
    }
    
}