-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounters.cpp
More file actions
119 lines (91 loc) · 2.25 KB
/
counters.cpp
File metadata and controls
119 lines (91 loc) · 2.25 KB
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
#include "counters.h"
#include "constants.h"
#include "debug.h"
#include "line.h"
#include "stats.h"
Facility summer("Summer");
Facility working_week("Working week");
Facility weekend("Weekend");
Facility start_break("Start break");
Facility end_break("End break");
void YearCounter::Behavior() {
Priority = DEFAULT_COUNTER_PRIORITY;
echo("Staring season counter");
long long start;
long long end;
while (true){
start = processed_cars;
// starting in another other season than summer
Seize(summer);
Wait(OTHER_SEASONS_TIME);
echo("It summer");
Release(summer);
Wait(SUMMER_TIME);
echo("It's winter");
end = processed_cars;
year(end - start);
}
}
void WeekCounter::Behavior() {
Priority = DEFAULT_COUNTER_PRIORITY;
echo("Starting weekend counter");
Seize(working_week);
while (true){
Seize(weekend);
Release(working_week);
echo("It's a week");
Wait(WEEK_DAYS);
echo("Weekend starting, party up!!!")
Release(weekend);
Seize(working_week);
Wait(WEEKEND_DAYS);
echo("End of weekend");
}
}
void BreakCounter::Behavior() {
Priority = DEFAULT_COUNTER_PRIORITY;
echo("Starting shift counter");
Seize(start_break);
Seize(end_break);
long long cars_before_shift;
long long cars_after_shift;
long long cars_start_day;
long long cars_end_day;
while (true) {
cars_start_day = processed_cars;
for (int i = 0; i < SHIFTS_IN_DAY; i++) {
cars_before_shift = processed_cars;
echo("Starting new shift");
// At this point we have both breaks
Wait(WORKING_TIME);
// First short break is comming
Release(start_break);
echo("Starting short break");
Wait(SHORT_BREAK);
Seize(start_break);
// end of first break
Release(end_break);
Priority = 0;
Seize(end_break);
Wait(WORKING_TIME);
// First short break is comming
Release(start_break);
echo("Starting long break");
Wait(LONG_BREAK);
Seize(start_break);
// end of first break
Release(end_break);
Priority = 0;
Seize(end_break);
Wait(WORKING_TIME);
cars_after_shift = processed_cars;
if (!working_week.Busy()){
throughput_8_hours(cars_after_shift - cars_before_shift);
}
}
cars_end_day = processed_cars;
if (!working_week.Busy()){
throughput_24_hours(cars_end_day - cars_start_day);
}
}
}