Esempio n. 1
0
    public static CompoundResult S_Priority(this ShProcess_Col Collection)
    {
        CompoundResult c_result = default;
        var            t_col    = Collection;
        var            duration = t_col.GetEndtime();

        t_col.Sort(EDataType.ArrivalTime);

        for (int i = 0; i <= duration;)
        {
            var A_list = t_col.shProcesses.GetProcessesWith(EDataType.ArrivalTime, i).PSort(EDataType.Priority).ToIndex(t_col.shProcesses);
            if (A_list != null)
            {
                foreach (var indx in A_list)
                {
                    t_col.shProcesses[indx].result.StartTime = i;
                    i = t_col.shProcesses[indx].result.EndTime = i + t_col.shProcesses[indx].info.Burst;
                    t_col.shProcesses[indx].ignore = true;
                }
            }
            else
            {
                i += 1;
            }
        }

        t_col.Calculate();
        c_result.cmpd_shProcesses = t_col;
        c_result.BuildGraphicsData_NP();
        return(c_result);
    }
Esempio n. 2
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (dataGridView1.Rows.Count <= 0)
            {
                return;
            }
            List <ShProcess> _procList = new List <ShProcess>();

            try{
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    Info info = new Info($"{dataGridView1[0, i].Value}",
                                         int.Parse(dataGridView1[1, i].Value.ToString()),
                                         int.Parse(dataGridView1[2, i].Value.ToString()),
                                         int.Parse(dataGridView1[3, i].Value.ToString()));
                    _procList.Add(new ShProcess(info, new Result(), false));
                }
            }
            catch
            {
                MessageBox.Show("Please input Valid Data Values");
            }


            shProcess_Col.shProcesses = _procList.ToArray();


            if (CheckDataInput())
            {
                switch (eScheduling)
                {
                case EScheduling.FCFS:
                    _Result = shProcess_Col.S_FCFS();
                    break;

                case EScheduling.SJF:
                    _Result = shProcess_Col.S_SJF();
                    break;

                case EScheduling.SRT:
                    _Result = shProcess_Col.S_SRTF();
                    break;

                case EScheduling.Priority_P:
                    _Result = shProcess_Col.S_Ppriority();
                    break;

                case EScheduling.Priority_NP:
                    _Result = shProcess_Col.S_Priority();
                    break;

                case EScheduling.RR:
                    _Result = shProcess_Col.S_RR(int.Parse(textBox1.Text));
                    break;
                }
                SolveTable(ref _Result);
                panel1.Refresh();
            }
        }
Esempio n. 3
0
 private void SolveTable(ref CompoundResult _Result)
 {
     for (int i = 0; i < dataGridView1.Rows.Count; i++)
     {
         var proc = _Result.cmpd_shProcesses.shProcesses.ToList().Find(p => p.info.Name == dataGridView1[0, i].Value.ToString());
         dataGridView1[4, i].Value = proc.result.Waitingtime;//response Time
         dataGridView1[5, i].Value = proc.result.TurnaroundTime;
     }
     RPavg.Text  = _Result.cmpd_shProcesses.Average_WaitingTime.ToString();
     TaTavg.Text = _Result.cmpd_shProcesses.Average_TurnArounTime.ToString();
 }
Esempio n. 4
0
    public static CompoundResult S_SRTF(this ShProcess_Col collection)
    {
        List <GraphicsData> graphicsDatas = new List <GraphicsData>();
        CompoundResult      result        = default;
        var t_col    = collection;
        var duration = t_col.GetEndtime();

        t_col.Sort(EDataType.ArrivalTime);

        ExtendedResult[]  extendedResults = new ExtendedResult[256];
        IEnumerable <int> A_list;

        int    elements = -1;// -1 empty
        string prevProc = "";

        for (int i = 0; i < duration;)
        {
            A_list = t_col.shProcesses.GetProcessesWith(EDataType.ArrivalTime, i).PSort(EDataType.BurstTime).ToIndex(t_col.shProcesses);
            if (A_list != null)
            {
                if (prevProc == t_col.shProcesses[A_list.FirstOrDefault()].info.Name)
                {
                    extendedResults[elements] = new ExtendedResult(t_col.shProcesses[A_list.FirstOrDefault()].info.Name,
                                                                   new Result(0, 0, extendedResults[elements].result.StartTime, i = i + 1));
                    t_col.shProcesses[A_list.FirstOrDefault()].info.Burst -= 1;
                }
                else
                {
                    ++elements;
                    extendedResults[elements] = new ExtendedResult(t_col.shProcesses[A_list.FirstOrDefault()].info.Name,
                                                                   new Result(0, 0, i, i = i + 1));
                    t_col.shProcesses[A_list.FirstOrDefault()].info.Burst -= 1;
                }
                prevProc = t_col.shProcesses[A_list.FirstOrDefault()].info.Name;
            }
            else
            {
                i += 1;
            }
            t_col.CleanUp();
        }
        extendedResults = extendedResults.Where(x => x.name != null).ToArray();
        t_col.ExtendedCalculate(extendedResults);
        result.cmpd_shProcesses     = t_col;
        result.cmpd_GetGraphicsData = extendedResults.EResultToGraphicsData();
        return(result);
    }
