日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

模拟FCFS调度算法(先来先服务)没错,是篇好文章!

發布時間:2024/10/5 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 模拟FCFS调度算法(先来先服务)没错,是篇好文章! 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 一、FCFS的介紹
  • 二、代碼演示
  • 三、代碼分析
    • 1.使用節點模擬進程
    • 2.SimulateFCFS(核心模擬FCFS類)
    • 3.創建一個節點為n的隊列(模擬就緒隊列)
    • 4.核心計算分析
    • 5.輸入到達時間和服務時間(模擬進程到達和服務)
    • 6.出隊列(模擬完成所有進程工作)


一、FCFS的介紹

先來先服務的調度算法:最簡單的調度算法,既可以用于作業調度 ,也可以用于程序調度,當作業調度中采用該算法時,系統將按照作業到達的先后次序來進行調度,優先從后備隊列中,選擇一個或多個位于隊列頭部的作業,把他們調入內存,分配所需資源、創建進程,然后放入“就緒隊列”,直到該進程運行到完成或發生某事件堵塞后,進程調度程序才將處理機分配給其他進程。

簡單了說就是如同名字 “先來先服務” ;

二、代碼演示

package com.zsh.blog;import java.util.Scanner;/*** @author:抱著魚睡覺的喵喵* @date:2021/3/19* @description:*/ public class SimulateSystem {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);SimulateFCFS simulateFCFS = new SimulateFCFS();boolean flag = true;char at = ' ';System.out.println("a:Simulate multiple processes to form a queue");System.out.println("b:Assign a process to the queue");System.out.println("d:Complete all process work");System.out.println("e:Exit the simulated system");while (flag) {System.out.println("Please enter your instructions:");at = scanner.next().charAt(0);switch (at) {case 'a':simulateFCFS.createQueue();break;case 'b':simulateFCFS.assignProcess();break;case 'd':simulateFCFS.finishAllProcessTask();return;case 'e':System.out.println("Simulated is end~");return;default:System.out.println("Your input is wrong, please re-enter!");break;}}}}class Queue {int arrTime; //timeOfArrivalint serviceTime; //timeOfServiceint finishTime; //timeOfComplishint turnTime; //timeOfTurnarounddouble weightTurnTime; //timeOfWeightTurnaroundString processName; //process numberQueue next;public Queue(int arrTime, int serviceTime, String processName) {this.arrTime = arrTime;this.serviceTime = serviceTime;this.processName = processName;}public Queue() {} }/*** Simulate FCFS algorithm class*/ class SimulateFCFS {private Queue head = new Queue(-1, -1, null);private int timer = 0;private Queue tail = head;public void createQueue() {Queue arr = null;Queue temp = head;Scanner scanner = new Scanner(System.in);System.out.printf("Please enter the number of process tasks to initialize the simulation:");int n = scanner.nextInt();for (int i = 1; i <= n; i++) {System.out.printf("Please enter the process number, start time, and service time of the %d process:",i);arr = new Queue();keyBordInput(arr, scanner);calTime(arr);temp.next = arr;temp = arr;}this.tail = arr;System.out.println("Simulation allocation is successful!");}/*** Completion time of calculation process - Turnaround time - Weighted turnaround time* @param arr*/public void calTime(Queue arr) {Queue temp = arr;if (this.timer < temp.arrTime) {this.timer = arr.arrTime;} else {if (timer == 0) {this.timer = temp.arrTime;}}temp.finishTime = temp.serviceTime + this.timer;temp.turnTime = temp.finishTime - temp.arrTime;temp.weightTurnTime = (temp.turnTime * 1.0) / (temp.serviceTime * 1.0);this.timer += temp.serviceTime;}/*** Process number,arrival time,service time entered from the keyboard* @param arr* @param scanner*/public void keyBordInput(Queue arr, Scanner scanner) {arr.processName = scanner.next();arr.arrTime = scanner.nextInt();arr.serviceTime = scanner.nextInt();}/*** Assign a process to the queue*/public void assignProcess() {Queue newProcess = new Queue();Scanner scanner = new Scanner(System.in);System.out.printf("Please enter the add process number,start time,and service time of the process:");keyBordInput(newProcess, scanner);calTime(newProcess);this.tail.next = newProcess;this.tail = newProcess;}/*** Complish a task of process from the queue*/ // public void finishProcessTask() { // Queue workingProcess = head; // // }/*** Complish all task of process from the queue*/public void finishAllProcessTask() {if (isEmpty()) {return;}Queue cur = head.next;System.out.println("Process number========Arrive time======Service time=======finish Time=======Turn time======WeightTurn time");while (true) {System.out.printf("\t\t%s\t\t\t\t%d\t\t\t\t\t%d\t\t\t\t\t%d\t\t\t\t%d\t\t\t\t%f",cur.processName,cur.arrTime,cur.serviceTime,cur.finishTime,cur.turnTime,cur.weightTurnTime);System.out.println();if (cur.next == null) {break;}cur = cur.next;}}public boolean isEmpty() {if (head.next == null) {System.out.println("Queue is null!");return true;}return false;} }

三、代碼分析


1.使用節點模擬進程

因為需要計算完成時間、周轉時間、帶權周轉時間,所以需要事先給出每個進程到達時間和服務時間

模擬時至少需要以下幾個屬性(Queue類對象模擬進程)

class Queue {int arrTime; //timeOfArrivalint serviceTime; //timeOfServiceint finishTime; //timeOfComplishint turnTime; //timeOfTurnarounddouble weightTurnTime; //timeOfWeightTurnaroundString processName; //process numberQueue next;public Queue(int arrTime, int serviceTime, String processName) {this.arrTime = arrTime;this.serviceTime = serviceTime;this.processName = processName;}public Queue() {} }

2.SimulateFCFS(核心模擬FCFS類)




以下分析核心模擬類

3.創建一個節點為n的隊列(模擬就緒隊列)

public void createQueue() {Queue arr = null;Queue temp = head; Scanner scanner = new Scanner(System.in);System.out.printf("Please enter the number of process tasks to initialize the simulation:");int n = scanner.nextInt(); //創建節點數為n的隊列for (int i = 1; i <= n; i++) {System.out.printf("Please enter the process number, start time, and service time of the %d process:",i);arr = new Queue();keyBordInput(arr, scanner);//這個自定義的函數主要用來輸入進程的到達時間和服務時間calTime(arr); //該自定義函數用來計算完成時間、周轉時間、帶權周轉時間temp.next = arr;temp = arr; //進行節點連接}this.tail = arr;System.out.println("Simulation allocation is successful!");}

4.核心計算分析

(如果是第一個進程) 完成時間 = 服務時間 + 到達時間


如果是n>1的進程就要考慮前面進程所花費的時間和該進程到達時間的長短問題。如果前面所花費的完成時間大于該進程的到達進程,則(完成時間 = 服務時間+上一個進程的完成時間)
反之則是 (完成時間= 服務時間+到達時間)

//timer是全局變量,用來計算完成時間(解決上面的問題) public void calTime(Queue arr) {Queue temp = arr;if (this.timer < temp.arrTime) {this.timer = arr.arrTime;} else {if (timer == 0) {this.timer = temp.arrTime;}}temp.finishTime = temp.serviceTime + this.timer;temp.turnTime = temp.finishTime - temp.arrTime;temp.weightTurnTime = (temp.turnTime * 1.0) / (temp.serviceTime * 1.0);this.timer += temp.serviceTime;}

5.輸入到達時間和服務時間(模擬進程到達和服務)

public void keyBordInput(Queue arr, Scanner scanner) {arr.processName = scanner.next();arr.arrTime = scanner.nextInt();arr.serviceTime = scanner.nextInt();}

6.出隊列(模擬完成所有進程工作)

public void finishAllProcessTask() {if (isEmpty()) {return;}Queue cur = head.next;System.out.println("Process number========Arrive time======Service time=======finish Time=======Turn time======WeightTurn time");while (true) {System.out.printf("\t\t%s\t\t\t\t%d\t\t\t\t\t%d\t\t\t\t\t%d\t\t\t\t%d\t\t\t\t%f",cur.processName,cur.arrTime,cur.serviceTime,cur.finishTime,cur.turnTime,cur.weightTurnTime);System.out.println();if (cur.next == null) {break;}cur = cur.next;}}

總結

以上是生活随笔為你收集整理的模拟FCFS调度算法(先来先服务)没错,是篇好文章!的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 91午夜理伦私人影院 | 射精一区二区 | 久久激情综合网 | 91黑人精品一区二区三区 | 伊人网视频在线观看 | 麻豆短视频 | 欧美一级一级 | 老司机一区 | 亚洲一区精品在线 | 久久久久久久久91 | 九九视频在线免费观看 | 视频一区二区三区精品 | 亚日韩| 一级片视频免费 | 国产精品99久久免费黑人人妻 | 男人手机天堂 | 捆绑调教在线观看 | 视频在线观看一区 | 影音先锋黄色网址 | 春日野结衣av | 在线播放一级片 | 国内自拍青青草 | 亚洲黄色短视频 | 毛片基地站 | 久久久久久国产精品三级玉女聊斋 | 国产精品久久久久久久久免费软件 | 亚洲欧美日韩国产精品 | 日日干日日插 | 精品国产乱码久久久久久蜜臀 | 国产精选网站 | 高清不卡一区二区三区 | 欧美你懂的| 澳门av网站| 国产欧美视频一区二区三区 | 韩日精品中文字幕 | 国产三级全黄裸体 | 亚洲精品一 | 99草在线视频 | caoporn超碰97| 扩阴视频 | 黄色网页入口 | 大白屁股一区二区视频 | 中文字幕7 | 超黄网站在线观看 | 久久亚洲一区二区 | 亚洲精品小说 | 69xx欧美| 极品尤物魔鬼身材啪啪仙踪林 | 老太婆av| 国产成人无码aa精品一区 | 欧美自拍色图 | 国产女人叫床高潮大片免费 | 在线看片成人 | 五月婷视频 | 久久久青 | 古装做爰无遮挡三级聊斋艳谭 | 香蕉视频污在线观看 | 熟妇人妻无乱码中文字幕真矢织江 | 乱色熟女综合一区二区三区 | www久久久久 | 国产精品自拍合集 | 国产又粗又猛又爽又黄的视频一 | 久久国产亚洲 | 欧美精品日韩精品 | 美女被草网站 | 久久精品国产久精国产 | 中文字幕在线视频第一页 | 强睡邻居人妻中文字幕 | 久久手机免费视频 | 最新中文字幕在线播放 | 成人精品久久久午夜福利 | 国产激情久久久 | 两性视频久久 | 夜色一区| 超碰2021| 色妞网站 | 国产精品伦一区二区三区 | 亚洲精选一区二区 | 久久久噜噜噜www成人 | 国产91综合 | 老牛嫩草二区三区观影体验 | 欧美美女一区二区三区 | 正在播放国产精品 | 久久精品免费在线 | 国产精品久久久久久亚洲影视 | 欧美aaa视频 | 手机在线观看av | 成人国产网站 | 欧美日本综合 | 日韩综合一区 | 亚洲午夜电影网 | 国产丝袜精品视频 | 伊人蕉久影院 | 综合一区| 亚洲国产高清在线 | 日韩第四页 | 久久精品中文 | 久久久久久久久99精品 | wwww在线观看|