forked from Zistack/Satisfactory-Optimizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recipe.py
366 lines (263 loc) · 7.52 KB
/
recipe.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
import commentjson
from collections import defaultdict
import utils
from corners import Corners
from machine import get_machine
from node_type import get_node_type
from item import load_finite_item_quantities
class RawRecipe:
def __init__ (
self,
pretty_name,
time,
machine,
power_consumption,
node_type = None,
well_configuration = None,
input_quantities = None,
output_quantities = None,
power_augmentation_factor = None,
):
self . pretty_name = pretty_name
self . time = time
self . machine = machine
self . power_consumption = power_consumption
self . node_type = node_type
self . well_configuration = well_configuration
self . input_quantities = input_quantities
self . output_quantities = output_quantities
self . power_augmentation_factor = power_augmentation_factor
def supports_overclocking (self):
return self . machine . supports_overclocking ()
def supports_productivity (self):
return self . machine . supports_productivity ()
def requires_somersloops (self):
return self . machine . requires_somersloops ()
def input_items (self):
return self . input_quantities . keys ()
def output_items (self):
return self . output_quantities . keys ()
def encode (
self,
constraints,
overclock_limits,
model_productivity
):
corners = Corners (
utils . name (self . pretty_name),
overclock_limits,
self . machine . supports_productivity () and model_productivity
)
corners . add_constraints (constraints)
return EncodedRecipe (self, corners)
class EncodedRecipe:
def __init__ (self, raw_recipe, corners):
self . raw_recipe = raw_recipe
self . corners = corners
def machine_count (self):
return self . corners . machine_count ()
def output_magnitude (self):
return self . corners . output_magnitude ()
def input_rate (self, item):
quantity = self . raw_recipe . input_quantities [item]
return (
self . corners . input_magnitude ()
* quantity
* 60
/ self . raw_recipe . time
)
def output_rate (self, item):
quantity = self . raw_recipe . output_quantities [item]
return (
self . corners . output_magnitude ()
* quantity
* 60
/ self . raw_recipe . time
)
def power_consumption (self):
return (
self . corners . power_magnitude (self . raw_recipe . machine)
* self . raw_recipe . power_consumption
)
def allocated_somersloops (self):
allocated_somersloops = self . corners . somersloops_slotted (
self . raw_recipe . machine
)
if self . raw_recipe . requires_somersloops ():
allocated_somersloops += (
self . corners . machine_count ()
* self . raw_recipe . machine . required_somersloops
)
return allocated_somersloops
def interpret (self, model):
interpreted_corners = self . corners . interpret_model (
model,
self . raw_recipe . machine
)
return InterpretedRecipe (self . raw_recipe, interpreted_corners)
class InterpretedRecipe:
def __init__ (self, raw_recipe, interpreted_corners):
self . raw_recipe = raw_recipe
self . interpreted_corners = interpreted_corners
def pretty_name (self):
return self . raw_recipe . pretty_name
def machine_count (self):
return self . interpreted_corners . machine_count
def output_magnitude (self):
return self . interpreted_corners . output_magnitude
def input_rate (self, item):
quantity = self . raw_recipe . input_quantities [item]
return (
self . interpreted_corners . input_magnitude
* quantity
* 60
/ self . raw_recipe . time
)
def output_rate (self, item):
quantity = self . raw_recipe . output_quantities [item]
return (
self . interpreted_corners . output_magnitude
* quantity
* 60
/ self . raw_recipe . time
)
def power_consumption (self):
return (
self . interpreted_corners . power_magnitude
* self . raw_recipe . power_consumption
)
def allocated_somersloops (self):
allocated_somersloops = self . interpreted_corners . somersloops_slotted
if self . raw_recipe . requires_somersloops ():
allocated_somersloops += (
self . interpreted_corners . machine_count
* self . raw_recipe . machine . required_somersloops
)
return allocated_somersloops
def get_report (self, precision):
if (
utils . interpret_approximate (
self . interpreted_corners . machine_count,
precision
) == 0
):
return None
interpretation = dict ()
interpretation ['machine_count'] = utils . format_value (
self . interpreted_corners . machine_count,
precision
)
interpretation ['power_consumption'] = utils . format_value (
self . interpreted_corners . power_magnitude
* self . raw_recipe . power_consumption,
precision
)
if (
utils . interpret_approximate (
self . interpreted_corners . overclock_setting,
6
) != 1
):
interpretation ['overclock_setting'] = utils . format_value (
self . interpreted_corners . overclock_setting,
6
)
if (
utils . interpret_approximate (
self . interpreted_corners . somersloops_slotted,
precision
) != 0
):
interpretation ['somersloops_slotted'] = utils . format_value (
self . interpreted_corners . somersloops_slotted,
precision
)
if self . raw_recipe . input_quantities:
interpretation ['inputs'] = dict (
(
item . pretty_name,
utils . format_value (
self . interpreted_corners . input_magnitude
* quantity
* 60
/ self . raw_recipe . time,
precision
)
)
for item, quantity
in self . raw_recipe . input_quantities . items ()
)
if self . raw_recipe . output_quantities:
interpretation ['outputs'] = dict (
(
item . pretty_name,
utils . format_value (
self . interpreted_corners . output_magnitude
* quantity
* 60
/ self . raw_recipe . time,
precision
)
)
for item, quantity
in self . raw_recipe . output_quantities . items ()
)
if self . raw_recipe . power_augmentation_factor:
interpretation [
'total_power_augmentation_factor'
] = utils . format_value (
self . interpreted_corners . machine_count
* self . raw_recipe . power_augmentation_factor,
precision
)
return interpretation
def load_node_type (recipe_data, node_types):
if 'node_type' in recipe_data:
return get_node_type (recipe_data ['node_type'], node_types)
else:
return None
def load_inputs (recipe_data, items):
if 'inputs' in recipe_data:
return load_finite_item_quantities (
recipe_data ['inputs'],
items
)
else:
return dict ()
def load_outputs (recipe_data, items):
if 'outputs' in recipe_data:
return load_finite_item_quantities (
recipe_data ['outputs'],
items
)
else:
return dict ()
def load_power_augmentation_factor (recipe_data):
if 'power_augmentation_factor' in recipe_data:
return utils . real (recipe_data ['power_augmentation_factor'])
else:
return None
def load_raw_recipe (
pretty_name,
recipe_data,
machines,
node_types,
items
):
time = utils . real (recipe_data ['time'])
machine = get_machine (recipe_data ['machine'], machines)
power_consumption = utils . real (recipe_data ['power_consumption'])
node_type = load_node_type (recipe_data, node_types)
input_quantities = load_inputs (recipe_data, items)
output_quantities = load_outputs (recipe_data, items)
power_augmentation_factor = load_power_augmentation_factor (recipe_data)
return RawRecipe (
pretty_name,
time,
machine,
power_consumption,
node_type = node_type,
input_quantities = input_quantities,
output_quantities = output_quantities,
power_augmentation_factor = power_augmentation_factor
)