-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgorithms.java
More file actions
50 lines (44 loc) · 1.41 KB
/
Copy pathAlgorithms.java
File metadata and controls
50 lines (44 loc) · 1.41 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
/** klasa abstrakcyjna Algorithms
* posiada metody uniwersalne dla każdego z algorytmów:
* extendQueue - sprawdza, czy jakieś procesy zgłosiły gotowość do wykonania, jeśli tak - dołącza je do kolejki
* averageWaitingTime - oblicza ŚCO dla danego algorytmu na podstawie danych zebranych w liście procesów obsłużonych **/
import java.util.ArrayList;
abstract class Algorithms
{
protected int processorTimer;
protected SimulationDataGenerator data;
protected int dataCollectionSize;
protected ArrayList<Process> readyProcesses;
protected ArrayList<Process> finishedProcesses;
public Algorithms(SimulationDataGenerator data)
{
processorTimer = 0;
this.data = data;
dataCollectionSize = data.size();
readyProcesses = new ArrayList<>();
finishedProcesses = new ArrayList<>();
}
protected void extendQueue()
{
if(!data.isEmpty())
{
if (processorTimer == data.get(0).getSubmitTime())
{
readyProcesses.add(data.get(0));
data.remove(0);
extendQueue();
}
}
}
protected int averageWaitingTime()
{
int temp = 0;
for (Process p : finishedProcesses)
{
temp = temp + p.getTotalWaitingTime();
}
temp = temp / dataCollectionSize;
return temp;
}
abstract int execute();
}