next up previous contents index
Next: Transducer Up: Throughput and System Time Previous: Job   Contents   Index

Generator

The class Generator in DEVSsharp/ModelBase/Generator.cs produces jobs depending on (1) autonomous mode, (2) generating delay pdf, and (3) producing job spectrum.

If Generator's bool m_bAutonomous filed is true then Generator keeps producing at Work phase, while it is false then Generator will be waiting for an external pull signal through the input port, ips as shown in Figure 4.6(b).

The generating time delay at Work phase of Generator can be determined by an random variable rv of a given pdf, m_PDFofInterGenerating.

The job spectrum can be determined by a PMF in which the probability of each job class is described. For more detail information for the class of PVofPMF, revisit to Section 2.4. The following codes show the interface ports, and internal data fields. Here int m_no_gen is used for tracking the job id which will be unique during a simulation run.

    public class Generator: Atomic
    {
        public OutputPort oout;//-- output port for job
        public InputPort ips;//-- pull signal port
        bool m_bAutonomous; // automatic or manual
        RVofPMF<Job> m_JobSpectrum; //-- Job Spectrum
        RVofPDF m_PDFofInterGenerating; // pdf of inter-generating time
        int m_no_gen; //-- to no of generating: used for job.id

        enum PHASE { Wait, Work }
        PHASE m_phase;

The constructor of Generator needs five arguments: (1) name as a string, (2) TimeUnit tu, (3) bool auto indicating autonomous or non-autonomous which is assign to the internal variable m_bAutonomous, (4) InterGenerating PDF as RVofPDF, and (5) Job spectrum as RVofPMF<Job> as follows.

    public Generator(string name, TimeUnit tu, bool auto, RVofPDF InterGenerating,
                     RVofPMF<Job> JobSelection):base(name,tu){...}

Generator::init() resets m_no_gen to zero. m_phase is set to Work if m_bAutonomous is true, otherwise, it is set to Wait. If m_JobSpectrum is not null m_statistics is initialized by each type of job available in m_JobSpectrum. m_statistics of Generator will collect statistics how may jobs have been produced.

    public override void init()
    {
        m_no_gen = 0; //
        if (m_bAutonomous)
            m_phase = PHASE.Work;
        else
            m_phase = PHASE.Wait;

        if (m_JobSpectrum != null)
        {
            foreach (Job job in m_JobSpectrum.pmf.Keys)
                m_statistics.Add(job.type.ToString(), 0.0);
        }
    }

When the phase of Generator is Work, Generator::tau() returns a random value from the pdf m_PDFofInterGenerating(which is set through the constructor function of Generator). If Generator's phase is Wait, it returns the infinity as the lifespan of Wait.

    public override double tau()
    {
        if (m_phase == PHASE.Work)
        {
            double t = m_PDFofInterGenerating.RN();
            return t;
        }else // PHASE.Wait
            return double.MaxValue;
    }

Generator::detla_x() treats the situation that Generator is non-autonomous, and it receives the pull signal through ips port when it waits for the signal. Otherwise, Generator ignores any input signal.

    public override bool delta_x(PortValue x)
    {
        if (m_bAutonomous == false && x.port == ips &&
            m_phase == PHASE.Wait)
        {
            m_phase = PHASE.Work;
            return true;
        }
        return false;
    }

In Generator::detla_y(), Generator has a non-trivial m_JobSpectrum , Generator picks one job by calling m_JobSpectrum.SampleV() and clones the picked job to clnt. The unique job id for clnt is assigned. At this time, Generator stamps the current time into clnt's TimeMap with its key value as the string ``SysIn''. This event time will be used when collecting System Time Performance Index by Transducer that we will look through later.

To collect of how many different jobs are generated, Generator accumulates the number of jobs generated with respect to their job types.

After generating a job (or null job) through oout port, if Generator is non-autonomous, it goes back to the phase Wait, otherwise it keep generating the next job by staying its phase Work.

    public override void delta_y(ref PortValue y)
    {
        if (m_JobSpectrum != null && m_JobSpectrum.pmf.Count > 0)
        {
            Job clnt = (m_JobSpectrum.SampleV()).Clone();
            clnt.id = ++m_no_gen;
            //-- (event, time) stamping
            clnt.TimeMap.Add("SysIn", Devs.TimeCurrent);
            y.Set(oout, clnt);

            m_statistics[clnt.type.ToString()] += 1;
        }
        else // no job value sent
            y.Set(oout);

        if (m_bActive == false)
            m_phase = PHASE.Wait;
    }


next up previous contents index
Next: Transducer Up: Throughput and System Time Previous: Job   Contents   Index
MHHwang 2007-05-08