Exemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("test output debug bos");
            using (var fileStream = File.OpenRead(textBox1.Text.ToString()))
                using (StreamReader sr = new StreamReader(fileStream))
                {
                    String line;

                    while ((line = sr.ReadLine()) != null)
                    {
                        List <String> items   = new List <string>(line.Split(' '));
                        Process       process = new Process(
                            Int32.Parse(items[0]),
                            Int32.Parse(items[1]),
                            Int32.Parse(items[2]),
                            Int32.Parse(items[3]),
                            Int32.Parse(items[4]),
                            Int32.Parse(items[5])
                            );
                        bfp.Add(process);
                    }

                    fifo = new FIFO(bfp);
                    rr   = new RR(bfp);
                    sjf  = new SJF(bfp);
                }
        }
Exemplo n.º 2
0
    void ThreSJF()
    {
        ProcessCompare compare = new ProcessCompare();
        List <Process> li      = new List <Process>(creationController.GetItens().ToArray());

        li.Sort(compare);
        sjf = SJF.Schedulering(li, progressRR);

        waitTimeSJF      = Benchmark.WaitTime(sjf, li.Count);
        turnarondTimeSJF = Benchmark.TurnarondTime(sjf, li);
        responseTimeSJF  = Benchmark.ResponseTime(sjf, li);

        Application.Invoke((sender, e) => OnSelectScheduler(SchedulerCombobox, e));
    }
