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).
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
=key
) of
Equation (4.3) over the interval from 0 to the
current time.