示例#1
0
 float Infection::GetInfectiousnessByRoute( const string& route ) const {
     if( infectiousnessByRoute.find( route ) == infectiousnessByRoute.end() )
     {
         throw BadMapKeyException( __FILE__, __LINE__, __FUNCTION__, "infectiousnesssByRoute", route.c_str() );
     }
     return infectiousnessByRoute.at(route); 
 }
    void SimpleTransmissionGroups::BuildRouteScalingMatrices( void )
    {
        InitializeCumulativeMatrix(scalingMatrix);

        // For each property, aggregate the propertyMatrix with the cumulative scaling matrix
        for (const auto& entry : propertyNameToValuesMap)
        {
            const string& propertyName = entry.first;
            const PropertyValueList_t& valueList = entry.second;
            AddPropertyValuesToValueToIndexMap(propertyName, valueList, scalingMatrix.size());
            if( propertyNameToMatrixMap.find( propertyName ) == propertyNameToMatrixMap.end() )
            {
                throw BadMapKeyException( __FILE__, __LINE__, __FUNCTION__, "propertyNameToMatrixMap", propertyName.c_str() );
            }
            AggregatePropertyMatrixWithCumulativeMatrix(propertyNameToMatrixMap[propertyName], scalingMatrix);
        }
    }
    void InterventionsContainer::ChangeProperty(
        const char * property,
        const char * new_value
    )
    {
/*
        LOG_DEBUG_F( "ChangeProperty: property = %s, new_value = %s\n", property, new_value );
        if( strlen( property ) == 0 )
        {
            throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "ChangeProperty called with empty property string." );
        }
        if( strlen( new_value ) == 0 )
        {
            throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "ChangeProperty called with empty value string." );
        }
*/
        // Get parent property (remove need for casts)
        IPKeyValueContainer* pProps = parent->GetEventContext()->GetProperties();

        // Check that property exists, except Age_Bins which are special case. We bootstrap individuals into age_bins at t=1,
        // with no prior existing age bin property.
        IPKey key( property );
        if( ( std::string( property ) != "Age_Bin" ) && !pProps->Contains( key ) )
        {
            throw BadMapKeyException( __FILE__, __LINE__, __FUNCTION__, "properties", property );
        }

        IPKeyValue new_kv( property, new_value );

        if( !pProps->Contains( new_kv ) )
        {
            IPKeyValue old_kv = pProps->Get( key );
            LOG_DEBUG_F( "Moving individual (%lu) property %s from %s to %s\n", parent->GetSuid().data, property, old_kv.GetValueAsString().c_str(), new_value );
            parent->UpdateGroupPopulation(-1.0f);
            pProps->Set( new_kv );
            parent->UpdateGroupMembership();
            parent->UpdateGroupPopulation(1.0f);
            parent->SetPropertyReportString("");

            //broadcast that the individual changed properties
            IIndividualEventBroadcaster* broadcaster = parent->GetEventContext()->GetNodeEventContext()->GetIndividualEventBroadcaster();
            LOG_DEBUG_F( "Individual %d changed property, broadcasting PropertyChange \n", parent->GetSuid().data );
            broadcaster->TriggerObservers( parent->GetEventContext(), EventTrigger::PropertyChange );
        }
    }
示例#4
0
    bool
    ReportEventRecorder::notifyOnEvent(
        IIndividualHumanEventContext *context,
        const EventTrigger& trigger
    )
    {
        int         id           = context->GetSuid().data;
        ExternalNodeId_t node_id = context->GetNodeEventContext()->GetExternalId();
        IdmDateTime sim_time     = context->GetNodeEventContext()->GetTime();
        const char* event_name   = trigger.c_str();
        float       age          = context->GetAge();
        const char  gender       = (context->GetGender() == Gender::MALE) ? 'M' : 'F' ;
        bool        infected     = context->IsInfected();
        float       infectious   = context->GetInfectiousness() ;


        GetOutputStream() << GetTime( sim_time ) << ","
                          << node_id             << ","
                          << event_name          << ","
                          << id                  << ","
                          << age                 << ","
                          << gender              << ","
                          << infected            << ","
                          << infectious;

        // Report requested properties
        const auto * pProp = context->GetProperties();

        for (const auto& prop_name : properties_to_report)
        {
            IPKey key( prop_name );
            if( !pProp->Contains( key ) )
            {
                throw BadMapKeyException( __FILE__, __LINE__, __FUNCTION__, "properties", prop_name.c_str() );
            }
            GetOutputStream() << "," << pProp->Get( key ).GetValueAsString();
        }

        GetOutputStream() << GetOtherData( context, trigger );
        GetOutputStream() << std::endl;

        return true ;
    }
    void SimpleTransmissionGroups::GetGroupMembershipForProperties( const RouteList_t& route, const tProperties* properties, TransmissionGroupMembership_t* membershipOut ) const
    {
        (*membershipOut)[0] = GroupIndex(0); // map route 0 to index 0
        std::ostringstream* msg = nullptr;
        if (LOG_LEVEL(DEBUG)) 
        {
            msg = new std::ostringstream();
            *msg << "(fn=GetGroupMembershipForProperties) ";
        }

        for (const auto& entry : (*properties))
        {
            const string& propertyName = entry.first;
            const string& propertyValue = entry.second;

            if (propertyValueToIndexMap.find(propertyName) != propertyValueToIndexMap.end())
            {
                if( propertyValueToIndexMap.at(propertyName).find( propertyValue ) != propertyValueToIndexMap.at(propertyName).end() )
                {
                    (*membershipOut)[0] += propertyValueToIndexMap.at(propertyName).at(propertyValue);
                }
                else
                {
                    throw BadMapKeyException( __FILE__, __LINE__, __FUNCTION__, (std::string("propertyValueToIndexMap[")+propertyName+"]").c_str(), propertyValue.c_str() );
                }
            }
            if (LOG_LEVEL(DEBUG))
            {
                release_assert( msg ); // ensure someone doesn't change logic above so this is not allocated.
                *msg << propertyName << "=" << propertyValue << ", ";
            }
        }
        if (LOG_LEVEL(DEBUG))
        {
            release_assert( msg ); // ensure someone doesn't change logic above so this is not allocated.
            *msg << "=> Group index for route 0 is " << (*membershipOut)[0] << std::endl;
            LOG_DEBUG( msg->str().c_str() );
            delete msg;
        }
    }