If we accumulate the time interval in cases
DEVS# calls the following function when_receive_cs for
collecting the time interval of a state segment in cases of above
(1) and (2).
public override void when_receive_cs()
{
double dT = TimeCurrent - TimeLastcs;// dT: accumulating time span
if (CollectStatisticsFlag())
{
string state_str = Get_Statistics_s();
if (m_statistics.ContainsKey(state_str)==false)
m_statistics.Add(state_str, 0.0); // add new entry
m_statistics[state_str] += dT;
}
TimeLastcs = TimeCurrent;
}
The function description 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
Dictionary<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.
public virtual Dictionary<string, double> GetPerformance()
{
Dictionary<string, double> statistics = new Dictionary<string,double>();
if(CollectStatisticsFlag()==true) {
foreach(string str in m_statistics.Keys)
{
double probability = m_statistics[str] / Devs.TimeCurrent;
if(probability < 0.0 || probability > 1.0)
throw new Exception("Invalid Probability!");
else
statistics[str] = probability;
}
}
return statistics;
}
As we can see, Atomic::GetPerformance() returns a
Dictionary<string, double> such that statistics[key]
= m_statistics[key]/TimeCurrent.
Thus statistics[key] contains the
=key) of
Equation (4.3) over the interval from 0 to the
current time.