Exemplo n.º 3
0
            protected override void HandleEvent(ModelEventArgs args)
            {
                bool   isDelete  = false;
                String outString = Model.tickNumber.ToString();
                /* Selecting of first process with the shortest readiness time or equal to it  */
                int i                = 0;
                int minLength        = -1;
                int minProcNumber    = -1;
                int minReadinessTime = -1;

                for (i = 0; i < Model.waitProcesses.Count; i++)
                {
                    if (Model.waitProcesses[i].readinessTime <= Model.tickNumber)
                    {
                        minLength        = Model.waitProcesses[i].requiredAmount;
                        minProcNumber    = i;
                        minReadinessTime = Model.waitProcesses[i].readinessTime;
                        break;
                    }
                }

                if (minLength != -1)
                {
                    /* Selecting of process with minimal length and equal or less readiness time */
                    for (int j = i + 1; j < Model.waitProcesses.Count; j++)
                    {
                        /* Process is ready */
                        if (Model.waitProcesses[j].readinessTime <= Model.tickNumber)
                        {
                            if (Model.waitProcesses[j].requiredAmount < minLength)
                            {
                                minLength        = Model.waitProcesses[j].requiredAmount;
                                minProcNumber    = j;
                                minReadinessTime = Model.waitProcesses[j].readinessTime;
                            }
                            else if ((Model.waitProcesses[j].requiredAmount == minLength && Model.waitProcesses[j].readinessTime < minReadinessTime))
                            {
                                minLength        = Model.waitProcesses[j].requiredAmount;
                                minProcNumber    = j;
                                minReadinessTime = Model.waitProcesses[i].readinessTime;
                            }
                        }
                    }

                    /*  */
                    for (int j = 0; j < Model.waitProcesses.Count; j++)
                    {
                        if (Model.waitProcesses[j].readinessTime <= Model.tickNumber)
                        {
                            if ((Model.waitProcesses[j].requiredAmount == minLength && Model.waitProcesses[j].readinessTime < minReadinessTime))
                            {
                                minLength        = Model.waitProcesses[j].requiredAmount;
                                minProcNumber    = j;
                                minReadinessTime = Model.waitProcesses[j].readinessTime;
                            }
                        }
                    }

                    /* [waitProcess] is not empty */
                    if (Model.waitProcesses.Count != 0)
                    {
                        /* Printing base tracing */
                        for (int j = 0; j < Model.processes.Count; j++)
                        {
                            bool isProcess        = false;
                            bool isBlockedProcess = false;
                            for (int k = 0; k < Model.waitProcesses.Count; k++)
                            {
                                /* There is current process from [waitProcesses] in [processes] */
                                if (Model.processes[j].number == Model.waitProcesses[k].number)
                                {
                                    /* Current process is ready */
                                    if (Model.waitProcesses[k].readinessTime <= Model.tickNumber)
                                    {
                                        /* Current process has minimal length */
                                        if (j == Model.waitProcesses[minProcNumber].number - 1)
                                        {
                                            outString += " В";
                                            isProcess  = true;
                                            Model.sjfExecTime++;
                                            break;
                                        }
                                        /* Current process does not have minimal length */
                                        else
                                        {
                                            outString += " Г";
                                            Model.sjfWaitTime++;
                                            isProcess = true;
                                            break;
                                        }
                                    }
                                    /* Current process is not ready */
                                    else
                                    {
                                        isBlockedProcess = true;
                                        isProcess        = true;
                                    }
                                }
                            }

                            /* Current process is blocked */
                            if (isBlockedProcess)
                            {
                                outString += " Б";
                            }

                            /* [waitProcesses] does not have current process */
                            if (!isProcess)
                            {
                                // -
                                outString += " Б";
                            }
                        }
                        Model.Tracer.AnyTrace(outString);
                    }

                    Model.waitProcesses[minProcNumber].requiredAmount--;
                    /* One of the processes ended */
                    if (Model.waitProcesses[minProcNumber].requiredAmount == 0)
                    {
                        isDelete = true;
                        Model.waitProcesses.RemoveAt(minProcNumber);
                        Model.NCP++;
                        //Random rand = new Random();
                        //int index = rand.Next(0, Model.processes.Count);

                        /* Adding new process */
                        if (Model.allSjfProcesses.Count > 0)
                        {
                            for (int k = 0; k < Model.allSjfProcesses.Count; k++)
                            {
                                bool isProcessWithCurrentNumber = false;
                                for (int j = 0; j < Model.waitProcesses.Count; j++)
                                {
                                    if (Model.waitProcesses[j].number == Model.allSjfProcesses[k].number)
                                    {
                                        isProcessWithCurrentNumber = true;
                                        break;
                                    }
                                }

                                if (!isProcessWithCurrentNumber)
                                {
                                    Model.waitProcesses.Add(new Process(Model.allSjfProcesses[k].number,
                                                                        Model.allSjfProcesses[k].readinessTime,
                                                                        Model.allSjfProcesses[k].requiredAmount,
                                                                        Model.allSjfProcesses[k].priority));
                                    Model.allSjfProcesses.RemoveAt(k);
                                    break;
                                }
                            }
                        }
                    }
                }
                /* [waitProcess] does not have ready process */
                else
                {
                    List <bool> isProcesses = new List <bool>();
                    for (int j = 0; j < Model.waitProcesses.Count; j++)
                    {
                        for (int k = 0; k < Model.waitProcesses.Count; k++)
                        {
                            if (j == Model.waitProcesses[k].number - 1)
                            {
                                isProcesses.Add(true);
                            }
                        }

                        if (isProcesses.Count < j + 1)
                        {
                            isProcesses.Add(false);
                        }
                    }

                    for (int j = 0; j < Model.waitProcesses.Count; j++)
                    {
                        if (isProcesses[j])
                        {
                            outString += " Б";
                        }
                        else
                        {
                            // -
                            outString += " Б";
                        }
                    }

                    Model.Tracer.AnyTrace(outString);
                }

                String[] elems1 = outString.Split();
                String[] elems2;
                if (Model.sjfTrace.Count != 0)
                {
                    elems2 = Model.sjfTrace[Model.sjfTrace.Count - 1].Split();
                    Model.Tracer.AnyTrace(outString + "\n" + elems2.Length);
                    for (int j = 1; j < elems2.Length; j++)
                    {
                        if (Model.newProcess || Model.sjfTrace.Count == 0 || elems1[j] != elems2[j])
                        {
                            Model.sjfTrace.Add(outString);
                            break;
                        }
                    }
                }
                else
                {
                    Model.sjfTrace.Add(outString);
                }

                Model.newProcess = isDelete;

                /* Printing queue */
                for (int k = 0; k < Model.waitProcesses.Count; k++)
                {
                    Model.Tracer.AnyTrace(Model.waitProcesses[k].number + " " + Model.waitProcesses[k].readinessTime + " " + Model.waitProcesses[k].requiredAmount);
                }

                Model.tickNumber++;

                /* All processes did not end */
                if (Model.NCP < Model.maxNCP)
                {
                    var ev = new SJF();
                    Model.PlanEvent(ev, 1.0);
                    Model.Tracer.AnyTrace("");
                }
                /* End of program */
                else
                {
                    if (outString != Model.fifoTrace[Model.fifoTrace.Count - 1])
                    {
                        Model.sjfTrace.Add(outString);
                    }
                    PrintShortTrace();
                    Model.isFinish = true;
                }
            }
