Пример #1
0
    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;
    }
 HIVARTStagingByCD4Diagnostic::HIVARTStagingByCD4Diagnostic()
 : HIVARTStagingAbstract()
 {
     initConfigComplexType("Threshold", &threshold, HIV_ASBCD_Threshold_DESC_TEXT);
     initConfigComplexType("If_Active_TB", &ifActiveTB, HIV_ASBCD_If_Active_TB_DESC_TEXT);
     initConfigComplexType("If_Pregnant", &ifPregnant, HIV_ASBCD_If_Pregnant_DESC_TEXT );
 }
Пример #3
0
    bool ScaleLarvalHabitat::Configure( const Configuration * inputJson )
    {
        initConfigComplexType( "Larval_Habitat_Multiplier", &m_LHM, SLH_Larval_Habitat_Multiplier_DESC_TEXT );

        // Don't call subclass SimpleVectorControlNode::Configure() because it will add cost_per_unit
        return BaseNodeIntervention::Configure( inputJson );
    }
    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;
    }
Пример #5
0
    bool AbstractBednet::ConfigureBlockingAndKilling( const Configuration * inputJson )
    {
        WaningConfig killing_config;
        WaningConfig blocking_config;
        initConfigComplexType( "Killing_Config", &killing_config, SB_Killing_Config_DESC_TEXT );
        initConfigComplexType( "Blocking_Config", &blocking_config, SB_Blocking_Config_DESC_TEXT );

        bool configured = BaseIntervention::Configure( inputJson );

        if( configured && !JsonConfigurable::_dryrun )
        {
            m_pEffectKilling = WaningEffectFactory::CreateInstance( killing_config );
            m_pEffectBlocking = WaningEffectFactory::CreateInstance( blocking_config );
        }

        return configured;
    }
Пример #6
0
    bool DiagnosticTreatNeg::Configure(
        const Configuration * inputJson
    )
    {
        EventOrConfig::Enum use_event_or_config;
        initConfig( "Event_Or_Config", use_event_or_config, inputJson, MetadataDescriptor::Enum("EventOrConfig", Event_Or_Config_DESC_TEXT, MDD_ENUM_ARGS( EventOrConfig ) ) );
        if( use_event_or_config == EventOrConfig::Event || JsonConfigurable::_dryrun )
        {
            initConfigTypeMap( "Negative_Diagnosis_Event", &negative_diagnosis_event, DTN_Negative_Diagnosis_Config_Event_DESC_TEXT );
            initConfigTypeMap( "Defaulters_Event", &defaulters_event, DTN_Defaulters_Diagnosis_Config_Event_DESC_TEXT );
        }

        if( use_event_or_config == EventOrConfig::Config || JsonConfigurable::_dryrun )
        {
            initConfigComplexType("Negative_Diagnosis_Config", &negative_diagnosis_config, DTN_Negative_Diagnosis_Config_DESC_TEXT, "Event_Or_Config", "Config" );
            initConfigComplexType("Defaulters_Config", &defaulters_config, DTN_Defaulters_Diagnosis_Config_DESC_TEXT, "Event_Or_Config", "Config" );
        }

        bool ret = SimpleDiagnostic::Configure( inputJson );
        if( ret  )
        {
            if( use_event_or_config == EventOrConfig::Config || JsonConfigurable::_dryrun )
            {
                InterventionValidator::ValidateIntervention( negative_diagnosis_config._json );
                InterventionValidator::ValidateIntervention( defaulters_config._json );
            }

            if( !JsonConfigurable::_dryrun && 
                negative_diagnosis_event.IsUninitialized() &&
                (negative_diagnosis_config._json.Type() == ElementType::NULL_ELEMENT) )
            {
                const char* msg = "You must define either Negative_Diagnosis_Event or Negative_Diagnosis_Config";
                throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, msg );
            }

            if( !JsonConfigurable::_dryrun && 
                defaulters_event.IsUninitialized() &&
                (defaulters_config._json.Type() == ElementType::NULL_ELEMENT) )
            {
                const char* msg = "You must define either Defaulters_Event or Defaulters_Config";
                throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, msg );
            }
        }
        return ret ;
    }
