Transducer
's behavior is pretty much
opposite to that of Generator
. Figure
4.6(b) shows its state transition
diagram. It has an input port in
and a buffer
Collector
as deque<tmValue*>
to collect
tmValue
s coming in. Transducer
also contains a
destructor called init()
.
class Transducer: public Atomic { protected: InputPort* in; deque<tmValue*> Collector; public: Transducer(const string& name=""): Atomic(name) { CollectStatistics(true); in = AddIP("in"); } virtual ~Transducer() { init(); }
Transducer::init()
clears all clients in Collector
.
Transducer::tau()
returns
all the time so it is
passive.
/*virtual*/ void init() { while(Collector.size()>0) // delete all pv in Collector { tmValue* pv = Collector[0]; Collector.pop_front(); delete pv; } } /*virtual*/ Time tau() const { return DBL_MAX; }
Transducer::delta_x()
castes the input value x.value
to pv
of tmValue
type. It stamps pv
with
(``SysOut'',CurrentTime), and pushes pv
into
Collector
. Since Transducer
is always passive, it
has no output, and so delta_y()
is not needed here;
/*virtual*/ bool delta_x(const PortValue& x) { tmValue* pv = dynamic_cast<tmValue*>(x.value); if(pv) { //-- (event, time) stamping pv->TimeMap.insert(make_pair("SysOut", Devs::TimeCurrent())); Collector.push_back(pv); // delete contents later in int(); }else THROW_DEVS_EXCEPTION("Type casting Failed!"); return false; }
Recall that Transducer
collects incoming tmValue
s
stamped with (``SysIn'',arrival-time) by Generator
,
(``SysOut'',departure-time) by Transducer
. Using these
data, GetPerformance()
of Transducers
returns
{(``Throughput'', value) and (``Average System Time'', value) }
as follows.
tmValue
s in Collector
divided by
the current time.
tmValue
in
Collector
.
Transducer::GetPerformance()
returns these
two indices.
/*virtual*/ map<string, double> GetPerformance() const { map<string, double> statistics; if(m_cs) { string str = "Throughput"; statistics.insert(make_pair(str, Collector.size()/TimeCurrent())); TimeSpan average_st=0; for(int i=0; i<(int)Collector.size(); i++){ tmValue* pv = Collector[i]; TimeSpan system_t = pv->TimeMap["SysOut"] - pv->TimeMap["SysIn"]; average_st += system_t; } average_st = average_st / (double)Collector.size(); str = "Average System Time"; statistics.insert(make_pair(str, average_st)); } return statistics; }