-
Notifications
You must be signed in to change notification settings - Fork 0
/
throwaway.py
218 lines (188 loc) · 6.69 KB
/
throwaway.py
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
# For scheduler class to be used as a component in the objective function
# def getactivitiesNotPushedFrontPenalty(self):
# # # Push activities as forward as possible
# breakBeforeActivities = []
# for i, actVar in enumerate(self.activityVars):
# actStartEndDifs = []
# actStartEndDifs.append(actVar.start)
# for actVar2 in self.activityVars:
# startEndDif = actVar.start - actVar2.end
# actStartEndDifs.append(startEndDif)
# breakBeforeAct = self.model.NewIntVar(0, self.endScheduleTime, 'break before ' + str(i))
# breakBeforeActivities.append(breakBeforeAct)
# return sum(breakBeforeActivities)
# def getactivitiesNotPushedBackPenalty(self):
# # Push activities as forward as possible
# breakBeforeActivities = []
# for i, actVar in enumerate(self.activityVars):
# actStartEndDifs = []
# actStartEndDifs.append(self.endScheduleTime - actVar.end)
# for actVar2 in self.activityVars:
# startEndDif = actVar.start - actVar2.end
# actStartEndDifs.append(startEndDif)
# breakBeforeAct = self.model.NewIntVar(0, self.endScheduleTime, 'break before ' + str(i))
# breakBeforeActivities.append(breakBeforeAct)
# return sum(breakBeforeActivities)
# def getActivitiesStartTimeBackPenalty(self):
# # The further the activity start time, the bigger the penalty
# presentIntervalsStart = []
# for actVar in self.activityVars:
# isPresentStart = self.model.NewIntVar(0, self.endScheduleTime, '')
# self.model.AddProdEquality(isPresentStart, [actVar.start, actVar.isPresent])
# presentIntervalsStart.append(isPresentStart)
# return sum([start for start in presentIntervalsStart])
# def getActivitiesNotPresentPenalty(self):
# penaltyByPriority = {
# 1: 14400,
# 2: 120,
# 3: 1
# }
# # Weighted penalties by priority (lower priority number == greater penalty)
# return sum(
# [(int(penaltyByPriority[int(actVar.data.priority)]) * (1 - actVar.isPresent))
# for actVar in self.activityVars]
# )
# # Case1 to Case6 - Test objective function's individual components
# # Each case forces a single penalty component to produce a penalty
# # Activity 'C' won't be fitted
# # Expected objective score = (120 / 5) * 100 = 2400
# case1 = {
# 'schedule-time': [
# ScheduleTime(0, 120)
# ],
# 'buffer-times': [],
# 'activities' : [
# Activity('A', 50),
# Activity('B', 40),
# Activity('C', 90)
# ],
# 'activity-groups': []
# }
# # Activity 'C' won't be fitted
# # Expected objective score = (120 / 3) * 100 = 4000
# case2 = {
# 'schedule-time': [
# ScheduleTime(0, 120)
# ],
# 'activities' : [
# Activity('A', 50, priority=3),
# Activity('B', 40, priority=3),
# Activity('C', 90, priority=3)
# ]
# }
# # Activities order will be changed :
# # 'B' will not be followed by 'C'
# # Expected objective score = 1
# case3 = {
# 'schedule-time': [
# ScheduleTime(0, 120)
# ],
# 'activities' : [
# Activity('A', 5, priority=3),
# Activity('B', 4, priority=3),
# Activity('C', 3, priority=3, startTime=5)
# ]
# }
# # Activities order will be changed :
# # 'A' will not be followed by 'B'
# # 'B' will not be followed by 'C'
# # Expected objective score = 2
# case4 = {
# 'schedule-time': [
# ScheduleTime(0, 120)
# ],
# 'activities' : [
# Activity('A', 10, priority=3),
# Activity('B', 5, priority=3, startTime=30),
# Activity('C', 30, priority=3, startTime=0),
# ]
# }
# # There will be a time gap of 10 min after A ends and B starts
# # Expected objective score = (num_of_activities_after_B + 1) * (lag time of B) = 1 * 10 = 10
# case5 = {
# 'schedule-time': [
# ScheduleTime(0, 120)
# ],
# 'activities' : [
# Activity('A', 10),
# Activity('B', 5, startTime=20)
# ]
# }
# # There will be a time gap of 10 min after A ends and B starts
# # However, unlike case 5 there is 1 activity after B
# # Expected objective score = (num_of_activities_after_B + 1) * (lag time of B) = 2 * 10 = 20
# case6 = {
# 'schedule-time': [
# ScheduleTime(0, 120)
# ],
# 'activities' : [
# Activity('A', 10),
# Activity('B', 5, startTime=20),
# Activity('C', 15, startTime=25)
# ]
# }
# # There is 10 min lag time for activity A, activity B, and activity C
# # Penalty for activity A = (num_of_activities_after_A + 1) * (lag time of A)= 3 * 10 = 30
# # Penalty for activity B = (num_of_activities_after_B + 1) * (lag time of B) = 2 * 10 = 20
# # Penalty for activity A = (num_of_activities_after_C + 1) * (lag time of C) = 1 * 10 = 10
# # Expected objective score = 60
# case7 = {
# 'schedule-time': [
# ScheduleTime(0, 120)
# ],
# 'activities' : [
# Activity('A', 10, startTime=10),
# Activity('B', 10, startTime=30),
# Activity('C', 10, startTime=50),
# ]
# }
# # Case to test that activities are pushed to front and order is maintained
# # if no startTime or group is specified
# case8 = {
# 'schedule-time': [
# ScheduleTime(0, 120)
# ],
# 'activities': [
# Activity('A', 15),
# Activity('B', 3),
# Activity('C', 20, priority=1),
# Activity('D', 7, priority=3),
# Activity('E', 10)
# ]
# }
# # Case to test that activities with higher priority are scheduled over activities with lower priorities
# # Notice that Activity D is scheduled instead of Activity F
# # (both D and F have same priority and duration but D is defined before)
# case9 = {
# 'schedule-time': [
# ScheduleTime(0, 120)
# ],
# 'activity-groups': [],
# 'activities': [
# Activity('A', 29, priority=2),
# Activity('B', 29, priority=2),
# Activity('C', 29, priority=1),
# Activity('D', 29, priority=3),
# Activity('E', 29, priority=1),
# Activity('F', 29, priority=3),
# Activity('G', 29, priority=2),
# Activity('H', 29, priority=2)
# ]
# }
# case10 = {
# 'schedule-time': [
# ScheduleTime(0, 120)
# ],
# 'activity-groups': [
# ActivityGroup('email', 30, 80)
# ],
# 'activities': [
# Activity('A', 10),
# Activity('B', 9, groupName='email'),
# Activity('C', 3, groupName='email'),
# Activity('D', 14),
# Activity('E', 9),
# Activity('F', 5, groupName='email'),
# ]
# }
# case11 = {}