-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFIFO.cpp
64 lines (55 loc) · 1.5 KB
/
FIFO.cpp
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
//
// IIM project
// FIFO.cpp
// Created by Wemy Ju on 16/07/2015.
//
#include "FIFO.h"
FIFO::FIFO(int m, int n){
num = n;
totalWaiting = 0;
completeTime = 0;
machine = m;
order.clear();
result.clear();
timer = new int[machine+1];
memset(timer, 0, (machine+1)*sizeof(int));
}
FIFO::~FIFO(){
delete[] timer;
}
bool FIFO::firstComeCmp(Dishes a, Dishes b){
if(a.getTimeR() != b.getTimeR())
return a.getTimeR() < b.getTimeR();
else
return a.getNo() < b.getNo();
}
void FIFO::addOrder(int timer, Dishes newDish){
order.insert(order.end(), newDish);
sort(order.begin(), order.end(), FIFO::firstComeCmp);
}
bool FIFO::checkSchedule(int clock){
for(int i=1; i<=machine; i++){
if(clock >= timer[i] && !order.empty()){
Dishes dish = *(order.begin());
dish.setMachineNo(i);
dish.setTimeS(clock);
dish.setTimeP(dish.getDishNo(), i);
dish.setTimeC(dish.getTimeS()+dish.getTimeP());
dish.setTimeW(dish.getTimeC()-dish.getTimeR());
if(dish.getTimeC()>completeTime)
completeTime = dish.getTimeC();
totalWaiting += dish.getTimeW();
timer[i] = dish.getTimeC();
result.insert(result.end(), dish);
order.erase(order.begin());
}
}
return order.empty();
}
void FIFO::printResult(){
cout << "Using FIFO\n";
Algorithm::getResult(result);
}
vector<Dishes> FIFO::getResult(){
return result;
}