-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFCFS_Scheduler.cs
59 lines (49 loc) · 1.59 KB
/
FCFS_Scheduler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
public class ProcessWrapper : JobsScheduler.Process, IComparable<ProcessWrapper>
{
public ProcessWrapper(JobsScheduler.Process p)
{
this.arrivalTime = p.arrivalTime;
this.burstTime = p.burstTime;
this.processNumber = p.processNumber;
}
int IComparable<ProcessWrapper>.CompareTo(ProcessWrapper other)
{
if (this.arrivalTime >= other.arrivalTime) return 1;
else return -1;
}
}
public class FCFS_Scheduler
{
public List<JobsScheduler.outputProcesses> outputList = new ();
public float averageWaitingTime = 0;
public FCFS_Scheduler(List<JobsScheduler.Process> processes)
{
List<ProcessWrapper> OrderOfExecution = new ();
foreach (var process in processes)
{
ProcessWrapper pw = new ProcessWrapper(process);
OrderOfExecution.Add(pw);
}
OrderOfExecution.Sort();
float acc = 0;
foreach (var process in OrderOfExecution)
{
acc += process.burstTime;
averageWaitingTime += acc;
}
averageWaitingTime -= acc;
averageWaitingTime = (float)averageWaitingTime / OrderOfExecution.Count;
float startingTime = 0;
foreach (var process in OrderOfExecution)
{
JobsScheduler.outputProcesses op = new ();
op.processNumber = process.processNumber;
op.startTime = startingTime;
op.usingTime = process.burstTime;
outputList.Add(op);
startingTime += process.burstTime;
}
}
}