next up previous contents index
Next: Average Queue Length in Up: Practice in DEVS++ Previous: Transducer   Contents   Index


Utilization in DEVS++

Recall that to get Utilization, we need to accumulate the time intervals of piece-wise constant time-segments associated with a state. Accumulating the time intervals can be done using the criterion of either ``as long as possible'' or ``as short as possible''. ``Longer'' is preferred over ``shorter'' because it requires less computational burden.

If we accumulate the time interval in cases

(1)
when the constant segment might change at discrete event points, or
(2)
when the simulation run stops
the ``as long as'' preference might be achieved. For example, in Figure 4.3, times at $ t=$ 5, 20, 23, 28, 30 for case (1) (discrete state transitions) and also at $ t=$ 40 for case (2) (simulation stop time).

DEVS++ calls the following function when_receive_cs for collecting the time interval of a state segment in cases of above (1) and (2).

void Atomic::when_receive_cs() {
    Time dT = TimeCurrent() - t_Lcs;// dT: accumulating time span
    if(CollectStatisticsFlag() == true)
    {
        string state_str = Get_Statistics_s();
        if(m_statistics.find(state_str) == m_statistics.end())
            m_statistics.insert(make_pair(state_str, 0.0));// new entry
        m_statistics[state_str] += dT;//add dT to staying time
    }
    t_Lcs = TimeCurrent(); // update t_Lcs as the current time.
}
The function dercription of when_receive_cs() shows that it records and accumulates the time interval dT from the last time we called when_receive_cs() to the current time if the flag of collecting statistics is true.

We are using m_statistics (defined as map<string, double>) to collect statistics. The key value of piece-wise constant segment will be a string returned from Get_Statistics_s().

If the string of Get_Statistics_s() was not yet registered in m_statistics, the pair(state_str,0.0) will be newly registered in m_statistics where
state_str=Get_Statistics_s(). The value of m_statistics[state_str] is increased by dT. Finally, t_Lcs that is the last time when we calls when_receive_cs() is updated by the current time.

Every time we need to print the current statistics (such as when we use the command print p), DEVS++ shows performance indices by calling each model's overriding GetPerformance(). The default implementation of Atomic:: GetPerformance() is as follows.

/*virtual*/ map<string, double> Atomic::GetPerformance() const {
    map<string, double> statistics;
    if(CollectStatisticsFlag()==true) {
        for(map<string, double>::const_iterator it = m_statistics.begin();
            it != m_statistics.end(); it++)
        {
            double probability = it->second / TimeCurrent();

            if(probability < 0.0 || probability > 1.0) {
                THROW_DEVS_EXCEPTION("Invalid Probability!");
            }
            else
                statistics[it->first] = probability;
        }
    }
    return statistics;
}

As we can see, Atomic::GetPerformance() returns a map<string, double> such that statistics[key] = m_statistics[key]/TimeCurrent().

Thus statistics[key] contains the $ P(C$ =key) of Equation (4.3) over the interval from 0 to the current time.


next up previous contents index
Next: Average Queue Length in Up: Practice in DEVS++ Previous: Transducer   Contents   Index
MHHwang 2007-05-07