next up previous contents index
Next: Client-Server System Up: Practice in DEVS++ Previous: Utilization in DEVS++   Contents   Index


Average Queue Length in DEVS++

The class Buffer in Ex_ClientServer shows how to collect the average queue length. The default implementation of Get_Statistics_s() at Atomic is to return Get_s(). However, Buffer overrides the Get_Statistics_s() such that it returns the number of jobs waiting in a buffer as follows.

    /*virtual*/ string Get_Statistics_s() const
    {
        char tmp[10]; sprintf(tmp, "%d",(int)m_Clients.size());
        return string(tmp); // length Only
    }

The class Buffer inherits Atomic::when_receive_cs() shown in the previous section. But it overrides GetPerformance() function as follows.

    /*virtual*/ map<string, double> Buffer::GetPerformance() const
    {
        map<string, double> statistics;
        if(CollectStatisticsFlag()==true) {
            TimeSpan E_i=0;// expectation of queue length
            for(map<string, double>::const_iterator it = m_statistics.begin();
                it != m_statistics.end(); it++)
            {
                double probability=it->second/TimeCurrent(); // P(i)

                if(probability < 0.0 || probability > 1.0) {
                    THROW_DEVS_EXCEPTION("Invalid Probability!");
                }
                else{
                    int i = atoi(it->first.data());
                    E_i += probability * i;// E(i)=\Sum_{i} i * P(i)
                }
            }
            string str = "Average Q length: ";
            statistics.insert(make_pair(str, E_i));
        }
        return statistics;
    }
It makes $ P(C$ =i) using m_statistics[i]. Then it makes $ E(C)$ by summing over i*$ P$ (i) for all i as defined in Equation (4.7).



MHHwang 2007-05-07