Exemplo n.º 1
0
        public void populate()
        {
            listbar = new LoadBar2[Numpro];
            prolist = new ProcessRR[Numpro];
            double mean   = (double)(Max + Min) / (double)2;
            double stdDev = (double)(Max - Min) / (double)6;

            for (int i = 0; i < Numpro; i++)

            {
                prolist[i]     = new ProcessRR();
                prolist[i].Num = i;
                if (ran == true)
                {
                    prolist[i].Arrival = Normal(mean, stdDev, Max, Min);
                    prolist[i].Burst   = Normal(mean, stdDev, Max, Min);
                }
                else
                {
                    prolist[i].Arrival = 0;
                    prolist[i].Burst   = 1;
                }
                flowLayoutPanel1.Controls.Add(prolist[i]);
            }
        }
Exemplo n.º 2
0
        private void prostart(ProcessRR p1)
        {
            ProcessRR k = new ProcessRR();

            k = p1;

            listbar[p1.Num]     = new LoadBar2();
            listbar[p1.Num].Max = k.Burst;
            listbar[p1.Num].setMax();
            Label k1 = new Label();
            Label k2 = new Label();

            k1.Text = "P" + p1.Num.ToString();
            k2.Text = "Start Time " + p1.Start.ToString();
            int i = tableLayoutPanel1.ColumnCount++;

            tableLayoutPanel1.Controls.Add(k1, i - 1, 0);
            tableLayoutPanel1.Controls.Add(listbar[p1.Num].b1, i - 1, 1);
            tableLayoutPanel1.Controls.Add(k2, i - 1, 2);
            k.proStart();
            listbar[p1.Num].proStart();
        }
Exemplo n.º 3
0
        private void Sched()
        {
            simulate = new Queue <int>();
            time     = new Queue <int>();
            dosched  = new ProcessRR[Numpro];

            for (int i = 0; i < Numpro; i++)
            {
                dosched[i]         = new ProcessRR();
                dosched[i].Arrival = prolist[i].Arrival;
                dosched[i].Burst   = prolist[i].Burst;
                dosched[i].Num     = i;
            }

            quantum = Convert.ToInt32(txtQuantum.Text.Trim());


            int total_Turnaround = 0;
            int total_WaitT      = 0;

            //string la = "";
            //for (int i = 0; i < Numpro; i++)
            //{
            //    la += prolist[i].End.ToString() + "-" + prolist[i].Num + " ";
            //}
            //MessageBox.Show(la);
            for (int k = 0; k < Numpro; k++)
            {
                for (int i = k + 1; i < Numpro; i++)
                {
                    if (dosched[k].Arrival > dosched[i].Arrival || ((dosched[i].Arrival == dosched[k].Arrival) && (dosched[k].Num > dosched[i].Num)))
                    {
                        ProcessRR temp = new ProcessRR();
                        temp       = dosched[i];
                        dosched[i] = dosched[k];
                        dosched[k] = temp;
                    }
                }
            }
            int[] burst_remaining = new int[Numpro];
            for (int i = 0; i < Numpro; i++)
            {
                burst_remaining[i] = dosched[i].Burst;
            }
            int idx;

            time.Enqueue(dosched[0].Arrival);
            Queue <int> q            = new Queue <int>();
            int         current_time = 0;

            q.Enqueue(0);
            simulate.Enqueue(dosched[0].Num);
            int completed = 0;

            int[] mark = new int[Numpro];

            mark[0] = 1;
            while (completed != Numpro)
            {
                idx = q.Dequeue();


                if (burst_remaining[idx] == dosched[idx].Burst)
                {
                    if (current_time > dosched[idx].Arrival)
                    {
                        dosched[idx].Start = current_time;
                    }
                    else
                    {
                        dosched[idx].Start = dosched[idx].Arrival;
                    }
                    //dosched[idx].Start = max(current_time, dosched[idx].Arrival);

                    current_time = dosched[idx].Start;
                }


                if (burst_remaining[idx] - quantum > 0)
                {
                    burst_remaining[idx] -= quantum;
                    current_time         += quantum;
                }

                else
                {
                    current_time        += burst_remaining[idx];
                    burst_remaining[idx] = 0;
                    completed++;

                    dosched[idx].End = current_time;

                    dosched[idx].Turnaround = dosched[idx].End - dosched[idx].Arrival;
                    dosched[idx].WaitT      = dosched[idx].Turnaround - dosched[idx].Burst;


                    total_Turnaround += dosched[idx].Turnaround;
                    total_WaitT      += dosched[idx].WaitT;
                }
                time.Enqueue(current_time);
                for (int i = 1; i < Numpro; i++)
                {
                    if (burst_remaining[i] > 0 && dosched[i].Arrival <= current_time && mark[i] == 0)
                    {
                        q.Enqueue(i);
                        simulate.Enqueue(dosched[i].Num);
                        mark[i] = 1;
                    }
                }

                if (burst_remaining[idx] > 0)
                {
                    q.Enqueue(idx);
                    simulate.Enqueue(dosched[idx].Num);
                }

                if (q.Count() == 0)
                {
                    for (int i = 1; i < Numpro; i++)
                    {
                        if (burst_remaining[i] > 0)
                        {
                            q.Enqueue(i);
                            simulate.Enqueue(dosched[i].Num);
                            mark[i] = 1;
                            break;
                        }
                    }
                }
            }
            avg_Turnaround = Math.Round((double)total_Turnaround / (double)Numpro, 2);
            avg_WaitT      = Math.Round((double)total_WaitT / (double)Numpro, 2);

            for (int i = 0; i < Numpro; i++)
            {
                for (int k = 0; k < Numpro; k++)
                {
                    if (dosched[i].Num == prolist[k].Num)
                    {
                        prolist[k].End   = dosched[i].End;
                        prolist[k].Start = dosched[i].Start;
                        prolist[k].WaitT = dosched[i].WaitT;
                    }
                }
            }

            //MessageBox.Show(la);
        }
Exemplo n.º 4
0
 private void proresume(ProcessRR p1)
 {
     p1.proStart();
     listbar[p1.Num].proStart();
 }
Exemplo n.º 5
0
 private void prostop(ProcessRR p1)
 {
     p1.proStop();
     listbar[p1.Num].proStop();
 }