Exemplo 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);
    }
Exemplo n.º 2
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);
    }
Exemplo n.º 3
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);
    }