Esempio n. 1
0
        private void DoSimulation(int m, int a, int R0, double pi1, double pi2)
        {
            Generator gen = new Generator(a, m, R0);
            int       taskCount = 0, doneTaskCount = 0, deletedTaskCount = 0;
            int       inputStatus = 2, queueStatus = 0, channel1Status = 0, channel2Status = 0;
            int       queueLengthSum = 0;

            for (var i = 1; i <= ticksCount; i++)
            {
                if (channel2Status == 1)      // if channel #2 has a task
                {                             // then check
                    if (gen.GetNext() <= pi2) // if event will happen
                    {                         // if happens then
                        doneTaskCount++;      // increase done task counter
                        channel2Status = 0;   // and make channel free
                    }
                }

                if (channel1Status == 1)         // if channel #2 has a task
                {                                // then check
                    if (gen.GetNext() <= pi1)    // if event will happen
                    {                            // if happens then
                        channel1Status = 0;      // and make channel free
                        if (channel2Status == 0) //check if channel #2 is free
                        {                        // if it's free
                            channel2Status = 1;  // put task in channel #2 and make it busy
                        }
                        else                     // if channel #2 is busy
                        {
                            deletedTaskCount++;  // then delete task and increase deleted task counter
                        }
                    }
                }

                if (queueStatus > 0)
                {
                    if (channel1Status == 0)
                    {
                        channel1Status = 1;
                        queueStatus--;
                    }
                }

                if (inputStatus == 1)
                {
                    taskCount++;
                    if (channel1Status == 0)
                    {
                        channel1Status = 1;
                    }
                    else
                    {
                        if (queueStatus < 2)
                        {
                            queueStatus++;
                        }
                        else
                        {
                            deletedTaskCount++;
                        }
                    }
                }

                queueLengthSum += queueStatus;

                if (inputStatus == 2)
                {
                    inputStatus = 1;
                }
                else
                {
                    inputStatus = 2;
                }
            }

            PLabel.Text = ((double)deletedTaskCount / (deletedTaskCount + doneTaskCount)).ToString();
            ALabel.Text = ((double)doneTaskCount / ticksCount).ToString();
            LLabel.Text = ((double)queueLengthSum / ticksCount).ToString();
        }