日韩性视频-久久久蜜桃-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调度算法(先来先服务)没错,是篇好文章!的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 在线观看国产欧美 | 久久久久综合 | 激情天堂网 | 国产精品国产三级国产Av车上的 | 夜夜骑av | 免费日本黄色网址 | 恶虐女帝安卓汉化版最新版本 | 欧美国产日韩在线 | 国产一毛片 | 国产精品国产三级国产aⅴ中文 | 夜夜天天拍拍 | 久久久久久亚洲中文字幕无码 | 99re在线| 偷拍亚洲精品 | 成人天堂噜噜噜 | 日本黄色不卡视频 | 久久久亚洲成人 | 欧美亚洲视频一区 | 成人精品在线 | 精品日韩在线视频 | 国产激情二区 | 亚洲国产成人va在线观看天堂 | 亚洲人妻一区二区三区 | 日本一区二区三区欧美 | 天天综合天天综合 | 一本大道一区二区 | 国产稀缺精品盗摄盗拍 | 天天干天天操天天插 | 日日摸日日碰夜夜爽av | 91成人在线免费 | 色宗合 | 午夜久久久久久久 | 粉嫩av | 日批网站在线观看 | 亚洲情人网 | 久草视频免费在线观看 | 奇米精品一区二区三区四区 | 波多野结衣电车痴汉 | 一级黄色片在线免费观看 | 久久图库 | 麻豆亚洲av成人无码久久精品 | 久久男人av | 日本三级吃奶头添泬无码苍井空 | 好看的中文字幕电影 | 五月激情网站 | 超碰在线9 | 亚洲精品一区二区三区四区乱码 | 黄片一区二区 | 免费看成人啪啪 | 午夜小视频免费 | 欧美 亚洲 激情 一区 | videos麻豆 | 国产h片在线观看 | 黄色av网址大全 | 很色的网站 | www黄在线观看 | 男女啪啪免费网站 | 怡红院成人影院 | 欧美老熟妇乱大交xxxxx | 日本免费不卡 | 色中色在线视频 | 天天澡天天狠天天天做 | 成人精品久久久午夜福利 | 欧美一级欧美三级 | 四虎影视永久免费 | 毛片哪里看 | 亚洲综合激情另类小说区 | 成人精品福利视频 | 春色激情 | 日韩一区二区三区精品 | 性生交大片免费看3p | 黄色观看网站 | 天天爱天天干天天操 | 国产美女永久无遮挡 | 亚洲精品高清视频在线观看 | 激情五月婷婷综合网 | 亚洲卡一卡二 | 人人草人人干 | 国产精品丝袜黑色高跟鞋的设计特点 | 爆操女秘书 | 午夜精品久久久久久久99黑人 | 国产wwwxxx | 男生坤坤放进女生坤坤里 | 国产精品一区二区三区在线免费观看 | a天堂在线观看 | 日韩欧美一区二区一幕 | ,亚洲人成毛片在线播放 | a v视频在线观看 | 国内自拍区 | 极度诱惑香港电影完整 | 欧美另类高清 | 亚洲av最新在线网址 | 天堂а√在线最新版中文在线 | 激情免费av | 对白超刺激精彩粗话av | 国产美女菊爆在线播放APP | 欧美日韩国产综合在线 | 亚洲成人中文字幕 | 新中文字幕 |