Пример #1
0
    bool NodeSTI::Configure( const Configuration* config )
    {
        // A PFA burnin of at least 1 day is required to ensure transmission
        initConfigTypeMap( "PFA_Burnin_Duration_In_Days", &pfa_burnin_duration, PFA_Burnin_Duration_In_Days_DESC_TEXT, 1, FLT_MAX, 1000 * DAYSPERYEAR );

        bool ret = society->Configure( config );
        if( ret )
        {
            ret = Node::Configure( config );
        }

        if( ret &&
            !JsonConfigurable::_dryrun &&
            (ind_sampling_type != IndSamplingType::TRACK_ALL     ) &&
            (ind_sampling_type != IndSamplingType::FIXED_SAMPLING) )
        {
            throw IncoherentConfigurationException( __FILE__, __LINE__, __FUNCTION__,
                                                    "Individual_Sampling_Type", IndSamplingType::pairs::lookup_key(ind_sampling_type),
                                                    "Simulation_Type", SimType::pairs::lookup_key( GET_CONFIGURABLE( SimulationConfig )->sim_type ),
                                                    "Relationship-based transmission network only works with 100% sampling."
                                                    );
        }

        return ret ;
    }
Пример #2
0
    bool HIVSimpleDiagnostic::Configure(const Configuration * inputJson)
    {
        if( getEventOrConfig( inputJson ) == EventOrConfig::Event || JsonConfigurable::_dryrun )
        {
            initConfigTypeMap( "Negative_Diagnosis_Event", &negative_diagnosis_event, HIV_SD_Negative_Diagnosis_Event_DESC_TEXT );
        }

        ConfigurePositiveEventOrConfig( inputJson );
        bool ret = JsonConfigurable::Configure(inputJson);
        if( ret )
        {
            // error if the cascadeState is an abortState
            if (abortStates.find(cascadeState) != abortStates.end())
            {
                std::string abort_state_list ;
                for( auto state : abortStates )
                {
                    abort_state_list += state + ", " ;
                }
                if( abortStates.size() > 0 )
                {
                    abort_state_list = abort_state_list.substr( 0, abort_state_list.length() - 2 );
                }
                throw IncoherentConfigurationException( __FILE__, __LINE__, __FUNCTION__,
                                                        "Cascade_State", cascadeState.c_str(),
                                                        "Abort_States", abort_state_list.c_str(),
                                                        "The Cascade_State cannot be one of the Abort_States." );
            }

            //CheckPostiveEventConfig();
        }
        return ret ;
    }
 void IncidenceEventCoordinator::CheckConfigureRepetitions()
 {
     if( m_NumTimestepsBetweenReps < m_pIncidenceCounter->GetCountEventsForNumTimeSteps() )
     {
         throw IncoherentConfigurationException( __FILE__, __LINE__, __FUNCTION__,
             "Timesteps_Between_Repetitions", m_NumTimestepsBetweenReps,
             "Count_Events_For_Num_Timesteps", m_pIncidenceCounter->GetCountEventsForNumTimeSteps(),
             "'Timesteps_Between_Repetitions' must be >= 'Count_Events_For_Num_Timesteps'" );
     }
 }
Пример #4
0
 void NodeSTI::SetMonteCarloParameters(float indsamplerate, int nummininf)
 {
     if( indsamplerate != 1.0f )
     {
         throw IncoherentConfigurationException( __FILE__, __LINE__, __FUNCTION__,
                                                "Base_Individual_Sampling_Rate", std::to_string( indsamplerate ).c_str(),
                                                "Simulation_Type", SimType::pairs::lookup_key( GET_CONFIGURABLE( SimulationConfig )->sim_type ),
                                                "Relationship-based transmission network only works with 100% sampling."
                                               );
     }
     return Node::SetMonteCarloParameters( indsamplerate, nummininf );
 }
Пример #5
0
    void IndividualHumanTB::InitializeStaticsTB( const Configuration* config ) // just called once!
    {
        LOG_DEBUG( "Configure\n" );
        SusceptibilityTBConfig fakeImmunity;
        fakeImmunity.Configure( config );
        InfectionTBConfig fakeInfection;
        fakeInfection.Configure( config );

        //Superinfection not yet supported for TB sims
        if (IndividualHumanConfig::superinfection )
        {
            throw IncoherentConfigurationException( __FILE__, __LINE__, __FUNCTION__, "Enable_Superinfection", IndividualHumanConfig::superinfection ? "1" : "0", "Simulation_Type", "TB_SIM" );
        }
    }
