Пример #1
0
        private void Add_Click(object sender, EventArgs e)
        {
            Delete.Enabled         = true;
            SchedulingType.Enabled = false;
            Preemtion.Enabled      = false;
            RoundTimeBox.Enabled   = false;
            Run.Enabled            = true;
            if (id == 1)
            {
                T.Columns.Add("PID", typeof(int));
                T.Columns.Add("Arrival Time", typeof(float));
                T.Columns.Add("Burst Time", typeof(float));
                T.Columns.Add("Priority", typeof(int));
                dataGridView1.Height += 21;
            }
            if (Priority.Checked == true)
            {
                T.Rows.Add(id, ArrivalTime.Value, BurstTime.Value, PriorityInput.Value);
            }
            else
            {
                T.Rows.Add(id, ArrivalTime.Value, BurstTime.Value);
            }
            dataGridView1.Height    += 21;
            dataGridView1.DataSource = T;
            process p = new process(id, (float)ArrivalTime.Value, (float)BurstTime.Value, (int)PriorityInput.Value);

            Global.inputs.Add(p);
            id++;
        }
Пример #2
0
        public void RRCalculate()
        {
            float sliceTime = (float)RoundTime.Value;
            int   size      = Global.inputs.Count;

            Global.inputs.Sort();
            float           Time           = 0f;
            float           waitingTime    = 0f;
            float           turnAroundTime = 0f;
            Queue <process> QP             = new Queue <process>(50);

            while ((Global.inputs.Count != 0) || (QP.Count != 0))
            {
                while (Global.inputs.Count != 0)
                {
                    float t = 0f;
                    if ((QP.Count == 0) && (Global.inputs[0].arrivalTime > Time))
                    {
                        Global.intervals.Add(new interval(Time, Global.inputs[0].arrivalTime));
                        Global.ids.Add(-1);
                        Time = Global.inputs[0].arrivalTime;
                    }
                    if (QP.Count != 0)
                    {
                        t = Math.Min(sliceTime, QP.Peek().timeLeft);
                    }
                    if (Global.inputs[0].arrivalTime > (Time + t))
                    {
                        break;
                    }
                    else
                    {
                        QP.Enqueue(Global.inputs[0]);
                        Global.inputs.RemoveAt(0);
                    }
                }

                process p = QP.Dequeue();
                if (p.timeLeft <= sliceTime)
                {
                    Global.intervals.Add(new interval(Time, Time + p.timeLeft));
                    Global.ids.Add(p.id);
                    Time           += p.timeLeft;
                    waitingTime    += (Time - p.arrivalTime - p.burstTime);
                    turnAroundTime += (Time - p.arrivalTime);
                }
                else
                {
                    p.timeLeft -= sliceTime;
                    Global.intervals.Add(new interval(Time, Time + sliceTime));
                    Global.ids.Add(p.id);
                    Time += sliceTime;
                    QP.Enqueue(p);
                }
            }
            Print();
            AvgWaitingTime.Text    = (waitingTime / (float)size).ToString();
            AvgTurnAroundTime.Text = (turnAroundTime / (float)size).ToString();
        }
Пример #3
0
 private static int burstTimeCompare(process a, process b)
 {
     return(a.burstTime.CompareTo(b.burstTime));
 }