Пример #7
0
    bool MultiInterventionDistributor::Configure( const Configuration * inputJson )
    {
        initConfigComplexType("Intervention_List", &intervention_list, MID_Intervention_List_DESC_TEXT);

        bool ret = BaseIntervention::Configure( inputJson );
        if( ret )
        {
            InterventionValidator::ValidateInterventionArray( intervention_list._json, inputJson->GetDataLocation() );
        }
        return ret ;
    }
    bool Responder::Configure( const Configuration * inputJson )
    {
        initConfig( "Threshold_Type", m_ThresholdType, inputJson, MetadataDescriptor::Enum( "ThresholdType", ICE_Threshold_Type_DESC_TEXT, MDD_ENUM_ARGS( ThresholdType ) ) );

        initConfigComplexType( "Action_List", &m_ActionList, ICE_Action_List_DESC_TEXT );

        bool ret = JsonConfigurable::Configure( inputJson );
        if( ret && !JsonConfigurable::_dryrun )
        {
            CheckConfiguration( inputJson );
            m_ActionList.CheckConfiguration();
        }
        return ret;
    }
Пример #9
0
    bool SimpleBednet::ConfigureUsage( const Configuration * inputJson )
    {
        WaningConfig usage_config;
        initConfigComplexType( "Usage_Config", &usage_config, SB_Usage_Config_DESC_TEXT );

        bool configured = JsonConfigurable::Configure( inputJson ); // AbstractBednet is responsible for calling BaseIntervention::Configure()

        if( configured && !JsonConfigurable::_dryrun )
        {
            m_pEffectUsage = WaningEffectFactory::CreateInstance( usage_config );
        }

        return configured;
    }
Пример #10
0
    bool
    SimpleHousingModification::Configure(
        const Configuration * inputJson
    )
    {
        initConfigComplexType("Killing_Config", &killing_config, HM_Killing_Config_DESC_TEXT );
        initConfigComplexType("Blocking_Config", &blocking_config, HM_Blocking_Config_DESC_TEXT );
        bool configured = JsonConfigurable::Configure( inputJson );
        if( !JsonConfigurable::_dryrun )
        {
            auto tmp_killing  = Configuration::CopyFromElement( killing_config._json  );
            auto tmp_blocking = Configuration::CopyFromElement( blocking_config._json );

            killing_effect  = WaningEffectFactory::CreateInstance( tmp_killing  );
            blocking_effect = WaningEffectFactory::CreateInstance( tmp_blocking );

            delete tmp_killing;
            delete tmp_blocking;
            tmp_killing  = nullptr;
            tmp_blocking = nullptr;
        }
        return JsonConfigurable::Configure( inputJson );
    }
