Ejemplo n.º 1
0
        private void SJFProcess_Preemptive()
        {
            List <int>         keys       = new List <int>();
            List <Job_Queue>   watingList = new List <Job_Queue>();
            List <printedList> PList      = new List <printedList>();
            int time = 0;

            // int count = 1;

            foreach (var item in Map.Keys)
            {
                keys.Add(item);
            }
            printedList pl = new printedList();

            for (int i = 0; i <= keys[keys.Count - 1]; i++)
            {
                if (Map.ContainsKey(i))
                {
                    watingList.AddRange(Map[i]);
                    watingList.Sort(new Short_Sort());
                }
                if (i == 0)
                {
                    pl.name     = watingList[i].name;
                    pl.duration = i + 1;
                }
                else
                {
                    if (pl.name == watingList[0].name)
                    {
                        pl.duration += 1;
                    }
                    else
                    {
                        PList.Add(pl);
                        pl.name     = watingList[0].name;
                        pl.duration = i + 1;
                    }
                }
                watingList[0].burstTime -= 1;
                if (watingList[0].burstTime == 0)
                {
                    watingList.RemoveAt(0);
                }
            }

            foreach (var i in PList)
            {
                table.Rows.Add(i.name, i.duration);
            }

            time = keys[keys.Count - 1] + 1;
            watingList.Sort(new Short_Sort());
            foreach (var job in watingList)
            {
                table.Rows.Add(job.name, time += job.burstTime);
            }

            DGV_QUEUES.DataSource = table;
            DGV_QUEUES.Update();
            DGV_QUEUES.Refresh();
        }
Ejemplo n.º 2
0
        private void PrProcess_Preemptive()
        {
            int                watingTime = 0; float avaregeTime = 0;
            List <int>         keys       = new List <int>();
            List <Job_Queue>   watingList = new List <Job_Queue>();
            List <printedList> PList      = new List <printedList>();
            int                time       = 0;

            // int count = 1;

            foreach (var item in Map.Keys)
            {
                keys.Add(item);
            }
            printedList pl = new printedList();

            for (int i = 0; i <= keys[keys.Count - 1]; i++)
            {
                if (Map.ContainsKey(i))
                {
                    watingList.AddRange(Map[i]);
                    watingList.Sort(new Priority_Sort());
                }
                // watingTime += time - watingList[0].arrivalTime;
                if (i == 0)
                {
                    pl.name     = watingList[i].name;
                    pl.duration = i + 1;
                }
                else
                {
                    if (pl.name == watingList[0].name)
                    {
                        pl.duration += 1;
                    }
                    else
                    {
                        PList.Add(pl);
                        watingTime += pl.duration - watingList[0].arrivalTime;
                        pl.name     = watingList[0].name;
                        pl.duration = i + 1;
                    }
                }
                watingList[0].burstTime -= 1;
                if (watingList[0].burstTime == 0)
                {
                    watingList.RemoveAt(0);
                }
            }

            foreach (var i in PList)
            {
                table.Rows.Add(i.name, i.duration);
            }

            time = keys[keys.Count - 1] + 1;
            watingList.Sort(new Priority_Sort());
            foreach (var job in watingList)
            {
                watingTime += time - job.arrivalTime;
                table.Rows.Add(job.name, time += job.burstTime);
            }
            avaregeTime           = (float)watingTime / JobDataList.Count;
            av_text.Text          = avaregeTime.ToString();
            DGV_QUEUES.DataSource = table;
            DGV_QUEUES.Update();
            DGV_QUEUES.Refresh();
        }