void BipartiteGraph::eraseEdge( size_t n1, size_t n2 ) {
    DAI_ASSERT( n1 < nrNodes1() );
    DAI_ASSERT( n2 < nrNodes2() );
    size_t iter;
    // Search for edge among neighbors of n1
    for( iter = 0; iter < nb1(n1).size(); iter++ )
        if( nb1(n1, iter).node == n2 ) {
            // Remove it
            nb1(n1).erase( nb1(n1).begin() + iter );
            break;
        }
    // Change the iter and dual values of the subsequent neighbors
    for( ; iter < nb1(n1).size(); iter++ ) {
        Neighbor &m2 = nb1( n1, iter );
        m2.iter = iter;
        nb2( m2.node, m2.dual ).dual = iter;
    }
    // Search for edge among neighbors of n2
    for( iter = 0; iter < nb2(n2).size(); iter++ )
        if( nb2(n2, iter).node == n1 ) {
            // Remove it
            nb2(n2).erase( nb2(n2).begin() + iter );
            break;
        }
    // Change the iter and node values of the subsequent neighbors
    for( ; iter < nb2(n2).size(); iter++ ) {
        Neighbor &m1 = nb2( n2, iter );
        m1.iter = iter;
        nb1( m1.node, m1.dual ).dual = iter;
    }
}
Example #2
0
double nball(double *x, double *par)
{
//   if (x[0]>=0.0 && x[0]<1.0) return nb0( par[0], par[1], 0.0, (1-par[4])*ntotal*(1-par[2]), (1-par[4])*ntotal*par[2], par[4]*ntotal*(1-par[2]), par[4]*ntotal*par[2], 2, par[3]);
//   else if (x[0]>=1.0 && x[0]<2.0) return nb1( par[0], par[1], 0.0, (1-par[4])*ntotal*(1-par[2]), (1-par[4])*ntotal*par[2], par[4]*ntotal*(1-par[2]), par[4]*ntotal*par[2],  2, par[3]);
//   else if (x[0]>=2.0 && x[0]<3.0) return nb2( par[0], par[1], 0.0, (1-par[4])*ntotal*(1-par[2]), (1-par[4])*ntotal*par[2], par[4]*ntotal*(1-par[2]), par[4]*ntotal*par[2],  2, par[3]);
//   else if (x[0]>=3.0 && x[0]<4.0) return nb3( par[0], par[1], 0.0, (1-par[4])*ntotal*(1-par[2]), (1-par[4])*ntotal*par[2], par[4]*ntotal*(1-par[2]), par[4]*ntotal*par[2],  2, par[3]);

   if (x[0]>=0.0 && x[0]<1.0) return nb0( par[0], par[1], 0.0, (1-par[4])*ntotal*(1-par[2]), (1-par[4])*ntotal*par[2], par[4]*ntotal*0.14, par[4]*ntotal*0.80, 0, par[4]*ntotal*0.03, 2, par[3]);
   else if (x[0]>=1.0 && x[0]<2.0) return nb1( par[0], par[1], 0.0, (1-par[4])*ntotal*(1-par[2]), (1-par[4])*ntotal*par[2], par[4]*ntotal*0.14, par[4]*ntotal*0.80, 0, par[4]*ntotal*0.03, 2, par[3]);
   else if (x[0]>=2.0 && x[0]<3.0) return nb2( par[0], par[1], 0.0, (1-par[4])*ntotal*(1-par[2]), (1-par[4])*ntotal*par[2], par[4]*ntotal*0.14, par[4]*ntotal*0.80, 0, par[4]*ntotal*0.03, 2, par[3]);
   else if (x[0]>=3.0 && x[0]<4.0) return nb3( par[0], par[1], 0.0, (1-par[4])*ntotal*(1-par[2]), (1-par[4])*ntotal*par[2], par[4]*ntotal*0.14, par[4]*ntotal, 0, par[4]*ntotal*0.03, 2, par[3]);
   else if (x[0]>=4.0 && x[0]<5.0) return nb4( par[0], par[1], 0.0, (1-par[4])*ntotal*(1-par[2]), (1-par[4])*ntotal*par[2], par[4]*ntotal*0.14, par[4]*ntotal, 0, par[4]*ntotal*0.03, 2, par[3]);
}
void BipartiteGraph::eraseNode2( size_t n2 ) {
    DAI_ASSERT( n2 < nrNodes2() );
    // Erase neighbor entry of node n2
    _nb2.erase( _nb2.begin() + n2 );
    // Adjust neighbor entries of nodes of type 1
    for( size_t n1 = 0; n1 < nrNodes1(); n1++ ) {
        for( size_t iter = 0; iter < nb1(n1).size(); ) {
            Neighbor &m2 = nb1(n1, iter);
            if( m2.node == n2 ) {
                // delete this entry, because it points to the deleted node
                nb1(n1).erase( nb1(n1).begin() + iter );
            } else if( m2.node > n2 ) {
                // update this entry and the corresponding dual of the neighboring node of type 2
                m2.iter = iter;
                m2.node--;
                nb2( m2.node, m2.dual ).dual = iter;
                iter++;
            } else {
                // skip
                iter++;
            }
        }
    }
}
void BipartiteGraph::eraseNode1( size_t n1 ) {
    DAI_ASSERT( n1 < nrNodes1() );
    // Erase neighbor entry of node n1
    _nb1.erase( _nb1.begin() + n1 );
    // Adjust neighbor entries of nodes of type 2
    for( size_t n2 = 0; n2 < nrNodes2(); n2++ ) {
        for( size_t iter = 0; iter < nb2(n2).size(); ) {
            Neighbor &m1 = nb2(n2, iter);
            if( m1.node == n1 ) {
                // delete this entry, because it points to the deleted node
                nb2(n2).erase( nb2(n2).begin() + iter );
            } else if( m1.node > n1 ) {
                // update this entry and the corresponding dual of the neighboring node of type 1
                m1.iter = iter;
                m1.node--;
                nb1( m1.node, m1.dual ).dual = iter;
                iter++;
            } else {
                // skip
                iter++;
            }
        }
    }
}