Пример #11
0
    bool WaningEffectMapAbstract::Configure( const Configuration * pInputJson )
    {
        initConfigTypeMap( "Initial_Effect",               &m_EffectCurrent,          WEE_Initial_Effect_DESC_TEXT,                0, 1, 1);
        initConfigTypeMap( "Expire_At_Durability_Map_End", &m_ExpireAtDurationMapEnd, WEM_Expire_At_Durability_Map_End_DESC_TEXT, false );

        initConfigComplexType( "Durability_Map", &m_DurationMap, WEM_Durability_Map_End_DESC_TEXT );

        bool ret = JsonConfigurable::Configure(pInputJson);
        if( ret )
        {
            m_EffectOriginal = m_EffectCurrent;
        }
        return ret;
    }
    bool IncidenceCounter::Configure( const Configuration * inputJson )
    {
        initConfigTypeMap( "Count_Events_For_Num_Timesteps", &m_CountEventsForNumTimeSteps, ICE_Count_Events_For_Num_Timesteps_DESC_TEXT, 1, INT_MAX, 1 );
        initConfigComplexType( "Node_Property_Restrictions", &m_NodePropertyRestrictions, ICE_Node_Property_Restriction_DESC_TEXT );
        
        m_DemographicRestrictions.ConfigureRestrictions( this, inputJson );
        ConfigureTriggers( inputJson );

        bool ret = JsonConfigurable::Configure( inputJson );
        if( ret && !JsonConfigurable::_dryrun )
        {
            m_DemographicRestrictions.CheckConfiguration();
            CheckConfigurationTriggers();
        }
        return ret;
    }
    bool CoverageByNodeEventCoordinator::Configure( const Configuration * inputJson )
    {
        initConfigComplexType("Coverage_By_Node", &coverage_by_node, Coverage_By_Node_DESC_TEXT );
        bool configured = StandardInterventionDistributionEventCoordinator::Configure(inputJson);

        try
        {
            if( !JsonConfigurable::_dryrun )
            {
            }
        }
        catch( const json::Exception &e )
        {
            throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, e.what() ); // ( "Coverage_By_Node json problem: Coverage_By_Node is valid json but needs to be an array of (nodeID,coverage) pairs." );
        }

        return configured;
    }
    bool
    NodeLevelHealthTriggeredIVScaleUpSwitch::Configure(
        const Configuration * inputJson
    )
    {
        initConfig("Demographic_Coverage_Time_Profile",  demographic_coverage_time_profile, inputJson, MetadataDescriptor::Enum("Demographic_Coverage_Time_Profile", NodeHTI_Demographic_Coverage_Time_Profile_DESC_TEXT, MDD_ENUM_ARGS(ScaleUpProfile) ) );
        if ( demographic_coverage_time_profile == ScaleUpProfile::Linear || JsonConfigurable::_dryrun )
        {
            initConfigTypeMap("Initial_Demographic_Coverage", &initial_demographic_coverage, NodeHTI_Initial_Demographic_Coverage_DESC_TEXT, 0.0f, 1.0f, 0.0f);
            initConfigTypeMap("Primary_Time_Constant", &primary_time_constant, NodeHTI_Primary_Time_Constant_DESC_TEXT, 0, INFINITE_TIME); //this is actually the time to reach the final demographic coverage, input as absolute days, not number of dts
        }
        //this has to be an array rather than a single intervention json so that it can be empty if you don't want to phase anything out
        initConfigComplexType("Not_Covered_IndividualIntervention_Configs", &not_covered_intervention_configs, NodeHTI_Not_Covered_IndividualIntervention_Configs_DESC_TEXT);


        bool ret= NodeLevelHealthTriggeredIV::Configure(inputJson);
        return ret;

    }
Пример #15
0
    bool InputEIR::Configure( const Configuration * inputJson )
    {
        initConfig( "Age_Dependence", age_dependence, inputJson, MetadataDescriptor::Enum("Age_Dependence", IE_Age_Dependence_DESC_TEXT, MDD_ENUM_ARGS(AgeDependentBitingRisk)) );
        initConfigComplexType( "Monthly_EIR", &monthly_EIR, IE_Config_Type_DESC_TEXT);

        switch(age_dependence)
        {
            case AgeDependentBitingRisk::OFF:
                risk_function=nullptr;
                break;

            case AgeDependentBitingRisk::LINEAR:
                risk_function = SusceptibilityVector::LinearBitingFunction;
                break;

            case AgeDependentBitingRisk::SURFACE_AREA_DEPENDENT:
                risk_function = SusceptibilityVector::SurfaceAreaBitingFunction;
                break;

            default:
                if( !JsonConfigurable::_dryrun )
                {
                    throw BadEnumInSwitchStatementException( __FILE__, __LINE__, __FUNCTION__, 
                        "age_dependence", age_dependence, 
                        AgeDependentBitingRisk::pairs::lookup_key(age_dependence) );
                }
        }

        bool configured = BaseNodeIntervention::Configure( inputJson );

        if(monthly_EIR.size() != MONTHSPERYEAR && JsonConfigurable::_dryrun == false )
        {
            throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, 
                "'Monthly_EIR' parameterizes the mean number of infectious bites experienced by an individual for each month of the year.  As such, it must be an array of EXACTLY length 12." );
        }

        return configured;
    }
