From 4f05e8939242609b420225a502c8af051f0ca70e Mon Sep 17 00:00:00 2001 From: dennis ko Date: Tue, 9 May 2023 22:24:00 +0900 Subject: [PATCH] fixed: npp gantt problem --- .../type/nonpreemptivePriority.ts | 2 + src/test/nonpreemptivePriority.ts | 60 ++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/schedulAlgorithm/type/nonpreemptivePriority.ts b/src/schedulAlgorithm/type/nonpreemptivePriority.ts index f04eb4b..6c95bdc 100644 --- a/src/schedulAlgorithm/type/nonpreemptivePriority.ts +++ b/src/schedulAlgorithm/type/nonpreemptivePriority.ts @@ -8,6 +8,8 @@ export default class nonpreemptivePriority extends schedular{ constructor(){ super() this.readyQueue = new PriorityQueue((a,b) => { + if(a.priority == b.priority) + return a.arrivalTime > b.arrivalTime ? 1 : -1 return a.priority > b.priority ? 1 : -1 }) } diff --git a/src/test/nonpreemptivePriority.ts b/src/test/nonpreemptivePriority.ts index b6dd5fe..9cbca69 100644 --- a/src/test/nonpreemptivePriority.ts +++ b/src/test/nonpreemptivePriority.ts @@ -1,7 +1,65 @@ import {createProcess} from "@/schedulAlgorithm/cpuScheduler" import staticPriority from "@/schedulAlgorithm/type/nonpreemptivePriority"; debugger; -const processArray = [...Array(5)].map((_, i) => createProcess(i, i, ~~(Math.random() * 10 ) + 1, i)); +// const processArray = [...Array(5)].map((_, i) => createProcess(i, i, ~~(Math.random() * 10 ) + 1, i)); + +const processArray = [ + { + pid: 0, + arrivalTime: 0, + burstTime: 10, + remainingTime: 10, + priority: 3, + waitingTime: 0, + completionTime: 0, + executeTime: 0, + lastfinishTime: 0 + }, + { + pid: 1, + arrivalTime: 1, + burstTime: 28, + remainingTime: 28, + priority: 2, + waitingTime: 0, + completionTime: 0, + executeTime: 0, + lastfinishTime: 1 + }, + { + pid: 2, + arrivalTime: 2, + burstTime: 6, + remainingTime: 6, + priority: 4, + waitingTime: 0, + completionTime: 0, + executeTime: 0, + lastfinishTime: 2 + }, + { + pid: 3, + arrivalTime: 3, + burstTime: 4, + remainingTime: 4, + priority: 1, + waitingTime: 0, + completionTime: 0, + executeTime: 0, + lastfinishTime: 3 + }, + { + pid: 4, + arrivalTime: 4, + burstTime: 14, + remainingTime: 14, + priority: 2, + waitingTime: 0, + completionTime: 0, + executeTime: 0, + lastfinishTime: 4 + } +] const StaticPriority = new staticPriority(); StaticPriority.simulate(processArray)