Skip to content

Commit 4f05e89

Browse files
committed
fixed: npp gantt problem
1 parent 32e779d commit 4f05e89

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/schedulAlgorithm/type/nonpreemptivePriority.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export default class nonpreemptivePriority extends schedular{
88
constructor(){
99
super()
1010
this.readyQueue = new PriorityQueue<Process>((a,b) => {
11+
if(a.priority == b.priority)
12+
return a.arrivalTime > b.arrivalTime ? 1 : -1
1113
return a.priority > b.priority ? 1 : -1
1214
})
1315
}

src/test/nonpreemptivePriority.ts

+59-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,65 @@
11
import {createProcess} from "@/schedulAlgorithm/cpuScheduler"
22
import staticPriority from "@/schedulAlgorithm/type/nonpreemptivePriority";
33
debugger;
4-
const processArray = [...Array(5)].map((_, i) => createProcess(i, i, ~~(Math.random() * 10 ) + 1, i));
4+
// const processArray = [...Array(5)].map((_, i) => createProcess(i, i, ~~(Math.random() * 10 ) + 1, i));
5+
6+
const processArray = [
7+
{
8+
pid: 0,
9+
arrivalTime: 0,
10+
burstTime: 10,
11+
remainingTime: 10,
12+
priority: 3,
13+
waitingTime: 0,
14+
completionTime: 0,
15+
executeTime: 0,
16+
lastfinishTime: 0
17+
},
18+
{
19+
pid: 1,
20+
arrivalTime: 1,
21+
burstTime: 28,
22+
remainingTime: 28,
23+
priority: 2,
24+
waitingTime: 0,
25+
completionTime: 0,
26+
executeTime: 0,
27+
lastfinishTime: 1
28+
},
29+
{
30+
pid: 2,
31+
arrivalTime: 2,
32+
burstTime: 6,
33+
remainingTime: 6,
34+
priority: 4,
35+
waitingTime: 0,
36+
completionTime: 0,
37+
executeTime: 0,
38+
lastfinishTime: 2
39+
},
40+
{
41+
pid: 3,
42+
arrivalTime: 3,
43+
burstTime: 4,
44+
remainingTime: 4,
45+
priority: 1,
46+
waitingTime: 0,
47+
completionTime: 0,
48+
executeTime: 0,
49+
lastfinishTime: 3
50+
},
51+
{
52+
pid: 4,
53+
arrivalTime: 4,
54+
burstTime: 14,
55+
remainingTime: 14,
56+
priority: 2,
57+
waitingTime: 0,
58+
completionTime: 0,
59+
executeTime: 0,
60+
lastfinishTime: 4
61+
}
62+
]
563

664
const StaticPriority = new staticPriority();
765
StaticPriority.simulate(processArray)

0 commit comments

Comments
 (0)