Пример #16
0
    bool
    SimpleVaccine::Configure(
        const Configuration * inputJson
    )
    {
        initConfigTypeMap("Vaccine_Take", &vaccine_take, SV_Vaccine_Take_DESC_TEXT, 0.0, 1.0, 1.0 ); 

        initConfig( "Vaccine_Type", vaccine_type, inputJson, MetadataDescriptor::Enum("Vaccine_Type", SV_Vaccine_Type_DESC_TEXT, MDD_ENUM_ARGS(SimpleVaccineType)));

        initConfigComplexType("Waning_Config",  &waning_config, IVM_Killing_Config_DESC_TEXT );

        bool configured = JsonConfigurable::Configure( inputJson );
        if( !JsonConfigurable::_dryrun )
        {
            auto tmp_waning = Configuration::CopyFromElement( waning_config._json );
            waning_effect = WaningEffectFactory::CreateInstance( tmp_waning );
            delete tmp_waning;
            tmp_waning = nullptr;
        }
        //release_assert( vaccine_type );
        LOG_DEBUG_F( "Vaccine configured with type %d and take %f.\n", vaccine_type, vaccine_take );
        return configured;
    }
Пример #17
0
    bool HIVDelayedIntervention::Configure( const Configuration * inputJson )
    {
        // should be lifted to HIVIntervention class later
        initConfigTypeMap("Expiration_Period", &days_remaining, HIV_Delayed_Intervention_Expiration_Period_DESC_TEXT, 0, FLT_MAX, FLT_MAX);

        // DelayedIntervention::Configure split into PreConfigure and MainConfigure to separate initConfig's from initConfigTypeMap-depends-on, and postpone JsonConfigurable::Configure
        DelayedIntervention::PreConfigure(inputJson);
        DelayedIntervention::DistributionConfigure(inputJson);

        // HIVDelayedIntervention specific
        if( delay_distribution.GetType() == DistributionFunction::PIECEWISE_CONSTANT 
            || delay_distribution.GetType() == DistributionFunction::PIECEWISE_LINEAR
            || JsonConfigurable::_dryrun )
        {
            initConfigComplexType( "Time_Varying_Constants",
                                   &year2DelayMap,
                                   HIV_Delayed_Intervention_TVC_DESC_TEXT,
                                   "Delay_Distribution",
                                   "PIECEWISE_CONSTANT || PIECEWISE_LINEAR" );
        }

        //DelayedIntervention::InterventionConfigure(inputJson);
        initConfigTypeMap( "Broadcast_Event", &broadcast_event, HIV_Delayed_Intervention_Broadcast_Event_DESC_TEXT );

        initConfigTypeMap( "Broadcast_On_Expiration_Event", &broadcast_on_expiration_event, HIV_Delayed_Intervention_Broadcast_On_Expiration_Event_DESC_TEXT );

        // skip DelayedIntervention::Configure() because we don't want those variables.
        bool ret = BaseIntervention::Configure(inputJson);
        if( ret )
        {
            // don't validate the intervention configuration since not supported
            DelayValidate();
        }

        LOG_DEBUG_F( "HIVDelayedIntervention configured with days_remaining = %f and remaining_delay_days = %f\n", (float) days_remaining, (float) remaining_delay_days );
        return ret ;
    }
Пример #18
0
 void StandardInterventionDistributionEventCoordinator::initializeInterventionConfig(
     const Configuration* inputJson
 )
 {
     initConfigComplexType("Intervention_Config", &intervention_config, Intervention_Config_DESC_TEXT );
 }