Esempio n. 5
0
    public static CompoundResult S_RR(this ShProcess_Col collection, int Quantum)
    {
        List <GraphicsData> graphicsDatas = new List <GraphicsData>();
        CompoundResult      result        = default;
        var t_col    = collection;
        var duration = t_col.GetEndtime();

        t_col.Sort(EDataType.ArrivalTime);

        ExtendedResult[]  extendedResults = new ExtendedResult[256];
        IEnumerable <int> A_list;

        int elements = -1;// -1 empty

        Queue <int> indexes = new Queue <int>();

        for (int i = 0; i < duration;)
        {
            A_list = t_col.shProcesses.GetProcessesWith(EDataType.ArrivalTime, i).ToIndex(t_col.shProcesses);
            if (A_list != null)
            {
                foreach (var v in A_list)
                {
                    if (!indexes.Contains(v))
                    {
                        indexes.Enqueue(v);
                    }
                }


                if (indexes != null)
                {
                    ++elements;
                    if (t_col.shProcesses[indexes.FirstOrDefault()].info.Burst >= Quantum)
                    {
                        extendedResults[elements] = new ExtendedResult(t_col.shProcesses[indexes.FirstOrDefault()].info.Name,
                                                                       new Result(0, 0, i, i = i + 1));
                        t_col.shProcesses[indexes.FirstOrDefault()].info.Burst -= 1;

                        for (int y = 1; y < Quantum; y++)
                        {
                            extendedResults[elements] = new ExtendedResult(t_col.shProcesses[indexes.FirstOrDefault()].info.Name,
                                                                           new Result(0, 0, extendedResults[elements].result.StartTime, i = i + y));
                            t_col.shProcesses[indexes.FirstOrDefault()].info.Burst -= 1;
                        }

                        if (indexes.Count() == 1)
                        {
                            t_col.CleanUp();
                            A_list = t_col.shProcesses.GetProcessesWith(EDataType.ArrivalTime, i).ToIndex(t_col.shProcesses);
                            if (A_list != null)
                            {
                                foreach (var v in A_list)
                                {
                                    if (!indexes.Contains(v))
                                    {
                                        indexes.Enqueue(v);
                                    }
                                }
                                indexes.Enqueue(indexes.Dequeue());
                            }
                            else
                            {
                                indexes.Dequeue();
                            }
                        }
                        else if (t_col.shProcesses[indexes.FirstOrDefault()].info.Burst != 0)
                        {
                            A_list = t_col.shProcesses.GetProcessesWith(EDataType.ArrivalTime, i).ToIndex(t_col.shProcesses);
                            if (A_list != null)
                            {
                                foreach (var v in A_list)
                                {
                                    if (!indexes.Contains(v))
                                    {
                                        indexes.Enqueue(v);
                                    }
                                }
                                indexes.Enqueue(indexes.Dequeue());
                            }
                        }
                        else if (t_col.shProcesses[indexes.FirstOrDefault()].info.Burst == 0)
                        {
                            indexes.Dequeue();
                        }
                        t_col.CleanUp();
                    }
                    else
                    {
                        extendedResults[elements] = new ExtendedResult(t_col.shProcesses[indexes.FirstOrDefault()].info.Name,
                                                                       new Result(0, 0, i, i = i + 1));
                        t_col.shProcesses[indexes.FirstOrDefault()].info.Burst -= 1;
                        indexes.Dequeue();
                    }
                }
            }
            else
            {
                i += 1;
            }
            t_col.CleanUp();
        }
        extendedResults = extendedResults.Where(x => x.name != null).ToArray();
        t_col.ExtendedCalculate(extendedResults);
        result.cmpd_shProcesses     = t_col;
        result.cmpd_GetGraphicsData = extendedResults.EResultToGraphicsData();
        return(result);
    }