-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTSystem.cpp
61 lines (56 loc) · 1.63 KB
/
TSystem.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
#include "TSystem.h"
TSystem::TSystem(int _tact) {
tact = _tact;
waiting = 0;
incoming = 0;
accepted = 0;
completed = 0;
}
TSystem::~TSystem() = default;
void TSystem::Work(TProcessor P, TTask T, TQueue Q) {
srand(tact);
int k = 0;
for (int i = 1; i <= tact; i++) {
cout << endl << "ÒÀÊÒ " << i << endl;
if (T.NewTask()) {
cout << "Ïîñòóïèëà çàäà÷à #" << i << endl;
incoming++;
if (!Q.Full()) {
cout << "Çàäà÷à #" << i << " ïðèíÿòà â î÷åðåäü íà èñïîëíåíèå" << endl << endl;
accepted++;
Q.Put(i);
}
else {
cout << "Î÷åðåäü ïåðåïîëíåíà. Îòêàç â îáñëóæèâàíèè." << endl << endl;
}
}
else {
cout << "Íà òåêóùåì òàêòå çàäà÷è íå ïîñòóïàëè." << endl << endl;
}
if (!P.Busy()) {
if (!Q.Empty()) {
k = Q.Get();
P.RunNewTask(k);
cout << "Íà÷àòî èñïîëíåíèå çàäà÷è #" << k << endl;
}
else {
cout << "Çàäà÷è îòñóòñòâóþò." << endl;
waiting++;
}
}
else {
cout << "Èä¸ò èñïîëíåíèå çàäà÷è #" << k << " ..." << endl << endl;
}
if (P.Done()) {
completed++;
}
}
cout << endl << endl;
cout << "Òàêòîâ: " << tact << endl;
cout << "Ñãåíåðèðîâàíî çàäà÷: " << incoming << endl;
cout << "Ïðèíÿòî çàäà÷ â î÷åðåäü íà èñïîëíåíèå: " << accepted << endl;
cout << "Çàâåðøåíî çàäà÷: " << completed << endl;
cout << "Îòêàçîâ â îáñëóæèâàíèè: " << incoming - accepted << " (" << ((double)incoming - (double)accepted) / (double)incoming * 100 << "%)" << endl;
cout << "Òàêòîâ ïðîñòîÿ: " << waiting << " (" << ((double)waiting / (double)tact) * 100.0 << "%)" << endl;
cout << "Ñðåäíåå êîëè÷åñòâî òàêòîâ âûïîëíåíèÿ çàäà÷: " << (double)(tact - waiting) / (double)completed << endl;
}