Exemple #1
0
 /* pid 순 정렬, 차트용 */
 private static int Follow_Default(ProcessData A, ProcessData B)
 {
     if (Convert.ToInt32(A.pid) < Convert.ToInt32(B.pid))
     {
         return(-1);
     }
     return(1);
 }
Exemple #2
0
 /* 우선순위 정렬 */
 private static int Follow_Priority(ProcessData A, ProcessData B)
 {
     if (Convert.ToInt32(A.priority) >= Convert.ToInt32(B.priority))
     {
         return(-1);
     }
     return(1);
 }
Exemple #3
0
 /* 도착 시간 정렬 */
 private static int Follow_Initialize(ProcessData A, ProcessData B)
 {
     if (Convert.ToInt32(A.arrived_time) < Convert.ToInt32(B.arrived_time))
     {
         return(-1);
     }
     return(1);
 }
Exemple #4
0
 /* 서비스 시간 정렬 */
 private static int Follow_SRT(ProcessData A, ProcessData B)
 {
     if (Convert.ToInt32(A.service_time) < Convert.ToInt32(B.service_time))
     {
         return(-1);
     }
     if ((Convert.ToInt32(A.service_time) == Convert.ToInt32(B.service_time)) &&
         (Convert.ToInt32(A.pid) < Convert.ToInt32(B.pid)))
     {
         return(-1);
     }
     return(1);
 }
        public List <ProcessData> working()
        {
            if (estimate_data.Count == 0)
            {
                List <ProcessData> ready_queue = new List <ProcessData>();

                int limit = data.Sum(item => Convert.ToInt32(item.arrived_time)) + data.Sum(item => Convert.ToInt32(item.service_time));

                init();

                for (int time = 0, pos = 0; time < limit; time++)
                {
                    // 첫 구동시 Ready Queue 등록(첫 구동에만 동작)
                    if (ready_queue.Count == 0)
                    {
                        for (int i = 0; i < data.Count; i++)
                        {
                            if (Convert.ToInt32(data[i].arrived_time) == time)
                            {
                                ready_queue.Add(data[i]);
                            }
                        }
                    }

                    if (ready_queue.Count > 0)
                    {
                        estimate_data.Add(new ProcessData(new string[]
                        {
                            ready_queue[0].no,
                            ready_queue[0].pid,
                            ready_queue[0].priority,
                            "" + time,
                            "" + Common.JOB
                        }));

                        ready_queue[0].service_time = "" + (Convert.ToInt32(ready_queue[0].service_time) - Common.JOB);

                        /* 프로세스 시간 */
                        for (int idx = 0; idx < ready_queue.Count; idx++)
                        {
                            if (ready_queue[idx].pid == estimate_data[estimate_data.Count - 1].pid)
                            {
                                return_data[Convert.ToInt32(ready_queue[idx].pid) - Common.START_PID]++;
                            }
                            else
                            {
                                delay_data[Convert.ToInt32(ready_queue[idx].pid) - Common.START_PID]++;
                                return_data[Convert.ToInt32(ready_queue[idx].pid) - Common.START_PID]++;
                            }
                        }

                        // 해당 time 에 도착한 프로세스 등록
                        for (int i = 0; i < data.Count; i++)
                        {
                            if (Convert.ToInt32(data[i].arrived_time) == (time + 1))
                            {
                                ready_queue.Add(data[i]);
                            }
                        }

                        // End job
                        if (Convert.ToInt32(ready_queue[0].service_time) < 1)
                        {
                            ready_queue.RemoveAt(0);
                            pos = 0;
                        }

                        // Time out
                        else if (pos++ % time_slice == (time_slice - 1))
                        {
                            ProcessData tmp = ready_queue[0];
                            ready_queue.RemoveAt(0);
                            ready_queue.Add(tmp);
                        }
                    }
                }
            }

            return(estimate_data);
        }
Exemple #6
0
        public List <ProcessData> working()
        {
            if (estimate_data.Count == 0)
            {
                int working_ps_no = -1;

                List <ProcessData> ready_queue = new List <ProcessData>();

                int limit = data.Sum(item => Convert.ToInt32(item.arrived_time)) + data.Sum(item => Convert.ToInt32(item.service_time));

                init();

                for (int time = 0, pos = 0; time < limit; time++)
                {
                    // 첫 구동시 Ready Queue 등록(첫 구동에만 동작)
                    if (ready_queue.Count == 0)
                    {
                        for (int i = 0; i < data.Count; i++)
                        {
                            if (Convert.ToInt32(data[i].arrived_time) == time)
                            {
                                ready_queue.Add(data[i]);
                            }
                        }
                    }

                    if (ready_queue.Count > 0)
                    {
                        estimate_data.Add(new ProcessData(new string[]
                        {
                            ready_queue[0].no,
                            ready_queue[0].pid,
                            ready_queue[0].priority,
                            "" + time,
                            "" + Common.JOB
                        }));

                        // 대기시간 계산
                        if (working_ps_no != Convert.ToInt32(ready_queue[0].no))
                        {
                            delay_data[Convert.ToInt32(ready_queue[0].pid) - Common.START_PID] = (time - Convert.ToInt32(data[Convert.ToInt32(ready_queue[0].no) - 1].arrived_time) - return_data[Convert.ToInt32(ready_queue[0].no) - 1]);
                        }
                        // 반환시간 계산
                        return_data[Convert.ToInt32(ready_queue[0].pid) - Common.START_PID] += Common.JOB;

                        ready_queue[0].service_time = "" + (Convert.ToInt32(ready_queue[0].service_time) - Common.JOB);

                        // 대기 시간 구하기 위한 flag
                        working_ps_no = Convert.ToInt32(ready_queue[0].no);


                        // 해당 time 에 도착한 프로세스 등록
                        for (int i = 0; i < data.Count; i++)
                        {
                            if (Convert.ToInt32(data[i].arrived_time) == (time + 1))
                            {
                                ready_queue.Add(data[i]);
                            }
                        }

                        // End job
                        if (Convert.ToInt32(ready_queue[0].service_time) < 1)
                        {
                            ready_queue.RemoveAt(0);
                            pos = 0;
                        }

                        // Time out
                        else if (pos++ % time_slice == (time_slice - 1))
                        {
                            ProcessData tmp = ready_queue[0];
                            ready_queue.RemoveAt(0);
                            ready_queue.Add(tmp);
                        }
                    }
                }
            }

            return(estimate_data);

            //foreach (var i in estimate_data)    Console.WriteLine(i.no + "\t" + i.pid + "\t" + i.priority + "\t" + i.arrived_time + "\t" + i.service_time);
        }