-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlgorithm.cpp
116 lines (101 loc) · 3.17 KB
/
Algorithm.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
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
//
// IIM project
// Algorithm.cpp
// Created bt Wemy Ju on 16/07/2015.
//
#include "Algorithm.h"
string* Algorithm::dishName = NULL;
void Algorithm::initOrder(vector<Dishes>& ordering, int& n, int d, int argc, char *argv[]){
if(argc>1)
ordering = readOrders(n, argc, argv);
else
ordering = produceOrders(n, d);
}
int Algorithm::getTotalWaiting(){
return totalWaiting;
}
int Algorithm::getCompleteTime(){
return completeTime;
}
void Algorithm::getResult(vector<Dishes> result){
cout << "----------------------------------------------------------------------------\n";
cout << " No. Dish Name Table Release Machine Start Process Complete Waiting \n";
for(int i=0; i<num; i++)
cout << " " << setw(3) << result[i].getNo()
<< setw(15) << result[i].getName()
<< setw(7) << result[i].getTable()
<< setw(9) << result[i].getTimeR()
<< setw(9) << result[i].getMachineNo()
<< setw(7) << result[i].getTimeS()
<< setw(9) << result[i].getTimeP()
<< setw(10) << result[i].getTimeC()
<< setw(9) << result[i].getTimeW() << endl;
cout << "Total Waiting Time : " << totalWaiting << endl;
cout << "Average Waiting Time : " << totalWaiting/num << endl;
cout << endl << endl;
}
vector<Dishes> Algorithm::getScheduleResult(){
return result;
}
vector<Dishes> Algorithm::produceOrders(int& n, int d){
int nextTime(0), order_num(0);
vector<Dishes> ordering;
srand(time(NULL));
n = rand()%10+50;
default_random_engine generator(time(NULL));
poisson_distribution<int> possion_dis(5);
normal_distribution<double> normal_dis(6, 2);
normal_distribution<double> normal_dis2(60, 30);
int Tr(0), table(1);
Dishes dish;
for(int i=0; i<n; table++){
do
order_num = (int)normal_dis(generator);
while(order_num <= 0);
//Tr += possion_dis(generator);
do
Tr = normal_dis2(generator);
while(Tr<0);
for(int j=0; j<order_num; j++, i++){
//Dishes *dish = new Dishes;
int dishNum = rand()%d+1;
dish.setDishNo(dishNum);
dish.setName(Dishes::getDishName(dishNum));
dish.setTimeR(Tr);
//dish.setTimeR(0);
dish.setNo(i+1);
dish.setTable(table);
ordering.push_back(dish);
}
if(i>n)
n=i;
}
return ordering;
}
vector<Dishes> Algorithm::readOrders(int &n, int argc, char* argv[]){
vector<Dishes> ordering;
fstream fp;
fp.open(argv[1], ios::in);
int orderNum(1), no(1), Tr;
string allOrders, name, temp;
fp >> orderNum;
getline(fp, temp);
for(int i=1; i<=orderNum; i++){
fp >> Tr;
getline(fp, temp);
getline(fp, allOrders);
stringstream ss(allOrders);
while (ss >> name){
Dishes dish;
dish.setTimeR(Tr);
dish.setNo(no++);
dish.setTable(i);
dish.setName(name);
dish.setDishNo(Dishes::getDishIndex(name));
ordering.push_back(dish);
}
}
n = no-1;
fp.close();
return ordering;
}