-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHRRN.java
More file actions
102 lines (82 loc) · 2.37 KB
/
HRRN.java
File metadata and controls
102 lines (82 loc) · 2.37 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
Title: HRRN.java
Name: Dylan Kapustka (Dlk190000)
Instructor: Professor Ozbirn
Course: CS 4348.001 - S21
Date: 05/01/2021
Description: HRRN class implements HRRN algorithm
*/
import java.util.ArrayList;
public class HRRN
{
//Main algorithm
public void mySchedule(ArrayList<myJob> list)
{
System.out.println("HRRN"); //Print algorithm name for graph
//Copy list
ArrayList<myJob> newList = new ArrayList<>();
for(myJob job: list)
{
newList.add(new myJob(job));
}
int time = 0;
while(!(newList.isEmpty()))
{
myJob selected = max(newList,time);
//Get index
int index = 0;
for(int i = 0; i < list.size(); i++)
{
if(list.get(i).getName().equals(selected.getName()))
{
index = i;
}
}
list.get(index).setSpaceCount(time);
time += selected.getDuration();
}
for(myJob job: list)
{
job.printMatrix();
}
}
//Helper function to find max
private myJob max(ArrayList<myJob> listCopy, int time)
{
double MinR = 0.0;
myJob selected = null;
//set up wait list
ArrayList<myJob> jobWaitList = new ArrayList<>();
for(myJob currentJob: listCopy)
{
if(currentJob.getArrivalTime() <= time)
{
jobWaitList.add(new myJob(currentJob));
}
}
int waitTime;
int serviceTime;
for(myJob currentJob: jobWaitList)
{
waitTime = time - currentJob.getArrivalTime();
serviceTime = currentJob.getDuration();
double R = (waitTime + serviceTime)/serviceTime;
if(R >= MinR)
{
selected = new myJob(currentJob);
MinR = R;
}
}
//Get index
int index = 0;
for(int i = 0; i < listCopy.size(); i++)
{
if(listCopy.get(i).getName().equals(selected.getName()))
{
index = i;
}
}
listCopy.remove(index);
return selected;
}
}