bool ReferenceTrackingEventCoordinator::Configure( const Configuration * inputJson ) { if( !JsonConfigurable::_dryrun && #ifdef ENABLE_TYPHOID (GET_CONFIGURABLE( SimulationConfig )->sim_type != SimType::TYPHOID_SIM) && #endif (GET_CONFIGURABLE( SimulationConfig )->sim_type != SimType::STI_SIM) && (GET_CONFIGURABLE( SimulationConfig )->sim_type != SimType::HIV_SIM) ) { throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "ReferenceTrackingEventCoordinator can only be used in STI, HIV, and TYPHOID simulations." ); } float update_period = DAYSPERYEAR; initConfigComplexType("Time_Value_Map", &year2ValueMap, RTEC_Time_Value_Map_DESC_TEXT ); initConfigTypeMap( "Update_Period", &update_period, RTEC_Update_Period_DESC_TEXT, 1.0, 10*DAYSPERYEAR, DAYSPERYEAR ); initConfigTypeMap( "End_Year", &end_year, RTEC_End_Year_DESC_TEXT, MIN_YEAR, MAX_YEAR, MAX_YEAR ); auto ret = StandardInterventionDistributionEventCoordinator::Configure( inputJson ); num_repetitions = -1; // unlimited if( JsonConfigurable::_dryrun == false ) { float dt = GET_CONFIGURABLE(SimulationConfig)->Sim_Tstep; tsteps_between_reps = update_period/dt; // this won't be precise, depending on math. if( tsteps_between_reps <= 0.0 ) { // don't let this be zero or it will only update one time tsteps_between_reps = 1; } } LOG_DEBUG_F( "ReferenceTrackingEventCoordinator configured with update_period = %f, end_year = %f, and tsteps_between_reps (derived) = %d.\n", update_period, end_year, tsteps_between_reps ); return ret; }
bool CampaignEventByYear::Configure( const Configuration * inputJson ) { if( !JsonConfigurable::_dryrun && #ifdef ENABLE_TYPHOID (GET_CONFIGURABLE( SimulationConfig )->sim_type != SimType::TYPHOID_SIM) && #endif (GET_CONFIGURABLE( SimulationConfig )->sim_type != SimType::STI_SIM) && (GET_CONFIGURABLE( SimulationConfig )->sim_type != SimType::HIV_SIM) ) { throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "CampainEventByYear can only be used in STI and HIV simulations." ); } float start_year; initConfigTypeMap( "Start_Year", &start_year, Start_Year_DESC_TEXT, MIN_YEAR, MAX_YEAR, MIN_YEAR ); initConfigComplexType( "Nodeset_Config", &nodeset_config, Nodeset_Config_DESC_TEXT ); initConfigComplexType( "Event_Coordinator_Config", &event_coordinator_config, Event_Coordinator_Config_DESC_TEXT ); // Bypasss CampaignEvent base class so that we don't break without Start_Day! bool ret = JsonConfigurable::Configure( inputJson ); if( Simulation::base_year > 0 ) { start_day = (start_year - Simulation::base_year) * DAYSPERYEAR; } return ret; }
bool BaseIntervention::Distribute( IIndividualHumanInterventionsContext *context, // interventions container usually ICampaignCostObserver * const pICCO ) { if( dont_allow_duplicates && context->ContainsExisting( typeid(*this).name() ) ) { return false ; } bool wasDistributed=false; IInterventionConsumer * ic; if (s_OK == (context->QueryInterface(GET_IID(IInterventionConsumer), (void**)&ic) ) ) { assert(ic); if( ic->GiveIntervention(this) ) { // Need to get Individual pointer from interventions container pointer. Try parent. IIndividualHumanEventContext * pIndiv = (context->GetParent())->GetEventContext(); if( pICCO ) { pICCO->notifyCampaignExpenseIncurred( cost_per_unit, pIndiv ); } wasDistributed = true; } } else { std::ostringstream oss; oss << "Unable to distribute intervention because IIndividualHumanInterventionsContext doesn't support IInterventionConsumer." << std::endl; throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, oss.str().c_str() ); } return wasDistributed; }
const char* EventTrigger::c_str() const { if( m_pInternal == nullptr ) { throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "Cannot use ToString(). EventTrigger is uninitialized." ); } return m_pInternal->m_Name.c_str(); }
int EventTrigger::GetIndex() const { if( m_pInternal == nullptr ) { throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "Cannot use ToString(). EventTrigger is uninitialized." ); } return m_pInternal->m_Index; }
float WaningEffectMapLinearAge::GetMultiplier( float timeSinceStart ) const { if( m_Parent == nullptr ) { throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "SetContextTo() has not been called properly." ); } float age_years = m_Parent->GetEventContext()->GetAge() / DAYSPERYEAR; return WaningEffectMapLinear::GetMultiplier( age_years ); }
EventTriggerInternal* EventTriggerFactory::GetEventTriggerInternal( const std::string& str ) { if( m_MapAll.count( str ) == 0 ) { std::stringstream ss; ss << "Undefined EventTrigger=" << str << ". Not built-in or found in " << EventTriggerFactory::CONSTRAINT_SCHEMA_STRING << "."; throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, ss.str().c_str() ); } return m_MapAll.at( str ); }
int HIVInterventionsContainer::SemaphoreIncrement( const std::string& counter ) { if (!SemaphoreExists(counter)) { std::stringstream msg; msg << "Could not find semaphore = " << counter ; throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, msg.str().c_str() ); } campaign_semaphores[counter]++; return campaign_semaphores[counter]; }
IRelationshipParameters* SocietyImpl::GetRelationshipParameters( RelationshipType::Enum type ) { for( int irel = 0; irel < RelationshipType::COUNT; irel++ ) { if( rel_params[ irel ]->GetType() == type ) { return rel_params[ irel ]; } } std::ostringstream msg; msg << "Unknown RelationshipType = " << type << " / " << RelationshipType::pairs::lookup_key( type ); throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, msg.str().c_str() ); }
void Bundle::stop() { if (QThread::currentThreadId() != m_owner) { //TODO: Operation execution by the owner thread throw UnsupportedOperationException("Bundle::install"); return; } if (m_state == ACTIVE) { m_state = STOPPING; if (m_bundleActivator != nullptr) { m_bundleActivator->stop(m_context); } m_state = RESOLVED; } throw IllegalOperationException("Try to stop a bundle with state " + toString(m_state)); }
void Bundle::uninstall() { if (QThread::currentThreadId() != m_owner) { //TODO: Operation execution by the owner thread throw UnsupportedOperationException("Bundle::uninstall"); } if (m_state == ACTIVE) { stop(); } if (m_state == RESOLVED) { m_bundleActivator = nullptr; m_libFile.unload(); m_state = UNINSTALLED; return; } throw IllegalOperationException("Try to uninstall a bundle with state " + toString(m_state)); }
void Bundle::start() { if (QThread::currentThreadId() != m_owner) { //TODO: Operation execution by the owner thread throw UnsupportedOperationException("Bundle::install"); } if (m_state == UNINSTALLED) { install(); } if (m_state == RESOLVED) { m_state = STARTING; if (m_bundleActivator != nullptr) { m_bundleActivator->start(m_context); } m_state = ACTIVE; } throw IllegalOperationException("Try to start a bundle with state " + toString(m_state)); }
bool HIVInterventionsContainer::SemaphoreDecrement( const std::string& counter ) { if (!SemaphoreExists(counter)) { std::stringstream msg; msg << "Could not find semaphore = " << counter ; throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, msg.str().c_str() ); } campaign_semaphores[counter]--; if (campaign_semaphores[counter] < 0) { campaign_semaphores[counter] = 0; return false; } return true; }
void Bundle::install() { if (QThread::currentThreadId() != m_owner) { //TODO: Operation execution by the owner thread throw UnsupportedOperationException("Bundle::install"); } if (m_state == UNINSTALLED) { try { m_libFile.load(); } catch (LoadSharedLibException e) { throw BundleException("Unable to load the bundle file: " + e.message()); } try { m_bundleActivator = (*(BundleActivator *(*)())(m_libFile.getSymbol("__manifest_get_BundleActivator")))(); } catch (SymbolSharedLibException e) {} return; } throw IllegalOperationException("Try to install a bundle with state " + toString(m_state)); }
void EventTriggerFactory::SetBuiltIn() { // ---------------------------------------------------- // --- See the top of the file about Built-in triggers. // --- Should only be called from DLLs and triggers should // --- not be used before hand. // ---------------------------------------------------- release_assert( (m_VectorBuiltIn.size() > 0) && (m_VectorBuiltIn[ 0 ].second->m_pInternal == nullptr) ); EventTriggerFactory* p_factory = (EventTriggerFactory*)Environment::getEventTriggerFactory(); release_assert( p_factory != nullptr ); for( int i = 0 ; i < m_VectorBuiltIn.size() ; ++i ) { if( p_factory->m_MapAll.count( m_VectorBuiltIn[ i ].first ) == 0 ) { std::stringstream ss; ss << "DLL Built-in trigger = " << m_VectorBuiltIn[ i ].first << " is missing in the EXE."; throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, ss.str().c_str() ); } m_VectorBuiltIn[i].second->m_pInternal = p_factory->m_MapAll.at( m_VectorBuiltIn[ i ].first ); } }
bool BaseNodeIntervention::Distribute( INodeEventContext *context, // interventions container usually IEventCoordinator2 * ec ) { bool wasDistributed=false; INodeInterventionConsumer * ic; if (s_OK == (context->QueryInterface(GET_IID(INodeInterventionConsumer), (void**)&ic) ) ) { assert(ic); if( ic->GiveIntervention(this) ) { wasDistributed = true; } } else { std::ostringstream oss; oss << "Unable to distribute intervention because INodeEventContext doesn't support INodeInterventionConsumer." << std::endl; throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, oss.str().c_str() ); } return wasDistributed; }
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; }
void VectorCohortIndividual::Merge( IVectorCohort* pCohortToAdd ) { throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "Individuals should not merge" ); }
IVectorCohort* VectorCohortIndividual::Split( uint32_t numLeaving ) { throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "Individuals should not Split" ); }
void VectorCohortIndividual::AdjustEggsForDeath( uint32_t numDied ) { throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "Should not be called for individuals" ); }
const std::vector<uint32_t>& VectorCohortIndividual::GetNewEggs() const { throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "Should not be called for individuals" ); }
void MasterInterventionsContainer::PurgeExisting( const std::string& iv_name ) { throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "MasterInterventionsContainer::PurgeExisting should never be called (for now)." ); }