Пример #19
0
    bool PairFormationParametersImpl::Configure( const Configuration* inputJson )
    {
        initConfig( "Formation_Rate_Type", 
                    formation_rate_type,
                    inputJson, 
                    MetadataDescriptor::Enum("Formation_Rate_Type", "TBD"/*Formation_Rate_Type_DESC_TEXT*/, MDD_ENUM_ARGS( FormationRateType ) ) );

        if( formation_rate_type == FormationRateType::CONSTANT )
        {
            initConfigTypeMap( "Formation_Rate_Constant", &formation_rate_constant, "TBD"/*Formation_Rate_DESC_TEXT*/, 0, 1, 0.001f );
        }
        else if( formation_rate_type == FormationRateType::SIGMOID_VARIABLE_WIDTH_HEIGHT )
        {
            initConfigTypeMap( "Formation_Rate_Sigmoid", &formation_rate_sigmoid, "TBD"/*Formation_Rate_Sigmoid_DESC_TEXT*/ );
        }
        else if( formation_rate_type == FormationRateType::INTERPOLATED_VALUES )
        {
            initConfigComplexType("Formation_Rate_Interpolated_Values", &formation_rate_value_map, "TBD"/*Formation_Rate_Interpolated_Values_DESC_TEXT*/ );
        }
        else
        {
            throw BadEnumInSwitchStatementException( __FILE__, __LINE__, __FUNCTION__, "Formation_Rate_Type", formation_rate_type );
        }

        initConfigTypeMap( "Extra_Relational_Rate_Ratio_Male",   &rate_ratio[Gender::MALE  ], PFA_Extra_Relational_Rate_Ratio_Male_DESC_TEXT,   1.0, FLT_MAX, 1.0f );
        initConfigTypeMap( "Extra_Relational_Rate_Ratio_Female", &rate_ratio[Gender::FEMALE], PFA_Extra_Relational_Rate_Ratio_Female_DESC_TEXT, 1.0, FLT_MAX, 1.0f );

        initConfigTypeMap( "Update_Period",                  &update_period,            "TBD"/*Update_Period_DESC_TEXT*/,         0,    FLT_MAX,    0      );
        initConfigTypeMap( "Number_Age_Bins_Male",           &male_age_bin_count,       Number_Age_Bins_Male_DESC_TEXT,           1,       1000,    1      );
        initConfigTypeMap( "Number_Age_Bins_Female",         &female_age_bin_count,     Number_Age_Bins_Female_DESC_TEXT,         1,       1000,    1      );
        initConfigTypeMap( "Age_of_First_Bin_Edge_Male",     &initial_male_age,         Age_of_First_Bin_Edge_Male_DESC_TEXT,     0,        100,    1      );
        initConfigTypeMap( "Age_of_First_Bin_Edge_Female",   &initial_female_age,       Age_of_First_Bin_Edge_Female_DESC_TEXT,   0,        100,    1      );
        initConfigTypeMap( "Years_Between_Bin_Edges_Male",   &male_age_increment,       Years_Between_Bin_Edges_Male_DESC_TEXT,   0.1f,     100.0f, 1.0f   );
        initConfigTypeMap( "Years_Between_Bin_Edges_Female", &female_age_increment,     Years_Between_Bin_Edges_Female_DESC_TEXT, 0.1f,     100.0f, 1.0f   );
        initConfigTypeMap( "Joint_Probabilities",            &joint_probabilities,      Joint_Probabilities_DESC_TEXT,            0.0,  FLT_MAX,    0.0f   ); 

        bool ret = false;
        bool prev_use_defaults = JsonConfigurable::_useDefaults ;
        bool reset_track_missing = JsonConfigurable::_track_missing;
        JsonConfigurable::_track_missing = false;
        JsonConfigurable::_useDefaults = false ;
        
        try
        {

            ret = JsonConfigurable::Configure( inputJson );

            JsonConfigurable::_useDefaults = prev_use_defaults ;
            JsonConfigurable::_track_missing = reset_track_missing;
        }
        catch( DetailedException& e )
        {
            JsonConfigurable::_useDefaults = prev_use_defaults ;
            JsonConfigurable::_track_missing = reset_track_missing;

            std::stringstream ss ;
            ss << e.GetMsg() << "\n" << "Was reading values for " << RelationshipType::pairs::lookup_key( rel_type ) << "." ;
            throw InvalidInputDataException( __FILE__, __LINE__, __FUNCTION__, ss.str().c_str() );
        }
        catch( json::Exception& e )
        {
            JsonConfigurable::_useDefaults = prev_use_defaults ;
            JsonConfigurable::_track_missing = reset_track_missing;

            std::stringstream ss ;
            ss << e.what() << "\n" << "Was reading values for " << RelationshipType::pairs::lookup_key( rel_type ) << "." ;
            throw InvalidInputDataException( __FILE__, __LINE__, __FUNCTION__, ss.str().c_str() );
        }

        if( ret )
        {
            CheckArraySizes();

            InitializeAgeBins( Gender::MALE,   male_age_bin_count,   initial_male_age,   male_age_increment   );
            InitializeAgeBins( Gender::FEMALE, female_age_bin_count, initial_female_age, female_age_increment );

            InitializeMarginalValues();
            InitializeCumulativeProbabilities();
        }
        return ret ;
    }
 void MultiInterventionEventCoordinator::initializeInterventionConfig(
     const Configuration * inputJson
 )
 {
     initConfigComplexType("Intervention_Configs", &intervention_config, MIEC_Intervention_Configs_DESC_TEXT );
 }
    bool CommunityHealthWorkerEventCoordinator::Configure( const Configuration * inputJson )
    {
        initConfigTypeMap("Duration",                &m_CoordinatorDaysRemaining, CHW_Duration_DESC_TEXT,                0.0f,     FLT_MAX, FLT_MAX );
        initConfigTypeMap("Max_Distributed_Per_Day", &m_MaxDistributedPerDay,     CHW_Max_Distributed_Per_Day_DESC_TEXT, 1,        INT_MAX, INT_MAX );
        initConfigTypeMap("Waiting_Period",          &m_QueueWaitingPeriodDays,   CHW_Waiting_Period_DESC_TEXT,          0.0f,     FLT_MAX, FLT_MAX );
        initConfigTypeMap("Days_Between_Shipments",  &m_DaysBetweenShipments,     CHW_Days_Between_Shipments_DESC_TEXT,  1.0f,     FLT_MAX, FLT_MAX );
        initConfigTypeMap("Amount_In_Shipment",      &m_AmountInShipment,         CHW_Amount_In_Shipment_DESC_TEXT,      0,        INT_MAX, INT_MAX );
        initConfigTypeMap("Max_Stock",               &m_MaxStock,                 CHW_Max_Stock_DESC_TEXT,               0,        INT_MAX, INT_MAX );

        DurationDistribution initial_amount;
        initial_amount.SetTypeNameDesc( "Initial_Amount_Distribution_Type", CHW_Initial_Amount_Distribution_Type_DESC_TEXT );
        initial_amount.AddSupportedType( DistributionFunction::FIXED_DURATION,       "Initial_Amount",      CHW_Initial_Amount_DESC_TEXT,      "", "" );
        initial_amount.AddSupportedType( DistributionFunction::UNIFORM_DURATION,     "Initial_Amount_Min",  CHW_Initial_Amount_Min_DESC_TEXT,  "Initial_Amount_Max",     CHW_Initial_Amount_Max_DESC_TEXT );
        initial_amount.AddSupportedType( DistributionFunction::GAUSSIAN_DURATION,    "Initial_Amount_Mean", CHW_Initial_Amount_Mean_DESC_TEXT, "Initial_Amount_Std_Dev", CHW_Initial_Amount_Std_Dev_DESC_TEXT );
        initial_amount.AddSupportedType( DistributionFunction::EXPONENTIAL_DURATION, "Initial_Amount",      CHW_Initial_Amount_DESC_TEXT,      "", "" );

        initial_amount.Configure( this, inputJson );
        m_DemographicRestrictions.ConfigureRestrictions( this, inputJson );

        initConfigTypeMap("Trigger_Condition_List", &m_TriggerConditionList, CHW_Trigger_Condition_List_DESC_TEXT );

        initConfigComplexType( "Node_Property_Restrictions", &m_NodePropertyRestrictions, CHW_Node_Property_Restriction_DESC_TEXT );

        initConfigComplexType( "Intervention_Config", &m_InterventionConfig, CHW_Intervention_Config_DESC_TEXT );

        bool retValue = JsonConfigurable::Configure( inputJson );

        if( retValue && !JsonConfigurable::_dryrun)
        {
            // ------------------------------------------------------
            // --- Check that the intervention exists and initialize
            // ------------------------------------------------------
            InterventionValidator::ValidateIntervention( m_InterventionConfig._json, inputJson->GetDataLocation() );

            m_DemographicRestrictions.CheckConfiguration();

            Configuration* qi_as_config = Configuration::CopyFromElement( m_InterventionConfig._json );

            m_InterventionName = std::string( json::QuickInterpreter(m_InterventionConfig._json)["class"].As<json::String>() );

            m_pInterventionIndividual = InterventionFactory::getInstance()->CreateIntervention( qi_as_config );
            if( m_pInterventionIndividual == nullptr )
            {
                m_pInterventionNode = InterventionFactory::getInstance()->CreateNDIIntervention( qi_as_config );
            }
            
            delete qi_as_config;
            qi_as_config = nullptr;

            // ---------------------------------------------------------------------------
            // --- If the user is attempting to define demographic restrictions when they
            // --- are using a node level intervention, then we need to error because these
            // --- restrictions are not doing anything.
            // ---------------------------------------------------------------------------
            if( (m_pInterventionNode != nullptr) && !m_DemographicRestrictions.HasDefaultRestrictions() )
            {
                std::ostringstream msg ;
                msg << "In CommunityHealthWorkerEventCoordinator, demographic restrictions such as 'Demographic_Coverage'\n";
                msg << "and 'Target_Gender' do not apply when distributing nodel level interventions such as ";
                msg << m_InterventionName;
                throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, msg.str().c_str() );
            }
            else if( (m_pInterventionNode == nullptr) && (m_NodePropertyRestrictions.Size() > 0) )
            {
                std::ostringstream msg;
                msg << "In CommunityHealthWorkerEventCoordinator, Node_Property_Restrictions only works when distributing node-level interventions.\n";
                msg << m_InterventionName << " is a individual-targeted intervention.\n";
                throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, msg.str().c_str() );
            }

            for( auto& event_name : m_RemoveIndividualEventList )
            {
                m_TriggerConditionList.push_back( event_name );
            }

            // --------------------
            // --- Initialize Stock
            // --------------------
            initial_amount.CheckConfiguration();
            m_CurrentStock = int( initial_amount.CalculateDuration() + 0.5); // round up
            if( m_CurrentStock > m_MaxStock )
            {
                m_CurrentStock = m_MaxStock;
            }

            m_DaysToNextShipment = int( float(m_CurrentStock) / float(m_MaxDistributedPerDay) );
            if( m_DaysToNextShipment > m_DaysBetweenShipments )
            {
                m_DaysToNextShipment = m_DaysBetweenShipments;
            }
        }

        return retValue;
    }
