Skip to content

Commit

Permalink
fixed: npp gantt problem
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis0324 committed May 9, 2023
1 parent 32e779d commit 4f05e89
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/schedulAlgorithm/type/nonpreemptivePriority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export default class nonpreemptivePriority extends schedular{
constructor(){
super()
this.readyQueue = new PriorityQueue<Process>((a,b) => {
if(a.priority == b.priority)
return a.arrivalTime > b.arrivalTime ? 1 : -1
return a.priority > b.priority ? 1 : -1
})
}
Expand Down
60 changes: 59 additions & 1 deletion src/test/nonpreemptivePriority.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 4f05e89

Please sign in to comment.