Пример #6
0
    Kernel::StrainIdentity* Outbreak::GetNewStrainIdentity(INodeEventContext *context)
    {
        StrainIdentity *outbreak_strainID = nullptr;

        // Important: Use the instance method to obtain the intervention factory obj instead of static method to cross the DLL boundary
        // NO usage of GET_CONFIGURABLE(SimulationConfig)->number_substrains in DLL
        IGlobalContext *pGC = nullptr;
        const SimulationConfig* simConfigObj = nullptr;
        if (s_OK == context->QueryInterface(GET_IID(IGlobalContext), (void**)&pGC))
        {
            simConfigObj = pGC->GetSimulationConfigObj();
        }
        if (!simConfigObj)
        {
            throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, "The pointer to IInterventionFactory object is not valid (could be DLL specific)" );
        }

        if (( antigen < 0 ) || ( antigen >= simConfigObj->number_basestrains ))
        {
            throw IncoherentConfigurationException( __FILE__, __LINE__, __FUNCTION__, "antigen", antigen, "number_basestrains", simConfigObj->number_basestrains );
        }

        if ( genome < 0 )
        {
            int ss = simConfigObj->number_substrains;
            if (ss & (ss-1))
            {
                throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, "Only supporting random genome generation for Number_Substrains as factor of two." );
            }
            unsigned int BARCODE_BITS = 0;
            while(ss >>= 1) ++BARCODE_BITS;
            uint32_t genome = context->GetRng()->ul() & ((1 << BARCODE_BITS)-1);
            //genome = context->GetRng()->i(simConfigObj->number_substrains);
            outbreak_strainID = _new_ StrainIdentity(antigen, genome);
            LOG_DEBUG_F("random genome generation... antigen: %d\t genome: %d\n", antigen, genome);
        }
    ISimulation * SimulationFactory::CreateSimulation()
    {
        EventTriggerFactory::GetInstance()->Configure( EnvPtr->Config );
        EventTriggerNodeFactory::GetInstance()->Configure( EnvPtr->Config );
        EventTriggerCoordinatorFactory::GetInstance()->Configure( EnvPtr->Config );
        NPFactory::CreateFactory();
        IPFactory::CreateFactory();

        ISimulation* newsim = nullptr;

        if ( CONFIG_PARAMETER_EXISTS( EnvPtr->Config, "Serialized_Population_Filenames" ) )
        {
            std::string path(".");
            if ( CONFIG_PARAMETER_EXISTS( EnvPtr->Config, "Serialized_Population_Path" ) )
            {
                path = GET_CONFIG_STRING(EnvPtr->Config, "Serialized_Population_Path");
            }
            std::vector<string> filenames = GET_CONFIG_VECTOR_STRING( EnvPtr->Config, "Serialized_Population_Filenames" );
            if ( filenames.size() != EnvPtr->MPI.NumTasks )
            {
                throw IncoherentConfigurationException(__FILE__, __LINE__, __FUNCTION__, "MPI.NumTasks", float(EnvPtr->MPI.NumTasks), "filenames.size()", float(filenames.size()), "Number of serialized population filenames doesn't match number of MPI tasks.");
            }
            std::string population_filename = FileSystem::Concat(path, filenames[EnvPtr->MPI.Rank]);
            auto t_start = std::chrono::high_resolution_clock::now();
            newsim = SerializedState::LoadSerializedSimulation( population_filename.c_str() );
            auto t_finish = std::chrono::high_resolution_clock::now();
            newsim->Initialize( EnvPtr->Config );
            double elapsed = uint64_t((t_finish - t_start).count()) * 1000 * double(std::chrono::high_resolution_clock::period::num) / double(std::chrono::high_resolution_clock::period::den);
            LOG_INFO_F( "Loaded serialized population from '%s' in %f ms\n.", population_filename.c_str(), elapsed );
            return newsim;
        }

        std::string sSimType;

        try
        {
            sSimType = GET_CONFIG_STRING(EnvPtr->Config, "Simulation_Type");

            SimType::Enum sim_type;
            if (sSimType == "GENERIC_SIM")
                sim_type = SimType::GENERIC_SIM;
#ifndef DISABLE_VECTOR
            else if (sSimType == "VECTOR_SIM")
                sim_type = SimType::VECTOR_SIM;
#endif
#ifndef DISABLE_MALARIA
            else if (sSimType == "MALARIA_SIM")
                sim_type = SimType::MALARIA_SIM;
#endif
#ifdef ENABLE_ENVIRONMENTAL
            else if (sSimType == "ENVIRONMENTAL_SIM")
                sim_type = SimType::ENVIRONMENTAL_SIM;
#endif
#ifdef ENABLE_POLIO
            else if (sSimType == "POLIO_SIM")
                sim_type = SimType::POLIO_SIM;
#endif
#ifdef ENABLE_ENVIRONMENTAL
            else if (sSimType == "ENVIRONMENTAL_SIM")
                sim_type = SimType::ENVIRONMENTAL_SIM;
#endif
#ifdef ENABLE_TYPHOID
            else if (sSimType == "TYPHOID_SIM")
                sim_type = SimType::TYPHOID_SIM;
#endif
#ifndef DISABLE_AIRBORNE
            else if (sSimType == "AIRBORNE_SIM")
                sim_type = SimType::AIRBORNE_SIM;
#endif
#ifndef DISABLE_TBHIV
            else if (sSimType == "TBHIV_SIM")
                sim_type = SimType::TBHIV_SIM;
#endif // TBHIV
#ifndef DISABLE_STI
            else if (sSimType == "STI_SIM")
                sim_type = SimType::STI_SIM;
#endif
#ifndef DISABLE_HIV
            else if (sSimType == "HIV_SIM")
                sim_type = SimType::HIV_SIM;
#endif // HIV
#ifdef ENABLE_DENGUE
            else if (sSimType == "DENGUE_SIM")
                sim_type = SimType::DENGUE_SIM;
#endif
#ifdef ENABLE_PYTHON_FEVER
            else if (sSimType == "PY_SIM")
                sim_type = SimType::PY_SIM;
#endif
            else
            {
                std::ostringstream msg;
                msg << "Simulation_Type " << sSimType << " not recognized." << std::endl;
                throw Kernel::GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, msg.str().c_str() );
            }

#ifdef _DLLS_

            // Look through disease dll directory, do LoadLibrary on each .dll,
            // do GetProcAddress on GetMimeType() and CreateSimulation
            typedef ISimulation* (*createSim)(const Environment *);
            std::map< std::string, createSim > createSimFuncPtrMap;

            // Note map operator [] will automatically initialize the pointer to NULL if not found
            DllLoader dllLoader;         
            if (!dllLoader.LoadDiseaseDlls(createSimFuncPtrMap) || !createSimFuncPtrMap[sSimType])
            {
                std::ostringstream msg;
                msg << "Failed to load disease emodules for SimType: " << SimType::pairs::lookup_key(sim_type) << " from path: " << dllLoader.GetEModulePath(DISEASE_EMODULES).c_str() << std::endl;
                throw Kernel::DllLoadingException( __FILE__, __LINE__, __FUNCTION__, msg.str().c_str());
                return newsim;
            }
            newsim = createSimFuncPtrMap[sSimType](EnvPtr);
            release_assert(newsim);

#else // _DLLS_
            switch (sim_type)
            {
                case SimType::GENERIC_SIM:
                    newsim = Simulation::CreateSimulation(EnvPtr->Config);
                break;
#if defined(ENABLE_ENVIRONMENTAL)
                case SimType::ENVIRONMENTAL_SIM:
                    newsim = SimulationEnvironmental::CreateSimulation(EnvPtr->Config);
                break;
#endif
#if defined( ENABLE_POLIO)
                case SimType::POLIO_SIM:
                    newsim = SimulationPolio::CreateSimulation(EnvPtr->Config);
                break;
#endif        
#if defined( ENABLE_TYPHOID)
                case SimType::TYPHOID_SIM:
                    newsim = SimulationTyphoid::CreateSimulation(EnvPtr->Config);
                break;
#endif        
#ifndef DISABLE_VECTOR
                case SimType::VECTOR_SIM:
                    newsim = SimulationVector::CreateSimulation(EnvPtr->Config);
                break;
#endif
#ifndef DISABLE_MALARIA
                case SimType::MALARIA_SIM:
                    newsim = SimulationMalaria::CreateSimulation(EnvPtr->Config);
                break;
#endif

#ifndef DISABLE_AIRBORNE
                case SimType::AIRBORNE_SIM:
                    throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "AIRBORNE_SIM currently disabled. Consider using GENERIC_SIM or TBHIV_SIM." );
                    newsim = SimulationAirborne::CreateSimulation(EnvPtr->Config);
                break;
#endif

#ifndef DISABLE_TBHIV
                case SimType::TBHIV_SIM:
                    newsim = SimulationTBHIV::CreateSimulation(EnvPtr->Config);
                break;
#endif // TBHIV

#ifndef DISABLE_STI
                case SimType::STI_SIM:
                    newsim = SimulationSTI::CreateSimulation(EnvPtr->Config);
                break;
#endif
#ifndef DISABLE_HIV 
                case SimType::HIV_SIM:
                    newsim = SimulationHIV::CreateSimulation(EnvPtr->Config);
                break;
#endif // HIV
#ifdef ENABLE_DENGUE
                case SimType::DENGUE_SIM:
                    newsim = SimulationDengue::CreateSimulation(EnvPtr->Config);
                break;
#endif 
#ifdef ENABLE_PYTHON_FEVER 
                case SimType::PY_SIM:
                    newsim = SimulationPy::CreateSimulation(EnvPtr->Config);
                break;
#endif
                default: 
                // Is it even possible to get here anymore?  Won't the SimulationConfig error out earlier parsing the parameter-string?
                //("SimulationFactory::CreateSimulation(): Error, Simulation_Type %d is not implemented.\n", sim_type);
                //throw BadEnumInSwitchStatementException( __FILE__, __LINE__, __FUNCTION__, "sim_type", sim_type, SimType::pairs::lookup_key( sim_typ )); // JB
                break;
            }
#endif
            release_assert(newsim);
        }
        catch ( GeneralConfigurationException& e ) {
            throw e;
        }

        return newsim;
    }