Exemplo n.º 4
0
            protected override void HandleEvent(ModelEventArgs args)
            {
                String outString = "";
                int    count     = 0;

                /* Adding processes in [QFIFO] */
                while (Model.QFIFO.Count < Model.processes.Count && Model.allProcesses.Count > 0)
                {
                    for (int i = 0; i < Model.allProcesses.Count; i++)
                    {
                        if (Model.allProcesses[i].readinessTime <= Model.tickNumber)
                        {
                            bool isProcessWithCurrentNumber = false;

                            for (int j = 0; j < Model.QFIFO.Count; j++)
                            {
                                if (Model.allProcesses[i].number == Model.QFIFO[j].number)
                                {
                                    isProcessWithCurrentNumber = true;
                                    break;
                                }
                            }

                            if (!isProcessWithCurrentNumber)
                            {
                                Model.QFIFO.Add(new Process(Model.allProcesses[i].number,
                                                            /*Model.tickNumber + */ Model.allProcesses[i].readinessTime,
                                                            Model.allProcesses[i].requiredAmount,
                                                            Model.allProcesses[i].priority));
                                Model.allProcesses.RemoveAt(i);
                                break;
                            }
                        }
                    }

                    count++;
                    if (count == 3)
                    {
                        break;
                    }
                }


                Model.Tracer.AnyTrace("123");

                /* Queue is not empty */
                if (Model.QFIFO.Count != 0)
                {
                    //Model.newProcess = true;
                    /* Printing of base tracing */
                    outString = Model.tickNumber.ToString();
                    for (int i = 0; i < Model.processes.Count; i++)
                    {
                        bool isProcess = false;
                        for (int j = 0; j < Model.QFIFO.Count; j++)
                        {
                            /* Process is ready */
                            if (Model.QFIFO[j].readinessTime <= Model.tickNumber)
                            {
                                /* Process found in [QFIFO] */
                                if (Model.processes[i].number == Model.QFIFO[j].number)
                                {
                                    /* Process is first in [QFIFO] */
                                    if (j == 0)
                                    {
                                        isProcess  = true;
                                        outString += " В";
                                        Model.fifoExecTime++;
                                        break;
                                    }
                                    /* Process is not first in [QFIFO] */
                                    else
                                    {
                                        isProcess  = true;
                                        outString += " Г";
                                        Model.fifoWaitTime++;
                                        break;
                                    }
                                }
                            }
                            /* Process is not ready */
                            else
                            {
                                isProcess  = true;
                                outString += " Б";
                                break;
                            }
                        }
                        /* Process is not found in [QFIFO] */
                        if (!isProcess)
                        {
                            // -
                            outString += " Б";
                        }
                    }

                    Model.Tracer.AnyTrace(outString);
                    String[] elems1 = outString.Split();
                    String[] elems2;
                    if (Model.fifoTrace.Count != 0)
                    {
                        elems2 = Model.fifoTrace[Model.fifoTrace.Count - 1].Split();
                        Model.Tracer.AnyTrace(outString + "\n" + elems2.Length);
                        for (int i = 1; i < elems2.Length; i++)
                        {
                            if (Model.newProcess || Model.fifoTrace.Count == 0 || elems1[i] != elems2[i] || Model.tickNumber == 0)
                            {
                                Model.fifoTrace.Add(outString);
                                break;
                            }
                        }
                    }
                    else
                    {
                        Model.fifoTrace.Add(outString);
                    }

                    //if (!Model.newProcess && (outString) != Model.fifoTrace[Model.fifoTrace.Count - 1] || Model.fifoTrace.Count == 0)
                    //{
                    //    Model.fifoTrace.Add(outString);
                    //}
                    /* Adding expected process in queue */
                    //Model.Tracer.AnyTrace("Такт №" + Model.measureNumber);
                    //int j = 0;
                    //if (Model.allProcesses.Count > 0)
                    //{
                    //    while (j < Model.allProcesses.Count)
                    //    {
                    //        if (Model.allProcesses[j].readinessTime <= Model.measureNumber)
                    //        {
                    //            Model.Tracer.AnyTrace("Процесс №" + (Model.allProcesses[j].number) + " добавлен в очередь" +
                    //                                  " " + (Model.allProcesses[j].readinessTime) + " " + (Model.allProcesses[j].requiredAmount));

                    //            Model.QFIFO.Add(
                    //            new Process(Model.allProcesses[j].number,
                    //                        Model.allProcesses[j].readinessTime,
                    //                        Model.allProcesses[j].requiredAmount,
                    //                        Model.allProcesses[j].priority));
                    //            Model.allProcesses.RemoveAt(j);

                    //            j--;
                    //        }
                    //        j++;
                    //    }
                    //}


                    /* Process is ready */
                    if (Model.QFIFO[0].readinessTime <= Model.tickNumber)
                    {
                        Model.QFIFO[0].requiredAmount--;

                        if (Model.QFIFO[0].requiredAmount == 0)
                        {
                            Model.newProcess = true;
                        }
                        else
                        {
                            Model.newProcess = false;
                        }

                        /* First process is completed */
                        if (Model.QFIFO[0].requiredAmount == 0)
                        {
                            Model.QFIFO.RemoveAt(0);
                            Model.NCP++;

                            //if (Model.allProcesses.Count > 0)
                            //{
                            //    Random rand = new Random();
                            //    int index = rand.Next(0, Model.processes.Count);

                            //    //Model.Tracer.AnyTrace("GПроцесс №" + (Model.processes[index].number) + " добавлен в очередь" +
                            //    //" " + (Model.processes[index].readinessTime) + " " + (Model.processes[index].requiredAmount));

                            //    Model.waitProcesses.Add(new Process(Model.allProcesses[index].number,
                            //                                        Model.measureNumber + Model.allProcesses[index].readinessTime,
                            //                                        Model.allProcesses[index].requiredAmount,
                            //                                        Model.allProcesses[index].priority));

                            //    //Model.waitProcesses.Last().readinessTime = Model.measureNumber + Model.processes[index].readinessTime;
                            //}
                        }
                    }

                    /* Printing queue */
                    for (int i = 0; i < Model.QFIFO.Count; i++)
                    {
                        Model.Tracer.AnyTrace(Model.QFIFO[i].number + " " + Model.QFIFO[i].readinessTime + " " + Model.QFIFO[i].requiredAmount);
                    }
                }
                else
                {
                    if (Model.fifoTrace.Count != 0)
                    {
                        String[] parts = Model.fifoTrace[Model.fifoTrace.Count - 1].Split();
                        String   tmp   = "";
                        for (int i = 1; i < parts.Length; i++)
                        {
                            tmp += " " + parts[i];
                        }

                        if (tmp != " Б Б Б")
                        {
                            Model.fifoTrace.Add(Model.tickNumber.ToString() + " Б Б Б");
                        }
                    }
                    else
                    {
                        Model.fifoTrace.Add(Model.tickNumber.ToString() + " Б Б Б");
                    }
                }

                Model.tickNumber++;

                /* All processes did not end */
                if (Model.NCP < Model.maxNCP)
                {
                    var ev = new FIFO();
                    Model.PlanEvent(ev, 1.0);
                    //Model.Tracer.PlanEventTrace(ev);
                    Model.Tracer.AnyTrace("");
                }
                /* All processes ended; transition to SJF */
                else
                {
                    if (outString != Model.fifoTrace[Model.fifoTrace.Count - 1])
                    {
                        Model.fifoTrace.Add(outString);
                    }
                    var ev = new SJF();
                    Model.PlanEvent(ev, 1.0);
                    Model.Tracer.AnyTrace("\n// SJF //\n");

                    /* Cleaning of variables */
                    Model.waitProcesses.Clear();
                    Model.fifoTickNumber = Model.tickNumber;
                    Model.tickNumber     = 0;
                    Model.NCP            = 0;

                    /* Initializing of processes start list for SJF */
                    foreach (Process process in Model.processes)
                    {
                        Model.waitProcesses.Add(new Process(process.number,
                                                            process.readinessTime,
                                                            process.requiredAmount,
                                                            process.priority));
                    }
                }
            }
