Example #1
0
 void IndividualHumanVector::ApplyTotalBitingExposure()
 {
     // Make random draw whether to acquire new infection
     // dt incorporated already in ExposeIndividual function arguments
     float acquisition_probability = float(EXPCDF(-m_total_exposure));
     if ( randgen->e() >= acquisition_probability ) return;
         
     // Choose a strain based on a weighted draw over values from all vector-to-human pools
     float strain_cdf_draw = randgen->e() * m_total_exposure;
     std::vector<strain_exposure_t>::iterator it = std::lower_bound( m_strain_exposure.begin(), m_strain_exposure.end(), strain_cdf_draw, compare_strain_exposure_float_less()); 
     AcquireNewInfection(&(it->first));
 }
Example #2
0
    void IndividualHumanMalaria::ApplyTotalBitingExposure()
    {
        // Unlike for vector sims, don't do the draw on probability of *any* infectious bites, i.e. EXPCDF(-m_total_exposure)
        // We will instead do a Poisson draw on how many infectious bites, with the equivalent behavior for zero bites.
        // Downstream (in createInfection), we will use the number of infected hepatocytes to initialize new infections.

        // First calculate number of infectious bites
        int n_infectious_bites = CalculateInfectiousBites();
        if ( n_infectious_bites == 0 ) return;

        // Then do sporozoite challenge (caching inital infected hepatocyte count for createInfection)
        if ( ChallengeWithBites( n_infectious_bites ) )
        {
            // If there is a non-zero number of initial infected hepatocytes,
            // choose a strain based on a weighted draw over values from all vector-to-human pools and acquire infection
            float strain_cdf_draw = randgen->e() * m_total_exposure;
            std::vector<strain_exposure_t>::iterator it = std::lower_bound( m_strain_exposure.begin(), m_strain_exposure.end(), strain_cdf_draw, compare_strain_exposure_float_less()); 
            AcquireNewInfection(&(it->first));
        }
    }
Example #3
0
    void IndividualHumanPy::Expose( const IContagionPopulation* cp, float dt, TransmissionRoute::Enum transmission_route )
    { 
#ifdef ENABLE_PYTHON_FEVER
        if( cp->GetTotalContagion() == 0 )
        {
            return;
        }

        LOG_DEBUG_F( "Calling py:expose with contagion pop %f\n", cp->GetTotalContagion() );

        static auto pFunc = PythonSupportPtr->IdmPyInit( PythonSupport::SCRIPT_PYTHON_FEVER.c_str(), "expose" );
        if( pFunc )
        {
            // pass individual id AND dt
            static PyObject * vars = PyTuple_New(4);

            vars = Py_BuildValue( "llls", GetSuid().data, int(cp->GetTotalContagion()), int(dt), PyLong_FromLong( transmission_route == TransmissionRoute::TRANSMISSIONROUTE_ENVIRONMENTAL ? 0 : 1 ) ); 
            PyObject * retVal = PyObject_CallObject( pFunc, vars );
            if( retVal == nullptr )
            {
                PyErr_Print();
                std::stringstream msg;
                msg << "Embedded python code failed: PyObject_CallObject failed in call to 'expose'.";
                throw Kernel::IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, msg.str().c_str() );
            }
            bool val = false;
            PyArg_Parse( retVal, "b", &val );
            if( val )
            {
                StrainIdentity strainId;
                AcquireNewInfection(&strainId);
            }
#if !defined(_WIN32) || !defined(_DEBUG)
            Py_DECREF( retVal );
#endif
        }
        return;
#endif
    }