forked from MxHbm/Management-Science
-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.py
343 lines (267 loc) · 15.4 KB
/
results.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
import pandas as pd
from parameters import Parameters
''' results.py '''
class Results:
def __init__(self, model, data:Parameters):
self.model = model
self.T = data.T
self.F = data.F
self.S = data.S
self.FT = data.FT
self.MP = data.MP
self.CT = data.CT
self.L = data.L
self.sales_t = self.create_sales_t()
self.lost_sales_t = self.create_lost_sales_t()
self.distressed_sales_t = self.create_distressed_sales_t()
self.raw_material_losses_t = self.create_raw_material_losses_t()
self.raw_material_purchase_t = self.create_raw_material_purchase_t()
self.exports_t = self.create_exports_t()
self.production_t = self.create_production_t()
self.product_shipped_t = self.create_product_shipped_t()
self.sales_income_mu = self.create_sales_income_mu()
self.distressed_sales_mu = self.create_distressed_sales_mu()
self.raw_material_losses_cost_mu = self.create_raw_material_losses_cost_mu()
self.raw_material_purchase_cost_mu = self.create_raw_material_purchase_cost_mu()
self.exports_income_mu = self.create_exports_income_mu()
self.cost_shipped_dc_mu = self.create_cost_shipped_dc_mu()
self.setups_cost_mu = self.create_setups_cost_mu()
self.expected_net_benefits_mu = self.create_expected_net_benefits_mu()
pd.set_option('display.width', 100)
pass
def paper_values_table6(self):
data = {
'Metric': ['Sales [t]', 'Lost Sales [t]', 'Distressed Sales of Products [t]', 'Raw Material Losses [t]', 'Raw Material Purchase [t]', 'Exports [t]', 'Production [t]', 'Product shipped to DC [t]', 'Sales Income [MU]', 'Distressed Sales of Products [MU]', 'Raw Material Losses Cost [MU]', 'Raw Material Purchase Cost [MU]', 'Exports Income [MU]', 'Cost for shipped to DC [MU]', 'Setups Cost [MU]', 'Expected Net Benefits [MU]'],
'SP': [12815, 1715.2, 3694.1, 22951, 1078.4, 975, 16561, 15556, 62241, 3516, 22951, 2156.90, 4875, 10814, 40, 34670.1],
'EMVP': [11149, 3381, 1410.2, 20334, 4471.9, 2500, 14460, 11607, 53541, 752, 20334, 8943.7, 12500, 8798.5, 80, 28636.8],
'Deviation': ['+14.9%', '-49.3%', '+162.0%', '+12.9%', '-75.9%', '-61.0%', '+14.5%', '+34.0%', '+16.2%', '+367.5%', '+12.9%', '-75.9%', '-61.0%', '+22.9%', '-50.0%', '+21.1%']
}
df = pd.DataFrame(data)
return df
def paper_values_table8(self):
data = {
'Metric': ['Production [t]', 'Production [t]', 'Production [t]', 'Production [t]',
'N° of PM Export Lots', 'Processed Raw Milk [t]',
'Required trucks', 'Required trucks', 'Required trucks',
'DCs Expected Stockout days', 'DCs Expected Stockout days', 'DCs Expected Stockout days', 'DCs Expected Stockout days',
'DCs Expected Overstock days', 'DCs Expected Overstock days', 'DCs Expected Overstock days',
'Expected number of days with raw milk Overstock',
'Expected number of days with raw milk bought at premium price',
'Expected Sales (MU)', 'Expected Raw Milk Costs (MU)', 'Expected Net Benefits (MU)'] ,
'Sub-Metric': ['UHT', 'Milk', 'Yogurt', 'Cheese',
'N° of PM Export Lots', 'Processed Raw Milk [t]',
'Fresh', 'Dry', 'UHT',
'Powdered Milk', 'Yogurt', 'Cheese', 'UHT',
'Powdered Milk', 'Yogurt', 'Cheese',
'Raw Milk', 'Raw Milk',
'Sales', 'Raw Milk', 'Net Benefits'] ,
'SP': [9881.6, 1938, 4465.3, 276.4, 39, 33759, 598, 1348, 9.7, 5.5, 10, 6.7, 3.5, 3.8, 6.4, 2.3, 10.5, 2.2, 62241, 25107, 34670.1],
'EMVP': [6600, 3360, 4499.8, None, 100, 397769, 554, 910, 20.2, 16.1, 13.1, 29.7, 7.9, 4.8, 18.1, 1.2, 12.1, 9, 53541, 29277, 28636.8]
}
df = pd.DataFrame(data)
df.set_index(['Metric', 'Sub-Metric'], inplace=True, drop=True)
return df
#df = pd.DataFrame(data)
#return df
def create_sales_t(self):
# Compute the value for 'Sales [t]'
sales_t = 0
for s in self.S:
for f in self.F:
for l in self.L:
for t in self.T:
if self.model.getVarByName(f'SAs_f_l_t[{s},{f},{l},{t}]') is not None:
sales_t += self.model.getVarByName(f'SAs_f_l_t[{s},{f},{l},{t}]').Obj
return sales_t
def create_lost_sales_t(self):
# Compute the value for 'Lost Sales [t]'
lost_sales_t = 0
for s in self.S:
for f in self.F:
for l in self.L:
for t in self.T:
if self.model.getVarByName(f'SOs_f_l_t[{s},{f},{l},{t}]') is not None:
lost_sales_t += self.model.getVarByName(f'SOs_f_l_t[{s},{f},{l},{t}]').Obj
print(lost_sales_t)
return lost_sales_t
def create_distressed_sales_t(self):
# Compute the value for 'Distressed Sales of Products [t]'
distressed_sales_t = 0
for s in self.S:
for f in self.F:
for l in self.L:
for t in self.T:
if self.model.getVarByName(f'OSs_f_l_t[{s},{f},{l},{t}]') is not None:
distressed_sales_t += self.model.getVarByName(f'OSs_f_l_t[{s},{f},{l},{t}]').Obj
return distressed_sales_t
def create_raw_material_losses_t(self):
# Compute the value for 'Raw Material Losses [t]'
raw_material_losses_t = 0
for s in self.S:
for t in self.T:
if self.model.getVarByName(f'ROs_t[{s},{t}]') is not None:
raw_material_losses_t += self.model.getVarByName(f'ROs_t[{s},{t}]').Obj
return raw_material_losses_t
def create_raw_material_purchase_t(self):
# Compute the value for 'Raw Material Purchase [t]'
raw_material_purchase_t = 0
for s in self.S:
for t in self.T:
if self.model.getVarByName(f'RSs_t[{s},{t}]') is not None:
raw_material_purchase_t += self.model.getVarByName(f'RSs_t[{s},{t}]').Obj
return raw_material_purchase_t
def create_exports_t(self):
# Compute the value for 'Exports [t]'
exports_t = 0
for f in self.F:
for t in self.T:
if self.model.getVarByName(f'Ef_t[{f},{t}]') is not None:
exports_t += self.model.getVarByName(f'Ef_t[{f},{t}]').Obj
return exports_t
def create_production_t(self):
# Compute the value for 'Production [t]'
production_t = 0
for f in self.F:
for t in self.T:
if self.model.getVarByName(f'FPf_t[{f},{t}]') is not None:
production_t += self.model.getVarByName(f'FPf_t[{f},{t}]').Obj
return production_t
def create_product_shipped_t(self):
# Compute the value for 'Product shipped to DC [t]'
product_shipped_t = 0
for f in self.F:
for l in self.L:
for t in self.T:
if self.model.getVarByName(f'DVf_l_t[{f},{l},{t}]') is not None:
product_shipped_t += self.model.getVarByName(f'DVf_l_t[{f},{l},{t}]').Obj
return product_shipped_t
def create_sales_income_mu(self):
# Compute the value for 'Sales Income [MU]'
sales_income_mu = 0
sales_income_mu = self.model.getVarByName('EXI').Obj
return sales_income_mu
def create_distressed_sales_mu(self):
# Compute the value for 'Distressed Sales of Products [MU]'
distressed_sales_mu = 0
return distressed_sales_mu
def create_raw_material_losses_cost_mu(self):
# Compute the value for 'Raw Material Losses Cost [MU]'
# Replace the following line with your computation
raw_material_losses_cost_mu = 1
return raw_material_losses_cost_mu
def create_raw_material_purchase_cost_mu(self):
# Compute the value for 'Raw Material Purchase Cost [MU]'
# Replace the following line with your computation
raw_material_purchase_cost_mu = 1
return raw_material_purchase_cost_mu
def create_exports_income_mu(self):
# Compute the value for 'Exports Income [MU]'
# Replace the following line with your computation
exports_income_mu = 1
return exports_income_mu
def create_cost_shipped_dc_mu(self):
# Compute the value for 'Cost for shipped to DC [MU]'
# Replace the following line with your computation
cost_shipped_dc_mu = 1
return cost_shipped_dc_mu
def create_setups_cost_mu(self):
# Compute the value for 'Setups Cost [MU]'
# Replace the following line with your computation
setups_cost_mu = 1
return setups_cost_mu
def create_expected_net_benefits_mu(self):
# Compute the value for 'Expected Net Benefits [MU]'
# Replace the following line with your computation
expected_net_benefits_mu = 1
return expected_net_benefits_mu
def calculate_deviation(self, value, comparison):
print(comparison)
if (comparison == int(0)) or comparison == float(0):
return 'N/A'
return f'+{round((value - comparison) / comparison * 100, 1)}%'
def PrintResults(self, table6, table8):
print('=========================================')
print('Results:')
print('Objective value: %g' % self.model.objVal)
print('table 6:')
print(table6)
print('table 8:')
print(table8)
def ComputeResultsOfTable6(self):
data = {'SP': [self.sales_t,
self.lost_sales_t,
self.distressed_sales_t,
self.raw_material_losses_t,
self.raw_material_purchase_t,
self.exports_t,
self.production_t,
self.product_shipped_t,
self.sales_income_mu,
self.distressed_sales_mu,
self.raw_material_losses_cost_mu,
self.raw_material_purchase_cost_mu,
self.exports_income_mu,
self.cost_shipped_dc_mu,
self.setups_cost_mu,
self.expected_net_benefits_mu]}
listOfResults = pd.DataFrame()
listOfResults['SP'] = data['SP']
data = {
'Metric': ['Sales [t]', 'Lost Sales [t]', 'Distressed Sales of Products [t]', 'Raw Material Losses [t]', 'Raw Material Purchase [t]', 'Exports [t]', 'Production [t]', 'Product shipped to DC [t]', 'Sales Income [MU]', 'Distressed Sales of Products [MU]', 'Raw Material Losses Cost [MU]', 'Raw Material Purchase Cost [MU]', 'Exports Income [MU]', 'Cost for shipped to DC [MU]', 'Setups Cost [MU]', 'Expected Net Benefits [MU]'],
'SP': [self.sales_t, self.lost_sales_t, self.distressed_sales_t, self.raw_material_losses_t, self.raw_material_purchase_t, self.exports_t, self.production_t, self.product_shipped_t, self.sales_income_mu, self.distressed_sales_mu, self.raw_material_losses_cost_mu, self.raw_material_purchase_cost_mu, self.exports_income_mu, self.cost_shipped_dc_mu, self.setups_cost_mu, self.expected_net_benefits_mu],
'EMVP': [self.sales_t, self.lost_sales_t, self.distressed_sales_t, self.raw_material_losses_t, self.raw_material_purchase_t, self.exports_t, self.production_t, self.product_shipped_t, self.sales_income_mu, self.distressed_sales_mu, self.raw_material_losses_cost_mu, self.raw_material_purchase_cost_mu, self.exports_income_mu, self.cost_shipped_dc_mu, self.setups_cost_mu, self.expected_net_benefits_mu],
'Deviation': [ self.calculate_deviation(self.sales_t, self.sales_t),
self.calculate_deviation(self.lost_sales_t, self.lost_sales_t),
self.calculate_deviation(self.distressed_sales_t, self.distressed_sales_t),
self.calculate_deviation(self.raw_material_losses_t, self.raw_material_losses_t),
self.calculate_deviation(self.raw_material_purchase_t, self.raw_material_purchase_t),
self.calculate_deviation(self.exports_t, self.exports_t),
self.calculate_deviation(self.production_t, self.production_t),
self.calculate_deviation(self.product_shipped_t, self.product_shipped_t),
self.calculate_deviation(self.sales_income_mu, self.sales_income_mu),
self.calculate_deviation(self.distressed_sales_mu, self.distressed_sales_mu),
self.calculate_deviation(self.raw_material_losses_cost_mu, self.raw_material_losses_cost_mu),
self.calculate_deviation(self.raw_material_purchase_cost_mu, self.raw_material_purchase_cost_mu),
self.calculate_deviation(self.exports_income_mu, self.exports_income_mu),
self.calculate_deviation(self.cost_shipped_dc_mu, self.cost_shipped_dc_mu),
self.calculate_deviation(self.setups_cost_mu, self.setups_cost_mu),
self.calculate_deviation(self.expected_net_benefits_mu, self.expected_net_benefits_mu)],
'SP-paper': self.paper_values_table6()['SP'],
'EMVP-paper': self.paper_values_table6()['EMVP'],
'Deviation-paper': self.paper_values_table6()['Deviation'],
#'diff SP paper-model': self.paper_values_table6()['SP'] - listOfResults,
#'diff EMVP paper-model': self.paper_values_table6()['EMVP'] - listOfResults,
#'deviation SP paper-model': self.calculate_deviation(listOfResults['SP'], self.paper_values_table6()['SP']),
}
df = pd.DataFrame(data)
return df
def ComputeResultsOfTable8(self):
data = {'SP': [self.sales_t,
self.lost_sales_t,
self.distressed_sales_t,
self.raw_material_losses_t,
self.raw_material_purchase_t,
self.exports_t,
self.production_t,
self.product_shipped_t,
self.sales_income_mu,
self.distressed_sales_mu,
self.raw_material_losses_cost_mu,
self.raw_material_purchase_cost_mu,
self.exports_income_mu,
self.cost_shipped_dc_mu,
self.setups_cost_mu,
self.expected_net_benefits_mu]}
listOfResults = pd.DataFrame()
listOfResults['SP'] = data['SP']
data = {
'SP-paper': self.paper_values_table8()['SP'],
'EMVP-paper': self.paper_values_table8()['EMVP'],
}
df = pd.DataFrame(data, index = self.paper_values_table8().index)
return df
def Evaluate_results(self):
table6 = self.ComputeResultsOfTable6()
table8 = self.ComputeResultsOfTable8()
self.PrintResults(table6, table8)
pass