Exemplo n.º 5
0
 // Start is called before the first frame update
 void Start()
 {
     sceneController = GameObject.FindGameObjectWithTag("GameController").GetComponent <SJF>();
 }
Exemplo n.º 6
0
        private void running()
        {
            int time_quantum = Convert.ToInt32(lfMenu.sliderTimequantum.Value);
            //data = get_data();        // 얕은 복사 실행(이 코드에선 사용금지)
            List <ProcessData> tmp = GenericCopier <List <ProcessData> > .DeepCopy(get_data());    // 깊은 복사 실행

            if (!checkValues(tmp))
            {
                MessageBox.Show("테이블 값의 범위는 우선순위 0~9, 나머지는 1~30 이어야 합니다.\n확인 후 다시 작업을 요청하십시오.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            List <ProcessData> data_fcfs = GenericCopier <List <ProcessData> > .DeepCopy(tmp);   // 깊은 복사 실행

            List <ProcessData> data_sjf = GenericCopier <List <ProcessData> > .DeepCopy(tmp);    // 깊은 복사 실행

            List <ProcessData> data_srt = GenericCopier <List <ProcessData> > .DeepCopy(tmp);    // 깊은 복사 실행

            List <ProcessData> data_hrn = GenericCopier <List <ProcessData> > .DeepCopy(tmp);    // 깊은 복사 실행

            List <ProcessData> data_prio = GenericCopier <List <ProcessData> > .DeepCopy(tmp);   // 깊은 복사 실행

            List <ProcessData> data_rrb = GenericCopier <List <ProcessData> > .DeepCopy(tmp);    // 깊은 복사 실행

            fcfs = new FCFS(data_fcfs);
            sjf  = new SJF(data_sjf);
            srt  = new SRT(data_srt);
            hrn  = new HRN(data_hrn);
            prio = new Priority(data_prio);
            rrb  = new RoundRobin(data_rrb, time_quantum);

            List <ProcessData> temp;

            switch (select_flag)
            {
            case ( int )proc.FCFS:
                temp = fcfs.working();
                sjf.working(); srt.working(); hrn.working();
                prio.working(); rrb.working();
                calc_time(fcfs.get_wait_time(), fcfs.get_return_time());
                break;

            case ( int )proc.SJF:
                temp = sjf.working();
                fcfs.working(); srt.working();
                hrn.working(); prio.working(); rrb.working();
                calc_time(sjf.get_wait_time(), sjf.get_return_time());
                break;

            case ( int )proc.SRT:
                temp = srt.working();
                fcfs.working(); sjf.working();
                hrn.working(); prio.working(); rrb.working();
                calc_time(srt.get_wait_time(), srt.get_return_time());
                break;

            case ( int )proc.HRN:
                temp = hrn.working();
                fcfs.working(); sjf.working(); srt.working();
                prio.working(); rrb.working();
                calc_time(hrn.get_wait_time(), hrn.get_return_time());
                break;

            case ( int )proc.PRIORITY:
                temp = prio.working();
                fcfs.working(); sjf.working(); srt.working();
                hrn.working(); rrb.working();
                calc_time(prio.get_wait_time(), prio.get_return_time());
                break;

            case ( int )proc.ROUNDROBIN:
                temp = rrb.working();
                fcfs.working(); sjf.working(); srt.working();
                hrn.working(); prio.working();
                calc_time(rrb.get_wait_time(), rrb.get_return_time());
                break;

            default:
                MessageBox.Show("올바르지 않은 접근입니다.\n확인 후 다시 작업을 요청하십시오.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            wait_time[( int )proc.FCFS - 1]       = Convert.ToDouble(string.Format("{0:#0.00}", fcfs.avg_wait()));
            wait_time[( int )proc.SJF - 1]        = Convert.ToDouble(string.Format("{0:#0.00}", sjf.avg_wait()));
            wait_time[( int )proc.SRT - 1]        = Convert.ToDouble(string.Format("{0:#0.00}", srt.avg_wait()));
            wait_time[( int )proc.HRN - 1]        = Convert.ToDouble(string.Format("{0:#0.00}", hrn.avg_wait()));
            wait_time[( int )proc.PRIORITY - 1]   = Convert.ToDouble(string.Format("{0:#0.00}", prio.avg_wait()));
            wait_time[( int )proc.ROUNDROBIN - 1] = Convert.ToDouble(string.Format("{0:#0.00}", rrb.avg_wait()));

            return_time[( int )proc.FCFS - 1]       = Convert.ToDouble(string.Format("{0:#0.00}", fcfs.avg_return()));
            return_time[( int )proc.SJF - 1]        = Convert.ToDouble(string.Format("{0:#0.00}", sjf.avg_return()));
            return_time[( int )proc.SRT - 1]        = Convert.ToDouble(string.Format("{0:#0.00}", srt.avg_return()));
            return_time[( int )proc.HRN - 1]        = Convert.ToDouble(string.Format("{0:#0.00}", hrn.avg_return()));
            return_time[( int )proc.PRIORITY - 1]   = Convert.ToDouble(string.Format("{0:#0.00}", prio.avg_return()));
            return_time[( int )proc.ROUNDROBIN - 1] = Convert.ToDouble(string.Format("{0:#0.00}", rrb.avg_return()));

            ProcessUpdate(temp);
            WaitUpdate();
            ReturnUpdate();
        }