Пример #22
0
    bool
    NodeLevelHealthTriggeredIV::Configure(
        const Configuration * inputJson
    )
    {
        JsonConfigurable::_useDefaults = InterventionFactory::useDefaults;

        if( JsonConfigurable::_dryrun || inputJson->Exist( "Actual_NodeIntervention_Config" ) )
        {
            initConfigComplexType( "Actual_NodeIntervention_Config", &actual_node_intervention_config, BT_Actual_NodeIntervention_Config_DESC_TEXT );
        }
        if( JsonConfigurable::_dryrun || inputJson->Exist( "Actual_IndividualIntervention_Config" ) )
        {
            initConfigComplexType( "Actual_IndividualIntervention_Config", &actual_individual_intervention_config, BT_Actual_IndividualIntervention_Config_DESC_TEXT );
        }
        if( !JsonConfigurable::_dryrun && 
            ( ( inputJson->Exist( "Actual_IndividualIntervention_Config" ) &&  inputJson->Exist( "Actual_NodeIntervention_Config" )) || 
              (!inputJson->Exist( "Actual_IndividualIntervention_Config" ) && !inputJson->Exist( "Actual_NodeIntervention_Config" )) ) )
        {
            throw InvalidInputDataException( __FILE__, __LINE__, __FUNCTION__, "You must specify either 'Actual_IndividualIntervention_Config' or 'Actual_NodeIntervention_Config' (but do not specify both)." );
        }

        initConfigTypeMap( "Distribute_On_Return_Home", &distribute_on_return_home, Distribute_On_Return_Home_DESC_TEXT, false );

        initConfigTypeMap("Duration", &max_duration, BT_Duration_DESC_TEXT, -1.0f, FLT_MAX, -1.0f ); // -1 is a convention for indefinite duration

        initConfigTypeMap( "Blackout_Period", &blackout_period, Blackout_Period_DESC_TEXT, 0.0f, FLT_MAX, 0.0f );
        initConfigTypeMap( "Blackout_Event_Trigger", &blackout_event_trigger, Blackout_Event_Trigger_DESC_TEXT );
        initConfigTypeMap( "Blackout_On_First_Occurrence", &blackout_on_first_occurrence, Blackout_On_First_Occurrence_DESC_TEXT, false );

        initConfigComplexType( "Node_Property_Restrictions", &node_property_restrictions, NLHTIV_Node_Property_Restriction_DESC_TEXT );

        demographic_restrictions.ConfigureRestrictions( this, inputJson );

        // --------------------------------------------------------------------------------------------------------------------
        // --- Phase 0 - Pre V2.0 - Trigger_Condition was an enum and users had to have all indivual events in the enum list.
        // --- Phase 1 -     V2.0 - Trigger_Condition was an enum but TriggerString and TriggerList were added to allow the 
        // ---                      user to use new User Defined events (i.e. strings).
        // --- Phase 2 - 11/12/15 - Trigger_Condition is now a string and so users don't need to use Trigger_Condition_String
        // ---                      in order to use the User Defined events.  However, we are leaving support here for 
        // ---                      Trigger_Condition_String for backward compatibility (and I'm lazy).
        // --- Phase 3 - 11/9/16    Consolidate so that the user only defines Trigger_Condition_List
        // --------------------------------------------------------------------------------------------------------------------
        JsonConfigurable::_useDefaults = InterventionFactory::useDefaults; // Why???
        initConfigTypeMap( "Trigger_Condition_List", &m_trigger_conditions, NLHTI_Trigger_Condition_List_DESC_TEXT );

        bool retValue = BaseNodeIntervention::Configure( inputJson );

        //this section copied from standardevent coordinator
        if( retValue && !JsonConfigurable::_dryrun )
        {
            demographic_restrictions.CheckConfiguration();
            if( inputJson->Exist( "Actual_IndividualIntervention_Config" ) )
            {
                InterventionValidator::ValidateIntervention( actual_individual_intervention_config._json, inputJson->GetDataLocation() );
                using_individual_config = true;
            }
            else if( inputJson->Exist( "Actual_NodeIntervention_Config" ) )
            {
                InterventionValidator::ValidateIntervention( actual_node_intervention_config._json, inputJson->GetDataLocation() );
                using_individual_config = false;
            }

            event_occured_list.resize( EventTriggerFactory::GetInstance()->GetNumEventTriggers() );

            bool blackout_configured = (inputJson->Exist("Blackout_Event_Trigger")) || (inputJson->Exist("Blackout_Period")) || (inputJson->Exist("Blackout_On_First_Occurrence"));
            bool blackout_all_configured = (inputJson->Exist("Blackout_Event_Trigger")) && (inputJson->Exist("Blackout_Period")) && (inputJson->Exist("Blackout_On_First_Occurrence"));
            if (blackout_configured && !blackout_all_configured)
            {
                std::vector<string> blackout_missing_str;
                if( !inputJson->Exist("Blackout_Event_Trigger") )       blackout_missing_str.push_back("Blackout_Event_Trigger");
                if( !inputJson->Exist("Blackout_Period") )              blackout_missing_str.push_back("Blackout_Period");
                if( !inputJson->Exist("Blackout_On_First_Occurrence") ) blackout_missing_str.push_back("Blackout_On_First_Occurrence");

                throw MissingParameterFromConfigurationException(__FILE__, __LINE__, __FUNCTION__, inputJson->GetDataLocation().c_str(), blackout_missing_str, " All three Blackout parameters must be configured.");
            }

            if( distribute_on_return_home )
            {
                if( (std::find( m_trigger_conditions.begin(), m_trigger_conditions.end(), EventTrigger::Emigrating ) != m_trigger_conditions.end()) ||
                    (std::find( m_trigger_conditions.begin(), m_trigger_conditions.end(), EventTrigger::Immigrating ) != m_trigger_conditions.end()) )
                {
                    throw InvalidInputDataException( __FILE__, __LINE__, __FUNCTION__, "When using Distribute_On_Return_Home, you cannot also use Emigrating or Immigrating." );
                }
                m_trigger_conditions.push_back( EventTrigger::Emigrating );
                m_trigger_conditions.push_back( EventTrigger::Immigrating );
            }
        }
        JsonConfigurable::_useDefaults = false;
        return retValue;    
    }