示例#1
0
文件: Priority.cs 项目: JUSTIVE/OS-ya
        private void StampProcess(Process p)           //선점 priority에서 프로세스 스탬프 찍어주는 함수
        {
            int     type = isNowInStamp(p, timestamp); //스탬프 어떻게 찍힐지 정함
            Stamp   s;
            int     startpoint = 0, endpoint = 0;
            Process next;

            switch (type)
            {
            case 0:     //프로세스가 중간에 끊기는 경우
                for (int i = 0; i < timestamp.Count; i++)
                {
                    if (p.getArrivalTime() < timestamp[i].getStartTime() && p.getArrivalTime() + p.getBurstTime() > timestamp[i].getStartTime())
                    {
                        startpoint = timestamp[i].getStartTime();
                        endpoint   = timestamp[i].getEndTime();
                        break;
                    }
                }
                int n_burst = p.getBurstTime() - (startpoint - p.getArrivalTime()); //업데이트될 Burst Time

                next = new Process(p.getName(), endpoint, n_burst);                 //다음에 스탬프로 찍어줄 업데이트된 프로세스
                s    = new Stamp(p.getName(), p.getArrivalTime(), startpoint);      //스탬프 쾅쾅

                addStamp(s);
                StampProcess(next);     //순환 호출
                break;

            case 1:         //프로세스가 이미 스탬프가 찍혀있는 범위에 있는 경우
                for (int i = 0; i < timestamp.Count; i++)
                {
                    //가장 먼저 만나는 스탬프의 endpoint를 시작시간으로 설정
                    if (p.getArrivalTime() >= timestamp[i].getStartTime() && p.getArrivalTime() < timestamp[i].getEndTime())
                    {
                        startpoint = timestamp[i].getStartTime();
                        endpoint   = timestamp[i].getEndTime();
                        break;
                    }
                }
                next = new Process(p.getName(), endpoint, p.getBurstTime()); //다음에 스탬프로 찍어줄 업데이트된 프로세스
                StampProcess(next);                                          //순환 호출
                break;

            case 2:         //그냥 찍으면 됨
                int end = p.getArrivalTime() + p.getBurstTime();
                s = new Stamp(p.getName(), p.getArrivalTime(), end);
                addStamp(s);        //스탬프 찍고 순환호출 안하고 끝내면 됩니다
                for (int i = 0; i < inputData.Count; i++)
                {
                    if (inputData[i].getName().Equals(s.getName()))
                    {
                        inputData[i].setEndTime(end);       //끝나는 시간을 설정해줌
                    }
                }
                break;
            }
        }
示例#2
0
 ////////////////////////////여기까지 라디오 버튼 누를때의 이벤트 처리
 public int stmp_compare(Stamp a, Stamp b)
 {
     if (a.getStartTime() > b.getStartTime())
     {
         return(1);
     }
     else if (a.getStartTime() == b.getStartTime())
     {
         return(0);
     }
     else
     {
         return(-1);
     }
 }                                                                                                                                                                       //스탬프의 정렬
示例#3
0
 public int SortStampInTime(Stamp a, Stamp b)//오름차순으로 찍힌 시간순으로 정렬
 {
     if (a.getStartTime() > b.getStartTime())
     {
         return(1);
     }
     else if (a.getStartTime() == b.getStartTime())
     {
         return(0);
     }
     else
     {
         return(-1);
     }
 }
示例#4
0
文件: SRT.cs 项目: JUSTIVE/OS-ya
        public void srt_run()
        {
            int remain = 0, smallest;
            int time;

            int[] remain_times = new int[20];

            for (int i = 0; i < Copy.Count; i++)
            {
                remain_times[i] = Copy[i].getBurstTime();
            }
            remain_times[19] = 999;

            for (time = 0; remain != Copy.Count; time++)
            {
                Console.WriteLine("time = " + time);
                smallest = 19;
                for (int i = 0; i < Copy.Count; i++)
                {
                    if ((Copy[i].getArrivalTime() <= time) && (remain_times[i] < remain_times[smallest]) && (remain_times[i] > 0))
                    {
                        smallest = i;
                    }
                }

                timestamp.Add(new Stamp(inputData[smallest].getName(), time, time + 1));
                remain_times[smallest]--;
                Console.WriteLine("remain:" + remain_times[smallest]);
                if (remain_times[smallest] == 0)
                {
                    remain++;
                    inputData[smallest].setEndTime(time + 1);
                    Console.WriteLine(inputData[smallest].getName() + " " + inputData[smallest].getEndTime());
                }
            }
            //스탬프 합치기
            for (int i = 0; i < timestamp.Count - 1; i++)
            {
                if (timestamp[i].getName().CompareTo(timestamp[i + 1].getName()) == 0)
                {
                    Stamp newStamp = new Stamp(timestamp[i].getName(), timestamp[i].getStartTime(), timestamp[i + 1].getEndTime());
                    timestamp.RemoveAt(i);
                    timestamp.RemoveAt(i);
                    timestamp.Insert(i, newStamp);
                    i--;
                }
            }
        }
