-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utilities.java
439 lines (356 loc) · 10.7 KB
/
Utilities.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
package fypScheduling;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import fypScheduling.Event.Type;
public class Utilities {
private Map<Integer, Venue> rooms;
private Map<Integer, Course> courses;
private Map<Integer, Grouping> grouping;
private Map<Integer, Faculty> faculty;
private Map<Integer, Event> events;
private ArrayList<Integer> eventList;
private Timetable bestTimetable;
private Map<String, History> history;
private Map<Integer, StudentPreference> studentPreference;
public Utilities(){
eventList = new ArrayList<Integer>();
rooms = new HashMap<Integer, Venue>();
courses = new HashMap<Integer, Course>();
grouping = new HashMap<Integer, Grouping>();
faculty = new HashMap<Integer, Faculty>();
events = new HashMap<Integer, Event>();
history = new HashMap<String, History>();
setStudentPreference(new HashMap<Integer, StudentPreference>());
}
public void addVenues(Venue room){
this.rooms.put(room.getId(), room);
}
public void addEvent(Event event) {
this.events.put(event.getId(), event);
}
public int getNoOfVenues(){
return this.rooms.size();
}
public Map<Integer, Venue> getVenues(){
return this.rooms;
}
public Map<Integer, Course> getCourses() {
return this.courses;
}
public void addCourses(Course course) {
this.courses.put(course.getId(), course);
}
public void addHistory(History history) {
this.history.put(history.getCourse().getCourseNum(), history);
}
public void setCoursesList(Map<Integer, Course> courses){
this.courses = courses;
}
public Map<Integer, Grouping> getGrouping() {
return grouping;
}
public void addGrouping(Grouping grouping) {
this.grouping.put(grouping.getId(), grouping);
}
public Map<Integer, Faculty> getFaculty() {
return faculty;
}
public void addFaculty(Faculty faculty) {
this.faculty.put(faculty.getId(), faculty);
}
public Map<Integer, Event> getEvents() {
return events;
}
public Event getEvents(int key) {
return events.get(key);
}
public void setEvents(Map<Integer, Event> events){
this.events = events;
}
public int getRandomEventList(){
Random rand = new Random();
int result = eventList.get(rand.nextInt(eventList.size()));
return result;
}
public double getTotalWLU(){
double result = 0;
for (Event child : events.values()){
result += child.getWLU();
}
return result;
}
public double getTotalTeachingContribution(){
double result = 0;
for (Faculty child : faculty.values()){
result += child.getTeachingContribution();
}
return result;
}
public void addEvents(){
int eventID = 1, eventDuration;
Random r = new Random(System.currentTimeMillis());
for (Grouping groupChild : grouping.values()){
for (Course courseChild : groupChild.getCourses()){
// assign ONLY 1 faculty to this course (can be further modified)
ArrayList<Faculty> possibleFaculty = new ArrayList<Faculty>();
for (Faculty facChild : faculty.values()){
if (facChild.isTeachable(courseChild.getCourseNum()) && facChild!=null){
possibleFaculty.add(facChild);
}
}
//Lecture
int rand1, rand2;
ArrayList<Faculty> chosenFaculty = new ArrayList<Faculty>();
if (possibleFaculty.size() !=1){
// assign 2 prof to teach a course lec is possible pool is bigger than 1
rand1 = r.nextInt(possibleFaculty.size());
rand2 = r.nextInt(possibleFaculty.size());
while(rand2==rand1){
rand2 = r.nextInt(possibleFaculty.size());
}
Faculty chosen1 = possibleFaculty.get(rand1);
chosenFaculty.add(chosen1);
Faculty chosen2 = possibleFaculty.get(rand2);
chosenFaculty.add(chosen2);
}
else{
// assign 1 prof to teach
rand1 = r.nextInt(possibleFaculty.size());
Faculty chosen1 = possibleFaculty.get(rand1);
chosenFaculty.add(chosen1);
}
// if course is senior year, lec can be taught back-to-back
if(groupChild.isSeniorYear()){
eventDuration = courseChild.getNoOfLecs();
Event event = new Event(Type.LEC, groupChild.getSize(),
chosenFaculty, courseChild,
groupChild, eventID, eventDuration);
eventID++;
events.put(event.getId(), event);
eventList.add(event.getId());
}
else{
eventDuration = 1;
for(int i = 0; i < courseChild.getNoOfLecs(); i++){
Event event = new Event(Type.LEC, groupChild.getSize(),
chosenFaculty, courseChild,
groupChild, eventID, eventDuration);
eventID++;
events.put(event.getId(), event);
eventList.add(event.getId());
}
}
// TUT
eventDuration = courseChild.getNoOfTuts();
if (eventDuration !=0){
possibleFaculty = new ArrayList<Faculty>();
for (Faculty facChild : faculty.values()){
if (facChild.isTeachableTut(courseChild.getCourseNum()) && facChild!=null){
possibleFaculty.add(facChild);
}
}
int groupSize = groupChild.getSize();
while (groupSize > 0){
// temp assignment - rightfully year 4 = LT size
int eventSize = 30;
rand1 = r.nextInt(possibleFaculty.size());
Faculty chosen = possibleFaculty.get(rand1);
chosenFaculty = new ArrayList<Faculty>();
chosenFaculty.add(chosen);
Event event = new Event(Type.TUT, eventSize,
chosenFaculty, courseChild,
groupChild, eventID, eventDuration);
eventID++;
events.put(event.getId(), event);
eventList.add(event.getId());
groupSize -= eventSize;
}
}
// LAB
eventDuration = courseChild.getNoOfLabs();
if(eventDuration !=0){
possibleFaculty = new ArrayList<Faculty>();
for (Faculty facChild : faculty.values()){
if (facChild.isTeachableLab(courseChild.getCourseNum()) && facChild!=null){
possibleFaculty.add(facChild);
}
}
int groupSize = groupChild.getSize();
while (groupSize >0){
// temp assignment
int eventSize = 50;
rand1 = r.nextInt(possibleFaculty.size());
Faculty chosen = possibleFaculty.get(rand1);
chosenFaculty = new ArrayList<Faculty>();
chosenFaculty.add(chosen);
Event event = new Event(Type.LAB, eventSize,
chosenFaculty, courseChild,
groupChild, eventID,eventDuration);
eventID++;
events.put(event.getId(), event);
eventList.add(event.getId());
groupSize -= eventSize;
}
}
}
}
}
public double getWorstWLUAllocated() {
double result = 0;
for(Faculty child : faculty.values()) {
double effiectiveTC = this.getAvgWLU() * child.getTeachingContribution();
double allocatedWLU = child.getAllocatedWLU();
double distribtion = ((allocatedWLU-effiectiveTC)/effiectiveTC) * 100;
if (distribtion <0) {
result +=0;
}
else if (distribtion < 10) {
result +=10;
}
else if (distribtion < 20) {
result +=20;
}
else if (distribtion < 20) {
result +=30;
}
else if (distribtion <40) {
result +=40;
}else {
result +=80;
}
}
return result;
}
public ArrayList<Course> getWorstAllocatedEvents(){
double worst = 0;
int facID = 0;
for(Faculty child : faculty.values()) {
if (child.getAllocatedWLU() > worst) {
worst = child.getAllocatedWLU();
facID = child.getId();
}
}
Faculty child = faculty.get(facID);
ArrayList<Course> courseList = child.getAssignedCourse();
return courseList;
}
private int randomInt(int low, int high){
Random r = new Random();
double result = (high-low) * r.nextDouble() + low;
return (int) result;
}
public ArrayList<Course> getWorstAllocatedEvents2(){
double worst = 0;
int facID = 0;
Queue queue = new Queue(10);
for(Faculty child : faculty.values()) {
double tc = child.getTeachingContribution();
double avg = getAvgWLU();
double optimalWLU = tc*avg;
double currentWLU = child.getAllocatedWLU();
double distribution = ((currentWLU - optimalWLU) / optimalWLU) * 100;
if (distribution > 40) {
facID = child.getId();
queue.insert(facID);
}
}
if (queue.isEmpty()) {
for(Faculty child : faculty.values()) {
double tc = child.getTeachingContribution();
double avg = getAvgWLU();
double optimalWLU = tc*avg;
double currentWLU = child.getAllocatedWLU();
double distribution = ((currentWLU - optimalWLU) / optimalWLU) * 100;
if (distribution > 30) {
facID = child.getId();
queue.insert(facID);
}
}
}
int pos = randomInt(0, queue.size());
while(pos!=0) {
queue.remove();
pos--;
}
facID = queue.peekFront();
Faculty child = faculty.get(facID);
ArrayList<Course> courseList = child.getAssignedCourse();
return courseList;
}
public Map<Integer, StudentPreference> getStudentPreference() {
return studentPreference;
}
public void setStudentPreference(Map<Integer, StudentPreference> studentPreference) {
this.studentPreference = studentPreference;
}
public Map<String, History> getHistory() {
return history;
}
public void setHistory(Map<String, History> history) {
this.history = history;
}
public double getAvgWLU() {
double result = 0;
for(Faculty child : faculty.values()) {
result += child.getAllocatedWLU();
}
result = result / getTotalTeachingContribution();
return result;
}
public int getOverloadedFac() {
// TODO Auto-generated method stub
double avgWLU = getAvgWLU();
double effectiveWLU;
int result = 0;
for(Faculty child : faculty.values()) {
effectiveWLU = child.getTeachingContribution() * avgWLU;
if (child.getAllocatedWLU() > effectiveWLU) {
result++;
}
}
return result;
}
public Timetable getBestTimetable() {
return bestTimetable;
}
public void setBestTimetable(Timetable bestTimetable) {
this.bestTimetable = bestTimetable;
}
public double getLecTotalWLU() {
double result = 0;
for (Event child : events.values()){
if (child.getType() == Type.LEC)
result += child.getWLU();
}
return result;
}
public double getTutTotalWLU() {
double result = 0;
for (Event child : events.values()){
if (child.getType() == Type.TUT)
result += child.getWLU();
}
return result;
}
public double getLabTotalWLU() {
double result = 0;
for (Event child : events.values()){
if (child.getType() == Type.LAB)
result += child.getWLU();
}
return result;
}
public double getAvgDistribution(double avgWLU) {
double result = 0;
double effectiveWLU, distribution = 0;
for(Faculty child : faculty.values()) {
effectiveWLU = child.getTeachingContribution() * avgWLU;
distribution = ((child.getAllocatedWLU() - effectiveWLU) / effectiveWLU) * 100;
result = result + (distribution);
}
result = result / faculty.size();
return result;
}
}