This repository has been archived by the owner on Jul 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab11_EDF.java
144 lines (119 loc) · 4.34 KB
/
Lab11_EDF.java
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import java.util.Scanner;
import java.util.*;
class EDF{
/*------------------------------------------------------
| Process_no |Arrival Time|Service Time| Deadline |
| 1 | 0 | 4 | 33 |
...*/
private int[][] table;
private int size;
EDF(int n){
size=n;
table=new int[n][4];
}
public void enter_table(){
Scanner input=new Scanner(System.in);
System.out.println("Enter the processes in the ascending order of their arriving time");
for(int i=0;i<size;i++)
{
System.out.println("for process"+(i+1));
table[i][0]=(i+1);
System.out.println("enter the process arrival time:");
table[i][1]=input.nextInt();
System.out.println("enter the process service time:");
table[i][2]=input.nextInt();
System.out.println("enter the process Deadline time:");
table[i][3]=input.nextInt();
}
}
public void print_table(){
for(int i=0;i<size;i++)
{
System.out.println(table[i][0]+" "+table[i][1]+" "+table[i][2]+" "+table[i][3]);
}
}
public void proceed(){
int[] dummy=new int[size];
for(int k=0;k<size;k++){
//arrival+deadline+id ...... service time
dummy[k]=(10000*table[k][1]+100*table[k][3]+ table[k][0])*100 + table[k][2];
}
Arrays.sort(dummy);
int sum=0;
for(int j=0;j<size;j++){
//System.out.println(dummy[j]);
sum=sum+table[j][2];
}
int total_clock = dummy[0]/1000000 + sum;
int Cnt=0;
int[] array = new int[total_clock];
int ind_array=0;
int[] queue=new int[size];
int head=0;
int tail=0;
int index=0;
int var=0;
int a,d,s,id;
while(Cnt<total_clock && index<size && ind_array<total_clock){
a=dummy[index]/1000000;
d=dummy[index]%1000000;
d=d/10000;
id=dummy[index]%10000;
s=id%100;
id=id/100;
if(index+1!=size){
if((dummy[index+1]/1000000)==Cnt && s>0){
//add to dueue and
queue[tail]=dummy[index];
System.out.println("queue tail"+queue[tail]);
tail++;
index++;
}
else if((dummy[index+1]/1000000)>Cnt && s>0){
//add id to array
array[ind_array]=id;
System.out.println("array add"+array[ind_array]);
dummy[index]--;
ind_array++;
}
else if((dummy[index+1]/1000000)==Cnt && s==0){
index++;
}
else if(s==0){
if((queue[head]%1000000)/10000 < (dummy[index+1]%1000000)/10000){
dummy[index]=queue[head];
head++;
}
else{
index++;
}
}
}
else{
while(dummy[index]%100!=0){
//System.out.println("hi i was not here");
var=dummy[index]%10000;
var=var/100;
array[ind_array]=var;
dummy[index]--;
Cnt++;}
}
//System.out.println("hi i was out of here");
Cnt++;
}
for(int k=0;k<array.length;k++){
System.out.print(array[k]+" ");
}
}
public static void main(String args[]){
int n;
Scanner in =new Scanner(System.in);
System.out.println("Enter number of process:");
n=in.nextInt();
EDF t1 =new EDF(n);
t1.enter_table();
t1.print_table();
System.out.println("Earliest Deadline FIrst!!");
t1.proceed();
}
}