示例#5
0
文件: HRN.cs 项目: JUSTIVE/OS-ya
        public void hrn_alg()   //HRN 알고리즘
        {
            int start = 0, end = 0;

            do
            {
                Process_HRN process;

                while (Ready.Count > 0 && Ready.Peek().getArrivalTime() <= currentTime) //도착한 프로세스를 Arrived 리스트로 옮김
                {
                    Arrived.Add(Ready.Dequeue());
                }

                if (Arrived.Count <= 0) //현재 시간에 도착 프로세스가 없는 경우
                {
                    currentTime++;      //현재 시간 1 증가
                    break;
                }

                for (int j = 0; j < Arrived.Count; j++)
                {
                    double p = (currentTime - Arrived[j].getArrivalTime() + Arrived[j].getBurstTime()) / (double)Arrived[j].getBurstTime();
                    Arrived[j].setPriority(p);         //우선순위 계산
                }
                Arrived.Sort(new Comparer_HRN());      //우선순위별로 정렬

                start        = currentTime;            //
                process      = Arrived.First();
                currentTime += process.getBurstTime(); //Burst Time만큼 현재 시간 증가
                end          = currentTime;

                for (int j = 0; j < inputData.Count; j++)
                {
                    if (inputData[j].getName().Equals(process.getName()))
                    {
                        inputData[j].setEndTime(end);   //프로세스 종료 시간 설정
                    }
                }

                Stamp s = new Stamp(process.getName(), start, end);
                addStamp(s);         //스탬프 찍어줌

                Arrived.RemoveAt(0); //제일 처음의 프로세스를 삭제
            } while (Ready.Count > 0 || Arrived.Count > 0);
        }
示例#6
0
 public void addStamp(Stamp stamp)
 {
     timestamp.Add(stamp);
 }
示例#7
0
文件: Priority.cs 项目: JUSTIVE/OS-ya
 private int stamp_compare(Stamp A, Stamp B)               //스탬프 정렬하려고 만듬
 {
     return(A.getStartTime().CompareTo(B.getStartTime())); //starttime 순으로 정렬
 }
示例#8
0
        public void rr_alg()    //라운드로빈 알고리즘
        {
            while (Ready.Count > 0)
            {
                int start = 0, remained = 0, end = 0;

                if (Ready.First().getArrivalTime() <= currentTime) //현재 시간이 도착 시간보다 큰 경우
                {
                    Process p = Ready.First();                     //먼저 큐에서 삭제
                    Ready.RemoveAt(0);
                    if (p.getBurstTime() > quant)                  //BURST 시간이 단위 시간보다 큰 경우
                    {
                        start = currentTime;                       //시작 시간 계산

                        remained = p.getBurstTime() - quant;
                        p.setBurstTime(remained); //남은 BURST 시간 QUANT만큼 줄임
                        currentTime += quant;     //현재 시간을 QUANT만큼 늘림

                        end = currentTime;        //끝 시간 계산

                        //레디큐에 끝나지 않은 프로세스 다시 삽입
                        int i;
                        for (i = 0; i < Ready.Count; i++)
                        {
                            if (Ready[i].getArrivalTime() > currentTime)
                            {
                                Ready.Insert(i, p);
                                break;
                            }
                        }
                        if (i == Ready.Count)
                        {
                            Ready.Add(p);
                        }

                        Stamp s = new Stamp(p.getName(), start, end, remained);
                        addStamp(s); //stamp 추가
                    }
                    else
                    {
                        start        = currentTime;      //시작 시간 계산
                        currentTime += p.getBurstTime(); //BURST 시간만큼 현재 시간 늘림
                        end          = currentTime;      //끝 시간 계산

                        for (int i = 0; i < inputData.Count; i++)
                        {
                            if (inputData[i].getName().Equals(p.getName()))
                            {
                                inputData[i].setEndTime(currentTime); //실행시킨 데이터의 종료 시간 설정
                                break;
                            }
                        }
                        Stamp s = new Stamp(p.getName(), start, end);
                        addStamp(s); //stamp 추가
                    }
                }
                else   //현재 실행 가능한 프로세스가 없는 경우
                {
                    currentTime++;
                }
            }
        }